baml.random.ChaCha20

A seedable, deterministic CSPRNG (ChaCha20). Given the same seed it always reproduces the same stream. It is cryptographically secure *only* when seeded with high-entropy input — e.g. 32 bytes drawn from `SystemRandom` (the default when no seed is given). A low-entropy or attacker-known seed makes its output predictable.

Reference version

Signature

class baml.random.ChaCha20

A seedable, deterministic CSPRNG (ChaCha20). Given the same seed it always reproduces the same stream. It is cryptographically secure only when seeded with high-entropy input — e.g. 32 bytes drawn from SystemRandom (the default when no seed is given). A low-entropy or attacker-known seed makes its output predictable.

Source:<builtin>/baml/ns_random/random.bamlbytes 4464–5750

Fields

_state

$rust_type

Opaque, mutex-guarded generator state owned by the Rust runtime.

Static methods

function

_new

(seed: uint8array) -> baml.random.ChaCha20 throws never
function

new

(seed: uint8array = …) -> baml.random.ChaCha20 throws never

Creates a new ChaCha20 pseudo-random number generator.

Parameters

  • seed: The seed for the random number generator. If no seed is provided, a random seed is generated using the system random number generator. The seed must be at least 32 bytes long.

Panics

If seed is shorter than 32 bytes.

Implementations

baml.Concrete for T

Source:<builtin>/baml/core.bamlbytes 763–795

baml.random.Rng for baml.random.ChaCha20

Instance methods

function

random

(self, bytes: int) -> uint8array throws never
function

random_int

(self) -> int throws never

Source:<builtin>/baml/ns_random/random.bamlbytes 5465–5748