Hey all. I'm writing a passwerd session handler (over CGI of course) and I want to generate big randoms as the key for each open transaction to maintain server-side session status info without embedding static security info within printed HTML. It's not a big deal but the first thing I tried was:
my $rndm = sprintf "%lx", int rand(16**8); #why only 4hex digits when num is 8?
I've printed 16**8 and gotten ~4billion which is 2**32. Are numerics maxed at 4bil unless you use Integer Modules for long text math? I'm using this now which werks fine but It's not as straight forward as the first.
my $rndm = int rand(16**4); my $sess = sprintf "%lx", $rndm; $rndm = int rand(16**4); $sess .= sprintf "%lx", $rndm;
Thanks for any insight. TTFN & Shalom.

-PipTigger
p.s. Is there a reason why not to have a "dec" function to be the reciprocal of "hex"? Why does ProgrammingPerl use sprintf to convert hex->dec instead of a function which seems cleaner?

In reply to Why doesn't this give an 8 character hex number? by PipTigger

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.