delphi中有没有随机函数,有的话是什么?

解决方案 »

  1.   

    Randomize;
      i := Random(256);
      

  2.   

    function Random [ ( Range: Integer) ];
      

  3.   

    Delphi syntax:function Random [ ( Range: Integer) ];
      

  4.   

    慢慢看吧:Delphi syntax:function Random [ ( Range: Integer) ];DescriptionIn 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 range0 <= 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.Note: Because the implementation of the Random function may change between compiler versions, we do not recommend using Random for encryption or other purposes that require reproducible sequences of pseudo-random numbers.这是一个例子:
    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;
      

  5.   

    function Random [ ( Range: Integer) ];不过不是真正意义上的“随机”,我发现每次应用程序取数据的顺序是一样的。
    例如
    random(20) 第一次总是取到0 以下依次是0,18,9,1,19,1,.....只是举个例子,在你的机器上不一定是这个数,但两次运行应用程序取数的顺序绝对相同,我很头疼这个问题。
      

  6.   

    在使用random前必须使用randommize 这样才能使每次都是随机的数。否则的话就会第一次随机,以后的都和第一次一样!