Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Random is the RND Function?

Status
Not open for further replies.

cyork

MIS
Apr 4, 2001
34
CA
Hi

I am currently using the RND function to add a random number to each record in a table in order to sort them randomly.

I have read on discussion boards that the RND function is not truly random and many people seem to have had problems with it.

3 Questions:

- Does anyone know what this function does to come-up with the random number?

- Are there any other functions that I can use?

- Excel has an analysis add-in which has a random number generator with several options - can I get this for Access? or can I somehow call this function from within Access?

Thanks,

Chris
 
While I don't have my documentation in front of me at the moment, and I'm not POSITIVE this will work in VBA, I know that it works in VBScript, so my guess would be that it works in VBA, too...

just precede the statement where you are generating the random number with 'Randomize'

The very next line should be the statment where you use Rnd

The way that random number generators work is that they are "seeded" with a number, and that number is fed into the algorithm... so if it's fed the same number each time, it will come up with the same "random" number each time. I think that the "Randomize" statement gets a value that is somehow based on the time of day or how many seconds have passed since some predetermined arbitrary date or some other like method in order to make it more random...

If the "Randomize" line doesn't work for you, then look into the documentation on how to seed the sequence (I'm sure it's in there somewhere), and then seed it with the time of day in seconds or something like that --

The key is to have a different seed if you want a different number.

good luck! :)
Paul Prewett
 
randomizing based on time
this should provide a number random enough ;-)

Randomize Right(Time$, 2) & Left(Right(Time$, 5), 2) & Left(Time$, 2)


 
Chris, If you're using 2000 have you checked out the GUID (globally unique identifier)? It is such a weird number and supposed to be globally unique. If you don't try checking over at MS where I'm sure you'll find a description of how they do it: Something like the machine + the date + the country + Bill's current net worth... :) Gord
ghubbell@total.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top