I seem to have $Config{randbits} = 48 and  $Config{longsize} = 4. But using $seed = int(rand(2**$Config{randbits} - 1)); produced very poor results. Even when the seed was different, I would get the same series random numbers using my $pick = int(rand(1e9))+1;

In any case, it's not important because I am now using Math::Random::MT, and its srand() function takes unsigned 32-bit integers. Thus I have to produce my seed between 0 and 2**32-1.

It worked quite well, but I noticed that I would get the same seed when my program was called several times in a short time frame. So I had to seed the PRNG with a fast-moving seed first before I could produce my actual random seed.

use Math::Random::MT qw(srand rand); I'm quite happy now with the result. I appreciate your advices GrandFather. The final code looks like this:
use Math::Random::MT qw(srand rand); sub seed_prng { # Seed the pseudo random number generator with a random or specified + seed # Returns what seed value is used my ($seed) = shift; if (not defined $seed) { # Want to produce an random unsigned 32-bit integer to feed to # Math::Random::MT::srand(). That means, first seed srand() with a + temporary # seed that varies quickly in time so we don't get twice the same +seed if we # request several seeds in a short interval of time. my $tmp_seed = time ^ ($$ + ($$ << 15)); # shown in srand's doc srand($tmp_seed); my $max = int(2**32-1); # Largest unsigned 32-bit integer $seed = int(rand($max+1)); # An integer between 0 and $max } srand($seed); return $seed; }

In reply to Re^6: Getting srand's seed by fangly
in thread Getting srand's seed by fangly

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.