Brahe - a heterogenous collection of mathematical tools

Main Index
Home Page

Created by Scott Robert Ladd


Data Structures | Enumerations | Functions | Variables
prng.h File Reference
#include "mathtools.h"

Go to the source code of this file.

Data Structures

struct  brahe_prng_state_t
 Contains state variables for a PRNG. More...
 

Enumerations

enum  brahe_prng_type_t {
  BRAHE_PRNG_MARSENNE_TWISTER = 0 , BRAHE_PRNG_KISS , BRAHE_PRNG_CMWC4096 , BRAHE_PRNG_MWC1038 ,
  BRAHE_PRNG_ISAAC
}
 Defines types of prngs. More...
 

Functions

bool brahe_prng_init (brahe_prng_state_t *prng_state, const brahe_prng_type_t type, const uint32_t seed)
 Initialize a psuedo-random number generator (PRNG)
 
void brahe_prng_free (brahe_prng_state_t *prng_state)
 Free resources used by PRNG.
 
uint32_t brahe_prng_next (brahe_prng_state_t *prng_state)
 Get the next integer.
 
uint32_t brahe_prng_range (brahe_prng_state_t *prng_state, const uint32_t lo, const uint32_t hi)
 Get the next integer in the range [lo,hi].
 
size_t brahe_prng_index (brahe_prng_state_t *prng_state, const size_t length)
 Get the next random value as a size_t index.
 
double brahe_prng_real1 (brahe_prng_state_t *prng_state)
 Get the next number in the range [0,1].
 
double brahe_prng_real2 (brahe_prng_state_t *prng_state)
 Get the next number in the range [0,1)
 
double brahe_prng_real3 (brahe_prng_state_t *prng_state)
 Get the next number in the range (0,1)
 
double brahe_prng_real53 (brahe_prng_state_t *prng_state)
 Get the next number in the range [0,1)
 

Variables

static uint32_t BRAHE_UNKNOWN_SEED = 0
 

Enumeration Type Documentation

◆ brahe_prng_type_t

Enumerator
BRAHE_PRNG_MARSENNE_TWISTER 

Marsenne Twister (Matsumoto & Nishimura)

BRAHE_PRNG_KISS 

Keep is Simple, Stupid (Marsaglia)

BRAHE_PRNG_CMWC4096 

CMWC4096 (Marsaglia)

BRAHE_PRNG_MWC1038 

MWC1038 (Marsaglia)

BRAHE_PRNG_ISAAC 

Indirect, Shift, Accumulate, Add, and Count (Jenkins)

Function Documentation

◆ brahe_prng_free()

void brahe_prng_free ( brahe_prng_state_t prng_state)

Frees the resources used by a PRNG

Parameters
prng_stateObject containing the state of a PRNG
Returns
true if successful, false if failed

◆ brahe_prng_index()

size_t brahe_prng_index ( brahe_prng_state_t prng_state,
const size_t  length 
)

Returns the next value as a size_t "index" in the range [0,length).

Parameters
prng_stateObject containing the state of a PRNG
length- Maximum value of result
Returns
A pseudorandom size_t value

◆ brahe_prng_init()

bool brahe_prng_init ( brahe_prng_state_t prng_state,
const brahe_prng_type_t  type,
const uint32_t  seed 
)

Initializes a psuedo-random number generator using a specified algorithm.

Parameters
prng_stateObject to be initialized for a specific algorithm
typeAlgorithm to be used for this PRNG
seedInitialization seed
Returns
true if successful, false if failed

◆ brahe_prng_next()

uint32_t brahe_prng_next ( brahe_prng_state_t prng_state)

Returns the next uint32_t in sequence.

Parameters
prng_stateObject containing the state of a PRNG
Returns
A pseudorandom uint32_t value

◆ brahe_prng_range()

uint32_t brahe_prng_range ( brahe_prng_state_t prng_state,
const uint32_t  lo,
const uint32_t  hi 
)

Returns the next int_value between lo and hi, inclusive.

Parameters
prng_stateObject containing the state of a PRNG
lo- Minimum value of result
hi- Maximum value of result
Returns
A pseudorandom uint32_t value

◆ brahe_prng_real1()

double brahe_prng_real1 ( brahe_prng_state_t prng_state)

Returns the next real number in the range [0,1], i.e., a number greater than or equal to 0 and less than or equal to 1. Provides 32-bit precision.

Parameters
prng_stateObject containing the state of a PRNG
Returns
A pseudorandom double value

◆ brahe_prng_real2()

double brahe_prng_real2 ( brahe_prng_state_t prng_state)

Returns the next real number in the range [0,1), i.e., a number greater than or equal to 0 and less than 1. Provides 32-bit precision.

Parameters
prng_stateObject containing the state of a PRNG
Returns
A pseudorandom double value

◆ brahe_prng_real3()

double brahe_prng_real3 ( brahe_prng_state_t prng_state)

Returns the next real number in the range (0,1), i.e., a number greater than 0 and less than 1. Provides 32-bit precision.

Parameters
prng_stateObject containing the state of a PRNG
Returns
A pseudorandom double value

◆ brahe_prng_real53()

double brahe_prng_real53 ( brahe_prng_state_t prng_state)

Returns the next real number in the range [0,1), i.e., a number greater than or equal to 0 and less than 1. Provides 53-bit precision.

Parameters
prng_stateObject containing the state of a PRNG
Returns
A pseudorandom double value

Variable Documentation

◆ BRAHE_UNKNOWN_SEED

uint32_t BRAHE_UNKNOWN_SEED = 0
static

© 2011 Scott Robert Ladd. All rights reserved.
HTML documentation generated by Dimitri van Heesch's excellent Doxygen tool.