diff options
author | Raymond Hettinger <python@rcn.com> | 2002-11-18 09:01:24 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2002-11-18 09:01:24 (GMT) |
commit | 311f4196284b894f86f56c287c71a0e59c4a72a2 (patch) | |
tree | edb7dfe9556fe53b3e55c75dfd3f707cbf7daf15 /Doc/lib/librandom.tex | |
parent | 8ddc176e2e7ef11b2c46062b29563bc776f177b8 (diff) | |
download | cpython-311f4196284b894f86f56c287c71a0e59c4a72a2.zip cpython-311f4196284b894f86f56c287c71a0e59c4a72a2.tar.gz cpython-311f4196284b894f86f56c287c71a0e59c4a72a2.tar.bz2 |
Improve comments. Clarify docs.
Replace "type(0)" with "int".
Replace "while 1" with "while True"
Diffstat (limited to 'Doc/lib/librandom.tex')
-rw-r--r-- | Doc/lib/librandom.tex | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/Doc/lib/librandom.tex b/Doc/lib/librandom.tex index 15e477b..1783659 100644 --- a/Doc/lib/librandom.tex +++ b/Doc/lib/librandom.tex @@ -182,20 +182,21 @@ Functions for sequences: \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. + \versionadded{2.3} - 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. + Returns a new list containing elements from the population while + leaving the original population unchanged. The resulting list is + in selection order so that all sub-slices will also be valid random + samples. This allows raffle winners (the sample) to be partitioned + into grand prize and second place winners (the subslices). - If indices are needed for a large population, use \function{xrange} - as an argument: \code{sample(xrange(10000000), 60)}. + Members of the population need not be hashable or unique. If the + population contains repeats, then each occurrence is a possible + selection in the sample. - 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} + To choose a sample from a range of integers, use \function{xrange} + as an argument. This is especially fast and space efficient for + sampling from a large population: \code{sample(xrange(10000000), 60)}. \end{funcdesc} |