I want to shuffle a long sequence (say it has more than 10,000 elements) many times (say 10,000). While reading the Python Random documentation, I found the following:
Note that even for small len (x), the total number of permutations x can grow rapidly more than the period of most random number generators. This means that most permutations of a long sequence can never be generated. For example, a sequence of length 2080 is the largest that can fit into the period of the Mersenne Twister random number generator
I have two groups (maybe more), and each has many meanings. The sequence I want to shuffle is a list of all available values, regardless of group. My concern is that the note implies that the shuffle I need may not be provided by the random.shuffle () function.
I thought of some workarounds:
- Initialize a random number generator (with random.seed ()) several in certain iterations. Thus, it does not matter if the permutations are more than a period, because different seeds will get different results.
- Use a pattern (range (sequence length), k = group size) to get random indexes and then use them to index inside each group. Thus, I cannot get out of permutations due to the period of the random number generator.
Did any of my alternatives help?
Thanks a lot!
source share