in reply to Re^13: How likely is rand() to repeat?
in thread How likely is rand() to repeat?
Okay. When reason fails, how's about a little empirical evidence?
#! perl -slw use strict; use Math::Random::MT qw[ rand srand ]; $|++; my @c = ( 'A'..'Z', 'a'..'z', 0..9 ); for my $run ( 1 .. 1e6 ) { my %seen; keys %seen = 1e6; printf "\rrun: $run"; for my $id ( 1 .. 1e6 ) { srand( $run + $id ); my $ID = join '', map $c[ int rand( 62 ) ], 1 .. 25; warn "Dup $ID at $run/$id" if exists $seen{ $ID }; undef $seen{ $ID }; } } __END__ C:\test>"IDrand(62)x25.pl" run: 254
That console log is a snapshot. After generating 254 sets of 1 million 25-char keys, with each key being generated at a new seed position, NO DUPS SEEN!
How long will it need to run before you are convinced that the OP is safe to use this?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^15: How likely is rand() to repeat?
by JavaFan (Canon) on Mar 09, 2012 at 23:33 UTC | |
by BrowserUk (Patriarch) on Mar 09, 2012 at 23:38 UTC | |
by JavaFan (Canon) on Mar 09, 2012 at 23:47 UTC | |
by BrowserUk (Patriarch) on Mar 10, 2012 at 00:50 UTC |