summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
authorArne Döring <arne.doering@gmx.net>2019-01-14 09:20:31 +0100
committerAndreas Rumpf <rumpf_a@web.de>2019-01-14 09:20:31 +0100
commit2b37bf5d5bf9e9ee7cd387fa455df8931f8e6666 (patch)
treec1a6656676505b9bb83af1c9fd03c3b750fcb0a4 /lib/pure
parentd983d998b25dc1eda004b2483d620315e9ea64b2 (diff)
downloadNim-2b37bf5d5bf9e9ee7cd387fa455df8931f8e6666.tar.gz
added proc rand for typedesc (#10259)
Diffstat (limited to 'lib/pure')
-rw-r--r--lib/pure/random.nim6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/pure/random.nim b/lib/pure/random.nim
index ee728ad4a..378ca6f87 100644
--- a/lib/pure/random.nim
+++ b/lib/pure/random.nim
@@ -158,10 +158,14 @@ proc rand*[T](x: HSlice[T, T]): T =
   result = rand(state, x)
 
 proc rand*[T](r: var Rand; a: openArray[T]): T {.deprecated.} =
-  ## returns a random element from the openarray `a`.
+  ## Returns a random element from the openarray `a`.
   ## **Deprecated since v0.20.0:** use ``sample`` instead.
   result = a[rand(r, a.low..a.high)]
 
+proc rand*[T: SomeInteger](t: typedesc[T]): T =
+  ## Returns a random integer in the range `low(T)..high(T)`.
+  result = cast[T](state.next)
+
 proc rand*[T](a: openArray[T]): T {.deprecated.} =
   ## returns a random element from the openarray `a`.
   ## **Deprecated since v0.20.0:** use ``sample`` instead.