sysl

Module

sysl.rand

rng Rng

Import import sysl.rand
Requires
no alloc

Index

rng Rng

Functions

rng

rng(seed: u64, seq: u64) -> Rng

A generator from a seed and a stream selector.

Two arguments, because the stream is not the seed. Two generators with the same seed and different seq produce different, equally good sequences – which is what a program wanting several independent streams from one seed needs, and what seeding several generators from consecutive seeds does not reliably give.

The initialization is the reference implementation’s: the increment is made odd, the state is advanced once, the seed is added, and the state is advanced again. The two steps are what stop a seed of zero from being a special case.

Types

Rng

struct Rng
    state: u64
    inc: u64

A generator: sixty-four bits of state, and the odd increment that selects one of 2^63 distinct streams.

A copy of an Rng is an independent generator continuing from the same point, which is a useful thing rather than an accident – it is how a simulation replays a branch from a saved position.

MemberSignatureDescription
next_u32next_u32(*self) -> u32The next 32 bits.
next_u64next_u64(*self) -> u64Sixty-four bits, as two draws with the first taken as the high half.
booleanboolean(*self) -> boolOne bit, taken from the top of a draw rather than the bottom.
belowbelow(*self, n: u64) -> u64A uniform value in [0, n), with no modulo bias.
rangerange(*self, lo: i64, hi: i64) -> i64A uniform value in [lo, hi), empty when hi is not above lo.
unitunit(*self) -> realA uniform value in [0, 1), from 53 bits.
shuffleshuffle[T](*self, xs: []T)The elements rearranged, every permutation equally likely.

Search

Esc
to navigate to open Esc to close