Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: rand() function on Windows systems

by LanX (Saint)
on Dec 30, 2016 at 20:37 UTC ( [id://1178681]=note: print w/replies, xml ) Need Help??


in reply to Re: rand() function on Windows systems
in thread rand() function on Windows systems

>  to give you always the same sequence of numbers.

But this IS documented behavior, see srand

The point is rather that you can't guarantee the same sequence for newer Perl versions because this would inhibit any progress.

Progress like being OS independent.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re^3: rand() function on Windows systems
by Laurent_R (Canon) on Dec 30, 2016 at 21:49 UTC
    But this IS documented behavior, see srand
    Yes, Rolf, agreed. I know that if you initialize srand with a specific number, you'll be able to get repeatedly the same sequence from rand if you run it several times on the same machine with the same Perl version. This is not specific to perl, many programming languages have the same feature. And this is useful especially for some testing purposes (e.g. to be able to test the same conditions several times).

    But I said: "you should probably not try to rely on a random number generator to give you always the same sequence of numbers." The word always is important in what I meant. One should not expect the same sequence forever.

    And the possible solution I suggested relies on that: if you need the same sequence of pseudo-random integers with different Perl versions and platforms, for whatever reason,, then store that sequence somewhere and re-use it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1178681]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-03-29 12:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found