|
From: David Harmon on 11 Apr 2008 13:44 Elsewhere I saw someone making an argument and using a Perl program to support it, one in which he calls rand() in a loop 2000000 times. Now, in my native C, rand() typically falls apart statistically long before that many iterations. Is there any guarantee in Perl on the randomness and/or length of the period of rand? "perldoc -f rand" doesn't tell.
From: xhoster on 11 Apr 2008 14:15 "Newsgroup only please, address is no longer replyable." <bad(a)example.invalid> wrote: > Elsewhere I saw someone making an argument and using a Perl program > to support it, one in which he calls rand() in a loop 2000000 times. And then what? We can't critique the argument if we don't know what it is. > Now, in my native C, I don't have a native C. I doubt you do either. Your computer might. If your computer's native C has crappy random number generators, I suspect your perl will inherit that crappiness. > rand() typically falls apart statistically long > before that many iterations. All psuedorandom number generators will fall about if your statistical criteria are stringent enough and you are willing to spend enough time finding the problem. So it is kind of meaningless to say that without specifying exactly what type of falling apart you are looking for. > Is there any guarantee in Perl on the > randomness and/or length of the period of rand? > "perldoc -f rand" doesn't tell. I don't think perl makes any guarantees about anything. By running ltrace on a simple program, I see that my perl calls drand48 to get its random numbers. Therefore, it inherits the same limitations as discussed in "man drand48". I find this good enough, but if you don't there are modules for Perl that try to give you cryptographic strength random numbers. I suspect they are God-awful slow. perl -le 'foreach(1..2e6) {die if $h{rand()}++}' Xho -- -------------------- http://NewsReader.Com/ -------------------- The costs of publication of this article were defrayed in part by the payment of page charges. This article must therefore be hereby marked advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate this fact.
From: smallpond on 11 Apr 2008 17:04 On Apr 11, 1:44 pm, David Harmon <sou...(a)netcom.com> wrote: > Elsewhere I saw someone making an argument and using a Perl program > to support it, one in which he calls rand() in a loop 2000000 times. > Now, in my native C, rand() typically falls apart statistically long > before that many iterations. Is there any guarantee in Perl on the > randomness and/or length of the period of rand? > "perldoc -f rand" doesn't tell. If you don't want to use a PRNG, use Crypt::Random.
From: Tim Smith on 11 Apr 2008 22:43 In article <45f278f2-ea71-4bef-b80b-1b4856650c65(a)m44g2000hsc.googlegroups.com>, smallpond <smallpond(a)juno.com> wrote: > > If you don't want to use a PRNG, use Crypt::Random. If the documentation on CPAN is right, that uses /dev/random. On some Unix systems, /dev/random is a PRNG. E.g., on FreeBSD, /dev/random uses the Yarrow PRNG. (Same for OS X). -- --Tim Smith
From: Abigail on 12 Apr 2008 06:55 _ xhoster(a)gmail.com (xhoster(a)gmail.com) wrote on VCCCXXXVII September MCMXCIII in <URL:news:20080411141536.213$fl(a)newsreader.com>: ~~ "Newsgroup only please, address is no longer replyable." ~~ <bad(a)example.invalid> wrote: ~~ > Elsewhere I saw someone making an argument and using a Perl program ~~ > to support it, one in which he calls rand() in a loop 2000000 times. ~~ ~~ And then what? We can't critique the argument if we don't know what it is. ~~ ~~ > Now, in my native C, ~~ ~~ I don't have a native C. I doubt you do either. Your computer might. ~~ If your computer's native C has crappy random number generators, I suspect ~~ your perl will inherit that crappiness. ~~ ~~ > rand() typically falls apart statistically long ~~ > before that many iterations. ~~ ~~ All psuedorandom number generators will fall about if your statistical ~~ criteria are stringent enough and you are willing to spend enough time ~~ finding the problem. So it is kind of meaningless to say that without ~~ specifying exactly what type of falling apart you are looking for. ~~ ~~ > Is there any guarantee in Perl on the ~~ > randomness and/or length of the period of rand? ~~ > "perldoc -f rand" doesn't tell. ~~ ~~ I don't think perl makes any guarantees about anything. ~~ ~~ By running ltrace on a simple program, I see that my perl calls drand48 ~~ to get its random numbers. Therefore, it inherits the same limitations as ~~ discussed in "man drand48". I find this good enough, but if you don't ~~ there are modules for Perl that try to give you cryptographic strength ~~ random numbers. I suspect they are God-awful slow. To see what function Perl uses for random numbers: perl -MConfig -E 'say $Config::Config {randfunc}' For its number of bits: perl -MConfig -E 'say $Config::Config {randbits}' Abigail ~~ ~~ perl -le 'foreach(1..2e6) {die if $h{rand()}++}' ~~ ~~ Xho ~~ -- :$:=~s:$":Just$&another$&:;$:=~s: :Perl$"Hacker$&:;chop$:;print$:#:
|
Next
|
Last
Pages: 1 2 Prev: Gisle Aas's Illustrated Perl Guts? Next: FAQ 8.42 How do I make a system() exit on control-C? |