怎样实现随机数的产生?

解决方案 »

  1.   

    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;
      

  2.   

    function Random [ ( Range: Integer) ];DescriptionRandom 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.
      

  3.   

    jinjazz(人雅的标记--落寞刺客) :同意,不矢为一种很好的方法
      

  4.   

    a :real;
    a :=0;
    a :=random(10.0) //随机数的取值范围
      

  5.   

    a :real;
    a :=0;
    a :=random(10) //随机数的取值范围
      

  6.   

    //看看这个算法如何?
    const
     multiplier=1194211693;
     adder=12345;
    var
    randseed:Integer;
    function MyRandom(n:Integer):Integer;
    begin
         randseed:=multiplier*randseed+adder;
         Result:=(randseed shr 16) mod n;
    end;procedure TForm1.FormCreate(Sender: TObject);
    var
         hh,mm,ss,ms:WORD;
    begin
         DecodeTime(Time,hh,mm,ss,ms);
         randseed:=ms;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
         ShowMessage(IntToStr(MyRandom(1000)));
    end;
      

  7.   

    Randomize;
    random(number);
    number是随机数的范围0-number之间