develooper Front page | perl.perl5.porters | Postings from February 2000

Re: bad default srand seed?

Thread Previous | Thread Next
From:
simon
Date:
February 9, 2000 04:35
Subject:
Re: bad default srand seed?
Message ID:
slrn8a2nna.vfh.simon@othersideofthe.earth.li
Tom Christiansen (lists.p5p):
>Witness:
>
>% repeat 20 perl -le '@n = sort { rand() <=> rand() } 1 .. 20; print "@n"'
>17 5 4 7 1 14 12 3 11 9 20 13 8 6 16 19 15 18 2 10
>17 5 4 7 1 14 12 3 11 9 20 13 8 6 16 19 15 18 2 10
>
>Now, that isn't particularly random.  Hm....
>
>That's with 5.005_54 on OpenBSD.
>Ideas?

Linux, glibc 2.1:

(repeat 1000 /tmp/perl5.005_03/perl -le '@n = sort { rand() <=> rand() } 1..20;
print "@n"') | sort | uniq | wc -l
   1000

(repeat 1000 /tmp/perl5.005_61/perl -le '@n = sort { rand() <=> rand() } 1..20;
print "@n"') | sort | uniq | wc -l
   1000

-- 
Solipsists of the World... you are already united.
		-- Kayvan Sylvan
-- 
The Second Law of Thermodynamics:
	If you think things are in a mess now, just wait!

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About