Brickworks > API documentation > bw_rand

bw_rand

Description

Pseudo-random number generators.

These are good enough for music DSP applications but should not be considered crypthographically secure.

All functions in this module are reentrant, RT-safe, thread-safe, and have no side effects.

The algorithms are based on the "simplified" Permuted Congruential Generator (PCG) by Chris Wellons, which is itself taken from

M. E. O'Neill, "PCG: A Family of Simple Fast Space-Efficient Statistically Good Algorithms for Random Number Generation", September 2014, available at https://www.cs.hmc.edu/tr/hmc-cs-2014-0905.pdf.

Info

Module type: utility

Version: 1.0.1

Requires:

API

bw_randu32()

static inline uint32_t bw_randu32(
	uint64_t * BW_RESTRICT state);

Returns a pseudo-random unsigned 32-bit integer in the range [0, UINT32_MAX].

state is a pointer to a 64-bit unsigned integer storing the state between calls and which gets updated by this function.

bw_randf()

static inline float bw_randf(
	uint64_t * BW_RESTRICT state);

Returns a pseudo-random unsigned 32-bit floating point number in the range [-1.f, 1.f].

state is a pointer to a 64-bit unsigned integer storing the state between calls and which gets updated by this function.

ChangeLog