procedure TForm1.Button1Click(Sender: TObject);
Const ASting='0123456789ABCDEF' ;
Num = 18 ;
Var i,RandomNum : Integer ;
begin
Randomize ;
Label1.Caption := '' ;
i := 0 ;
Repeat
RandomNum := Round(Random*17) ;
If (RandomNum>0) And (RandomNum<=16) Then Begin
Label1.Caption := Label1.Caption+ASting[RandomNum] ;
i := i+1 ;
End ;
Until (i=Num)
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i,n:byte;
str:string[18];
begin
Randomize;
i:=0;
str:='';
while i<=18 do begin
n:=Random(70)+1;
if n in [48..57,65..70] then
begin
str:=str+char;
inc(i);
end;
end;
showmessage(str);
end;
需要在程序开始的时候执行一次Randomize,只需要在程序开始的时候执行一次,不要放到其他地方被多次执行:
代码:
var
str:string;
begin
str:=IntToHex(Random($1000000),6);
str:=str+IntToHex(Random($1000000),6);
str:=str+IntToHex(Random($1000000),6);
ShowMessage(str);
end;