var RandSeed : LongInt;
Description
The RandSeed variable is used in conjunction with the Random function. It changes the seed used that Delphi uses to generate its range of 232 pseudo random numbers.
Related commands
Random Generate a random floating point or integer number
Randomize Reposition the Random number generator next value
RandomRange Generate a random integer number within a supplied range
Example code : Run this code twice to see the effect of RandSeed
var
int : Integer;
i : Integer;
hours, mins, secs, milliSecs : Word;
begin
// Get random numbers using the default random seed value
ShowMessage('Fixed first 5 random numbers');
for i := 1 to 5 do
begin
int := 1 + Random(100); // The 100 value gives a range 0..99
ShowMessage('int = '+IntToStr(int));
end;
// Now change the random seed to the milliseconds value
// of the current time
DecodeTime(now, hours, mins, secs, milliSecs);
ShowMessage('');
ShowMessage('Setting randSeed to value : '+IntToStr(milliSecs));
ShowMessage('');
RandSeed := milliSecs;
// Get an integer random number in the range 1..100
ShowMessage('Random next 5 numbers');
for i := 1 to 5 do
begin
int := 1 + Random(100); // The 100 value gives a range 0..99
ShowMessage('int = '+IntToStr(int));
end;
end;
Show full unit code
Fixed first 5 random numbers
int = 1
int = 4
int = 87
int = 21
int = 28
Setting random seed to value : 660
Random next 5 numbers
int = 72
int = 62
int = 28
int = 63
int = 44