As we don't want to exercise Cargo Cult....

Guilty as charged, and I thank you for pointing these details out.

"time()", "rand()" and "$$" are good for that while "{}", ref to an anonymous hash, doesnt help much, because it's always the same.

Actually, what you are seeing with the repeating "{}" value will not always be true. It seems (from my experimentation (look ma, no Cargo Cult)), is that it seems the repeating value you were seeing was something to the effect of perl's first memory location. So on each loop through the script you were seeing the location reaped and reused, and even when I forked each time within the loop, it did the same thing too. However, if you can be sure that this is not the first (?) ref created, you get a bit more randomness to that value. See the code below (spaces added for readability.

my @rand; for (1..10) { # add a random number of elements to the array push @rand => $_ for (0 .. ((rand() * 10) % 10)); my $rand_id = time() . " " . { time => time() } . " " . rand() + . " " . $$; printf "%s\n", $rand_id; } __OUTPUT__ 1092953284 HASH(0x1806be4) 0.351068406456278 15758 1092953284 HASH(0x180820c) 0.581041221829715 15758 1092953284 HASH(0x1808230) 0.936157439122312 15758 1092953284 HASH(0x1808284) 0.183180004399297 15758 1092953284 HASH(0x18082c0) 0.943342015904591 15758 1092953284 HASH(0x1808338) 0.424439000654708 15758 1092953284 HASH(0x1808350) 0.935454533284215 15758 1092953284 HASH(0x180838c) 0.771976549032949 15758 1092953284 HASH(0x1808398) 0.549340888274884 15758 1092953284 HASH(0x18083e0) 0.984217993290265 15758
Now of course, as the OP has pointed out to us, not all session generation is alike. This may not work for you if your script starts a fresh perl interpreter each time and the hash-ref always gets the same value. However, if you are in a long running process, this would seem to contribute to the initial entropy.

-stvn

In reply to Re^5: MD5-based Unique Session ID Generator by stvn
in thread MD5-based Unique Session ID Generator by radiantmatrix

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.