summaryrefslogtreecommitdiffstats
path: root/Doc/lib/librandom.tex
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2002-11-12 17:41:57 (GMT)
committerRaymond Hettinger <python@rcn.com>2002-11-12 17:41:57 (GMT)
commitf24eb35d185c0623315cfbd9977d37c509860dcf (patch)
tree336a055089a3bd51d89bf4fdc987fb90ce743e09 /Doc/lib/librandom.tex
parent3a7ad5c5843467dc67ddf4c6622dd466f0f42c74 (diff)
downloadcpython-f24eb35d185c0623315cfbd9977d37c509860dcf.zip
cpython-f24eb35d185c0623315cfbd9977d37c509860dcf.tar.gz
cpython-f24eb35d185c0623315cfbd9977d37c509860dcf.tar.bz2
SF patch 629637: Add sample(population, k) method to the random module.
Used for random sampling without replacement.
Diffstat (limited to 'Doc/lib/librandom.tex')
-rw-r--r--Doc/lib/librandom.tex19
1 files changed, 19 insertions, 0 deletions
diff --git a/Doc/lib/librandom.tex b/Doc/lib/librandom.tex
index 846b931..15e477b 100644
--- a/Doc/lib/librandom.tex
+++ b/Doc/lib/librandom.tex
@@ -179,6 +179,25 @@ Functions for sequences:
long sequence can never be generated.
\end{funcdesc}
+\begin{funcdesc}{sample}{population, k}
+ Return a \var{k} length list of unique elements chosen from the
+ population sequence. Used for random sampling without replacement.
+
+ Returns a new list containing elements from the population. The
+ list itself is in random order so that all sub-slices are also
+ random samples. The original sequence is left undisturbed.
+
+ If the population has repeated elements, then each occurence is a
+ possible selection in the sample.
+
+ If indices are needed for a large population, use \function{xrange}
+ as an argument: \code{sample(xrange(10000000), 60)}.
+
+ Optional argument random is a 0-argument function returning a random
+ float in [0.0, 1.0); by default, the standard random.random.
+ \versionadded{2.3}
+\end{funcdesc}
+
The following functions generate specific real-valued distributions.
Function parameters are named after the corresponding variables in the