Re: Random number generator
[ Related Articles and Replies ] [ Delphi FAQ ]
Posted by webmaster Guido:
In Reply to: Random number generator posted by BeckyR:
: I want to generate random numbers but I need to set the range to start at 1000000000 instead of 0.
Is there a way the starting number can be set? -------
The function Random(RANGE) returns an integer number X with 0 <= X < RANGE.
RANGE must be an integer, so you are limited to the largest integer that is possible in Win32 Delphi.
That's 2147483648 (a bit over 2000 million).
Example: Random(50) can return 0 or 12 or 49 and so on (but not 50).
If RANGE is not specified, the result is a real number in the range 0 <= X < 1.
Example: To get a random integer in the range from 1 to 1000 you use:
R := Random(1000) + 1;
To get a random integer in the range from 1000000000 to 1000001000 you use:
R := Random(1000) + 1000000000;
Delphi FAQ
|