[docs] [issue18928] Remove misleading documentation for random.shuffle
report at bugs.python.org
Thu Sep 5 02:18:34 CEST 2013
New submission from David Benbennick:
Since Python 2.1 , when random.shuffle was added, the documentation has said:
"""Note that for even rather small len(x), the total number of permutations of x is larger than the period of most random number generators; this implies that most permutations of a long sequence can never be generated."""
This comment is incorrect and misleading. In fact, I claim that shuffle can produce "all" permutations for any representable sequence.
To shuffle a sequence of length N requires log(N!) ~ N * log(N/e) bits of randomness . The random module provides a generator with "a period of 2**19937-1", meaning you can get 2**19937 bits of randomness out of it before it starts repeating.
All of which is to say that any representable sequence, say N < 2**50, will need no more than 2**60 bits of randomness to shuffle. That is well within the period of the random number generator.
Attached is a patch that deletes the comment.
An illustration of this misconception is at .
assignee: docs at python
nosy: dbenbenn, docs at python
title: Remove misleading documentation for random.shuffle
Added file: http://bugs.python.org/file31593/mywork.patch
Python tracker <report at bugs.python.org>
More information about the docs