in reply to rand() function on Windows systems

So, in essence, you want your random numbers not to be random, that's a kind of oxymoron.

Running your code on my Windows box, with ActiveState Perl v5.16.3, I get 56:

C:\Users\Laurent>perl -e "srand(555); my $range = 1000; my $number = i +nt(rand($range)); print $number ;" 56
On the same Windows platform, running Perl v5.14.4 under Cygwin, I get 466:
Laurent@Laurent-HP ~ $ perl -e 'srand(555); > my $range = 1000; > my $number = int(rand($range)); > print $number,"\n";' 466
If you really need the same pseudo-random numbers as on you old Perl version, then run your old Perl version, write the pseudo-numbers generated to a file and use the numbers in this file on your new version.

But the bottom line is, IMHO, that you should probably not try to rely on a random number generator to give you always the same sequence of numbers.

Replies are listed 'Best First'.
Re^2: rand() function on Windows systems
by LanX (Saint) on Dec 30, 2016 at 20:37 UTC
    >  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!

      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.

Re^2: rand() function on Windows systems
by stevieb (Canon) on Dec 30, 2016 at 20:40 UTC

    I get the desired `56` on Strawberry Perl 5.10.1 Portable Edition, so if you only need a quick one-off without having to install anything, look here.

      I also got 56 on ActiveState 5.16 (and BrowserUK also, apparently), but the OP seems to be looking for 52:
      older versions of Perl output a number of 52
      I wonder which version of Perl was being used then.
        I apologize. I was meant to be 56

        Whoops! In my haste to leave the office for the day, somehow I must have gone a bit weird and thought a 2 meant 6. Good thing I wasn't working with accounting systems today ;)