Random Number

kimmer6160

New member
Local time
Today, 09:41
Joined
Aug 12, 2002
Messages
9
I need to create a random number field. I want the number to be 6 digits and it can be duplicated. Is this possible to create and if so, how do I do it?
 
Look in the Help files for the topic "Random" - which will lead you to the Randomize and Rnd function calls.

Here are the wrinkles you face.

The random-number function has to be initialized. Once it has been initialized, you can generate random numbers by calling the function with no arguments. It will give you a single-precision number (type Single) normalized in the range [0-1) where in this case, the range DOES NOT include the high end. I.e. you will never actually get 1.0 as a number though you might get 0.0 as a number. Subsequent calls will give you new random values.

The discussion in the Rnd topic describes how to get an integer in a given range. You can get 6 digits out of Rnd, but don't ask for a 7 digit result. Singles don't make it out to that far reliably.

Now if you want a "true" random sequence, you must randomize it first. So making a table for which a field's default value is set to be "=Rnd()" won't REALLY give you a random number. Each time you call Rnd in that context, you might get the SAME random number. Ditto if you use a query to populate the field. You can no more call randomize from a query than you could from the default value associated with a table.

The only way to produce a "truly" random number is to use VBA code that issues a "randomize" statement then steps through the recordset for that table, updating the selected field at will. Any other time, you can't get to the randomize statement reliably.
 

Users who are viewing this thread

Back
Top Bottom