Random Number not so random

  • Thread starter Thread starter Rockn
  • Start date Start date
R

Rockn

I am trying to create a random Job number when my form loads using the
onLoad event to process this:

Me.Textfield = Format(Date, "mmddyyyy") & "" & Int((99 - 1 + 1) * Rnd() + 1)

Which will create a job number like 08212007** with the last two numbers
being "random". The numbers are created fine, but ALWAYS the same numbers
are generated on the initial load and subsequent loads of the form as
follows:

0821200770
0821200753
0821200758
0821200729
0821200730

and so on. I guess it really isn't a random number function in it's truest
sense.
 
You need to call the Randomize statement before using the Rnd function to
reset the seed value.
 
Hi Rock,
Yes, Doug had pointed you in the right direction. I just would like to add
additional information here for clarifying the cause more clearly.
The root cause of this issue is that for any given initial seed, the same
number sequence is generated because each successive call to the Rnd
function uses the previous number as a seed for the next number in the
sequence.

The Randomize statement without an argument is necessary here, since it
will initialize the random-number generator with a seed based on the system
timer.

You may also refer to the following articles:
Rnd Function
http://office.microsoft.com/en-us/access/HA012289011033.aspx

ACC2000: How to Fill a Table with Random Records from Another Table
http://support.microsoft.com/kb/210616/en-us

Please feel free to let us know if you have any other questions or
concerns.
Have a nice day!

Sincerely,
Charles Wang
Microsoft Online Community Support
=====================================================
When responding to posts, please "Reply to Group" via
your newsreader so that others may learn and benefit
from this issue.
======================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
======================================================
 
Back
Top