in reply to srand producing the same sequence of random numbers

The question here, I believe, is not related to the nature of (pseudo) random distributions - just why the same initial sequence gets displayed?

Well, as stated by another responder, that's one of the uses of srand() - from the perldoc -f srand output:

You can call srand($seed) with the same $seed to reproduce the same sequence from rand(), but this is usually reserved for generating predictable results for testing or debugging. Otherwise, don't call srand() more than once in your program.

Since srand is implicitly called on the first rand() call, there is no need to even call srand. Unless you need to :)

  • Comment on Re: srand producing the same sequence of random numbers

Replies are listed 'Best First'.
Re^2: srand producing the same sequence of random numbers
by locked_user sundialsvc4 (Abbot) on Oct 12, 2010 at 14:05 UTC

    As far as I am aware, this behavior is the only (practical) purpose for the existence of srand().

    Certain statistical tests require that a (pseudo-)random sample be taken from a population, then at some future point, another sample is taken which examines the same elements.   One way to do this, of course, would be to store the random sequence, but that can be memory-intensive.   Hence, srand().   First, you obtain a random number in the usual way.   Then, you use srand() to establish that (randomly chosen) number as the new “seed.”   Now, you can easily produce an arbitrarily long pseudo-random number sequence that can be repeated perfectly, just by re-assigning the seed.

    Because this is Perl, “TMTOWTDI.™”   Perl has many pseudo-random number generator packages available.

Re^2: srand producing the same sequence of random numbers
by locked_user sundialsvc4 (Abbot) on Oct 12, 2010 at 14:05 UTC

    As far as I am aware, this behavior is the only (practical) purpose for the existence of srand().

    Certain statistical tests require that a (pseudo-)random sample be taken from a population, then at some future point, another sample is taken which examines the same elements.   One way to do this, of course, would be to store the random sequence, but that can be memory-intensive.   Hence, srand().   First, you obtain a random number in the usual way.   Then, you use srand() to establish that (randomly chosen) number as the new “seed.”   Now, you can easily produce an arbitrarily long pseudo-random number sequence that can be repeated perfectly, just by re-assigning the seed.

    Because this is Perl, &ldquolTMTOWTDI.™”   Perl has many pseudo-random number generator packages available.