Simple algorithm question - how to reorder a sequence economically
John Ladasky
john_ladasky at sbcglobal.net
Sat May 25 21:25:16 EDT 2013
On Friday, May 24, 2013 10:33:47 AM UTC-7, Yours Truly wrote:
> If you don't reshuffle p, it guarantees the maximum interval between reusing
> the same permutation.
Of course, that comes at a certain price. Given two permutations p[x] and p[x+1], they will ALWAYS be adjacent, in every repetition of the list, unless you reshuffle. So the "spurious correlation" problem that Peter is worrying about would still exist, albeit at a meta-level.
You could play clever games, such as splitting p in half once you get to the end of it, shuffling each half independently, and then concatenating the halves. This algorithm scrambles the p[x]'s and p[x+1]'s pretty well, at the cost of cutting the average interval between repeats of a given p[x] from len(p) to something closer to len(p)/2.
Because someone's got to say it... "The generation of random numbers is too important to be left to chance." — Robert R. Coveyou
More information about the Python-list
mailing list