ppad-censor-0.6.0: Anytime-valid sequential constant-time testing.
Copyright(c) 2026 Jared Tobin
LicenseMIT
MaintainerJared Tobin <jared@ppad.tech>
Safe HaskellNone
LanguageHaskell2010

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.

Synopsis

Stateful generator

data Rng Source #

splitmix64 state threaded through an IORef.

mkRng :: Word64 -> IO Rng Source #

Create a generator from a seed. Equal seeds yield equal streams.

nextWord :: Rng -> IO Word64 Source #

Draw the next Word64 from the 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.

Pure step

splitMix :: Word64 -> (Word64, Word64) Source #

The pure splitmix64 step: from a state, produce the successor state and an output word.