summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2019-11-23 10:22:13 (GMT)
committerGitHub <noreply@github.com>2019-11-23 10:22:13 (GMT)
commit041d8b48a2e59fa642b2c5124d78086baf74e339 (patch)
treef189a49ce0107fdeef9eeb75e9e6c63fb169e83c /Doc
parent84b1ff65609c5910b4f838adbe1ead83baae7dbf (diff)
downloadcpython-041d8b48a2e59fa642b2c5124d78086baf74e339.zip
cpython-041d8b48a2e59fa642b2c5124d78086baf74e339.tar.gz
cpython-041d8b48a2e59fa642b2c5124d78086baf74e339.tar.bz2
bpo-38881: choices() raises ValueError when all weights are zero (GH-17362)
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/random.rst8
1 files changed, 6 insertions, 2 deletions
diff --git a/Doc/library/random.rst b/Doc/library/random.rst
index 1bd1856..933da3f 100644
--- a/Doc/library/random.rst
+++ b/Doc/library/random.rst
@@ -165,8 +165,9 @@ Functions for sequences
The *weights* or *cum_weights* can use any numeric type that interoperates
with the :class:`float` values returned by :func:`random` (that includes
- integers, floats, and fractions but excludes decimals). Weights are
- assumed to be non-negative.
+ integers, floats, and fractions but excludes decimals). Behavior is
+ undefined if any weight is negative. A :exc:`ValueError` is raised if all
+ weights are zero.
For a given seed, the :func:`choices` function with equal weighting
typically produces a different sequence than repeated calls to
@@ -177,6 +178,9 @@ Functions for sequences
.. versionadded:: 3.6
+ .. versionchanged:: 3.9
+ Raises a :exc:`ValueError` if all weights are zero.
+
.. function:: shuffle(x[, random])