NOMAD Source  Version 4.0.0 Beta
RNG Class Reference

Class for random number generator. More...

#include <RNG.hpp>

Public Types

typedef uint32_t result_type
 

Public Member Functions

result_type operator() ()
 Functor to get a random integer. More...
 

Static Public Member Functions

static constexpr result_type min ()
 
static constexpr result_type max ()
 
static int getSeed ()
 Get current seed. More...
 
static void setSeed (int s)
 Set seed. More...
 
static result_type rand ()
 Get a random integer. More...
 
static double rand (double a, double b)
 Get a random number having a normal distribution as double. More...
 
static double normalRandMean0 (double Var=1, int Nsample=12)
 Get a random number using a normal distribution centered on 0. More...
 
static double normalRand (double Mean=0, double Var=1)
 Get a random number approaching a normal distribution N(Mean,Var) as double. More...
 
static void resetPrivateSeedToDefault ()
 Reset seed to its default value. More...
 
static void getPrivateSeed (uint32_t &x, uint32_t &y, uint32_t &z)
 Get private values. More...
 
static void setPrivateSeed (uint32_t x, uint32_t y, uint32_t z)
 Reset seed to given values. More...
 

Static Private Attributes

static uint32_t x_def
 
static uint32_t y_def
 
static uint32_t z_def
 Initial values for the random number generator. More...
 
static uint32_t _x
 
static uint32_t _y
 
static uint32_t _z
 Current values for the random number generator. More...
 
static int _s
 

Detailed Description

Class for random number generator.

This class is used to set a seed for the random number generator and get a random integer or a random double between two values.
http://madrabbit.org/~ray/code/xorshf96.c with period 2^96-1

Definition at line 70 of file RNG.hpp.

Member Typedef Documentation

◆ result_type

Definition at line 73 of file RNG.hpp.

Member Function Documentation

◆ getPrivateSeed()

static void RNG::getPrivateSeed ( uint32_t x,
uint32_t y,
uint32_t z 
)
inlinestatic

Get private values.

Definition at line 148 of file RNG.hpp.

149  {
150  x = _x;
151  y = _y;
152  z = _z;
153  }

◆ getSeed()

static int RNG::getSeed ( )
inlinestatic

Get current seed.

Returns
An integer in [0,UINT32_MAX].

Definition at line 82 of file RNG.hpp.

83  {
84  return _s;
85  }

◆ max()

static constexpr result_type RNG::max ( )
inlinestaticconstexpr

Definition at line 76 of file RNG.hpp.

76 { return UINT32_MAX; }

◆ min()

static constexpr result_type RNG::min ( )
inlinestaticconstexpr

Definition at line 75 of file RNG.hpp.

75 { return 0; }

◆ normalRand()

static double RNG::normalRand ( double  Mean = 0,
double  Var = 1 
)
static

Get a random number approaching a normal distribution N(Mean,Var) as double.

A series of Nsample random numbers Xi in the interval [-sqrt(3*Var);+sqrt(3*Var)] is used -> E[Xi] = 0, Var(Xi) = var.
See http://en.wikipedia.org/wiki/Central_limit_theorem

Parameters
MeanMean of the target normal distribution – IN.
VarVariance of the target normal distribution – IN.
Returns
A random number.

◆ normalRandMean0()

static double RNG::normalRandMean0 ( double  Var = 1,
int  Nsample = 12 
)
static

Get a random number using a normal distribution centered on 0.

Get a random number approaching a normal distribution (N(0,Var)) as double

Parameters
VarVariance of the target normal distribution – IN.
NsampleNumber of samples for averaging – IN.
Returns
A double in the interval [-sqrt(3*Var);+sqrt(3*Var)].

◆ operator()()

result_type RNG::operator() ( )
inline

Functor to get a random integer.

Returns
An integer in the interval [0,UINT32_MAX].

Definition at line 103 of file RNG.hpp.

103 { return rand(); }

◆ rand() [1/2]

static result_type RNG::rand ( )
static

Get a random integer.

Returns
An integer in the interval [0,UINT32_MAX].

◆ rand() [2/2]

static double RNG::rand ( double  a,
double  b 
)
inlinestatic

Get a random number having a normal distribution as double.

Parameters
aLower bound – IN.
bUpper bound – IN.
Returns
A double in the interval [a,b].

Definition at line 111 of file RNG.hpp.

112  {
113  return a+((b-a)*RNG::rand())/UINT32_MAX;
114  }

◆ resetPrivateSeedToDefault()

static void RNG::resetPrivateSeedToDefault ( )
inlinestatic

Reset seed to its default value.

Definition at line 140 of file RNG.hpp.

141  {
142  _x = x_def;
143  _y = y_def;
144  _z = z_def;
145  }

◆ setPrivateSeed()

static void RNG::setPrivateSeed ( uint32_t  x,
uint32_t  y,
uint32_t  z 
)
inlinestatic

Reset seed to given values.

Used to set back RNG in a known state.

Definition at line 159 of file RNG.hpp.

160  {
161  _x = x;
162  _y = y;
163  _z = z;
164  }

◆ setSeed()

static void RNG::setSeed ( int  s)
static

Set seed.

Parameters
sThe seed – IN.

Member Data Documentation

◆ _s

int RNG::_s
staticprivate

Definition at line 171 of file RNG.hpp.

◆ _x

uint32_t RNG::_x
staticprivate

Definition at line 169 of file RNG.hpp.

◆ _y

uint32_t RNG::_y
staticprivate

Definition at line 169 of file RNG.hpp.

◆ _z

uint32_t RNG::_z
staticprivate

Current values for the random number generator.

Definition at line 169 of file RNG.hpp.

◆ x_def

uint32_t RNG::x_def
staticprivate

Definition at line 168 of file RNG.hpp.

◆ y_def

uint32_t RNG::y_def
staticprivate

Definition at line 168 of file RNG.hpp.

◆ z_def

uint32_t RNG::z_def
staticprivate

Initial values for the random number generator.

Definition at line 168 of file RNG.hpp.


The documentation for this class was generated from the following file:
RNG::_y
static uint32_t _y
Definition: RNG.hpp:169
RNG::_s
static int _s
Definition: RNG.hpp:171
RNG::_z
static uint32_t _z
Current values for the random number generator.
Definition: RNG.hpp:169
RNG::y_def
static uint32_t y_def
Definition: RNG.hpp:168
RNG::_x
static uint32_t _x
Definition: RNG.hpp:169
RNG::x_def
static uint32_t x_def
Definition: RNG.hpp:168
RNG::rand
static result_type rand()
Get a random integer.
RNG::z_def
static uint32_t z_def
Initial values for the random number generator.
Definition: RNG.hpp:168
UINT32_MAX
#define UINT32_MAX
Definition: defines.hpp:89