Name
Randomize Procedure
Syntax
procedure Randomize;
Description
Call Randomize
once at the start of a program to
start the sequence of pseudorandom numbers at a different number each
time you run the program. Randomize sets the
RandSeed variable to a value based on the time of
day. Randomize is a real procedure.
Tips and Tricks
When testing a program, do not call
Randomize. That way, you will get the same sequence of pseudorandom numbers every time you run the program, and you can compare results between runs. After testing, add the call toRandomizeso that each time the program runs, it starts the sequence of pseudorandom numbers differently.Do not call
Randomizemore than once in the same program. Doing so destroys the randomness of the pseudorandom numbers.Randomizeuses the time of day to initializeRandSeed. If the program runs at the same time every day, you should find a different way to initializeRandSeed.
Example
unit RandomDice;
interface
...
function Die: TDieRoll;
function Dice: TDiceRoll;
implementation
...
initialization
Randomize;
end.See Also
| Random Function, RandSeed Variable |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access