Unsorting(randomizing) a sequence

Aahz Maruch aahz at netcom.com
Thu Aug 19 01:01:59 EDT 1999


In article <000701bee917$d8161cc0$eaa22299 at tim>,
Tim Peters <tim_one at email.msn.com> wrote:
>
>I'll save you a near-infinity of work, then <wink>:  Python's Wichmann-Hill
>uniform generator has a period of around 1e12 to 1e13.  Since the point at
>which you begin in the period completely determines the permutation that
>will be generated, you can't get more than 1e13 distinct permutations out of
>it.  So a sequence of length 16 is the longest for which it could even
>conceivably produce all permutations; if you use it to, e.g., shuffle a deck
>of cards, the number of permutations any algorithm based on WH can get back
>is a vanishingly small fraction of the possibilities (since 52! ~= 1e66; we
>can only get back at most 1 of each 1e66/1e13 = 1e53 possibilities).

What happens if you re-seed?

I'm curious because I just wrote some code that re-seeds every hundred
calls to random().  In my case, though, it's necessary because I
actually don't care that much about randomness per se; I'm using it to
generate unique numbers (with duplicate detection), and I need to ensure
that if I ever do happen on the same random number sequence as a
previous run of the process, it gets aborted reasonably quickly.

(This is a temporary hack to deal with an unfortunate choice in hashing
functions until we can switch to some code that uses SQL Server GUIDs.
And, yes, I did find out about Python's hash() function *after* I wrote
this....  <sigh>)
--
                      --- Aahz (@netcom.com)

Androgynous poly kinky vanilla queer het    <*>      http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6  (if you want to know, do some research)




More information about the Python-list mailing list