I took a quick look at the code, looks pretty nice. My only real comment concerns the _seed function. You specify the different seeding strategies as code blocks with a huge if/elsif/elsif/else chain.

I would tend to split these blocks out into seperate subroutines, e.g. _seed_dev_random, _seed_random_org and so forth. And there's probably a bit of redundant code that could be hoisted out of the /dev/random and /dev/urandom seeding routines.

Also, bear in mind that that on OpenBSD, the two devices are known as /dev/srandom and /dev/random (If I remember correctly, it's been a few years...). FreeBSD also names them slightly differently.

If you adopt this approach, it simplifies the addition of additional seeding strategies with a minimum of fuss. It also opens up the possibility that client code can add their own seeding routine, maybe reading from /dev/audio, or running a one-way hash digest on the gzipped output of top(1) or something or other.

This is probably a better tactic for getting patches sent in for additional seeding routines. Telling people to fill out and array and pass it to the seeds() routine seems a little cumbersome to me. And if the seeds() routine is called without any parameters, you should return the current seed array, so that people have the chance of serialising the state of the generator, in case they wish to "pick up where they left off" in a subsequent program invocation.

Oh, one last thing... you ought to add some statistical tests in your test suite to test that there aren't any glaring non-random errors occurring. Just saying things are between 0 and 1 is a little too simple.

One thing I really liked about the original MT implementation when I looked at it was that you could get a random number back from 0 .. MAXINT. Which is really nice, because then it becomes trivial to generate numbers on the [0,1] interval, rather than [0,1), which is sometimes nice to have. And if you're scaling up to integers anyway, you can save a few cycles by avoiding the initial reciprocal division that way. Being able to get at the raw U32 value would be nice.

- another intruder with the mooring in the heart of the Perl


In reply to Re: New CPAN Module: Math::Random::MT::Auto by grinder
in thread New CPAN Module: Math::Random::MT::Auto by jdhedden

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.