summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2016-11-17 09:50:16 (GMT)
committerRaymond Hettinger <python@rcn.com>2016-11-17 09:50:16 (GMT)
commitf0cb7f4a7e4e7ee478db517772144fab56040e0d (patch)
tree6f77caa797e31a61a210ea6d2371a1a45e4887c2 /Doc
parentb2d6bd0fbdec08dc10638ad7d63db1a77482c04a (diff)
parenta3950e42b0806c3a2d350561c80221993b596e7d (diff)
downloadcpython-f0cb7f4a7e4e7ee478db517772144fab56040e0d.zip
cpython-f0cb7f4a7e4e7ee478db517772144fab56040e0d.tar.gz
cpython-f0cb7f4a7e4e7ee478db517772144fab56040e0d.tar.bz2
merge
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/random.rst22
1 files changed, 14 insertions, 8 deletions
diff --git a/Doc/library/random.rst b/Doc/library/random.rst
index 3d0abbb..43c07dd 100644
--- a/Doc/library/random.rst
+++ b/Doc/library/random.rst
@@ -152,13 +152,19 @@ Functions for sequences:
.. function:: shuffle(x[, random])
- Shuffle the sequence *x* in place. The optional argument *random* is a
- 0-argument function returning a random float in [0.0, 1.0); by default, this is
- the function :func:`.random`.
+ Shuffle the sequence *x* in place.
- 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.
+ The optional argument *random* is a 0-argument function returning a random
+ float in [0.0, 1.0); by default, this is the function :func:`.random`.
+
+ To shuffle an immutable sequence and return a new shuffled list, use
+ ``sample(x, k=len(x))`` instead.
+
+ Note that even for small ``len(x)``, the total number of permutations of *x*
+ can quickly grow larger than the period of most random number generators.
+ This implies that most permutations of a long sequence can never be
+ generated. For example, a sequence of length 2080 is the largest that
+ can fit within the period of the Mersenne Twister random number generator.
.. function:: sample(population, k)
@@ -175,9 +181,9 @@ Functions for sequences:
Members of the population need not be :term:`hashable` or unique. If the population
contains repeats, then each occurrence is a possible selection in the sample.
- To choose a sample from a range of integers, use an :func:`range` object as an
+ To choose a sample from a range of integers, use a :func:`range` object as an
argument. This is especially fast and space efficient for sampling from a large
- population: ``sample(range(10000000), 60)``.
+ population: ``sample(range(10000000), k=60)``.
If the sample size is larger than the population size, a :exc:`ValueError`
is raised.