Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Note that this is not a (real) answer to your question, but some (side)notes ...

If you use use strict; use warnings;, you would get this warning:

Hexadecimal number > 0xffffffff non-portable at line 9

Of course with the name of your script and the location of that 0xf...

But when using large numbers like that, I'd advice to use decimal notation instead of hexadecimal, just for portability.

Than it depends on your perl being compiled with -Duse64bitint or another (default) option that causes IV's (perl internal integers) allow 64bit data. That is easy to check though:

$ perl -V:ivsize ivsize='8'; $ perl -wle'print 1152921504606846975' 1152921504606846975 $ perl -wle'printf "%x\n", 1152921504606846975' fffffffffffffff

Compare to a perl with 32bit IV's:

$ gperl32 -V:ivsize ivsize='4'; $ gperl32 -wle'print 1152921504606846975' 1.15292150460685e+18 $ gperl32 -wle'printf "%x\n", 1152921504606846975' ffffffff

Maybe this helps on the short term:

use 5.18.2; use warnings; $|++; srand 54321; say "One rand"; for (1 .. 20) { my $n = int rand 1152921504606846975; printf "\r%064b %016X\n", $n, $n; } say "Two rands"; for (1 .. 20) { my ($n1, $n2) = map { int rand 0xffff_ffff } 0, 1; my $n = unpack "Q>", pack "L>L>", $n1, $n2; printf "\r%064b %016X\n", $n, $n; }


One rand 0000000001011110010111000001101110010101000100000000111111111111 005E5 +C1B95100FFF 0000110011101111101010000101100110100110001101110111111111111111 0CEFA +859A6377FFF 0000001100101010000101011010101110100010101000100010111111111111 032A1 +5ABA2A22FFF 0000011011010000111100010101011000110110001011110001111111111111 06D0F +156362F1FFF 0000110100101100101001111001010011101000110100010100111111111111 0D2CA +794E8D14FFF 0000010111010101110101111110100011101110111111111011111111111111 05D5D +7E8EEFFBFFF 0000000100000101000100010010110010001001011001010110111111111111 01051 +12C89656FFF 0000111111000110001001000000101011100010110100010101111111111111 0FC62 +40AE2D15FFF 0000010010010000101010101010111100101111011001101000111111111111 0490A +AAF2F668FFF 0000110010001101100001001001101000010100000010111111111111111111 0C8D8 +49A140BFFFF 0000110100001100110001101010110101010001000111001010111111111111 0D0CC +6AD511CAFFF 0000001010011101011001011011110110001111010101111001111111111111 029D6 +5BD8F579FFF 0000000000110000111000100000011001000010000011111100111111111111 0030E +206420FCFFF 0000010100111111100010001111100000010101100111000011111111111111 053F8 +8F8159C3FFF 0000010010011010111000001001011010010101000001111110111111111111 049AE +0969507EFFF 0000010011101110110111110111001111010110000000011101111111111111 04EED +F73D601DFFF 0000011011011111100000001001001001001110000011010000111111111111 06DF8 +0924E0D0FFF 0000011101111101110010000101010110110111111100000111111111111111 077DC +855B7F07FFF 0000111011000101111100000111011101100100011001110010111111111111 0EC5F +07764672FFF 0000110101111000101000011100101010110101000100000001111111111111 0D78A +1CAB5101FFF Two rands 0110111011001000100010011001000010011000011110001101000001011011 6EC88 +9909878D05B 1000011111110001011001111000011100001110111101111100100010001100 87F16 +7870EF7C88C 1011000100011111101001110011000101100011010110101001110101110011 B11FA +731635A9D73 1110001111001110010011000011100101001011111110010101000101001010 E3CE4 +C394BF9514A 1110001001010010001001100101001001010011000011001111000101011100 E2522 +652530CF15C 1111001101101100101000011110101010011011111101000110000011101110 F36CA +1EA9BF460EE 0011110101110110001011001101001110011110001101000111010011011010 3D762 +CD39E3474DA 1110010101011100001011111011000101010100110100110110010100001010 E55C2 +FB154D3650A 0001000100010110101111100011110000100000111001010100000101000011 1116B +E3C20E54143 1001010000111100010000111000111010100100101100111001100011011000 943C4 +38EA4B398D8 1101101010011010011001010001001100110100111010100111000101000001 DA9A6 +51334EA7141 0101010111110100011011011110000100101100011001110000110110100100 55F46 +DE12C670DA4 0101011101011010100111010111001010011010111011110111100111010110 575A9 +D729AEF79D6 1110111111111001000000000001111001110000011001000101010101100110 EFF90 +01E70645566 0111010100101110110101001101001101110110111101111000111110100000 752ED +4D376F78FA0 1010110111001100010000101100000111011001001100111011001110110010 ADCC4 +2C1D933B3B2 0110010100000111000100110010110101100110100011111001110001011110 65071 +32D668F9C5E 1000010010001000100101101000000010100011000000111111100011010100 84889 +680A303F8D4 1001011101011111101000010100010000010010111010111000100010110010 975FA +14412EB88B2 1001001001001110111101001100000001101010000011110110101100110110 924EF +4C06A0F6B36

Enjoy, Have FUN! H.Merijn

In reply to Re: how to get a 64bit random number with rand() ? by Tux
in thread how to get a 64bit random number with rand() ? by iglake

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2022-05-16 05:43 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (62 votes). Check out past polls.