Randomize

From Delphi Pascal wiki
Jump to navigation Jump to search

Initializes the built-in random number generator with a random value (obtained from the system clock).

Declaration
procedure Randomize;
Target
Windows, Real, Protected
Remarks
If Range is not specified, the result is a Real-type random number within the range 0 <= X < 1. If Range is specified, it must be an expression of type Word, and the result is a Word-type random number within the range 0 <= X < Range. If Range equals 0, a value of 0 is returned.
The random number generator should be initialized by making a call to Randomize, or by assigning a value to RandSeed.
See Also
Random


Sample Code

{Random.PAS}
{Sample code for the Random function and Randomize procedure.}

{ For Windows: }
{ uses WinCrt; }

uses Crt;
begin
  Randomize;
  repeat
    { Write random numbers }
    Writeln (Random(1000));
  until KeyPressed;
end.