hopes has asked for the wisdom of the Perl Monks concerning the following question:
Hi to all!:
I would like to know how srand works.
In srand it is said this:
Do not call srand multiple times in your program unless you know exactly what you're doing and why you're doing it. The point of the function is to "seed" the rand function so that rand can produce a different sequence each time you run your program. Just do it once at the top of your program, or you won't get random numbers out of rand! but doesn't explain the extrange behaviour of
Yes, I know I was told not to do that, but I want to know WHY...:-)
Why canīt I modify the seed during the execution?
When is srand evaluated, in runnig time or during the parsing?
Why does de code generates equal numbers?
Hopes
I would like to know how srand works.
In srand it is said this:
Do not call srand multiple times in your program unless you know exactly what you're doing and why you're doing it. The point of the function is to "seed" the rand function so that rand can produce a different sequence each time you run your program. Just do it once at the top of your program, or you won't get random numbers out of rand! but doesn't explain the extrange behaviour of
srand (time ^ ($$ + ($$ << 11))); print join ",", map { srand (time ^ ($$ + ($$ << 11))); $_=int(rand(10)) }(0..10);
Yes, I know I was told not to do that, but I want to know WHY...:-)
Why canīt I modify the seed during the execution?
When is srand evaluated, in runnig time or during the parsing?
Why does de code generates equal numbers?
Hopes
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: srand and seed
by japhy (Canon) on Oct 23, 2001 at 03:54 UTC | |
Keep this in mind
by Fletch (Bishop) on Oct 23, 2001 at 04:36 UTC | |
by tenya (Beadle) on Nov 04, 2001 at 00:43 UTC | |
Re: srand and seed
by hopes (Friar) on Oct 23, 2001 at 04:03 UTC | |
by fokat (Deacon) on Oct 23, 2001 at 05:17 UTC |
Back to
Seekers of Perl Wisdom