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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.