more useful options PerlMonks

### Re^2: Check randomly generated numbers have not been used before

by BrowserUk (Pope)
 on Jun 20, 2014 at 19:28 UTC ( #1090675=note: print w/replies, xml ) Need Help??

If you had any programming skills, you'd make some attempt to verify a wild-assed guess like that:

```#! perl -slw
use strict;
use Math::Random::MT qw[ rand ];

our \$T //= 50;

my( \$total, \$min, \$max ) = ( 0, 1e9, 0 );
for( 1 .. \$T ) {
my( %h, \$r );
while( 1 ) {
\$r = int( 1e6 + rand( 9e6 ) );
++\$h{ \$r } == 2 and last;
}
my \$subt = scalar keys %h;
\$total += \$subt;
\$min = \$subt if \$subt < \$min;
\$max = \$subt if \$subt > \$max;
printf "Duplicate value(\$r) seen after %d iterations\n", \$subt;
}

printf "Ave.%.3f Min:%d Max:%d\n", \$total / \$T, \$min, \$max;

__END__
C:\test>junk54
Duplicate value(2665199) seen after 4496 iterations
Duplicate value(6555509) seen after 5166 iterations
Duplicate value(8242500) seen after 1302 iterations
Duplicate value(8032591) seen after 1597 iterations
Duplicate value(6169187) seen after 4540 iterations
Duplicate value(3999236) seen after 6578 iterations
Duplicate value(4470150) seen after 7858 iterations
Duplicate value(4580644) seen after 3798 iterations
Duplicate value(4856238) seen after 4780 iterations
Duplicate value(9540961) seen after 1793 iterations
Duplicate value(8106058) seen after 5114 iterations
Duplicate value(8231462) seen after 1289 iterations
Duplicate value(5437248) seen after 1915 iterations
Duplicate value(6177470) seen after 2986 iterations
Duplicate value(7463793) seen after 3506 iterations
Duplicate value(3028064) seen after 5916 iterations
Duplicate value(9985723) seen after 1536 iterations
Duplicate value(4848638) seen after 1384 iterations
Duplicate value(1227666) seen after 3463 iterations
Duplicate value(8764243) seen after 4122 iterations
Duplicate value(6364225) seen after 5994 iterations
Duplicate value(5322923) seen after 506 iterations
Duplicate value(7557328) seen after 1820 iterations
Duplicate value(4731867) seen after 2791 iterations
Duplicate value(8199944) seen after 1903 iterations
Duplicate value(8481265) seen after 4763 iterations
Duplicate value(5209684) seen after 1039 iterations
Duplicate value(3202941) seen after 6198 iterations
Duplicate value(6657755) seen after 5574 iterations
Duplicate value(7013349) seen after 2369 iterations
Duplicate value(7736365) seen after 3088 iterations
Duplicate value(3171737) seen after 1359 iterations
Duplicate value(5533710) seen after 2921 iterations
Duplicate value(9403663) seen after 2459 iterations
Duplicate value(8811253) seen after 4271 iterations
Duplicate value(1649095) seen after 5702 iterations
Duplicate value(4630011) seen after 3550 iterations
Duplicate value(9044573) seen after 6169 iterations
Duplicate value(5711853) seen after 4171 iterations
Duplicate value(3313811) seen after 2539 iterations
Duplicate value(5055725) seen after 5712 iterations
Duplicate value(6910134) seen after 4571 iterations
Duplicate value(5598759) seen after 6135 iterations
Duplicate value(8065116) seen after 2466 iterations
Duplicate value(4587634) seen after 6195 iterations
Duplicate value(4192726) seen after 1373 iterations
Duplicate value(4299363) seen after 5448 iterations
Duplicate value(2418217) seen after 4396 iterations
Duplicate value(2225622) seen after 1414 iterations
Duplicate value(4347823) seen after 1962 iterations

Ave.3639.940 Min:506 Max:7858

Using one of the best PRNGs around, that hits a duplicate after less than 4000 attempts on average, and as few 500.

Best you stick to your fluff pieces, handing out bad advice that could ruin young guys careers; at least then you cannot be proven wrong!.

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.

Create A New User
Node Status?
node history
Node Type: note [id://1090675]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (11)
As of 2018-10-17 12:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
When I need money for a bigger acquisition, I usually ...

Results (92 votes). Check out past polls.

Notices?