# std/random

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.

## Rng

`type`, at line 10.

```vyrn
type Rng = { state: UInt64 }
```

PRNG state. Copy it to fork a reproducible stream.

## Draw

`type`, at line 13.

```vyrn
type Draw = { value: Int64, rng: Rng }
```

One draw: the value and the advanced generator.

## randomSeed

`fn`, at line 20.

```vyrn
fn randomSeed() -> Int64
```

An unpredictable seed from the host CSPRNG. A host effect, so generators and comptime code cannot call it.

## seededRng

`fn`, at line 26.

```vyrn
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.

## nextInt

`fn`, at line 32.

```vyrn
fn nextInt(rng: Rng) -> Draw
```

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

## nextInRange

`fn`, at line 52.

```vyrn
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.

---

From https://vyrn-lang.github.io/docs/std/random.html — generated by `site/export.vyrn` from the Vyrn repository.
