normal.h¶
Gaussian samples by Box-Muller, from a source or from a secret seed.
The support is unbounded: a caller needing a tail bound clamps or resamples. Box-Muller is not constant time in its input.
Note
Thread-safe.
Functions
-
double normal_random(Random source, double sigma)¶
Returns one sample of a zero-mean Gaussian with standard deviation
sigma, from 16 bytes ofsource.- Parameters:
source – [in] A source, or
NULLfor the entropy stream.sigma – [in] The standard deviation.
- Returns:
The sample.
-
void normal_from_seed(int64_t *out, uint64_t count, double sigma, const uint8_t *seed, uint64_t seed_len)¶
Writes samples of the same distribution, each rounded to the nearest integer, from the BLAKE3 XOF of a secret seed.
A function of
seedalone, so a parallel kernel that gives each unit of work a seed of its own draws the same noise on any number of threads. The seed is as secret as the noise: draw it from the source, never from a transcript.- Parameters:
out – [out] Receives
countsamples.count – [in] Samples.
sigma – [in] The standard deviation.
seed – [in] Any length.
seed_len – [in] Bytes of
seed.