Lyricdev
GitHub

class Random

pub class Random

A generator of random numbers: ChaCha8 (eight rounds), 64 bits a draw.

Methods

pub static fn seeded(seed: uint64): Random

Returns the generator whose stream seed names.

The same seed gives the same stream in every 5.x.

pub static fn fresh(): Random

Returns a generator keyed from 32 of the system's random bytes, a stream no run repeats.

pub mut fn nextUint64(): uint64

Returns the next 64 bits of the stream.

pub mut fn nextInt(): int

Returns the next 64 bits as an int, each value from int.min to int.max alike.

pub mut fn nextInRange(r: Range<int>): int

Returns an integer of r, each alike.

Draws that would favour the low results are rejected and drawn again, so a call can take more than one draw.

Panics

Panics if r is empty.

pub mut fn nextFloat(): float

Returns a float in [0, 1) from the high 53 bits of a draw, each value of that grid alike.

pub mut fn nextBool(): bool

Returns true or false, alike, from the high bit of a draw.

pub mut fn nextBytes(into: Slice<uint8>): void

Fills into with random bytes.

Each draw gives eight bytes, the low byte first; a tail of fewer than eight takes a draw's low bytes.

pub mut fn nextNormal(mean: float = 0.0, stdDev: float = 1.0): float

Returns a normally distributed float with the given mean and standard deviation.

Uses Marsaglia's polar method: two draws a try, a try taken inside the unit circle, one of the pair it makes kept.

pub mut fn shuffle<T>(s: Slice<T>): void

Shuffles s in place, each of its orders alike (Fisher–Yates, from the back).

pub mut fn choice<T>(s: Slice<T>): ?T

Returns an element of s, each alike.

Returns null for an empty slice, without drawing.

pub mut fn sample<T>(s: Slice<T>, k: int): T[]

Returns k elements of s from k different places, in a random order.

Panics

Panics if k is negative or greater than the length of s.