This is a small header-only library implementing a handful of routines for
uniform sampling in floating-point. See the blog posts Sampling in
Floating Point (1/3): The Unit

and Sampling in Floating Point (2/3): 1D

for further context and documentation.

The main entrypoints are:

  • Sample01(): returns uniform floating-point values in [0,1).
  • SampleToPowerOfTwo(x): uniformly samples in [0,2^x).
  • SampleRange(a, b): uniformly samples in [a,b).

It is expected that the user will provide implementations of two functions
to generate random values:

uint64_t Random64Bits();
uint32_t Random32Bits();

For previous implementations of these ideas, see:


View Github