Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Slightly Srandom JAPH

by BenGoldberg (Sexton)
on Dec 28, 2013 at 02:43 UTC ( [id://1068576]=note: print w/replies, xml ) Need Help??


in reply to Re: Slightly Srandom JAPH
in thread Slightly Srandom JAPH

The integer overflow error you got seems very surprising, since I would expect srand JAPH to be the same thing as srand "JAPH", which should be the same thing as srand 0.

On the other hand... I know that my code is dependent on perl having specific implementations of srand, rand, and sort, so if you run it, and it prints out an apparently random shuffling of the letters of HnlcrhJsre_Pt_aeAeuot_, then I wouldn't be surprised.

The version of perl I tested it against was 5.16.0, so I would expect that version of perl to produce the right output.

To create your own (admittedly version specific) JAPH based on this, you can do it the way I did.
perl -e 'print length "just another perl hacker"' 24 perl -e 'my $x = ("a".."z")[23]; print $x' x perl -e 'srand 42; print sort {4-rand 9} ("a".."x")' gnkhwqpiejbaxdlcrfomtsuv perl -e '$_ = join "", "a".."x"; y/gnkhwqpiejbaxdlcrfomtsuv/Just_anoth +er_Perl_hacker/' rerPt_Jtohseauhnalkcer__ perl -e 'srand 42; print sort {4-rand 9} split //, rerPt_Jtohseauhnalk +cer__' Just_another_Perl_hacker
This time, this was done with 5.12.1.

Replies are listed 'Best First'.
Re^3: Slightly Srandom JAPH
by Athanasius (Archbishop) on Dec 28, 2013 at 08:01 UTC
    ...I would expect srand JAPH to be the same thing as srand "JAPH", which should be the same thing as srand 0.

    Since v5.14, srand returns the random number seed as well as setting it. So perl -e "print srand JAPH;" shows how JAPH is interpreted as a seed. On the perls I have to hand (all Strawberry Perl, except for v5.16.3, which is Citrus Perl), srand JAPH is the same as srand "JAPH", but in version 5.18 it is no longer the same as srand 0:

    perlsrand JAPH
    5.14.40 but true
    5.16.00 but true
    5.16.30 but true
    5.18.018446744073709551615
    5.18.118446744073709551615

    I haven’t found the reason for this. But the resulting warning was introduced in v5.18. From the “New Warnings” section of perl5180delta#New-Diagnostics:

    "Integer overflow in srand" srand() now warns when passed a value that doesn't fit in a UV (since +the value will be truncated rather than overflowing) [perl #40605].

    See also perldiag#Integer-overflow-in-srand.

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      To complete that table: all perl versions 5.003_07 .. 5.13.3 will print 1, 5.13.4 .. 5.17.1 will print 0 but true, and 5.17.2 .. 5.19.6 will print 18446744073709551615 with the "Integer overflow in srand" warning.


      Enjoy, Have FUN! H.Merijn

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1068576]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-16 17:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found