baml.random.Rng
A source of random bytes.
Reference version
Signature
interface baml.random.RngA source of random bytes.
Three implementations are provided by the standard library:
SystemRandomis a secure singleton provider that calls out to the system's entropy sourceXoshiro256PlusPlusis a fast seedable PRNGChaCha20is a secure seedable PRNG
Source:<builtin>/baml/ns_random/random.bamlbytes 290–1648
Required instance methods
function
random
(self, bytes: int) -> uint8array throws neverProduces bytes uniformly random bytes.
Panics
- If
bytesis negative. - If
bytesbytes cannot be allocated (baml.panics.AllocFailure). - If the implementation fails to produce the requested number of bytes (for example, if the underlying system random number generator is unavailable)
Default instance methods
function
random_int
(self) -> int throws neverReturns a uniformly random int over the full [int.min_value(), int.max_value()] range.
BAML int is 63-bit, so this discards a single bit of the 64 drawn (the
top bit of the first byte). The remaining 63 bits are uniform, and so is
the value they spell.