PDA

View Full Version : How does Rnd() work? (WXP-Pro)



jdharm
03-15-2006, 08:04 PM
A purely academic exercise, but one that might clarify my image of how a computer thinks.

I know that Rnd() generates a 7 digit decimal between 0 and 1. I wrote a script that used the command "Randomize" with no modifier, generated a random number, then evaluated it and looped back to "Randomize", counting the incidence of random numbers generated between 0 and .1, .1 and .2, .2 and .3, etc. along the way. The distribution is pretty close to flat when run 5000 times and gets even flatter with each order of magnitude in the cycle count.

Shouldn't I see a bell curve somewhere in here? What is it about the generation process that makes the distribution flat and not biased to a median?

Josh
<a target="_blank" href=http://www.jdharm.com>www.jdharm.com</a>

Brf
03-16-2006, 04:59 AM
It uses some some of computation....

I have made my own random number generators in the past by using the computer milliseconds as a "seed" and then multiplying by a large number with like 7 places before and after the decimal place.... and then taking the decimal part as my random number. That random number then becomes the seed to the next.

This simple computation gives a pretty good flat distribution. The Rnd() uses the same sort of computation, but it involves more than a single multiply.