The Rnd function returns a value less than 1 but greater than or equal to 0. The value of number determines how Rnd generates random numbers.
Rnd function
describe
Returns a random number.
grammar
Rnd[(number)]
The number parameter can be any valid numeric expression.
illustrate
The Rnd function returns a value less than 1 but greater than or equal to 0. The value of number determines how Rnd generates random numbers:
If number is generated by Rnd
A value less than zero that is the same every time, using number as the seed.
The next random number in the sequence greater than zero.
The most recently generated number equal to zero.
Omit the next random number in the sequence.
Because each successive call to the Rnd function uses the previous number in the sequence as the seed for the next number, the same sequence of numbers will be generated for any initially given seed.
Before calling Rnd, use the parameterless Randomize statement to initialize a random number generator with a system timer-based seed.
To generate a specified range of random integers, use the following formula:
Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
Here, upperbound is the upper bound of this range and lowerbound is the lower bound of this range.
-------------------------------------------------- ----------------------------------
Note To repeat a sequence of random numbers, call Rnd with a negative argument immediately before calling Randomize with a numeric argument. Randomize using the same number value cannot repeat the previous random number sequence.
----------------------------------
Example:
We usually use now() as the seed, so that we can get a more perfect random sequence. If we need a random number between 1-100
Randomize()
n=Int((100-1+1)*Rnd(now())+1)