Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^4: Mersenne Twister

by swl (Prior)
on Jan 05, 2024 at 23:42 UTC ( [id://11156733]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Mersenne Twister
in thread Mersenne Twister

The Mersenne Twister is a popular pseudo-random number generator (PRNG) because it has good distribution properties and a long period length (2^19937 - 1) before the sequence repeats. It passes all the diehard tests of randomness, and nearly all of the TestUO1 tests. (Wikipedia is a reasonable source of info for this: https://en.wikipedia.org/wiki/Mersenne_Twister).

The algorithm you describe is a Linear Congruential Generator (LCG). These have global correlation structures that cause issues at the square root or cubed root of the period length.

Perl's rand() uses the drand48 algorithm on all operating systems since 5.20 (https://metacpan.org/release/RJBS/perl-5.20.0/view/pod/perldelta.pod#rand-now-uses-a-consistent-random-number-generator). This has a longer period length (2^48) than the standard ANSI C rand (2^31) but is still an LCG and thus has issues with correlation structures. Some useful illustrations are at https://wellington.pm.org/archive/200704/randomness/index.html, for example slide7, slide8 and slide 14.

Whether all the above matters depends on the application. If it is just selecting from a small pool of items a small number of times then the choice of PRNG is unlikely to be an issue. Applications with larger data sets require better quality PRNGs.

Replies are listed 'Best First'.
Re^5: Mersenne Twister
by harangzsolt33 (Deacon) on Jan 06, 2024 at 00:44 UTC
    "since 5.20"

    Hmm... Interesting. That's good to know... I have been using TinyPerl 5.8 mostly. When plotting random lines, I did notice that there is a visible difference or should I say "resemblance of a pattern" visible with what you mentioned, LCG, but when I plotted lines with Mersenne Twister, the lines appeared completely random.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2026-03-12 20:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.