in reply to Re: Golf: 3 hole golf game
in thread Golf: 3 hole golf game

"The implementation of rand guarantees that the same value cannot be returned twice in a very large number of calls"

Wouldn't that be considered a bug in perl? I mean if it guarantees not to return the same number, then that number is no longer equaly likely to be picked. I had assumed that everytime rand was called every possible outcome is equaly likely. Of course I might just be a crazy lunatic.


___________
Eric Hodges

Replies are listed 'Best First'.
Re^3: Golf: 3 hole golf game
by tilly (Archbishop) on Nov 27, 2004 at 08:26 UTC
    No, that is not a bug in Perl, it is a limitation that comes from fundamental facts of computer science. Perl's rand is a pseudo-random number generator. (That the documentation for rand doesn't make this clear is a bug in the documentation though...) It can't produce really random numbers (producing random numbers by a deterministic algorithm is a neat trick), but it produces something that looks pretty random for a very long time.

    If you want to produce really random numbers, then you need a source of random data to sample. Which can be done, but has its own problems (the call to fetch a random number may take a while if there is no random data in the pool right now). For normal purposes, pseudorandom is fast, easy, and good enough. Plus for some purposes it is very nice to be able to call srand and get a predictable set of numbers out.

    But if you really want something more random then see Math::TrulyRandom.