Skip to content

Commit 32df6c9

Browse files
committed
fix(Lib): random.randrange(stop) may be stop; fix(py): not ValueError is stop < 1
1 parent 118c5db commit 32df6c9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/pylib/Lib/random_impl/proc_dispatched.nim

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ genGbls:
2727
2828
func randint*[T: SomeInteger](self; a, b: T): T = rnd.rand(a .. b)
2929
30-
func randrange*[T: SomeInteger](self; stop: T): T = rnd.rand stop
30+
func randrange*[T: SomeInteger](self; stop: T): T =
31+
if stop < 1:
32+
raise newException(ValueError, "empty range for randrange()")
33+
rnd.rand stop - 1
3134
func randrange*[T: SomeInteger](self; start, stop: T): T = rnd.rand start..<stop
3235
3336
#template randrange*[T: SomeInteger](start, stop: T; step: int): T =

0 commit comments

Comments
 (0)