| Copyright | (c) 2026 Jared Tobin |
|---|---|
| License | MIT |
| Maintainer | Jared Tobin <jared@ppad.tech> |
| Safe Haskell | None |
| Language | Haskell2010 |
Censor.Rng
Description
A minimal splitmix64 PRNG for input samplers.
Samplers feeding runCT want a pseudorandom source that is
deterministic under a fixed seed, cheap, and light on allocation,
so that sampling work does not itself perturb the measurement (see
the measurement-hygiene notes in Censor). This module provides
exactly that and nothing more. It is not a cryptographic
generator; the sampled inputs only need to be independent of the
target's timing distribution, not unpredictable.
Stateful generator
reseed :: Rng -> Word64 -> IO () Source #
Reset a generator to a seed in place: after reseed g s the
generator draws exactly the stream of a fresh .mkRng s
Lets one long-lived generator replay a pinned stream, or adopt a fresh one, without allocating per use — so the two classes of a fix-vs-random sampler can share a single generator object and differ only in the seed value written into it.
Byte fills
randomBytes :: Rng -> Int -> IO ByteString Source #
Draw n pseudorandom bytes as a strict ByteString.
The result is a fresh, fully-materialised heap value -- no thunks for the meter to pay inside the timed region -- so a sampler can return it directly.
fillRandom :: Rng -> Ptr Word8 -> Int -> IO () Source #
Fill n bytes at the pointer with pseudorandom bytes drawn
from the generator.