in reply to Slightly Srandom JAPH

Sorry, doesn’t seem to work for me:

12:00 >perl -e "print sort {4-rand 9} split //, HnlcrhJsre_Pt_aeAeuot_ +kr if srand JAPH;" Integer overflow in srand at -e line 1. _nhoeuJAHl_ktscPrt_rreea 12:00 >perl -v This is perl 5, version 18, subversion 1 (v5.18.1) built for MSWin32-x +86-multi-thread-64int ...

:-(

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

Replies are listed 'Best First'.
Re^2: Slightly Srandom JAPH
by BenGoldberg (Sexton) on Dec 28, 2013 at 02:43 UTC

    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.
      ...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