diff options
author | Araq <rumpf_a@web.de> | 2014-08-14 00:02:39 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-08-14 00:02:39 +0200 |
commit | 27b9d10570078c35a5d1b59010ccc6c1a3927f04 (patch) | |
tree | ffb852b72130f8de8026f961edfca296ab221e06 /lib/pure/math.nim | |
parent | f3d530e482249215da56cf1898edd20b51d4480d (diff) | |
parent | add0a0e9bc5383923eef9c764788feb810f8edc6 (diff) | |
download | Nim-27b9d10570078c35a5d1b59010ccc6c1a3927f04.tar.gz |
Merge branch 'devel' of https://github.com/Araq/Nimrod into devel
Diffstat (limited to 'lib/pure/math.nim')
-rw-r--r-- | lib/pure/math.nim | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/pure/math.nim b/lib/pure/math.nim index e76e96da5..8af09114b 100644 --- a/lib/pure/math.nim +++ b/lib/pure/math.nim @@ -279,8 +279,13 @@ proc `mod`*(x, y: float): float = result = if y == 0.0: x else: x - y * (x/y).floor proc random*[T](x: TSlice[T]): T = + ## For a slice `a .. b` returns a value in the range `a .. b-1`. result = random(x.b - x.a) + x.a - + +proc random[T](a: openarray[T]): T = + ## returns a random element from the openarray `a`. + result = a[random(a.low..a.len)] + type TRunningStat* {.pure,final.} = object ## an accumulator for statistical data n*: int ## number of pushed data |