PythonGreg
Messages postés68Date d'inscriptionjeudi 3 novembre 2011StatutMembreDernière intervention 6 février 2015
-
16 juin 2012 à 08:06
PythonGreg
Messages postés68Date d'inscriptionjeudi 3 novembre 2011StatutMembreDernière intervention 6 février 2015
-
17 juin 2012 à 01:55
Bonjour est t'il posible de générer plusieur série de chaine aléatoire sans passé par un TTimer
voici la function que j'utilise :
Function KeyRandom : String ;
const
ChAlpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
begin
Randomize;
repeat
Result := Result + ChAlpha[Random(Length(ChAlpha)) + 1];
until Length(Result) = 4; // Longueur de la clé
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Memo1.Lines.Add ( KeyRandom + '-' + KeyRandom + '-' + KeyRandom + '-' + KeyRandom );
end;
end.
Cirec
Messages postés3833Date d'inscriptionvendredi 23 juillet 2004StatutModérateurDernière intervention18 septembre 202250 16 juin 2012 à 18:41
Salut,
...
implementation
uses Math; // pour RandomRange
{$R *.dfm}
// fonction générant une chaine aléatoire
// de longueur aLen.
function KeyRandom(const aLen: Integer): string;
begin
Result := EmptyStr;
if aLen < 1 then
Exit;
repeat
Result := Result + Chr(RandomRange(Ord('A'), Ord('Z') + 1));
until Length(Result) = aLen;
end;
// Génération et affichage du résultat
procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption := KeyRandom(4) + '-' + KeyRandom(4) + '-' + KeyRandom(4) + '-' + KeyRandom(4);
end;
// le Randomize ne s'appelle qu'une seule fois
// c'est pourquoi on le met dans le OnCreate de la fiche
procedure TForm1.FormCreate(Sender: TObject);
begin
Randomize;
end;
end.