Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^13: How likely is rand() to repeat?

by JavaFan (Canon)
on Mar 09, 2012 at 21:00 UTC ( [id://958794]=note: print w/replies, xml ) Need Help??


in reply to Re^12: How likely is rand() to repeat?
in thread How likely is rand() to repeat?

why do you think it is named MT19937?
Lemme guess, because they followed the example of drand48, and put the number of number of bits that's needed for the state in the name? Or perhaps because it's related to the length of the period? Not quite sure which point you're trying to make. I never claimed it was a "32-bit PRNG", but I guess you seem to think it is. After all, a few posts ago, you write By that assessment, then neither is MT19973 a "32-bit PRNG", which makes me think that's a classification that's important to you.
And it does make a difference.
Well, that's fine. It doesn't make a difference to me, and if all you can say about the difference that it exists, I cannot imagine it's an important difference.

Replies are listed 'Best First'.
Re^14: How likely is rand() to repeat?
by BrowserUk (Patriarch) on Mar 09, 2012 at 21:09 UTC

    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?

      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?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://958794]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2024-04-18 16:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found