[Python-checkins] Document differences between random.choices() and random.choice(). (GH-11703) (GH-11706)

Raymond Hettinger webhook-mailer at python.org
Wed Jan 30 16:49:26 EST 2019


https://github.com/python/cpython/commit/e31f8604e692c46800abd70f88d9928fa1f17b7c
commit: e31f8604e692c46800abd70f88d9928fa1f17b7c
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Raymond Hettinger <rhettinger at users.noreply.github.com>
date: 2019-01-30T13:49:23-08:00
summary:

Document differences between random.choices() and random.choice(). (GH-11703) (GH-11706)

files:
M Doc/library/random.rst

diff --git a/Doc/library/random.rst b/Doc/library/random.rst
index 4f251574a327..a543ff016a62 100644
--- a/Doc/library/random.rst
+++ b/Doc/library/random.rst
@@ -162,6 +162,13 @@ Functions for sequences
    with the :class:`float` values returned by :func:`random` (that includes
    integers, floats, and fractions but excludes decimals).
 
+   For a given seed, the :func:`choices` function with equal weighting
+   typically produces a different sequence than repeated calls to
+   :func:`choice`.  The algorithm used by :func:`choices` uses floating
+   point arithmetic for internal consistency and speed.  The algorithm used
+   by :func:`choice` defaults to integer arithmetic with repeated selections
+   to avoid small biases from round-off error.
+
    .. versionadded:: 3.6
 
 



More information about the Python-checkins mailing list