我想得到一组8位的随机函数,我是这样写的:
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text := InttoStr(Random(11111111));
end;
可是当我第一次按Button的时候Edit中却显示的为0,第二次以后就正常了。请问各位大虾为什么?
(在线等)
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text := InttoStr(Random(11111111));
end;
可是当我第一次按Button的时候Edit中却显示的为0,第二次以后就正常了。请问各位大虾为什么?
(在线等)
begin
Randomize;
Edit1.Text := InttoStr(Random(11111111));
end;// 是不是这个问题?
begin
Randomize
Edit1.Text := InttoStr(Random(11111111));
end;
var
a:integer;
begin
randomize;
a:=round(Random*100000000);
Edit1.Text := inttostr(a);
edit2.text:=inttostr(length(Edit1.Text));
end;
这个表示 播下随机种子
system.pas这样的代码
procedure Randomize;
{$IFDEF LINUX}
begin
RandSeed := _time(nil);
end;相当于 srand( (unsigned)time( NULL ) );表示以当前时间为时间种子,做为随机数<伪随机数>发生器的种子,如果你不种下种子的话 你后面每次得到的随机数都为同一个数.
Counter: Int64;
begin
if QueryPerformanceCounter(Counter) then
RandSeed := Counter
else
RandSeed := GetTickCount;
end;