We don't bite newbies here... much | |
PerlMonks |
Re: Old random number generatorby haukex (Archbishop) |
on May 09, 2020 at 21:27 UTC ( [id://11116626]=note: print w/replies, xml ) | Need Help?? |
Is there a way to get the old behavior back? From what little I can tell from this, it may still be possible to compile Perl on Windows to use the old way. But that seems overly complex. I have a few programs that depend upon generating repeatable pseudorandom number sequences. The new random number generator still does this, it's even more reliable because it'll be the same no matter what platform. So I suspect that's not really your point - I suspect you've got code that is depending on a certain sequence of random numbers? Note that, in general, this isn't reliable anyway, since AFAICT, Perl before 5.20 didn't guarantee a certain algorithm to be used. What you probably really want is a PRNG with a known algorithm. Before 5.20, srand 0;print rand in Strawberry Perl always gave me 0.00115966796875. Well, the following appears to work (after installing Microsoft Visual C++ 2010 Redistributable Package (x64); I'm not a Windows expert so maybe there's a better way*) - at least for the single value you provided. But again, you're probably better off choosing a known PRNG instead, possibly from CPAN.
* Update: I can confirm that 'msvcrt' instead of 'msvcr100' works for me as well, thanks syphilis! /Update And after a bit of digging, the Linear congruential generator that Windows uses can be reimplemented in Perl:
The output of this function can be used in the same way, i.e. the first call to winrand()/(1<<15) also produces 0.00115966796875, and further calls to winrand() produce the same as $rand->Call() in the above code. Note I've only tested this on a 64-bit Perl.
In Section
Seekers of Perl Wisdom
|
|