diff options
author | narimiran <narimiran@disroot.org> | 2019-09-27 10:55:18 +0200 |
---|---|---|
committer | narimiran <narimiran@disroot.org> | 2019-09-30 13:58:05 +0200 |
commit | 6c994b24980413bcef1808cbff47c9d80bc4fa91 (patch) | |
tree | e19071d6081f1e127aa9e6bf56075facbcbd9eb8 /lib/pure/random.nim | |
parent | aa513d78e7d966ef2d31866835d2263fe7481357 (diff) | |
download | Nim-6c994b24980413bcef1808cbff47c9d80bc4fa91.tar.gz |
[backport] run nimpretty on numbers stuff
Diffstat (limited to 'lib/pure/random.nim')
-rw-r--r-- | lib/pure/random.nim | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/lib/pure/random.nim b/lib/pure/random.nim index 9abbe947e..c3ccd121b 100644 --- a/lib/pure/random.nim +++ b/lib/pure/random.nim @@ -78,10 +78,10 @@ ## <lib.html#pure-libraries-cryptography-and-hashing>`_ ## in the standard library -import algorithm #For upperBound +import algorithm #For upperBound include "system/inclrtl" -{.push debugger:off.} +{.push debugger: off.} when defined(JS): type ui = uint32 @@ -94,18 +94,18 @@ else: type Rand* = object ## State of a random number generator. - ## - ## Create a new Rand state using the `initRand proc<#initRand,int64>`_. - ## - ## The module contains a default Rand state for convenience. - ## It corresponds to the default random number generator's state. - ## The default Rand state always starts with the same values, but the - ## `randomize proc<#randomize>`_ can be used to seed the default generator - ## with a value based on the current time. - ## - ## Many procs have two variations: one that takes in a Rand parameter and - ## another that uses the default generator. The procs that use the default - ## generator are **not** thread-safe! + ## + ## Create a new Rand state using the `initRand proc<#initRand,int64>`_. + ## + ## The module contains a default Rand state for convenience. + ## It corresponds to the default random number generator's state. + ## The default Rand state always starts with the same values, but the + ## `randomize proc<#randomize>`_ can be used to seed the default generator + ## with a value based on the current time. + ## + ## Many procs have two variations: one that takes in a Rand parameter and + ## another that uses the default generator. The procs that use the default + ## generator are **not** thread-safe! a0, a1: ui when defined(JS): @@ -481,7 +481,7 @@ proc sample*[T](a: openArray[T]): T = doAssert sample(marbles) == "red" result = a[rand(a.low..a.high)] -proc sample*[T, U](r: var Rand; a: openArray[T], cdf: openArray[U]): T = +proc sample*[T, U](r: var Rand; a: openArray[T]; cdf: openArray[U]): T = ## Returns an element from ``a`` using a cumulative distribution function ## (CDF) and the given state. ## @@ -509,14 +509,14 @@ proc sample*[T, U](r: var Rand; a: openArray[T], cdf: openArray[U]): T = doAssert r.sample(marbles, cdf) == "red" doAssert r.sample(marbles, cdf) == "green" doAssert r.sample(marbles, cdf) == "blue" - assert(cdf.len == a.len) # Two basic sanity checks. + assert(cdf.len == a.len) # Two basic sanity checks. assert(float(cdf[^1]) > 0.0) #While we could check cdf[i-1] <= cdf[i] for i in 1..cdf.len, that could get #awfully expensive even in debugging modes. let u = r.rand(float(cdf[^1])) a[cdf.upperBound(U(u))] -proc sample*[T, U](a: openArray[T], cdf: openArray[U]): T = +proc sample*[T, U](a: openArray[T]; cdf: openArray[U]): T = ## Returns an element from ``a`` using a cumulative distribution function ## (CDF). ## |