# How exactly does the random number generator work?

Printable View

• 08-23-2007
Finchie_88
How exactly does the random number generator work?
I was wondering. How exactly are random numbers generated, and by that I don't mean the method of seeding the random number generator etc, I mean "under the hood" as it were (I dislike that phrase with a passion, but its the only phrase which came to mind). Also, exactly how random are these supposedly random numbers?
• 08-23-2007
hk_mp5kpdw
• 08-23-2007
ArseNiC
Well it works like any function I believe, although the rand() function may be more complex, a simple approach is, you can make a function called MyRand(47); and then you use a series of equations, and then you get some different number, but you have to use the initial number in the formula multiple times. The result will seem random, but it's not. So every time you type 47, you'll get maybe 535, but of course that wouldn't always work out. So how can it be random? Well you base the initial number on time, so its almost always random.

MyRand(time()); time() being a function that grabs the current time. GetTickCount() in win32 would work too.

However, remember rand() itself is probably a lot more complex resulting in more random numbers.

The reason for all this? Random doesn't exist that's why. Everything in nature and the world, is based on cause and effect. Just like programming functions. Hence IMO the human brain itself can also be a big C++ program if someone had the time to create such a complex and time consuming program.

If you don't believe me, well, think about how you define random? A dice roll? Well dice gives you a random number but it actually gives you the number that appears after the amount of force you used to throw the dice and the surface area and other conditions causes the dice to roll and tumble into a certain position, which can probably be calculated, but of course, its not random.
• 08-24-2007
laserlight
I suggest reading Prelude's Random Numbers and Using rand() articles. If you are interested in something less deterministic than pseudorandom number generation algorithms, then take a look at HotBits.

Quote:

If you don't believe me, well, think about how you define random? A dice roll?
That would be a rather poor definition since it defines a property in terms of a specific example. One cannot conclude that the alleged property does not exist because it can be explained away in the specific example.
• 08-24-2007
ArseNiC
Quote:

Originally Posted by laserlight
That would be a rather poor definition since it defines a property in terms of a specific example. One cannot conclude that the alleged property does not exist because it can be explained away in the specific example.

Science is observation not the absence of observation being the proof.
Therefore, unless you can prove to me random exists, mathematically or whatever, then tell me :P. (And if it is I apologize, my Math is not that great).

So a dice would be a way some describe a random number. Or perhaps the thing that picks the lottery numbers, which also isn't random, just depends on the physics of the air and balls pumped inside etc.

I dont know how else you can describe a random number in nature.
• 08-24-2007
laserlight
Quote:

Science is observation not the absence of observation being the proof.
Therefore, unless you can prove to me random exists, mathematically or whatever, then tell me :P. (And if it is I apologize, my Math is not that great).
One can define randomness as a statistical property, in which case it clearly exists because it has been observed in nature and in our pseudorandom number algorithms. One could also define it as some objective inherent unpredictability, in which case physics provides a possible example as exploited by HotBits.

Quote:

So a dice would be a way some describe a random number. Or perhaps the thing that picks the lottery numbers, which also isn't random, just depends on the physics of the air and balls pumped inside etc.

I dont know how else you can describe a random number in nature.
Describing the effect of a property and defining a property are two different things. I do not object to using dice as an example to describe randomness, and then pointing out that it is not really random, though humans often perceive it as such. In practice though, it is "random", since for its purpose the outcome of the roll of a fair die is unpredictable.
• 08-24-2007
whiteflags
> Science is observation not the absence of observation being the proof.

Observation alone should be able to tell you that there is randomness in nature. Just experiment: try to sort a deck into ordered suit piles several times, or roll six sixes several times in a row. The results are probabalistic, not deterministic, and pretty much up to chance. If the results were deterministic they would not be random.

Hopefully that explains why cheating at the game is not random.

What makes PRNGs so non-random is how the results are computed, but that's not natural. And even then they fake it pretty nicely.