libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_random.h File Reference

Go to the source code of this file.

Macros

#define GBL_SEED_COUNT
 
#define GBL_RAND_GENERATOR_DEFAULT
 

Typedefs

typedef int(* GblRandomGeneratorFn) (void)
 

Functions

Basic API

Basic API for driving random number generation

uint64_t gblSeed (uint8_t index)
 
void gblSeedRand (uint8_t index, uint64_t seed)
 
int gblRand (void)
 
void gblSetRand (GblRandomGeneratorFn pFnGen)
 
Generators

Builtin random number generators

int gblRandLibC (void)
 
int gblRandLehmer (void)
 
Utilities

Utility functions for random data generation

GblBool gblRandBool (void)
 
void gblRandBuffer (void *pData, size_t size)
 
int gblRandString (char *pBuffer, int minSize, int maxSize, const char *pCharList)
 
Discrete Distributions

Random number generation for different discrete distributions

int gblRandBernoulli (float p)
 
int gblRandBinomial (int n, float p)
 
int gblRandEquilikely (int a, int b)
 
int gblRandGeometric (float p)
 
int gblRandPascal (int n, float p)
 
int gblRandPoisson (float m)
 
Continuous Distributions

Random number generation for different continuous distributions

float gblRandUniform (float a, float b)
 
float gblRandExponential (float m)
 
float gblRandErlang (int n, float b)
 
float gblRandNormal (float m, float s)
 
float gblRandLogNormal (float a, float b)
 
float gblRandChisquare (int n)
 
float gblRandStudent (int n)
 

Detailed Description

Random number generators and utilities.

This file contains the API and types surrounding random number generation. A series of utilities are provided for generating different types of random output (integer, float, bool, string, etc) as well as a variety of random number distributions.

Note
gblRandLehmer() and the various statistical disbributions are based on: "Random Number Generators: Good Ones Are Hard To Find" Steve Park and Keith Miller Communications of the ACM, October 1988
Todo:
  • Changing channels to swap between seeds
Author
1998 Steve Park
1998 Keith Miller
2023 Falco Girgis

Definition in file gimbal_random.h.

Macro Definition Documentation

◆ GBL_SEED_COUNT

#define GBL_SEED_COUNT

Number of different seeds maintained.

Definition at line 30 of file gimbal_random.h.

◆ GBL_RAND_GENERATOR_DEFAULT

#define GBL_RAND_GENERATOR_DEFAULT

Default random number generator backing gblRand()

Definition at line 34 of file gimbal_random.h.

Typedef Documentation

◆ GblRandomGeneratorFn

typedef int(* GblRandomGeneratorFn) (void)

Function prototype for a custom random generator to be set with gblSetRand()

Definition at line 40 of file gimbal_random.h.

Function Documentation

◆ gblSeed()

uint64_t gblSeed ( uint8_t  index)

Returns the seed associated with the given index.

◆ gblSeedRand()

void gblSeedRand ( uint8_t  index,
uint64_t  seed 
)

Sets the seed associated with the given index to seed.

◆ gblRand()

int gblRand ( void  )

Returns a random number between 0 and RAND_MAX using the current random number generator.

◆ gblSetRand()

void gblSetRand ( GblRandomGeneratorFn  pFnGen)

Sets the current random number generator to pFnGen, which drives gblRand()

◆ gblRandLibC()

int gblRandLibC ( void  )

The builtin rand() generator from the C standard library.

◆ gblRandLehmer()

int gblRandLehmer ( void  )

Lehmer linear congruential random number generator.

◆ gblRandBool()

GblBool gblRandBool ( void  )

Generates a random boolean value using the current generator.

◆ gblRandBuffer()

void gblRandBuffer ( void *  pData,
size_t  size 
)

Fills in the given buffer with random bytes using the current generator.

◆ gblRandString()

int gblRandString ( char *  pBuffer,
int  minSize,
int  maxSize,
const char *  pCharList 
)

Fills in buffer with a sized random word (optionally generated using a list of characters)

◆ gblRandBernoulli()

int gblRandBernoulli ( float  p)

Generates a random integer using the current random number generator over a Bernoulli distribution.

◆ gblRandBinomial()

int gblRandBinomial ( int  n,
float  p 
)

Generates a random integer using the current random number generator over a Binomial distribution.

◆ gblRandEquilikely()

int gblRandEquilikely ( int  a,
int  b 
)

Generates a random integer using the current random number generator over the given range [a, b].

◆ gblRandGeometric()

int gblRandGeometric ( float  p)

Generates a random integer using the current random number generator over a Geometric distribution.

◆ gblRandPascal()

int gblRandPascal ( int  n,
float  p 
)

Generates a random integer using the current random number generator over a Pascal distribution.

◆ gblRandPoisson()

int gblRandPoisson ( float  m)

Generates a random integer using the current random number generator over a Poisson distribution.

◆ gblRandUniform()

float gblRandUniform ( float  a,
float  b 
)

Generates a random float using the current random number generator over the given range [a, b].

◆ gblRandExponential()

float gblRandExponential ( float  m)

Generates a random float using the current random number generator over an Exponential distribution.

◆ gblRandErlang()

float gblRandErlang ( int  n,
float  b 
)

Generates a random float using the current random number generator over an Erlang distribution.

◆ gblRandNormal()

float gblRandNormal ( float  m,
float  s 
)

Generates a random integer using the current random number generator over a Normal distribution.

◆ gblRandLogNormal()

float gblRandLogNormal ( float  a,
float  b 
)

Generates a random integer using the current random number generator over a Log Normal distribution.

◆ gblRandChisquare()

float gblRandChisquare ( int  n)

Generates a random integer using the current random number generator over a Chisquare distribution.

◆ gblRandStudent()

float gblRandStudent ( int  n)

Generates a random integer using the current random number generator over a Student distribution.