Module random

This module is just a convenience import. It exports random.mersenne and random.urandom and defines a global instance of Mersenne twister with alias procedures that use this instance.

Vars

mersenneTwisterInst: MersenneTwister

A global instance of Mersenne twister used by the alias functions of this module.

When the module is imported, it is seeded using an array of bytes provided by urandom, or, in case of failure, using the current time.

Due to this silent fallback and the fact that any other code can use this global instance (and there is no thread safety), it is not recommended to use it (through the functions in this module or otherwise) if you have any concerns for security.

  Source

Procs

proc randomInt[](T: typedesc[SomeInteger]): T:type {.inline.}
  Source
proc randomByte(): uint8 {.inline, deprecated, raises: [], tags: [].}
  Source
proc randomInt(max: Positive): Natural {.inline, raises: [], tags: [].}
  Source
proc randomInt(min, max: int): int {.inline, raises: [], tags: [].}
  Source
proc randomInt(range: Slice[int]): int {.inline, raises: [], tags: [].}
  Source
proc randomBool(): bool {.inline, raises: [], tags: [].}
  Source
proc random(): float64 {.inline, raises: [], tags: [].}
  Source
proc random(max: float): float {.inline, raises: [], tags: [].}
  Source
proc random(min, max: float): float {.inline, raises: [], tags: [].}
  Source
proc randomPrecise(): float64 {.inline, raises: [], tags: [].}
  Source
proc randomChoice[RAContainer](arr: RAContainer): auto {.inline.}
  Source
proc shuffle[RAContainer](arr: var RAContainer) {.inline.}
  Source
proc randomSample[T](iter: iterator (): T; n: Natural): seq[T] {.inline.}
  Source

Iterators

iterator randomSample(range: Slice[int]; n: Natural): int {.inline, 
    raises: [ValueError], tags: [].}
  Source
iterator randomSample[RAContainer](arr: RAContainer; n: Natural): auto {.inline.}
  Source