Creating a Random Number

Zippyfrog

Registered User.
Local time
Today, 16:31
Joined
Jun 24, 2003
Messages
103
Quick question, how do I have access generate a random number between 1 and 8? I want it to generate either a 1,2,3,4,5,6,7, or 8. (no zero, no nine)

Expr1: Fix(Rnd(8-1)*10*Rnd()) is what I have been using, but this always generates the number 2? I do want the decimals to be rounded to the nearest integer, thus I have Fix.

If someone could please help me, it would be greatly appreciated! Thanks in advance.
 
Rnd F1:

To produce random integers in a given range, use this formula:

Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
 
Searching VBA help:
Dim MyValue
Randomize ' Initialize random-number generator.

MyValue = Int((6 * Rnd) + 1) ' Generate random value between 1 and 6.



I use:
Dim lNo as Long
Randomize ' Initialize random-number generator.
lNo = Int(8 * Rnd + 1)

Dave
 
Thanks for that help. I am just beginning to learn VB and I worked with that Random formula a while ago, but just couldn't get the right setup.

One more question: when I use the random number formula on my query, it gives the same random number to every record in the query. Is there a way to make it so that the random number is random for each record in the query?
 

Users who are viewing this thread

Back
Top Bottom