Random Rdn() Funtion Help Please (1 Viewer)

graviz

Registered User.
Local time
Yesterday, 23:34
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
 

Steve R.

Retired
Local time
Today, 01:34
Joined
Jul 5, 2006
Messages
4,705
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)
 

graviz

Registered User.
Local time
Yesterday, 23:34
Joined
Aug 4, 2009
Messages
167
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.
 

Brianwarnock

Retired
Local time
Today, 06:34
Joined
Jun 2, 2003
Messages
12,701
Seems pretty clear when I just read the randomize statement in help, even has a simple example.

Brian
 

graviz

Registered User.
Local time
Yesterday, 23:34
Joined
Aug 4, 2009
Messages
167
You mean what I did in my original post?
 

Brianwarnock

Retired
Local time
Today, 06:34
Joined
Jun 2, 2003
Messages
12,701
Did you use the Randomize function?
If not have you read about it.

Brian
 

graviz

Registered User.
Local time
Yesterday, 23:34
Joined
Aug 4, 2009
Messages
167
Isn't that what I did in my original post? If not please explain what it is.
 

Brianwarnock

Retired
Local time
Today, 06:34
Joined
Jun 2, 2003
Messages
12,701
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
 

boblarson

Smeghead
Local time
Yesterday, 22:34
Joined
Jan 12, 2001
Messages
32,059
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.
 

ASherbuck

Registered User.
Local time
Yesterday, 22:34
Joined
Feb 25, 2008
Messages
194
They're telling you to hit F1 while looking at your code and search for Rnd() or Randomize.
 

graviz

Registered User.
Local time
Yesterday, 23:34
Joined
Aug 4, 2009
Messages
167
Thanks for the help everyone. It works perfectly now. I apologize that I was completely missing it.
 

Users who are viewing this thread

Top Bottom