vyrn

std/random

6 exports, from std/random.vyrn.

Deterministic pseudo-randomness with a host-seeded escape.

The generator is a value (Rng): each draw returns the value and the advanced Rng, so a seeded run reproduces on every engine. There is no ambient random(); randomSeed is the one host effect. The algorithm is SplitMix64. It is not cryptographic: use it for shuffles, sampling and tests, not for secrets. PRNG state. Copy it to fork a reproducible stream.

Dependencies

The import graph shows the whole library.

Imports
Imported by
fn seededRng(seed: Int64) -> Rng

A generator seeded by any Int64. SplitMix64 has no bad states, so the seed's bit pattern is the initial state.

fn nextInt(rng: Rng) -> Draw

Advances the generator once: value covers the full Int64 range. Pure, so generators and comptime code can call it.

fn nextInRange(rng: Rng, lo: Int64, hi: Int64) -> Draw

A draw in the inclusive range [lo, hi], or lo if the range is empty. Modulo reduction, so a very wide range has a slight low bias.

The span is UInt64 because hi - lo + 1 reaches 2^64. That wraps to 0, which means the full range: every draw lands inside it and the reduction is skipped.

Tests

2 test blocks in std/random.vyrn. CI runs all of them.

Test names
  • nextInRange covers the full Int64 range without trapping
  • nextInRange stays deterministic and in range on wide spans

Examples

1 program in examples/ import this module. Each runs as WebAssembly and as a native binary.