in reply to Re: Non-Repetitive Random Numbers
in thread Non-Repetitive Random Numbers
That doesn't guarantee unique values. With the built-in rand/srand, it produces repeats within 30 picks for seeds:
seed : no.of picks before repeat 89 : 12 178 : 17 485 : 9 504 : 14 555 : 22 662 : 16 688 : 23 761 : 19 766 : 18 920 : 26 936 : 25 943 : 19 955 : 17 982 : 14 1004 : 27 1032 : 19 1192 : 23 1200 : 9 1385 : 24 1427 : 17 1439 : 29 1459 : 22 1582 : 14 1593 : 22 1602 : 29 1668 : 12 1737 : 22 1924 : 29 1933 : 24 1969 : 18 2186 : 27 2261 : 12 2297 : 12 2380 : 18 2410 : 29 2660 : 25 2690 : 28 2733 : 24 2817 : 13 2863 : 4 2875 : 19 2964 : 28 3023 : 27 3052 : 9 3198 : 24 3208 : 23 3240 : 28 3292 : 16 3415 : 2 3529 : 26 3669 : 22 3692 : 29 3741 : 21 3754 : 13 3791 : 23 3805 : 28 3842 : 24 3854 : 8 3956 : 28 4077 : 27 4202 : 20 -- More --
Testcase:
#! perl -slw use strict; for my $i ( 1 .. 100000 ) { my %hash; srand $i; ++$hash{ int rand 100000 } == 2 and print "$i : ", scalar keys %ha +sh while keys %hash < 30; }
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Non-Repetitive Random Numbers
by LanX (Saint) on Apr 05, 2013 at 14:54 UTC | |
by BrowserUk (Patriarch) on Apr 05, 2013 at 15:24 UTC |
In Section
Seekers of Perl Wisdom