In Access, the Rnd function returns a single containing a random number. You can specify the random number to be a value between 2 user-specified numbers.
The syntax for the Rnd function is:
Rnd ( number )
The argument number can be any valid numeric expression. The Rnd function returns a value less than 1 but greater than or equal to zero. To produce random integers in a given range, use this formula:
Int((upperbound – lowerbound + 1) * Rnd + lowerbound)
Here, upperbound is the highest number in the range, and lowerbound is the lowest number in the range.
Example
|
VBA Code
|
This example uses the Rnd function to generate a random integer from 1 to 6. Now the MyNumber variable would contain this value.
SQL query
You can also use the Rnd function in a query.
|