SiReNe Simulation Software  1.0
GenLib.h File Reference

Internal library for generating pseudo-random numbers. More...

#include <stdint.h>
#include <math.h>
Include dependency graph for GenLib.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

union  UnionPRNG
 Polymorphic representation of the PRNG value. More...
 
struct  PRNGState
 PRNG state. More...
 

Macros

#define RandomReal(State)   ((double)ValPRNGl(&State) / (~0UL))
 Macro for random real generator complient to multi-threading. More...
 
#define UniformNoise(State, Bound)   (Bound * (2.0 * RandomReal(State) - 1.0))
 Macro for symmetric uniform random number generator complient to multi-threading. More...
 
#define SpecificNoise(State, Bound)   (1.0 + UniformNoise(State, Bound))
 Macro for specific noise function complient to multi-threading. More...
 

Typedefs

typedef unsigned char uchar
 

Functions

void InitPRNG (uint64_t Seed, PRNGState *State)
 Initialization of the PRNG using Splitmix64 from S. Vigna and D. Lemire. More...
 
uint32_t ValPRNGi (PRNGState *State)
 Generation of one pseudo-random int at a time using Lehmer64 RNG (D. Lemire version) More...
 
uint64_t ValPRNGl (PRNGState *State)
 Generation of one pseudo-random long int at a time using Lehmer64 RNG (D. Lemire version) More...
 

Macro Definition Documentation

◆ RandomReal

#define RandomReal (   State)    ((double)ValPRNGl(&State) / (~0UL))

The generated number is between 0 and 1

◆ SpecificNoise

#define SpecificNoise (   State,
  Bound 
)    (1.0 + UniformNoise(State, Bound))

◆ UniformNoise

#define UniformNoise (   State,
  Bound 
)    (Bound * (2.0 * RandomReal(State) - 1.0))

The generated number is between -Bound and Bound

Typedef Documentation

◆ uchar

typedef unsigned char uchar

Function Documentation

◆ InitPRNG()

void InitPRNG ( uint64_t  Seed,
PRNGState State 
)

Parameters
SeedInitialization value of the PRNG
StateInitialized state of the PRNG

References PRNGState::State.

Referenced by main(), and RandomConnections().

◆ ValPRNGi()

uint32_t ValPRNGi ( PRNGState State)

See also
https://lemire.me/blog/2019/03/19/the-fastest-conventional-random-number-generator-that-can-pass-big-crush
Parameters
StatePRNG state used to generate the next value
Returns
A pseudo-random unsigned int

References UnionPRNG::i, PRNGState::Index, UnionPRNG::l, PRNGState::State, and PRNGState::Value.

Referenced by RandomConnections().

◆ ValPRNGl()

uint64_t ValPRNGl ( PRNGState State)

See also
https://lemire.me/blog/2019/03/19/the-fastest-conventional-random-number-generator-that-can-pass-big-crush
Parameters
StatePRNG state used to generate the next value
Returns
A pseudo-random unsigned long int

References UnionPRNG::l, PRNGState::State, and PRNGState::Value.