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

Which as each pick is 'independant' of the previous and next picks, it increases the effective entropy.
But that's exactly the problem. As I indicated, if rand() would be perfect, it will pick each of the 645345427773512447880377451634304602899218432 different possible string with an equal chance.

But with most implementations of rand the picks are not independant; the sequence of return values of rand is completely determined by the value of the seed. If srand takes a 64 bit number as argument, then there are at most 264 sequences of return values of rand() possible. But that requires an excellent implementation of rand(), and you got to be lucky enough the mapping to 0..61 doesn't provide duplicates.

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

    Let's say we were on a 2 bit processor and we had a 2-bit PRNG. There could only be 22 starting points (seeds).

    But the (non-repeating) sequences it could produce are any permutation of the following 24 permutations of the 4 basic values it can produce:

    {0, 1, 2, 3} | {0, 1, 3, 2} | {0, 2, 1, 3} | {0, 2, 3, 1} | {0, 3, 1, 2} | {0, 3, 2, 1} | {1, 0, 2, 3} | {1, 0, 3, 2} | {1, 2, 0, 3} | {1, 2, 3, 0} | {1, 3, 0, 2} | {1, 3, 2, 0} | {2, 0, 1, 3} | {2, 0, 3, 1} | {2, 1, 0, 3} | {2, 1, 3, 0} | {2, 3, 0, 1} | {2, 3, 1, 0} | {3, 0, 1, 2} | {3, 0, 2, 1} | {3, 1, 0, 2} | {3, 1, 2, 0} | {3, 2, 0, 1} | {3, 2, 1, 0}

    Hence, the 32-bit, Mersenne Twister MT19937 can produce 219937 - 1 values (from any given starting point) before it repeats itself exactly.


    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?

      But the (non-repeating) sequences it could produce are any permutation of the following 24 permutations of the 4 basic values it can produce:
      Can you explain how it does that? Given just four different values for the seed, how can you pick from 24, with each element having a chance to be selected?
      Hence, the 32-bit, Mersenne Twister MT19937 can produce 219937 - 1 values (from any given starting point) before it repeats itself exactly.
      Sure. But how many different such sequences can it make? Looking at the pseudo code implementation on Wikipedia, it's all derived from a single, 32-bit seed. Which would limit the number of possible sequences to 232.
        Given just four different values for the seed, how can you pick from 24,

        I didn't say it could generate all those sequences. Only that from any given starting point, the non-repeating sequence could be any permutation of those 24 permutations.

        Sure. But how many different such sequences can it make?

        That's the wrong question. When generating the OPs 25-char sequences, you don't re-seed before starting each new sequence. You seed (implicitely) once and then follow that sequence until you have enough.

        Therefore the upper bound is the length of the non-repeating sequence (the period) the prng can generate. (4.31e+6001 in the Mersenne Twister).

        Of course, that is further constrained because of the modulo operation to bring the generated random values into the 0 .. 61 range. hence 6.45e44.

        For the 15-bit RCPRNG built-in to perl on win32, the period (at least when seeded(1), seems (by experiment) to be 214741815.

        Which looks suspiciously close to 2^31, but not quite.


        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?