Home
 ASP
 PHP
 SQL
 HTML
 JavaScript
 Search
 Contact
Search
or browse popular tags
Subscription

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

# 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.

#### Example

 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

Tags:

Add To: dzone | digg | del.icio.us | stumbleupon

• Comments

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