A seedable pseudo-random number generator.
ChaCha12 at the core, the sampling and distributions on top, all of it held to one Rng contract. Thirty-two bytes fix the whole stream — and the same numbers come out bit for bit on native, JS, wasm and wasm-gc.
01 / overview
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 nineteen 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.
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
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
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.
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.
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
Left is the call, right is the shape it promises. The root package is here — the sampling, the distributions, the default generator. The draws take an Rng, a bound written out in full on the reference page, where the other twenty-two packages and their sixty-three generators are listed.
05 / demo
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
ChaCha12 is fast; it is not a shield. Keys, nonces, one-time passwords — use moonseed's ChaCha20 with platform entropy instead.
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 internal buffer pool, no unbounded allocation. fill comes from the trait's default implementation; reach for it only when you need it.