Looking for a good random number generator

Thread: Looking for a good random number generator

1. Junior Member
Join Date
Dec 1969
Posts
3

Looking for a good random number generator

I have been looking for bout a couple of weeks. I need a random number generator that is actually pretty random not just the rnd command. I am simulating a dice roll, so it&#039;s pretty important that the numbers be as random as i can get.

2. ks
Senior Member
Join Date
Dec 1969
Posts
734

Rnd is not random?

Try this MSDN example<BR><BR>Randomize<BR>a = Int(6 * Rnd + 1)<BR><BR>or<BR>a = (Timer Mod 6) + 1

3. Senior Member
Join Date
Dec 1969
Posts
96,118

No, it is not...

...it fails most tests of randomness.<BR><BR>Especially those for sequence and grouping, which tend to be pretty important when you are doing things like playing dice.<BR><BR>If you care, look up random numbers in Donald Knuth&#039;s classic 3 books on computer science..."The Art of Computer Programming". [And note that he indeed calls it an "Art" instead of a "Science"!]<BR><BR>You *can* pull some cute tricks, though, to improve the performance of RND. <BR><BR>For example, instead of just using MOD to convert an RND result to a range, consider doing bit masks and shifting and then MOD.<BR><BR>Or consider getting a count via RND and then throwing away that count of RND numbers before taking the next one.<BR><BR>Or or or...<BR><BR>But, really, a *good* random number generator is very tough to do. I did one in...ummm...1977, I think, that took me 3 days of poring over Knuth&#039;s book and then a week or more of writing test cases to be sure I was getting results random enough to pass Knuth&#039;s requirements. And I *barely* squeaked through. This was in assembly language, using decimal arithmetic, of all things.<BR><BR><BR><BR>

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•