Merge pull request #1351 from def-/random-openarrays
Add random() for openarrays
This commit is contained in:
commit
add0a0e9bc
1 changed files with 6 additions and 1 deletions
|
|
@ -279,8 +279,13 @@ proc `mod`*(x, y: float): float =
|
||||||
result = if y == 0.0: x else: x - y * (x/y).floor
|
result = if y == 0.0: x else: x - y * (x/y).floor
|
||||||
|
|
||||||
proc random*[T](x: TSlice[T]): T =
|
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
|
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
|
type
|
||||||
TRunningStat* {.pure,final.} = object ## an accumulator for statistical data
|
TRunningStat* {.pure,final.} = object ## an accumulator for statistical data
|
||||||
n*: int ## number of pushed data
|
n*: int ## number of pushed data
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue