randomfrom函数使用(15分)

  • 主题发起人 主题发起人 small pig
  • 开始时间 开始时间
S

small pig

Unregistered / Unconfirmed
GUEST, unregistred user!
edit1.text:= inttostr(random([1,2,3,5]));

为什么编译不过?
 
random函数不能这么用吧?

Delphi syntax:

function Random [ ( Range: Integer) ];

Description

In Delphi code, Random returns a random number within the range 0 <= X < Range. If Range is not specified, the result is a real-type random number within the range

0 <= X < 1.

To initialize the random number generator, add a single call Randomize or assign a value to the RandSeed variable before making any calls to Random.
 
补充:
random丢了from,应该为randomfrom
edit1.text:= inttostr(randomfrom([1,2,3,5]));

为什么编译不过?
 
var

I: Integer;
begin
Randomize;
for I := 1 to 50 do begin
{ Write to window at random locations }
Canvas.TextOut(Random(Width), Random(Height), 'Boo!');
end;
end;
 
randomfrom应该在MathStrUtils单元,不过我机器没有这个单元,编译不了,看了一下帮助应该是这样写吧。你试试
var
int:array[0..4] of integer;
begin
int[0]:=1;
int[1]:=2;
int[3]:=3;
int[4]:=5;
edit1.Text:=inttostr(randomfrom(int));
end;
 
接受答案了.
 
后退
顶部