in reply to how portable is the random number generator?

Why? It's a random number generator.

If this is for testing, then mock the rand function (or wrap it in a function for easier mocking).

If you need a reliable sequence of pseudo-random numbers for whatever reason, then use a fixed PRNG implementation (search CPAN for PRNG and Math::Random). There are even ones simple enough that you can implement them yourself, like say Xorshift (though there's a module on CPAN for that too, of course).

If it's just for a JAPH, then the perldelta for 5.20 says "Perl now uses its own internal drand48() implementation on all platforms" (also mentioned in the rand doc), with no mention of the PRNG in the deltas since then - but no guarantees that this won't change in the future, since again, it's a random number generator.

But at least that answers your question: Your JAPH should produce the same output on Perl 5.20 though at least the current 5.42 on all platforms.

  • Comment on Re: how portable is the random number generator?

Replies are listed 'Best First'.
Re^2: how portable is the random number generator?
by haukex (Archbishop) on Jan 24, 2026 at 15:40 UTC
    no guarantees that this won't change in the future

    Indeed, just yesterday on P5P: Should we upgrade to a new PRNG in core?

    And a relevant note from that thread by Russ Allbery:

    The most secure option is to not use any type of pseudo-random number generator and instead rely on /dev/random. If your concern is security, you should not use rand and you should not use any other new algorithm that similarly does not use /dev/random. ... If /dev/random is available and you want random numbers for security purposes, you should just use it via Crypt::URandom, Crypt::Random, etc.