summary refs log tree commit diff stats
path: root/lib/pure/random.nim
diff options
context:
space:
mode:
authorMiran <narimiran@disroot.org>2019-04-11 08:38:18 +0200
committerAndreas Rumpf <rumpf_a@web.de>2019-04-11 08:38:18 +0200
commit9f94199d0c18077210a710d26a98b94e489579ae (patch)
treebafbcfc68dfee1c766c5a12c1ca3b51beff1f53d /lib/pure/random.nim
parent2846156e13b26ac566092e394e9900df52059039 (diff)
downloadNim-9f94199d0c18077210a710d26a98b94e489579ae.tar.gz
random: works for slices and enums, fixes #7698 (#10998)
Diffstat (limited to 'lib/pure/random.nim')
-rw-r--r--lib/pure/random.nim6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/pure/random.nim b/lib/pure/random.nim
index 4115d147b..e29ad7955 100644
--- a/lib/pure/random.nim
+++ b/lib/pure/random.nim
@@ -318,7 +318,7 @@ proc rand*(max: float): float {.benign.} =
     ## f = 8.717181376738381e-07
   rand(state, max)
 
-proc rand*[T](r: var Rand; x: HSlice[T, T]): T =
+proc rand*[T: Ordinal](r: var Rand; x: HSlice[T, T]): T =
   ## For a slice `a..b`, returns a value in the range `a..b` using the given
   ## state.
   ##
@@ -333,9 +333,9 @@ proc rand*[T](r: var Rand; x: HSlice[T, T]): T =
     doAssert r.rand(1..6) == 4
     doAssert r.rand(1..6) == 4
     doAssert r.rand(1..6) == 6
-  result = T(rand(r, x.b - x.a)) + x.a
+  result = T(rand(r, int(x.b) - int(x.a)) + int(x.a))
 
-proc rand*[T](x: HSlice[T, T]): T =
+proc rand*[T: Ordinal](x: HSlice[T, T]): T =
   ## For a slice `a..b`, returns a value in the range `a..b`.
   ##
   ## If `randomize<#randomize>`_ has not been called, the sequence of random