moonrand 0.1.0 · MIT
moonbitstack / moonrand

moonrand

A seedable pseudo-random number generator.

ChaCha12 at the core, fourteen draws on top, one Rng contract underneath. Thirty-two bytes fix the whole stream — and the same stream comes out bit for bit on native, JS, wasm and wasm-gc.

moon addmoonbitstack/moonrand
掷 32 bytes in, one stream out

01 / overview

One seed in, one stream outwhat it does

moonrand does one thing: it turns a seed into a reproducible stream, and the stream into the shape you asked for — uniform, normal, gamma, Poisson, integers, bits. The default generator needs no configuration; when the algorithm matters, pick one of the eleven subpackages.

The core is ChaCha12: Daniel J. Bernstein's ARX stream cipher, twelve rounds. Not a linear congruential generator — the low bits do not degrade, and a few million draws in a row still show no stripe. One stream runs for 232 blocks of sixty-four bytes; after that you reseed, and it never loops back to the start.

// three methods; everything else grows on top pub(open) trait Rng { fn next_u64(Self) -> UInt64 fn next_u32(Self) -> UInt = _ fn fill(Self, FixedArray[Byte]) -> Unit = _ }

Every sampling and distribution function takes the same Rng. Pass a StdRng, a xoshiro, a PCG, a Mersenne Twister, or your own implementation — the signatures are not tied to a concrete type.

02 / start

Two lines to beginquick start

// 32 bytes. Where they come from is your business let rng = @auto.rng() // platform entropy, 32 bytes // or a fixed seed, reproducible let again = @moonrand.seeded(b"a seed") // from here, every number comes out of this stream let u = @moonrand.uniform(rng, 0.0, 1.0) // [0, 1) let n = @moonrand.randint(rng, 1, 6) // 1..6 let g = @moonrand.gauss(rng, 0.0, 1.0) // N(0, 1)

seeded takes a BytesView and returns a StdRng, which is ChaCha12 under a shorter name. Same bytes, same stream, forever; change one byte and the whole stream changes. To use another algorithm, build a type from @xoshiro or @pcg instead: not one line below changes.

No seed at hand? @auto.rng() asks the platform for thirty-two bytes and hands you a stream that cannot be reproduced. This path raises — it does not quietly degrade into something deterministic, it tells you the machine has no entropy.

03 / guarantees

Three, no morewhat it guarantees

01

Bit-for-bit reproducible

One seed, four backends (native / js / wasm / wasm-gc), one sequence of numbers. The RFC 8439 vectors are pinned in the test suite; a single wrong bit turns it red.

02

No hidden state

A generator is a value, not a global singleton. Two streams can sit side by side in one function without touching each other; copy one and it continues from the same place.

03

Entropy is not here

moonrand never touches the operating system. For real randomness, go to moonseed; for reproducibility, go to seeded. Keeping them apart is what stops either from deciding for you.

04 / api

The whole surfaceroot, contract, core

Left is the signature, right is the shape it promises. Functions take Rng first; the types and contracts follow.

moonbitstack/moonrand22 functions · 1 alias
pub fn seeded(seed : BytesView) -> StdRng
Start from thirty-two bytes. The same bytes give the same stream, bit for bit on all four backends.
random(rng : R) -> Double
A real in [0, 1) with exactly fifty-three bits, the same draw as Python's random().
uniform(rng : R, low : Double, high : Double) -> Double
Anywhere in [low, high), equally thick. Reversed ends are taken as given.
randint(rng : R, low : Int64, high : Int64) -> Int64
An integer, both ends included. A high below low returns low.
randrange(rng : R, stop : Int64, start~ : Int64 = 0, step? : Int64) -> Int64
An integer, right end excluded, with an optional start and step. An empty range or a zero step aborts.
getrandbits(rng : R, k : Int32) -> UInt64
The low k bits, not one more. Above sixty-four, the whole word comes back.
choice(rng : R, items : ArrayView[T]) -> T?
Take one, or None when there is nothing to take.
choices(rng : R, items : ArrayView[T], k~ : Int32 = 1, weights? : ArrayView[Double]) -> Array[T]
Take k with replacement; give weights and the draws follow them. All-zero weights are read as none.
sample(rng : R, items : ArrayView[T], k : Int32) -> Array[T]
Take k without replacement, no repeats. A k past the end takes all of them.
shuffle(rng : R, a : Array[T]) -> Unit
Shuffle in place. Every element stays, no position does.
gauss(rng : R, mu~ : Double = 0.0, sigma~ : Double = 1.0) -> Double
One normal draw by Box–Muller, centred on mu, as wide as sigma.
expovariate(rng : R, lambd : Double) -> Double
One exponential draw at rate lambda, mean its reciprocal. A non-positive rate aborts.
lognormvariate(rng : R, mu~ : Double = 0.0, sigma~ : Double = 1.0) -> Double
One lognormal draw: a normal draw, exponentiated.
pub type StdRng = @chacha.ChaCha12
The default generator's name. Change this line and the whole library follows.
gammavariate(rng : R, alpha : Double, beta : Double) -> Double
One gamma draw by Marsaglia-Tsang: shape alpha, scale beta.
betavariate(rng : R, alpha : Double, beta : Double) -> Double
One beta draw: two gamma draws, one over their sum, in (0, 1).
poisson(rng : R, mu : Double) -> Int64
One Poisson draw with mean mu: multiplication below thirty, transformed rejection above it.
binomialvariate(rng : R, n : Int64, p : Double) -> Int64
The number of successes in n trials of probability p, by inverting the distribution term by term.
triangular(rng : R, low~ : Double = 0.0, high~ : Double = 1.0, mode? : Double) -> Double
One triangular draw peaking at mode, the midpoint when it is not given.
vonmisesvariate(rng : R, mu : Double, kappa : Double) -> Double
One draw on the circle, mean angle mu, concentration kappa, in [0, 2 pi).
paretovariate(rng : R, alpha : Double) -> Double
One Pareto draw of shape alpha: a long tail with no upper bound.
weibullvariate(rng : R, alpha : Double, beta : Double) -> Double
One Weibull draw, scale alpha, shape beta.
normalvariate(rng : R, mu~ : Double = 0.0, sigma~ : Double = 1.0) -> Double
One normal draw by Kinderman-Monahan; the same seed gives a different stream than gauss.
moonbitstack/moonrand/contract3 traits
pub(open) trait Rng {
fn next_u64(Self) -> UInt64
fn next_u32(Self) -> UInt32 = _
fn fill(Self, buf : FixedArray[Byte]) -> Unit = _
}
The contract every generator keeps: uniform machine words. Only next_u64 is yours to write; the other two have defaults.
pub(open) trait Secure : Rng {}
A marker for generators fit for cryptography. Philox and PCG pass the statistics and do not carry it.
pub(open) trait Seeded : Rng {
fn from_seed(BytesView) -> Self
fn seed_size() -> Int32
}
A generator rebuilt from a seed, for reproducible runs. seed_size says how many bytes it wants.
moonbitstack/moonrand/chacha3 types · 24 functions
pub struct ChaCha8
new(seed : BytesView) -> ChaCha8
with_nonce(seed : BytesView, nonce0 : UInt32, nonce1 : UInt32, nonce2 : UInt32, ctr : UInt32)
next_u32() -> UInt32 · next_u64() -> UInt64 · fill(buf : FixedArray[Byte])
Eight rounds: fastest, thinnest margin, for places no key passes through.
pub struct ChaCha12
new(seed : BytesView) -> ChaCha12
with_nonce(seed : BytesView, nonce0 : UInt32, nonce1 : UInt32, nonce2 : UInt32, ctr : UInt32)
next_u32() -> UInt32 · next_u64() -> UInt64 · fill(buf : FixedArray[Byte])
Twelve rounds, the default: the middle of the road between speed and margin.
pub struct ChaCha20
new(seed : BytesView) -> ChaCha20
with_nonce(seed : BytesView, nonce0 : UInt32, nonce1 : UInt32, nonce2 : UInt32, ctr : UInt32)
next_u32() -> UInt32 · next_u64() -> UInt64 · fill(buf : FixedArray[Byte])
Twenty rounds, RFC 8439's count: the widest margin, the least speed.
pub fn ChaCha12::advance(self : ChaCha12, n : UInt64) -> Unit
Skip n 64-bit words by moving the counter, not by drawing them.
pub fn ChaCha8::advance(self : ChaCha8, n : UInt64) -> Unit
As ChaCha12: skip n words.
pub fn ChaCha20::advance(self : ChaCha20, n : UInt64) -> Unit
As ChaCha12: skip n words.
pub fn ChaCha12::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn ChaCha12::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn ChaCha12::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn ChaCha12::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn ChaCha12::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn ChaCha12::seed_size() -> Int32
How many bytes a seed is.
pub fn ChaCha12::with_nonce(BytesView, UInt32, UInt32, UInt32, UInt32) -> Self
Part of the generator's surface.
pub fn ChaCha20::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn ChaCha20::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn ChaCha20::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn ChaCha20::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn ChaCha20::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn ChaCha20::seed_size() -> Int32
How many bytes a seed is.
pub fn ChaCha20::with_nonce(BytesView, UInt32, UInt32, UInt32, UInt32) -> Self
Part of the generator's surface.
pub fn ChaCha8::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn ChaCha8::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn ChaCha8::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn ChaCha8::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn ChaCha8::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn ChaCha8::seed_size() -> Int32
How many bytes a seed is.
pub fn ChaCha8::with_nonce(BytesView, UInt32, UInt32, UInt32, UInt32) -> Self
Part of the generator's surface.
moonbitstack/moonrand/auto1 function
pub fn rng() -> @moonrand.StdRng raise @moonseed.Unavailable
One import, one call: ask the platform for 32 bytes and hand them to the default generator. No entropy, no stream.
moonbitstack/moonrand/bits4 functions
pub fn mix64(z : UInt64) -> UInt64
The SplitMix64 finalizer: three shifted xors and two odd multipliers, one word to one word.
pub fn mul_hi(a : UInt64, b : UInt64) -> UInt64
The high half of a 64-bit product, without a 128-bit type: four half-word products and a carry.
pub fn mul_wide(a : UInt64, b : UInt64) -> (UInt64, UInt64)
Both halves of a 64-bit product, low half first.
pub fn seed_words(seed : BytesView, n : Int32) -> FixedArray[UInt64]
Turn a seed into n state words: fold the bytes into SplitMix64, then run it forward. Every byte counts.
moonbitstack/moonrand/xoshiro9 types · 81 functions
pub struct Xoroshiro128p {
Two words of state, an addition as the output.
pub fn Xoroshiro128p::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Xoroshiro128p::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Xoroshiro128p::from_state(FixedArray[UInt64]) -> Self
Start from a state you already have, unchanged.
pub fn Xoroshiro128p::jump(Self) -> Unit
A fixed distance ahead, by the reference polynomial.
pub fn Xoroshiro128p::long_jump(Self) -> Unit
Further ahead than jump, the same way.
pub fn Xoroshiro128p::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Xoroshiro128p::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Xoroshiro128p::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Xoroshiro128p::seed_size() -> Int32
How many bytes a seed is.
pub struct Xoroshiro128pp {
Two words of state, a rotated sum as the output.
pub fn Xoroshiro128pp::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Xoroshiro128pp::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Xoroshiro128pp::from_state(FixedArray[UInt64]) -> Self
Start from a state you already have, unchanged.
pub fn Xoroshiro128pp::jump(Self) -> Unit
A fixed distance ahead, by the reference polynomial.
pub fn Xoroshiro128pp::long_jump(Self) -> Unit
Further ahead than jump, the same way.
pub fn Xoroshiro128pp::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Xoroshiro128pp::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Xoroshiro128pp::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Xoroshiro128pp::seed_size() -> Int32
How many bytes a seed is.
pub struct Xoroshiro128ss {
Two words of state, a scrambled product as the output.
pub fn Xoroshiro128ss::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Xoroshiro128ss::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Xoroshiro128ss::from_state(FixedArray[UInt64]) -> Self
Start from a state you already have, unchanged.
pub fn Xoroshiro128ss::jump(Self) -> Unit
A fixed distance ahead, by the reference polynomial.
pub fn Xoroshiro128ss::long_jump(Self) -> Unit
Further ahead than jump, the same way.
pub fn Xoroshiro128ss::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Xoroshiro128ss::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Xoroshiro128ss::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Xoroshiro128ss::seed_size() -> Int32
How many bytes a seed is.
pub struct Xoshiro256p {
A 256-bit state, an addition as the output.
pub fn Xoshiro256p::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Xoshiro256p::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Xoshiro256p::from_state(FixedArray[UInt64]) -> Self
Start from a state you already have, unchanged.
pub fn Xoshiro256p::jump(Self) -> Unit
A fixed distance ahead, by the reference polynomial.
pub fn Xoshiro256p::long_jump(Self) -> Unit
Further ahead than jump, the same way.
pub fn Xoshiro256p::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Xoshiro256p::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Xoshiro256p::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Xoshiro256p::seed_size() -> Int32
How many bytes a seed is.
pub struct Xoshiro256pp {
A 256-bit state, a rotated sum as the output.
pub fn Xoshiro256pp::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Xoshiro256pp::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Xoshiro256pp::from_state(FixedArray[UInt64]) -> Self
Start from a state you already have, unchanged.
pub fn Xoshiro256pp::jump(Self) -> Unit
A fixed distance ahead, by the reference polynomial.
pub fn Xoshiro256pp::long_jump(Self) -> Unit
Further ahead than jump, the same way.
pub fn Xoshiro256pp::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Xoshiro256pp::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Xoshiro256pp::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Xoshiro256pp::seed_size() -> Int32
How many bytes a seed is.
pub struct Xoshiro256ss {
A 256-bit state, a scrambled product as the output.
pub fn Xoshiro256ss::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Xoshiro256ss::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Xoshiro256ss::from_state(FixedArray[UInt64]) -> Self
Start from a state you already have, unchanged.
pub fn Xoshiro256ss::jump(Self) -> Unit
A fixed distance ahead, by the reference polynomial.
pub fn Xoshiro256ss::long_jump(Self) -> Unit
Further ahead than jump, the same way.
pub fn Xoshiro256ss::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Xoshiro256ss::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Xoshiro256ss::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Xoshiro256ss::seed_size() -> Int32
How many bytes a seed is.
pub struct Xoshiro512p {
The 512-bit form of xoshiro256+.
pub fn Xoshiro512p::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Xoshiro512p::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Xoshiro512p::from_state(FixedArray[UInt64]) -> Self
Start from a state you already have, unchanged.
pub fn Xoshiro512p::jump(Self) -> Unit
A fixed distance ahead, by the reference polynomial.
pub fn Xoshiro512p::long_jump(Self) -> Unit
Further ahead than jump, the same way.
pub fn Xoshiro512p::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Xoshiro512p::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Xoshiro512p::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Xoshiro512p::seed_size() -> Int32
How many bytes a seed is.
pub struct Xoshiro512pp {
The 512-bit form of xoshiro256++.
pub fn Xoshiro512pp::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Xoshiro512pp::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Xoshiro512pp::from_state(FixedArray[UInt64]) -> Self
Start from a state you already have, unchanged.
pub fn Xoshiro512pp::jump(Self) -> Unit
A fixed distance ahead, by the reference polynomial.
pub fn Xoshiro512pp::long_jump(Self) -> Unit
Further ahead than jump, the same way.
pub fn Xoshiro512pp::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Xoshiro512pp::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Xoshiro512pp::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Xoshiro512pp::seed_size() -> Int32
How many bytes a seed is.
pub struct Xoshiro512ss {
The 512-bit form of xoshiro256**.
pub fn Xoshiro512ss::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Xoshiro512ss::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Xoshiro512ss::from_state(FixedArray[UInt64]) -> Self
Start from a state you already have, unchanged.
pub fn Xoshiro512ss::jump(Self) -> Unit
A fixed distance ahead, by the reference polynomial.
pub fn Xoshiro512ss::long_jump(Self) -> Unit
Further ahead than jump, the same way.
pub fn Xoshiro512ss::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Xoshiro512ss::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Xoshiro512ss::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Xoshiro512ss::seed_size() -> Int32
How many bytes a seed is.
moonbitstack/moonrand/pcg3 types · 24 functions
pub struct Pcg32 {
A 64-bit LCG, 32 bits of permuted output.
pub fn Pcg32::advance(Self, UInt64) -> Unit
Skip n draws without making them.
pub fn Pcg32::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Pcg32::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Pcg32::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Pcg32::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Pcg32::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Pcg32::seed_size() -> Int32
How many bytes a seed is.
pub fn Pcg32::with_state(UInt64, UInt64) -> Self
Start from a state you already have, unchanged.
pub fn Pcg32::with_stream(UInt64, UInt64) -> Self
Start where the reference seeding puts it.
pub struct Pcg64 {
A 128-bit LCG with the XSL-RR permutation.
pub fn Pcg64::advance(Self, UInt64) -> Unit
Skip n draws without making them.
pub fn Pcg64::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Pcg64::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Pcg64::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Pcg64::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Pcg64::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Pcg64::seed_size() -> Int32
How many bytes a seed is.
pub fn Pcg64::with_state(UInt64, UInt64, UInt64, UInt64) -> Self
Start from a state you already have, unchanged.
pub struct Pcg64Dxsm {
A 128-bit LCG with the double-xorshift-multiply output.
pub fn Pcg64Dxsm::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Pcg64Dxsm::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Pcg64Dxsm::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Pcg64Dxsm::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Pcg64Dxsm::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Pcg64Dxsm::seed_size() -> Int32
How many bytes a seed is.
pub fn Pcg64Dxsm::with_state(UInt64, UInt64, UInt64, UInt64) -> Self
Start from a state you already have, unchanged.
moonbitstack/moonrand/mt3 types · 24 functions
pub struct MT19937 {
The 32-bit Mersenne Twister.
pub fn MT19937::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn MT19937::from_array(FixedArray[UInt32]) -> Self
Start from a key array, the reference seeding.
pub fn MT19937::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn MT19937::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn MT19937::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn MT19937::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn MT19937::seed_size() -> Int32
How many bytes a seed is.
pub fn MT19937::with_word(UInt32) -> Self
Start from one word, the reference seeding.
pub struct MT19937_64 {
The 64-bit Mersenne Twister.
pub fn MT19937_64::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn MT19937_64::from_array(FixedArray[UInt64]) -> Self
Start from a key array, the reference seeding.
pub fn MT19937_64::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn MT19937_64::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn MT19937_64::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn MT19937_64::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn MT19937_64::seed_size() -> Int32
How many bytes a seed is.
pub fn MT19937_64::with_word(UInt64) -> Self
Start from one word, the reference seeding.
pub struct Sfmt19937 {
The SIMD-oriented Fast Mersenne Twister.
pub fn Sfmt19937::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Sfmt19937::from_array(FixedArray[UInt32]) -> Self
Start from a key array, the reference seeding.
pub fn Sfmt19937::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Sfmt19937::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Sfmt19937::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Sfmt19937::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Sfmt19937::seed_size() -> Int32
How many bytes a seed is.
pub fn Sfmt19937::with_word(UInt32) -> Self
Start from one word, the reference seeding.
moonbitstack/moonrand/splitmix1 type · 8 functions
pub struct SplitMix64 {
A counter through the SplitMix64 finalizer.
pub fn SplitMix64::advance(Self, UInt64) -> Unit
Skip n draws without making them.
pub fn SplitMix64::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn SplitMix64::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn SplitMix64::from_state(UInt64) -> Self
Start from a state you already have, unchanged.
pub fn SplitMix64::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn SplitMix64::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn SplitMix64::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn SplitMix64::seed_size() -> Int32
How many bytes a seed is.
moonbitstack/moonrand/sfc1 type · 7 functions
pub struct Sfc64 {
Three words and a counter, added and shifted.
pub fn Sfc64::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Sfc64::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Sfc64::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Sfc64::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Sfc64::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Sfc64::seed_size() -> Int32
How many bytes a seed is.
pub fn Sfc64::with_state(UInt64, UInt64, UInt64) -> Self
Start from a state you already have, unchanged.
moonbitstack/moonrand/jsf1 type · 7 functions
pub struct Jsf64 {
Jenkins' small fast generator: four words, one rotate.
pub fn Jsf64::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Jsf64::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Jsf64::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Jsf64::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Jsf64::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Jsf64::seed_size() -> Int32
How many bytes a seed is.
pub fn Jsf64::with_state(UInt64, UInt64, UInt64, UInt64) -> Self
Start from a state you already have, unchanged.
moonbitstack/moonrand/xorshift5 types · 35 functions
pub struct Xorshift128 {
Four 32-bit words, the original 128-bit xorshift.
pub fn Xorshift128::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Xorshift128::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Xorshift128::from_state(FixedArray[UInt32]) -> Self
Start from a state you already have, unchanged.
pub fn Xorshift128::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Xorshift128::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Xorshift128::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Xorshift128::seed_size() -> Int32
How many bytes a seed is.
pub struct Xorshift128Plus {
Two 64-bit words, their sum as the output.
pub fn Xorshift128Plus::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Xorshift128Plus::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Xorshift128Plus::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Xorshift128Plus::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Xorshift128Plus::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Xorshift128Plus::seed_size() -> Int32
How many bytes a seed is.
pub fn Xorshift128Plus::with_state(UInt64, UInt64) -> Self
Start from a state you already have, unchanged.
pub struct Xorshift32 {
One 32-bit word, three xorshifts.
pub fn Xorshift32::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Xorshift32::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Xorshift32::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Xorshift32::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Xorshift32::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Xorshift32::seed_size() -> Int32
How many bytes a seed is.
pub fn Xorshift32::with_state(UInt32) -> Self
Start from a state you already have, unchanged.
pub struct Xorshift64 {
One 64-bit word, three xorshifts.
pub fn Xorshift64::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Xorshift64::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Xorshift64::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Xorshift64::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Xorshift64::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Xorshift64::seed_size() -> Int32
How many bytes a seed is.
pub fn Xorshift64::with_state(UInt64) -> Self
Start from a state you already have, unchanged.
pub struct Xorwow {
Xorshift128 with a Weyl increment added.
pub fn Xorwow::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Xorwow::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Xorwow::from_state(FixedArray[UInt32]) -> Self
Start from a state you already have, unchanged.
pub fn Xorwow::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Xorwow::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Xorwow::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Xorwow::seed_size() -> Int32
How many bytes a seed is.
moonbitstack/moonrand/well2 types · 14 functions
pub struct Well1024 {
Thirty-two words, period 2^1024-1.
pub fn Well1024::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Well1024::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Well1024::from_state(FixedArray[UInt32]) -> Self
Start from a state you already have, unchanged.
pub fn Well1024::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Well1024::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Well1024::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Well1024::seed_size() -> Int32
How many bytes a seed is.
pub struct Well512 {
Sixteen words, period 2^512-1.
pub fn Well512::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Well512::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Well512::from_state(FixedArray[UInt32]) -> Self
Start from a state you already have, unchanged.
pub fn Well512::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Well512::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Well512::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Well512::seed_size() -> Int32
How many bytes a seed is.
moonbitstack/moonrand/lcg6 types · 44 functions
pub struct Ccg64 {
x := a x^3 + b x^2 + c, rotated as it leaves.
pub fn Ccg64::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Ccg64::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Ccg64::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Ccg64::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Ccg64::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Ccg64::seed_size() -> Int32
How many bytes a seed is.
pub fn Ccg64::with_params(UInt64, UInt64, UInt64, UInt64) -> Self
Start from the parameters and a seed.
pub struct Icg32 {
x := a x^-1 + c over the prime 2^32-5.
pub fn Icg32::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Icg32::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Icg32::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Icg32::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Icg32::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Icg32::seed_size() -> Int32
How many bytes a seed is.
pub fn Icg32::with_params(UInt64, UInt64, UInt64) -> Self
Start from the parameters and a seed.
pub struct Lcg48 {
The 48-bit recurrence behind drand48.
pub fn Lcg48::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Lcg48::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Lcg48::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Lcg48::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Lcg48::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Lcg48::seed_size() -> Int32
How many bytes a seed is.
pub fn Lcg48::with_state(UInt64) -> Self
Start from a state you already have, unchanged.
pub struct Lcg64 {
A linear congruential generator modulo 2^64.
pub fn Lcg64::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Lcg64::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Lcg64::glibc(UInt64) -> Self
The parameters the C library uses.
pub fn Lcg64::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Lcg64::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Lcg64::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Lcg64::numerical_recipes(UInt64) -> Self
The parameters Numerical Recipes prints.
pub fn Lcg64::seed_size() -> Int32
How many bytes a seed is.
pub fn Lcg64::with_params(UInt64, UInt64, UInt64) -> Self
Start from the parameters and a seed.
pub struct MinStd {
16807 modulo 2^31-1, the minimal standard.
pub fn MinStd::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn MinStd::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn MinStd::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn MinStd::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn MinStd::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn MinStd::seed_size() -> Int32
How many bytes a seed is.
pub fn MinStd::with_state(UInt64) -> Self
Start from a state you already have, unchanged.
pub struct Qcg64 {
x := a x^2 + c, rotated as it leaves.
pub fn Qcg64::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Qcg64::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Qcg64::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Qcg64::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Qcg64::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Qcg64::seed_size() -> Int32
How many bytes a seed is.
pub fn Qcg64::with_params(UInt64, UInt64, UInt64) -> Self
Start from the parameters and a seed.
moonbitstack/moonrand/chaos4 types · 28 functions
pub struct Chebyshev {
x := cos(n acos x).
pub fn Chebyshev::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Chebyshev::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Chebyshev::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Chebyshev::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Chebyshev::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Chebyshev::seed_size() -> Int32
How many bytes a seed is.
pub fn Chebyshev::with_params(Double, Double) -> Self
Start from the parameters and a seed.
pub struct Logistic {
x := r x (1 - x).
pub fn Logistic::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Logistic::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Logistic::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Logistic::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Logistic::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Logistic::seed_size() -> Int32
How many bytes a seed is.
pub fn Logistic::with_params(Double, Double) -> Self
Start from the parameters and a seed.
pub struct Sine {
x := sin(pi x).
pub fn Sine::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Sine::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Sine::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Sine::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Sine::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Sine::seed_size() -> Int32
How many bytes a seed is.
pub fn Sine::with_state(Double) -> Self
Start from a state you already have, unchanged.
pub struct Tent {
The tent map, folded at one half.
pub fn Tent::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Tent::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Tent::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Tent::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Tent::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Tent::seed_size() -> Int32
How many bytes a seed is.
pub fn Tent::with_params(Double, Double) -> Self
Start from the parameters and a seed.
moonbitstack/moonrand/lfsr5 types · 35 functions
pub struct Gfsr {
Generalized feedback over 250 words.
pub fn Gfsr::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Gfsr::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Gfsr::from_state(FixedArray[UInt32]) -> Self
Start from a state you already have, unchanged.
pub fn Gfsr::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Gfsr::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Gfsr::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Gfsr::seed_size() -> Int32
How many bytes a seed is.
pub struct Lfsr113 {
Four linear feedback registers, period near 2^113.
pub fn Lfsr113::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Lfsr113::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Lfsr113::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Lfsr113::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Lfsr113::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Lfsr113::seed_size() -> Int32
How many bytes a seed is.
pub fn Lfsr113::with_state(UInt32, UInt32, UInt32, UInt32) -> Self
Start from a state you already have, unchanged.
pub struct Lfsr258 {
Five linear feedback registers over 64-bit words.
pub fn Lfsr258::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Lfsr258::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Lfsr258::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Lfsr258::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Lfsr258::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Lfsr258::seed_size() -> Int32
How many bytes a seed is.
pub fn Lfsr258::with_state(UInt64, UInt64, UInt64, UInt64, UInt64) -> Self
Start from a state you already have, unchanged.
pub struct Lfsr64 {
A 64-bit Galois shift register.
pub fn Lfsr64::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Lfsr64::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Lfsr64::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Lfsr64::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Lfsr64::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Lfsr64::seed_size() -> Int32
How many bytes a seed is.
pub fn Lfsr64::with_state(UInt64) -> Self
Start from a state you already have, unchanged.
pub struct Taus88 {
Three Tausworthe registers, xored.
pub fn Taus88::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Taus88::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Taus88::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Taus88::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Taus88::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Taus88::seed_size() -> Int32
How many bytes a seed is.
pub fn Taus88::with_state(UInt32, UInt32, UInt32) -> Self
Start from a state you already have, unchanged.
moonbitstack/moonrand/fib6 types · 42 functions
pub struct AddWithCarry {
Lag 55 addition with a carry bit.
pub fn AddWithCarry::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn AddWithCarry::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn AddWithCarry::from_state(FixedArray[UInt32]) -> Self
Start from a state you already have, unchanged.
pub fn AddWithCarry::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn AddWithCarry::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn AddWithCarry::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn AddWithCarry::seed_size() -> Int32
How many bytes a seed is.
pub struct AdditiveCongruential {
x(n) = x(n-55) + x(n-24).
pub fn AdditiveCongruential::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn AdditiveCongruential::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn AdditiveCongruential::from_state(FixedArray[UInt32]) -> Self
Start from a state you already have, unchanged.
pub fn AdditiveCongruential::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn AdditiveCongruential::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn AdditiveCongruential::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn AdditiveCongruential::seed_size() -> Int32
How many bytes a seed is.
pub struct LaggedFibonacci {
The same recurrence with lags 607 and 273.
pub fn LaggedFibonacci::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn LaggedFibonacci::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn LaggedFibonacci::from_state(FixedArray[UInt32]) -> Self
Start from a state you already have, unchanged.
pub fn LaggedFibonacci::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn LaggedFibonacci::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn LaggedFibonacci::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn LaggedFibonacci::seed_size() -> Int32
How many bytes a seed is.
pub struct Ranlux24 {
Subtract-with-borrow over 24-bit words, discarding most.
pub fn Ranlux24::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Ranlux24::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Ranlux24::from_state(FixedArray[UInt32]) -> Self
Start from a state you already have, unchanged.
pub fn Ranlux24::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Ranlux24::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Ranlux24::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Ranlux24::seed_size() -> Int32
How many bytes a seed is.
pub struct Ranlux48 {
The same over 48-bit words.
pub fn Ranlux48::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Ranlux48::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Ranlux48::from_state(FixedArray[UInt64]) -> Self
Start from a state you already have, unchanged.
pub fn Ranlux48::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Ranlux48::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Ranlux48::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Ranlux48::seed_size() -> Int32
How many bytes a seed is.
pub struct SubtractWithBorrow {
Lag 55 subtraction with a borrow bit.
pub fn SubtractWithBorrow::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn SubtractWithBorrow::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn SubtractWithBorrow::from_state(FixedArray[UInt32]) -> Self
Start from a state you already have, unchanged.
pub fn SubtractWithBorrow::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn SubtractWithBorrow::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn SubtractWithBorrow::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn SubtractWithBorrow::seed_size() -> Int32
How many bytes a seed is.
moonbitstack/moonrand/mrg1 type · 8 functions
pub struct Mrg32k3a {
Two order-three recurrences over primes, subtracted.
pub fn Mrg32k3a::advance(Self, UInt64) -> Unit
Skip n draws without making them.
pub fn Mrg32k3a::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Mrg32k3a::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Mrg32k3a::from_state(FixedArray[Int64]) -> Self
Start from a state you already have, unchanged.
pub fn Mrg32k3a::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Mrg32k3a::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Mrg32k3a::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Mrg32k3a::seed_size() -> Int32
How many bytes a seed is.
moonbitstack/moonrand/lxm2 types · 16 functions
pub struct L64X128 {
A 64-bit LCG added to xoroshiro128+.
pub fn L64X128::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn L64X128::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn L64X128::jump(Self) -> Unit
A fixed distance ahead, by the reference polynomial.
pub fn L64X128::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn L64X128::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn L64X128::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn L64X128::seed_size() -> Int32
How many bytes a seed is.
pub fn L64X128::with_state(UInt64, UInt64, UInt64) -> Self
Start from a state you already have, unchanged.
pub struct L64X256 {
A 64-bit LCG added to xoshiro256+.
pub fn L64X256::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn L64X256::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn L64X256::jump(Self) -> Unit
A fixed distance ahead, by the reference polynomial.
pub fn L64X256::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn L64X256::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn L64X256::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn L64X256::seed_size() -> Int32
How many bytes a seed is.
pub fn L64X256::with_state(UInt64, UInt64, UInt64, UInt64, UInt64) -> Self
Start from a state you already have, unchanged.
moonbitstack/moonrand/philox2 types · 16 functions
pub struct Philox4x32 {
Four 32-bit counter words, ten rounds.
pub fn Philox4x32::advance(Self, UInt64) -> Unit
Skip n draws without making them.
pub fn Philox4x32::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Philox4x32::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Philox4x32::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Philox4x32::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Philox4x32::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Philox4x32::seed_size() -> Int32
How many bytes a seed is.
pub fn Philox4x32::with_key(UInt32, UInt32) -> Self
Start from a key, with the counter at zero.
pub struct Philox4x64 {
The same round over 64-bit words.
pub fn Philox4x64::advance(Self, UInt64) -> Unit
Skip n draws without making them.
pub fn Philox4x64::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Philox4x64::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Philox4x64::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Philox4x64::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Philox4x64::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Philox4x64::seed_size() -> Int32
How many bytes a seed is.
pub fn Philox4x64::with_key(UInt64, UInt64) -> Self
Start from a key, with the counter at zero.
moonbitstack/moonrand/threefry3 types · 24 functions
pub struct Threefry2x64 {
Two counter words, thirteen rounds.
pub fn Threefry2x64::advance(Self, UInt64) -> Unit
Skip n draws without making them.
pub fn Threefry2x64::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Threefry2x64::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Threefry2x64::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Threefry2x64::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Threefry2x64::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Threefry2x64::seed_size() -> Int32
How many bytes a seed is.
pub fn Threefry2x64::with_key(UInt64, UInt64) -> Self
Start from a key, with the counter at zero.
pub struct Threefry4x32 {
The same schedule over 32-bit words.
pub fn Threefry4x32::advance(Self, UInt64) -> Unit
Skip n draws without making them.
pub fn Threefry4x32::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Threefry4x32::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Threefry4x32::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Threefry4x32::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Threefry4x32::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Threefry4x32::seed_size() -> Int32
How many bytes a seed is.
pub fn Threefry4x32::with_key(UInt32, UInt32) -> Self
Start from a key, with the counter at zero.
pub struct Threefry4x64 {
Four 64-bit counter words, twenty rounds, no multiply.
pub fn Threefry4x64::advance(Self, UInt64) -> Unit
Skip n draws without making them.
pub fn Threefry4x64::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Threefry4x64::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Threefry4x64::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Threefry4x64::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Threefry4x64::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Threefry4x64::seed_size() -> Int32
How many bytes a seed is.
pub fn Threefry4x64::with_key(UInt64, UInt64) -> Self
Start from a key, with the counter at zero.
moonbitstack/moonrand/squares1 type · 8 functions
pub struct Squares {
A keyed counter through three rounds of squaring.
pub fn Squares::advance(Self, UInt64) -> Unit
Skip n draws without making them.
pub fn Squares::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Squares::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Squares::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Squares::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Squares::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Squares::seed_size() -> Int32
How many bytes a seed is.
pub fn Squares::with_key(UInt64, UInt64, UInt64, UInt64) -> Self
Start from a key, with the counter at zero.
moonbitstack/moonrand/classic5 types · 35 functions
pub struct Bbs {
The square modulo a Blum integer.
pub fn Bbs::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn Bbs::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn Bbs::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn Bbs::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn Bbs::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn Bbs::seed_size() -> Int32
How many bytes a seed is.
pub fn Bbs::with_params(UInt64, UInt64) -> Self
Start from the parameters and a seed.
pub struct CollatzWeyl {
The Collatz map xored with a Weyl sequence.
pub fn CollatzWeyl::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn CollatzWeyl::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn CollatzWeyl::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn CollatzWeyl::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn CollatzWeyl::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn CollatzWeyl::seed_size() -> Int32
How many bytes a seed is.
pub fn CollatzWeyl::with_state(UInt64) -> Self
Start from a state you already have, unchanged.
pub struct MiddleProduct {
Multiply by a constant, keep the middle bits.
pub fn MiddleProduct::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn MiddleProduct::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn MiddleProduct::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn MiddleProduct::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn MiddleProduct::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn MiddleProduct::seed_size() -> Int32
How many bytes a seed is.
pub fn MiddleProduct::with_params(UInt64, UInt64) -> Self
Start from the parameters and a seed.
pub struct MiddleSquare {
Square the word, keep the middle bits.
pub fn MiddleSquare::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn MiddleSquare::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn MiddleSquare::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn MiddleSquare::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn MiddleSquare::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn MiddleSquare::seed_size() -> Int32
How many bytes a seed is.
pub fn MiddleSquare::with_state(UInt64) -> Self
Start from a state you already have, unchanged.
pub struct MiddleSquareWeyl {
Middle square plus a Weyl sequence.
pub fn MiddleSquareWeyl::fill(Self, FixedArray[Byte]) -> Unit
Fill a byte array from the stream.
pub fn MiddleSquareWeyl::from_seed(BytesView) -> Self
Rebuild from a seed of seed_size bytes.
pub fn MiddleSquareWeyl::new(BytesView) -> Self
Seed it: the bytes go through SplitMix64, a short seed padded.
pub fn MiddleSquareWeyl::next_u32(Self) -> UInt32
The contract's draw: one 32-bit word.
pub fn MiddleSquareWeyl::next_u64(Self) -> UInt64
The contract's draw: one 64-bit word.
pub fn MiddleSquareWeyl::seed_size() -> Int32
How many bytes a seed is.
pub fn MiddleSquareWeyl::with_state(UInt64) -> Self
Start from a state you already have, unchanged.

05 / one stream, three looks

Same bytes, same dishdrawn by this page's stream

These three dishes are not illustrations. How many times the fret band folds, which character sits in the well — both came out of their own stream, just now, and no two wells take the same character. Reload and they change; write the seed under each dish into your code and they stay exactly these three, down to the petal.

06 / limits

What it is notthe honest side

Not cryptographically secure

ChaCha12 is fast; it is not a shield. Keys, nonces, one-time passwords — use moonseed's ChaCha20 with platform entropy instead.

No cross-version promise

Bit-for-bit within a version. A major release may swap the core and the stream moves, so pin the version alongside the seed.

No memory management

No internal buffer pool, no unbounded allocation. fill comes from the trait's default implementation; reach for it only when you need it.