Built-in random number generator


Detailed Description

This part implements a simple pseudorandom number generator. The generator produces the same sequence of numbers on all platforms; it is intended for tests which require reproducible results.


Defines

#define BUILTIN_RNG_BITS   15
 The number of random bits returned by builtin_rng.
#define BUILTIN_RNG_MAX   ((1U << BUILTIN_RNG_BITS) - 1)
 The maximum value returned by builtin_rng.
#define BUILTIN_RNG_LARGE_BITS   (BUILTIN_RNG_BITS * 2)
 The number of random bits returned by builtin_rng_large.
#define BUILTIN_RNG_LARGE_MAX   ((1U << BUILTIN_RNG_LARGE_BITS) - 1)
 The maximum value returned by builtin_rng_large.

Typedefs

typedef uint_fast32_t builtin_rng_state_t
 The internal state of builtin_rng.

Functions

static void builtin_rng_init (builtin_rng_state_t *state)
 Initialise the state used by builtin_rng.
static uint_fast16_t builtin_rng (builtin_rng_state_t *state)
 Builtin pseudorandom number generator.
static uint_fast32_t builtin_rng_large (builtin_rng_state_t *state)
 Builtin pseudorandom number generator.
static unsigned builtin_rng_n (builtin_rng_state_t *state, unsigned n)
 Return a random unsigned integer between 0 and n-1.


Define Documentation

#define BUILTIN_RNG_BITS   15

The number of random bits returned by builtin_rng.

Definition at line 255 of file types.c.

Referenced by builtin_rng_large().

#define BUILTIN_RNG_LARGE_BITS   (BUILTIN_RNG_BITS * 2)

The number of random bits returned by builtin_rng_large.

Definition at line 261 of file types.c.

#define BUILTIN_RNG_LARGE_MAX   ((1U << BUILTIN_RNG_LARGE_BITS) - 1)

The maximum value returned by builtin_rng_large.

Definition at line 264 of file types.c.

Referenced by builtin_rng_n().

#define BUILTIN_RNG_MAX   ((1U << BUILTIN_RNG_BITS) - 1)

The maximum value returned by builtin_rng.

Definition at line 258 of file types.c.

Referenced by builtin_rng().


Typedef Documentation

typedef uint_fast32_t builtin_rng_state_t

The internal state of builtin_rng.

Definition at line 267 of file types.c.


Function Documentation

static uint_fast16_t builtin_rng ( builtin_rng_state_t state  )  [inline, static]

Builtin pseudorandom number generator.

Return a pseudorandom unsigned integer between 0 and BUILTIN_RNG_MAX. The algorithm is mentioned in the C standard (ISO/IEC 9899:1999), and it is also used in the GNU C Library to implement rand_r.

Definition at line 279 of file types.c.

References BUILTIN_RNG_MAX.

Referenced by builtin_rng_large().

static void builtin_rng_init ( builtin_rng_state_t state  )  [inline, static]

Initialise the state used by builtin_rng.

Definition at line 271 of file types.c.

static uint_fast32_t builtin_rng_large ( builtin_rng_state_t state  )  [inline, static]

Builtin pseudorandom number generator.

Return a pseudorandom unsigned integer between 0 and BUILTIN_RNG_LARGE_MAX.

Definition at line 288 of file types.c.

References builtin_rng(), and BUILTIN_RNG_BITS.

Referenced by builtin_rng_n().

static unsigned builtin_rng_n ( builtin_rng_state_t state,
unsigned  n 
) [inline, static]

Return a random unsigned integer between 0 and n-1.

Definition at line 297 of file types.c.

References builtin_rng_large(), and BUILTIN_RNG_LARGE_MAX.

Referenced by builtin_rng_permutation().