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?


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.

The start of some sanity?

Replies are listed 'Best First'.
Re^15: How likely is rand() to repeat?
by JavaFan (Canon) on Mar 09, 2012 at 23:33 UTC
    How long will it need to run before you are convinced that the OP is safe to use this?
    Did I ever claim otherwise?

    All I've been claiming is that if you're seeding a deterministic random number generator with k bits, you will not be getting more than 2k sequences, and that I've seen no evidence whatsoever that you can pull more out of thin air.

    After generating 254 sets of 1 million 25-char keys, with each key being generated at a new seed position, NO DUPS SEEN!
    254 sets of 1 million keys? Call me confused, but:
    for my $run ( 1 .. 1e6 ) { ... for my $id ( 1 .. 1e6 ) { srand ( $run + $id ); ... } }
    Aren't you generating a million sets of a million keys each? But with only 2 million different keys, as $run + $id ranges from 2 .. 2e6.

    But never mind that. I've never questioned that picking a different seed is very likely to give you a different key. My claim is, that if you have only 232 different seeds you will not get more than 232 keys this way. You exercise showed that if you pick a million different seeds, you get a million different keys. And you repeated that experiment a million times, each time removing a single seed from the set of a million, and adding another one.

      More to your satisfaction?

      #! 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 .. 1e5 ) { srand( $run * $id ); for( 1 .. 10 ) { 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: 54

      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.

      The start of some sanity?

        More to your satisfaction?
        There's no need to satisfy me.

        I just don't see what point you're trying to make. You've been arguing against my viewpoint that having a seed of k bits cannot lead to more than 2k sequences. I fail to see how your exercise supports your argument, or contradicts mine.