Friends,
With the below code, if I call the function twice it returns same values. But it should return different values.
function GeraChave(tipo: string; tamanho:integer):string; {$ifndef linux} stdcall; {$else} cdecl; {$endif} export;
var
i:integer;
chave:string='';
sort:string;
begin
if (tamanho>=10) and (tamanho<=30)
then begin end
else begin
randomize;
tamanho:=random(21)+10;
end;
case AnsiIndexStr(LowerCase(tipo),['bin','oct','dec','duo','hex','afncs','afnci']) of
0: sort:='01';
1: sort:='012345678';
2: sort:='0123456789';
3: sort:='0123456789AB';
4: sort:='0123456789ABCDEF';
5: sort:='1234567890NOPQRSTUVWXYZabcdefghijklmn01234567891234567890opqrstuvwxyzABCDEFGHIJKLM0123456789';
else sort:='0123456789abcdefghijklmnopqrstuvwxyz1234567890';
end;
randomize;
for i:=1 to tamanho do begin
chave:=chave+sort[random(length(sort))+1];
end;
result:=chave;
end;Gera=Make, Chave=Key, Tipo=Type, Tamanho=Length.
For example:
GeraChave('bin',10); It twice should return different values, but not.
GeraChave('bin',random(10));
GeraChave('oct',random(10)); That way, returns different values, but always with same length. The length should be random.
How to solve this problem? what I did wrong?
Sorry by my poor English.
Tanks.