Closed p5pRT closed 20 years ago
The rand() function should produce a specific\, repeatable sequence of number given some specific seed value passed to srand(). I have found that all the Unix ports of Perl\, versions 5.004 and 5.005\, do behave in this manner but the Intel ports do not. Using the simple program
srand('028350); print rand()\, "\n";
from the command line the following results were obtained.
======== Win95 perl -e "srand('028350');print rand();" 0.826446533203125 perl -v This is perl\, version 5.005_03 built for MSWin32-x86-object
perl -e "srand('028350');print rand();" 0.6142578125 This is perl\, version 5.004_02
======== Linux (Intel) perl -e 'srand("028350");print rand()\,"\n";' 0.0450114482082427 perl -v This is perl\, version 5.005_03 built for i686-linux
======== AIX perl -e 'srand("028350");print rand()\,"\n";' 0.053741455078125 perl -v This is perl\, version 5.004_01
perl -e 'srand("028350"); print rand()\,"\n";' 0.053741455078125 perl -v This is perl\, version 5.005_02 built for aix
======== DEC Unix perl -e 'srand("028350");print rand()\,"\n";' 0.053741455078125 perl -v This is perl\, version 5.004_01
======== HPUX perl -e 'srand("028350");print rand()\,"\n";' 0.053741455078125 perl -v This is perl\, version 5.004_01
comparing unix ports and intel ports is weird. Probably means win32 and unix.
different platforms may use different rand() functions.
As long as the sequence generated by:
srand( 10 ); for (1..3) { print rand(); }
is consistent between multiple runs on one platform\, this isn't a bug.
Obviously - the above snippet should be extendable to any srand value or any length sequence.
The idea _is_ to generate a random number\, not something that can be specified.
Migrated from rt.perl.org#875 (status was 'resolved')
Searchable as RT875$