summaryrefslogtreecommitdiffstats
path: root/Lib/random.py
diff options
context:
space:
mode:
authorWolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de>2018-04-05 15:19:44 (GMT)
committerRaymond Hettinger <rhettinger@users.noreply.github.com>2018-04-05 15:19:44 (GMT)
commit091e95e9004b794280ab35becec2c3e30dd5e96e (patch)
tree72be905acc5dd7a26b7a90a3d14efb58b99cbcad /Lib/random.py
parent74940913d26d9f94b8572eca794369841fa6d9b6 (diff)
downloadcpython-091e95e9004b794280ab35becec2c3e30dd5e96e.zip
cpython-091e95e9004b794280ab35becec2c3e30dd5e96e.tar.gz
cpython-091e95e9004b794280ab35becec2c3e30dd5e96e.tar.bz2
bpo-33203: Ensure random.choice always raises IndexError on empty sequence (GH-6338)
Diffstat (limited to 'Lib/random.py')
-rw-r--r--Lib/random.py2
1 files changed, 2 insertions, 0 deletions
diff --git a/Lib/random.py b/Lib/random.py
index 91065b7..0bc2417 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -242,6 +242,8 @@ class Random(_random.Random):
"enough bits to choose from a population range this large.\n"
"To remove the range limitation, add a getrandbits() method.")
return int(random() * n)
+ if n == 0:
+ raise ValueError("Boundary cannot be zero")
rem = maxsize % n
limit = (maxsize - rem) / maxsize # int(limit * maxsize) % n == 0
r = random()