Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Go Back   Foros Club Delphi > Principal > OOP
Register FAQ Members List Calendar Guía de estilo Today's Posts

Coloboración Paypal con ClubDelphi

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07/06/2010
Aprendiendo Aprendiendo is offline
Miembro
 
Join Date: May 2003
Location: España
Posts: 122
Poder: 24
Aprendiendo Va por buen camino
Question numeración alfanumérica y aleatoria

Hola a tod@s,

Necesitaría una función la cual me devolviera una numeración alfanumérica pero aleatoria.

Esperando una pronta respuesta, reciban un cordial saludo...
Reply With Quote
  #2  
Old 07/06/2010
Casimiro Noteví's Avatar
Casimiro Noteví Casimiro Noteví is offline
Merodeador
 
Join Date: Sep 2004
Location: En algún lugar.
Posts: 32,702
Poder: 10
Casimiro Noteví Tiene un aura espectacularCasimiro Noteví Tiene un aura espectacular
Si es aleatoria entonces será una cadena de texto, no?

Código Delphi [-]
function DameClave( iLongitud:integer; iTipo:integer=1 ) : string;
const
  cValoresNum      = '0123456789';
  cValoresAlpha    = 'abcdefghijklmnopqrstuvwxyz';
  cValoresAlphaNum = cValoresNum + cValoresAlpha;
var
  iX : integer;
begin
  Result := '';
  //
  Randomize;  
  //
  case iTipo of
    0 : for iX := 1 to iLongitud do
          Result := Result + cValoresNum[ Random(length(cValoresNum))+1 ];
    1 : for iX := 1 to iLongitud do
          Result := Result + cValoresAlpha[ Random(length(cValoresAlpha))+1 ];
    2 : for iX := 1 to iLongitud do
          Result := Result + cValoresAlphaNum[ Random(length(cValoresAlphaNum))+1 ];
  end;
end;

Y para llamarla está claro, le dices la longitud y el tipo.
Reply With Quote
  #3  
Old 07/06/2010
Aprendiendo Aprendiendo is offline
Miembro
 
Join Date: May 2003
Location: España
Posts: 122
Poder: 24
Aprendiendo Va por buen camino
Thumbs up

Gracias por tu pronta respuesta,

Voy a probar y te comento.

Un saludo...
Reply With Quote
  #4  
Old 09/06/2010
Aprendiendo Aprendiendo is offline
Miembro
 
Join Date: May 2003
Location: España
Posts: 122
Poder: 24
Aprendiendo Va por buen camino
Thumbs up

Probé la función y funciona perfectamente.

Gracias por tu aportación.
Reply With Quote
  #5  
Old 17/08/2011
Antoniov's Avatar
Antoniov Antoniov is offline
Miembro
NULL
 
Join Date: Aug 2011
Location: Tenerife
Posts: 42
Poder: 0
Antoniov Va por buen camino
Cadena Aleatoria

Para generar una clave de forma aleatoria podemos usar esta esta función sencilla

Para hacerla algo más interesante, he puesto distintas probabilidades para mayúsculas, minúsculas y números.

Código Delphi [-]
function CadenaAleatoria (Largo:integer):string;
var i:integer;
begin
  randomize;
  result := '';
  for i := 0 to largo-1 do
    begin
    case Random (7) of
      0:       result := result + Chr (ord ('0')+ random (1 + ord('9')-ord('0')) );
      1,2:     result := result + Chr (ord ('A')+ random (1 + ord('Z')-ord('A')) );
      3,4,5,6: result := result + Chr (ord ('a')+ random (1 + ord('z')-ord('a')) );
    end;
    end;
end;
Reply With Quote
  #6  
Old 06/09/2011
juanlaplata's Avatar
juanlaplata juanlaplata is offline
Miembro
 
Join Date: Jan 2007
Location: La Plata, Bs. As. (Argentina)
Posts: 212
Poder: 20
juanlaplata Va por buen camino
exelentes aportes, me sirvieron mucho.
Gracias
Reply With Quote
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reproduccion aleatoria con un listbox mattgaviota Varios 6 02/07/2008 10:06
cleanScreen,letra aleatoria yessika19 Varios 13 04/11/2007 22:14
Imagen aleatoria en Fastreport jegrebahe1 Impresión 0 10/06/2007 01:04
crear una llave alfanumerica con un generador reina SQL 3 17/08/2005 19:49
Extraer números en una string alfanumérica Tonio Varios 4 23/10/2003 10:22


All times are GMT +2. The time now is 12:35.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi