Home page
or browse popular tags
Access Functions

Sign up for the free email newsletter for new tips, tutorials and more. Enter your email address below, and then click the button.

Privacy Policy

RSS Twitter

Access: Rnd Function


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.


Int((7-1 +1) * Rnd + 1)              returns a random value between 1 and 6.
Int((30-20 +1) * Rnd + 20)           returns a random value between 20 and 30.

VBA Code

Dim MyNumber
MyNumber = Int((6-1+1)*Rnd +1) 

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.

SELECT Int((10-1+1)*Rnd()+1) AS Expr1
FROM Orders

If you'd like to see how it works, enter SQL statement and press Execute


Add To: Add to dzone dzone | Digg this digg | Add to del.icio.us del.icio.us | Stumble it stumbleupon

  • Comments

Copyright © 2005-2023             www.WebCheatSheet.com All Rights Reserved.