W3cubDocs

/Nim

Module random

Nim's standard random number generator. Based on the xoroshiro128+ (xor/rotate/shift/rotate) library.

Do not use this module for cryptographic use!

Imports

times

Procs

proc random(max: int): int {.gcsafe, locks: 0, raises: [], tags: [].}
Returns a random number in the range 0..max-1. The sequence of random number is always the same, unless randomize is called which initializes the random number generator with a "random" number, i.e. a tickcount.
proc random(max: float): float {.gcsafe, locks: 0, raises: [], tags: [].}
Returns a random number in the range 0..<max. The sequence of random number is always the same, unless randomize is called which initializes the random number generator with a "random" number, i.e. a tickcount.
proc random[T](x: Slice[T]): T
For a slice a .. b returns a value in the range a .. b-1.
proc random[T](a: openArray[T]): T
returns a random element from the openarray a.
proc randomize(seed: int64) {.gcsafe, locks: 0, raises: [], tags: [].}
Initializes the random number generator with a specific seed.
proc shuffle[T](x: var openArray[T])
Will randomly swap the positions of elements in a sequence.
proc randomize() {.gcsafe, locks: 0, raises: [], tags: [TimeEffect].}
Initializes the random number generator with a "random" number, i.e. a tickcount. Note: Does not work for NimScript.

© 2006–2017 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/random.html