Skip to content

Commit 40ebe94

Browse files
authored
Document differences between random.choices() and random.choice(). (GH-11703)
1 parent cf991e6 commit 40ebe94

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Doc/library/random.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ Functions for sequences
162162
with the :class:`float` values returned by :func:`random` (that includes
163163
integers, floats, and fractions but excludes decimals).
164164

165+
For a given seed, the :func:`choices` function with equal weighting
166+
typically produces a different sequence than repeated calls to
167+
:func:`choice`. The algorithm used by :func:`choices` uses floating
168+
point arithmetic for internal consistency and speed. The algorithm used
169+
by :func:`choice` defaults to integer arithmetic with repeated selections
170+
to avoid small biases from round-off error.
171+
165172
.. versionadded:: 3.6
166173

167174

0 commit comments

Comments
 (0)