Nemo's bash challenge for the day
Martijn van Oosterhout
kleptog at svana.org
Mon Apr 1 11:52:14 EST 2002
On Sun, Mar 31, 2002 at 12:48:19PM +1000, Michael Still wrote:
> On Sun, 31 Mar 2002, Martijn van Oosterhout wrote:
>
> > On Fri, Mar 29, 2002 at 10:14:17AM +1100, Michael Still wrote:
> > > PS: How good is the bash random? See the attachment output.count for a
> > > summary of 100,000 numbers between 1 and 10 being generated with the
> > > default seed. It's probably good enough for most people.
> >
> > > 1: 9964
> > > 2: 10009
> > > 3: 9978
> > > 4: 10015
> > > 5: 9997
> > > 6: 10020
> > > 7: 10011
> > > 8: 10008
> > > 9: 10006
> > > 10: 9992
> >
> > You do realise that if they were all exactly 10,000 that would be a definite
> > sign of non-randomness!
>
> Ummm, surely for an extremely large sample you would expect to see an
> equal frequency for all of the options?
Nope. There is this thing called the "random-walk". Flip a coin and if it's
heads move one unit to the right, if it's tails you move one unit to the
left. After you flip the coin N times, on average you will be around the
square-root of N units from where you started.
Put it another way, after you flip a coin 1 million times, on average you
would have flipped one side 1000 times more than the other.
If you think about it, if you expected the results to come out equal, that
would mean at some stage the result was forced to produce this "even"
result, hence it wasn't random...
That's enough counter-intuitiveness for today I think.
--
Martijn van Oosterhout <kleptog at svana.org> http://svana.org/kleptog/
> Ignorance continues to thrive when intelligent people choose to do
> nothing. Speaking out against censorship and ignorance is the imperative
> of all intelligent people.
More information about the linux
mailing list