/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 purposes!

times

## Types

```Rand = object
a0, a1: ui```
State of the random number generator. The procs that use the default state are not thread-safe!

## Procs

`proc next(r: var Rand): uint64 {...}{.raises: [], tags: [].}`
Uses the state to compute a new `uint64` random number.
`proc skipRandomNumbers(s: var Rand) {...}{.raises: [], tags: [].}`
This is the jump function for the generator. It is equivalent to 2^64 calls to next(); it can be used to generate 2^64 non-overlapping subsequences for parallel computations.
`proc random(max: int): int {...}{.gcsafe, locks: 0, deprecated, 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. Deprecated since version 0.18.0. Use `rand` instead.
`proc random(max: float): float {...}{.gcsafe, locks: 0, deprecated, 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. Deprecated since version 0.18.0. Use `rand` instead.
`proc random[T](x: HSlice[T, T]): T {...}{.deprecated.}`
For a slice a .. b returns a value in the range a .. b-1. Deprecated since version 0.18.0. Use `rand` instead.
`proc random[T](a: openArray[T]): T {...}{.deprecated.}`
returns a random element from the openarray a. Deprecated since version 0.18.0. Use `rand` instead.
`proc rand(r: var Rand; max: Natural): int {...}{.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 rand(max: int): int {...}{.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 rand(r: var Rand; max: range[0.0 .. high(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 rand(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 rand[T](r: var Rand; x: HSlice[T, T]): T`
For a slice a .. b returns a value in the range a .. b.
`proc rand[T](x: HSlice[T, T]): T`
For a slice a .. b returns a value in the range a .. b.
`proc rand[T](r: var Rand; a: openArray[T]): T`
returns a random element from the openarray a.
`proc rand[T](a: openArray[T]): T`
returns a random element from the openarray a.
`proc initRand(seed: int64): Rand {...}{.raises: [], tags: [].}`
Creates a new `Rand` state from `seed`.
`proc randomize(seed: int64) {...}{.gcsafe, locks: 0, raises: [], tags: [].}`
Initializes the default random number generator with a specific seed.
`proc shuffle[T](r: var Rand; x: var openArray[T])`
Swaps the positions of elements in a sequence randomly.
`proc shuffle[T](x: var openArray[T])`
Swaps the positions of elements in a sequence randomly.
`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.