Re: Math.Random question
Posted: Tue Feb 05, 2013 6:07 pm
Robin's explanation was better than my own, but I'll expand upon it. The idea of something being "random" means that it's suitably unpredictable. But, there are certain probabilistic properties that come out of looking at a lot of numbers that came out of the random number generator.
Lets try this list: 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1.
Is that random? Well, you can say it is random, because it's unpredictable where the 3s and 2s appear, but since the 1s appear so common, it's unsuitable. We call this "Biased" or "Weighted." So, for a proper random number generator to be usable, it needs to not be biased, meaning that all numbers have the same chance of showing up as any other.
Now, lets try this: -4 4 1 3 -5 -5 -5 -5 5 -3 5 4 -5 -4 2 4 5 4 2 -1
If you add those all together, you get 2, meaning that you didn't travel very far from the start. So, here's the core problem: You're misunderstanding what random really is. If you keep doing random events over and over and over, they eventually even out because it has to, otherwise it would be biased and no good to you. The period before it evens out is really really long, but the effects start to become noticeable soon enough.
So again, the tip: Use it less. Generate the random number once, and use it for a bit of time before getting another one.
Also, when I said cosmic radiation, I was being half-facetious. Home computers don't have a way to detect cosmic radiation. Government and Academic science labs, and the brains of cats, are where you detect cosmic radiation and get truly random events.
Lets try this list: 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1.
Is that random? Well, you can say it is random, because it's unpredictable where the 3s and 2s appear, but since the 1s appear so common, it's unsuitable. We call this "Biased" or "Weighted." So, for a proper random number generator to be usable, it needs to not be biased, meaning that all numbers have the same chance of showing up as any other.
Now, lets try this: -4 4 1 3 -5 -5 -5 -5 5 -3 5 4 -5 -4 2 4 5 4 2 -1
If you add those all together, you get 2, meaning that you didn't travel very far from the start. So, here's the core problem: You're misunderstanding what random really is. If you keep doing random events over and over and over, they eventually even out because it has to, otherwise it would be biased and no good to you. The period before it evens out is really really long, but the effects start to become noticeable soon enough.
So again, the tip: Use it less. Generate the random number once, and use it for a bit of time before getting another one.
Also, when I said cosmic radiation, I was being half-facetious. Home computers don't have a way to detect cosmic radiation. Government and Academic science labs, and the brains of cats, are where you detect cosmic radiation and get truly random events.