Re: rand and srand across builds and platforms?
by davis (Vicar) on Mar 08, 2005 at 15:34 UTC
|
No:
$ perl5.8.5 -le"srand(1); print rand for 1 .. 10"
0.0416303447718782
0.454492444728629
0.834817218166915
0.3359860301452
0.565489403566136
0.00176691239174431
0.18758951699996
0.990434079937664
0.750497133229519
0.366273638152734
Update:
Interestingly enough, my 32bit and 64bit HP-UX boxen produce the same output as above. Still, it's not the same as what you've got
davis
It wasn't easy to juggle a pregnant wife and a troubled child, but somehow I managed to fit in eight hours of TV a day.
| [reply] [d/l] |
|
|
This is what I get too, with perl 5.8.6.
| [reply] |
|
|
| [reply] |
Re: rand and srand across builds and platforms?
by Fletch (Bishop) on Mar 08, 2005 at 15:35 UTC
|
0.203723445340199
0.893308938570904
0.262596539117187
0.776595210641958
0.739336229299024
0.131970010506016
0.834684628984551
0.842243446561724
0.776803253700376
0.467943108165379
However I think Math::Random is more consistent.
| [reply] [d/l] |
|
|
However I think Math::Random is more consistent.
I think my favorite Math::Random::MT might be also, but it would be too much to add a prerequisite for a compiled package that's only used in testing I think.
I can embed a few useful sequences I guess.
Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.
| [reply] |
Re: rand and srand across builds and platforms?
by kvale (Monsignor) on Mar 08, 2005 at 16:20 UTC
|
As seen above, the rand() and srand() functions are machine dependent. If you need consistency across CPUs and C-libraries, I would recommend using a module with it's own self-contained routine. Math::Random::MT is one of the best.
| [reply] |
Re: rand and srand across builds and platforms?
by JediWizard (Deacon) on Mar 08, 2005 at 15:38 UTC
|
$ perl -le"srand(1); print rand for 1 .. 10"
0.0416303447718782
0.454492444728629
0.834817218166915
0.3359860301452
0.565489403566136
0.00176691239174431
0.18758951699996
0.990434079937664
0.750497133229519
0.366273638152734
A truely compassionate attitude towards other does not change, even if they behave negatively or hurt you His Holiness, The Dalai Lama
| [reply] [d/l] |
|
|
| [reply] [d/l] |
|
|
| [reply] |
|
|
| [reply] |
Re: rand and srand across builds and platforms?
by ikegami (Patriarch) on Mar 08, 2005 at 15:50 UTC
|
This is perl, v5.8.0 built for MSWin32-x86-multi-thread
This is perl, v5.6.1 built for MSWin32-x86-multi-thread
| [reply] [d/l] |
|
|
Thanks. I'd tried AS 5.6.1/5.6.2/5.8.4/5.8.5/5.8.6 and home-built versions (using the same compiler as AS) of the latter two and got consistant results.
From the responses, it seems likely that the underlying C-library/compiler has a lot to do with the result. Either just how the rands are generated or possibly srand uses an initialisation that is platform dependant.
It just makes testing randomly generated test sequences harder to verify than if it were consistant across builds and platforms.
Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.
| [reply] [d/l] |
Re: rand and srand across builds and platforms?
by Anonymous Monk on Mar 08, 2005 at 17:05 UTC
|
It will not. See the various Japhs floating around that (a)buse (s)rand to produce an appropriate string. They aren't cross-platform. For instance, from t/japh/abigail.t in the Perl source directory:
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"
SKIP: Solaris specific.
which is skipped when running the test, because it's "Solaris specific" - or at least, it claims to be so. And the only thing that's possibly system specific in the above Japh is the use of srand/rand. | [reply] [d/l] |
Re: rand and srand across builds and platforms?
by esskar (Deacon) on Mar 08, 2005 at 17:13 UTC
|
It's probably a problem of running on a POSIX system or on ne not POSIX system! | [reply] |
|
|
| [reply] [d/l] |
|
|
| [reply] |
|
|
|
|
|