Random Rdn() Funtion Help Please

graviz

Registered User.
Local time
Today, 17:55
Joined
Aug 4, 2009
Messages
167
I have a query of a bunch of records and I'm trying to assign a random number to each one. The issue is when the data pulls, it's giving the same number to each record. My expression is below:

Random: Int((999-100+1)*Rnd()+100)

I've also tried just Rnd() and it also doesn't work.

Any idea what I'm doing wrong
 
I have a query of a bunch of records and I'm trying to assign a random number to each one. The issue is when the data pulls, it's giving the same number to each record. My expression is below: Int((999-100+1)*Rnd()+100)

Access Help has the following:
Before calling Rnd, use the Randomize statement without an argument to initialize the random-number generator with a seed based on the system timer.

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

Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
 
Access Help has the following:

What does the Randomize statement mean? I tried the expression you pasted as you can see in my first post.
 
Seems pretty clear when I just read the randomize statement in help, even has a simple example.

Brian
 
You mean what I did in my original post?
 
Did you use the Randomize function?
If not have you read about it.

Brian
 
Isn't that what I did in my original post? If not please explain what it is.
 
You have used the Rnd() function, as indicated in the quote by Steve there is a Randomize function that is used to initialize randomisation, look it up in help.

Brian
 
If you look in the VBA Help -
From the VBA Help File said:
Randomize Statement


Initializes the random-number generator.

Syntax

Randomize [number]

The optional number argument is a Variant or any valid numeric expression.

Remarks

Randomize uses number to initialize the Rnd function's random-number generator, giving it a new seed value. If you omit number, the value returned by the system timer is used as the new seed value.

If Randomize is not used, the Rnd function (with no arguments) uses the same number as a seed the first time it is called, and thereafter uses the last generated number as a seed value.

Note To repeat sequences of random numbers, call Rnd with a negative argument immediately before using Randomize with a numeric argument. Using Randomize with the same value for number does not repeat the previous sequence.
 
They're telling you to hit F1 while looking at your code and search for Rnd() or Randomize.
 
Thanks for the help everyone. It works perfectly now. I apologize that I was completely missing it.
 

Users who are viewing this thread

Back
Top Bottom