RNG Class Reference

This is a class that generates random numbers i.e. named the Random Number Generator (RNG). More...

#include <RNG.h>

Public Member Functions

 RNG ()
 default constructor More...
 
void setRandomSeed (unsigned long int new_seed)
 This is the seed for the random number generator (note the call to seed_LFG is only required really if using that type of generator, but the other one is always required) More...
 
void read (std::istream &is)
 
void write (std::ostream &os) const
 
Mdouble getRandomNumber ()
 This is a random generating routine can be used for initial positions. More...
 
Mdouble getRandomNumber (Mdouble min, Mdouble max)
 
Mdouble operator() (Mdouble min, Mdouble max)
 Shorthand for getRandomNumber(min, max) More...
 
Mdouble operator() ()
 
Mdouble getNormalVariate ()
 Produces a random number according to a normal distribution with mean 0 and standard deviation 1. More...
 
Mdouble getNormalVariate (Mdouble mean, Mdouble stdev)
 Produces a random number according to a normal distribution. More...
 
unsigned int getPoissonVariate (Mdouble lambda)
 Produces a random number according to a Poisson distribution. More...
 
Mdouble test ()
 This function tests the quality of random numbers, based on the chi-squared test. More...
 
void setLinearCongruentialGeneratorParmeters (const unsigned int a, const unsigned int c, unsigned int m)
 This functions set the parameters for the LCG random number generator. It goes multiplier, addition, mod. More...
 
void randomise ()
 sets the random variables such that they differ for each run More...
 
void setLaggedFibonacciGeneratorParameters (const unsigned int p, const unsigned int q)
 This function sets the parameters for the LFG random number generator. More...
 
void setRandomNumberGenerator (RNGType type)
 Allows the user to set which random number generator is used. More...
 

Private Member Functions

Mdouble getRandomNumberFromLinearCongruentialGenerator (Mdouble min, Mdouble max)
 This is a basic Linear Congruential Generator Random. More...
 
Mdouble getRandomNumberFromLaggedFibonacciGenerator (Mdouble min, Mdouble max)
 This is a Lagged Fibonacci Generator. More...
 
void seedLaggedFibonacciGenerator ()
 This seed the LFG. More...
 

Private Attributes

unsigned long int randomSeedLinearCongruentialGenerator_
 This is the initial seed of the RNG. More...
 
std::vector< MdoublerandomSeedLaggedFibonacciGenerator_
 This is the seeds required for the LFG. More...
 
unsigned long int a_
 This are the two parameters that control the LCG random generated. More...
 
unsigned long int c_
 
unsigned long int m_
 
unsigned long int p_
 This are the parameters that control the LFG random generator. More...
 
unsigned long int q_
 
RNGType type_
 This is the type of random number generator. More...
 
bool haveSavedBoxMuller_
 A flag that keeps track of whether or not to generate a new pair of normal variates (using Box–Muller) More...
 
Mdouble savedBoxMuller_
 A storage space for the so-far-unused variate from the pair generated by Box–Muller. More...
 

Detailed Description

This is a class that generates random numbers i.e. named the Random Number Generator (RNG).

This is a stand-along class; but is encapsulated (used) by the MD class. To make it architecture safe the both LCG and function is hard codes i.e. does not use the internal C++ one.

Todo:
(AT) implement new C++-standard RNG instead of this one (Kudos on the hard work done here though ;). NB: maybe something for Mercury 2?

Constructor & Destructor Documentation

◆ RNG()

RNG::RNG ( )

default constructor

This is a random number generator and returns a Mdouble within the range specified

Todo:
{Thomas: This code does sth. when min>max; I would prefer to throw an error.}
16 {
18  a_ = 1103515245;
19  c_ = 12345;
20  m_ = 1024 * 1024 * 1024;
22  p_ = 607;
23  q_ = 273;
26 
27  haveSavedBoxMuller_ = false;
28  savedBoxMuller_ = 0;
29 
30 }
@ LAGGED_FIBONACCI_GENERATOR
unsigned long int m_
Definition: RNG.h:143
unsigned long int q_
Definition: RNG.h:148
Mdouble savedBoxMuller_
A storage space for the so-far-unused variate from the pair generated by Box–Muller.
Definition: RNG.h:169
unsigned long int randomSeedLinearCongruentialGenerator_
This is the initial seed of the RNG.
Definition: RNG.h:133
unsigned long int c_
Definition: RNG.h:143
RNGType type_
This is the type of random number generator.
Definition: RNG.h:153
unsigned long int a_
This are the two parameters that control the LCG random generated.
Definition: RNG.h:143
bool haveSavedBoxMuller_
A flag that keeps track of whether or not to generate a new pair of normal variates (using Box–Muller...
Definition: RNG.h:164
void seedLaggedFibonacciGenerator()
This seed the LFG.
Definition: RNG.cc:233
unsigned long int p_
This are the parameters that control the LFG random generator.
Definition: RNG.h:148
std::vector< Mdouble > randomSeedLaggedFibonacciGenerator_
This is the seeds required for the LFG.
Definition: RNG.h:138

References a_, c_, haveSavedBoxMuller_, LAGGED_FIBONACCI_GENERATOR, m_, p_, q_, randomSeedLaggedFibonacciGenerator_, randomSeedLinearCongruentialGenerator_, savedBoxMuller_, seedLaggedFibonacciGenerator(), and type_.

Member Function Documentation

◆ getNormalVariate() [1/2]

Mdouble RNG::getNormalVariate ( )

Produces a random number according to a normal distribution with mean 0 and standard deviation 1.

145 {
146  static const double epsilon = std::numeric_limits<Mdouble>::min();
147 
149  {
150  /* If we have already generated a normal variate, use it. */
151  haveSavedBoxMuller_ = false;
152  return savedBoxMuller_;
153  }
154  else
155  {
156  /* Otherwise, generate a pair of normal variates, return one of them,
157  * and save the other. */
159  do
160  {
161  radius = getRandomNumber(0, 1);
163  } while (radius <= epsilon);
164  // make sure that the radius generated is not too small
165  // (unlikely to happen, just a safety check)
166 
167  savedBoxMuller_ = sqrt(-2.0 * log(radius)) * sin(theta);
168  haveSavedBoxMuller_ = true;
169  return sqrt(-2.0 * log(radius)) * cos(theta);
170  }
171 }
AnnoyingScalar cos(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:136
AnnoyingScalar sin(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:137
AnnoyingScalar sqrt(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:134
double Mdouble
Definition: GeneralDefine.h:13
Mdouble getRandomNumber()
This is a random generating routine can be used for initial positions.
Definition: RNG.cc:123
#define min(a, b)
Definition: datatypes.h:22
double theta
Definition: two_d_biharmonic.cc:236
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 log(const bfloat16 &a)
Definition: BFloat16.h:618
radius
Definition: UniformPSDSelfTest.py:15
const Mdouble pi
Definition: ExtendedMath.h:23
double epsilon
Definition: osc_ring_sarah_asymptotics.h:43

References cos(), oomph::SarahBL::epsilon, getRandomNumber(), haveSavedBoxMuller_, Eigen::bfloat16_impl::log(), min, constants::pi, UniformPSDSelfTest::radius, savedBoxMuller_, sin(), sqrt(), and BiharmonicTestFunctions2::theta.

Referenced by getNormalVariate().

◆ getNormalVariate() [2/2]

Mdouble RNG::getNormalVariate ( Mdouble  mean,
Mdouble  stdev 
)

Produces a random number according to a normal distribution.

174 {
175  if (stdev == 0) {
176  logger(WARN,
177  "[RNG::getNormalVariate(Mdouble, Mdouble)] Zero stdev?");
178  return mean;
179  } else if (stdev < 0) {
180  logger(ERROR,
181  "[RNG::getNormalVariate(Mdouble, Mdouble)] Negative stdev is not allowed.");
182  return 0;
183  } else {
184  return getNormalVariate() * stdev + mean;
185  }
186 }
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
@ WARN
@ ERROR
Mdouble getNormalVariate()
Produces a random number according to a normal distribution with mean 0 and standard deviation 1.
Definition: RNG.cc:144

References ERROR, getNormalVariate(), logger, and WARN.

◆ getPoissonVariate()

unsigned int RNG::getPoissonVariate ( Mdouble  lambda)

Produces a random number according to a Poisson distribution.

This uses Knuth's algorithm for generating Poisson variates. It's simple but slow for large values of lambda — beware.

193 {
194  if (lambda > 50)
195  {
196  logger(WARN, "[RNG::getPoissonVariate(Mdouble)] Knuth's algorithm for Poissons may be slow for lambda = %", lambda);
197  }
198  unsigned int k = 0;
199  Mdouble u;
200  do
201  {
202  k++;
203  u = getRandomNumber(0, 1);
204  }
205  while (u > exp(-lambda));
206  return k-1;
207 }
cout<< "The eigenvalues of A are:"<< endl<< ces.eigenvalues()<< endl;cout<< "The matrix of eigenvectors, V, is:"<< endl<< ces.eigenvectors()<< endl<< endl;complex< float > lambda
Definition: ComplexEigenSolver_compute.cpp:9
char char char int int * k
Definition: level2_impl.h:374
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 exp(const bfloat16 &a)
Definition: BFloat16.h:615

References Eigen::bfloat16_impl::exp(), getRandomNumber(), k, lambda, logger, and WARN.

Referenced by CurvyChute::createBottom().

◆ getRandomNumber() [1/2]

Mdouble RNG::getRandomNumber ( )

This is a random generating routine can be used for initial positions.

124 {
125  return getRandomNumber(0, 1);
126 }

Referenced by SmoothChute::actionsBeforeTimeStep(), Chutebelt::actionsOnRestart(), NautaMixer::addParticles(), HeaterBoundary::checkBoundaryAfterParticleMoved(), BaseCluster::computeInternalStructure(), LawinenBox::create_inflow_particle(), ChutePeriodic::create_inflow_particle(), ChuteWithContraction::create_inflow_particle(), Funnel::create_inflow_particle(), AngleOfRepose::create_inflow_particle(), FlowRule::create_inflow_particle(), SilbertPeriodic::create_inflow_particle(), SegregationWithHopper::create_inflow_particle(), Slide::create_rough_wall(), Chute::createBottom(), CurvyChute::createBottom(), Chute::createFlowParticle(), PSD::drawSample(), InsertionBoundary::generateParticle(), BidisperseCubeInsertionBoundary::generateParticle(), PolydisperseInsertionBoundary::generateParticle(), getNormalVariate(), getPoissonVariate(), InitialConditions< SpeciesType >::InitialConditions(), HorizontalMixer::introduceParticlesInDomain(), LeesEdwardsSelfTest::LeesEdwardsSelfTest(), main(), operator()(), BaseCluster::particleInsertionSuccessful(), FixedClusterInsertionBoundary::placeParticle(), ChuteInsertionBoundary::placeParticle(), CubeInsertionBoundary::placeParticle(), CylinderInsertionBoundary::placeParticle(), HopperInsertionBoundary::placeParticle(), PolydisperseInsertionBoundary::placeParticle(), RandomClusterInsertionBoundary::placeParticle(), SphereInsertionBoundary::placeParticle(), MD_demo::RandomRadius(), DPMBase::setMeanVelocityAndKineticEnergy(), BaseCluster::setRadii(), ClosedCSCWalls::setupInitialConditions(), CSCInit::setupInitialConditions(), CSCWalls::setupInitialConditions(), MercuryLogo::setupInitialConditions(), SmoothChute::setupInitialConditions(), NozzleDemo::setupInitialConditions(), Binary::setupInitialConditions(), FreeCooling2DinWallsDemo::setupInitialConditions(), FreeCooling3DDemoProblem::setupInitialConditions(), FreeCooling3DinWallsDemo::setupInitialConditions(), FreeCoolingDemoProblem::setupInitialConditions(), HourGlass2D::setupInitialConditions(), HourGlass::setupInitialConditions(), MinimalExampleDrum::setupInitialConditions(), TimeDependentPeriodicBoundary3DSelfTest::setupInitialConditions(), FiveParticles::setupInitialConditions(), Cstatic2d::setupInitialConditions(), InitialBed::setupInitialConditions(), NozzleSelfTest::setupInitialConditions(), ParticleCreation::setupInitialConditions(), ParticleParticleCollision::setupInitialConditions(), WallParticleCollision::setupInitialConditions(), my_problem_HGRID::setupInitialConditions(), TriangulatedScrewSelfTest::setupInitialConditions(), TriangulatedWallSelfTest::setupInitialConditions(), DrumRot::setupInitialConditions(), RotatingDrum::setupInitialConditions(), ScalingTestInitialConditionsRelax::setupInitialConditions(), GranularCollapse::setupInitialConditions(), EllipticalSuperQuadricCollision::setupInitialConditions(), Tutorial11::setupInitialConditions(), MD_demo::setupInitialConditions(), MpiMaserChuteTest::setupInitialConditions(), MpiPeriodicBoundaryUnitTest::setupInitialConditions(), ChuteBottom::setupInitialConditions(), and test().

◆ getRandomNumber() [2/2]

Mdouble RNG::getRandomNumber ( Mdouble  min,
Mdouble  max 
)
129 {
130  logger.assert_debug(min <= max, "getRandomNumber: min % cannot be larger than max %", min, max);
133  } else {
135  }
136 }
@ LINEAR_CONGRUENTIAL_GENERATOR
Mdouble getRandomNumberFromLinearCongruentialGenerator(Mdouble min, Mdouble max)
This is a basic Linear Congruential Generator Random.
Definition: RNG.cc:214
Mdouble getRandomNumberFromLaggedFibonacciGenerator(Mdouble min, Mdouble max)
This is a Lagged Fibonacci Generator.
Definition: RNG.cc:245
#define max(a, b)
Definition: datatypes.h:23

References getRandomNumberFromLaggedFibonacciGenerator(), getRandomNumberFromLinearCongruentialGenerator(), LINEAR_CONGRUENTIAL_GENERATOR, logger, max, min, and type_.

◆ getRandomNumberFromLaggedFibonacciGenerator()

Mdouble RNG::getRandomNumberFromLaggedFibonacciGenerator ( Mdouble  min,
Mdouble  max 
)
private

This is a Lagged Fibonacci Generator.

This is a basic Linear Fibonacci Generator Random Is described by three parameters, the multiplication a, the addition c and the mod m

246 {
247 #pragma optimize( "", off )
249  static_cast<Mdouble>(1.0));
250  //Update the random seed
252  randomSeedLaggedFibonacciGenerator_.emplace_back(new_seed);
253 
254  //Generate a random number in the required range
255 
256  Mdouble random_num;
257 
258  Mdouble range = max - min;
259  random_num = min + range * new_seed;
260  return random_num;
261 #pragma optimize( "", on )
262 }
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 fmod(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:648

References Eigen::bfloat16_impl::fmod(), max, min, p_, q_, and randomSeedLaggedFibonacciGenerator_.

Referenced by getRandomNumber().

◆ getRandomNumberFromLinearCongruentialGenerator()

Mdouble RNG::getRandomNumberFromLinearCongruentialGenerator ( Mdouble  min,
Mdouble  max 
)
private

This is a basic Linear Congruential Generator Random.

This is a basic Linear Congruential Generator Random Is described by three parameters, the multiplication a, the addition c and the mod m

215 {
216  //Update the random seed
218 
219  //Generate a random number in the required range
220 
221  Mdouble range = max - min;
222  Mdouble random_num = min + range * randomSeedLinearCongruentialGenerator_ / (static_cast<Mdouble>(m_) + 1.0);
223 
224  return random_num;
225 }

References a_, c_, m_, max, min, and randomSeedLinearCongruentialGenerator_.

Referenced by getRandomNumber(), and seedLaggedFibonacciGenerator().

◆ operator()() [1/2]

Mdouble RNG::operator() ( )
inline
68  {
69  return getRandomNumber(0.0, 1.0);
70  }

References getRandomNumber().

◆ operator()() [2/2]

Mdouble RNG::operator() ( Mdouble  min,
Mdouble  max 
)
inline

Shorthand for getRandomNumber(min, max)

60  {
61  return getRandomNumber(min, max);
62  }

References getRandomNumber(), max, and min.

◆ randomise()

void RNG::randomise ( )

sets the random variables such that they differ for each run

79 {
80 #ifdef MERCURYDPM_USE_MPI
81  //First set a random seed on the root
82  if (PROCESSOR_ID == 0)
83  {
84  setRandomSeed(static_cast<unsigned long int>(time(nullptr)));
85  }
86 
87  //Communicate this to the rest of the processes
88  std::vector<int> values(7);
89  if (PROCESSOR_ID == 0)
90  {
91  values[0] = static_cast<unsigned int>(type_);
92  values[1] = a_;
93  values[2] = c_;
94  values[3] = m_;
95  values[4] = p_;
96  values[5] = q_;
98  }
99  MPIContainer::Instance().broadcast(values.data(),7,0);
100 
101  //Update the generators on the other processors
102  if (PROCESSOR_ID != 0)
103  {
104  type_ = static_cast<RNGType>(values[0]);
105  a_ = values[1];
106  c_ = values[2];
107  m_ = values[3];
108  p_ = values[4];
109  q_ = values[5];
111  }
113 #else
114  setRandomSeed(static_cast<unsigned long int>(time(nullptr)));
115 #endif
116 }
#define PROCESSOR_ID
Definition: GeneralDefine.h:42
RNGType
Definition: RNG.h:18
std::enable_if< std::is_scalar< T >::value, void >::type broadcast(T &t, int fromProcessor=0)
Broadcasts a scalar from the root to all other processors.
Definition: MpiContainer.h:420
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:113
void setRandomSeed(unsigned long int new_seed)
This is the seed for the random number generator (note the call to seed_LFG is only required really i...
Definition: RNG.cc:32

References a_, MPIContainer::broadcast(), c_, MPIContainer::Instance(), m_, p_, PROCESSOR_ID, q_, randomSeedLinearCongruentialGenerator_, seedLaggedFibonacciGenerator(), setRandomSeed(), and type_.

Referenced by FixedClusterInsertionBoundary::checkBoundaryBeforeTimeStep(), RandomClusterInsertionBoundary::checkBoundaryBeforeTimeStep(), LawinenBox::LawinenBox(), main(), FixedClusterInsertionBoundary::placeParticle(), RandomClusterInsertionBoundary::placeParticle(), DPMBase::readNextArgument(), and RotatingDrumBidisperse::RotatingDrumBidisperse().

◆ read()

void RNG::read ( std::istream &  is)
Todo:
tw @at should that number be part of the restart file? It seems to be computed from the other numbers.
39 {
40  std::string dummy;
41  unsigned int type;
42  is >> type;
43  type_ = static_cast<RNGType>(type);
44  is >> a_;
45  is >> c_;
46  is >> m_;
47  is >> p_;
48  is >> q_;
51  //note: the seeds for the LaggedFibonacciGenerator cannot be restarted currently.
53  //randomSeedLaggedFibonacciGenerator_.resize(p_);
54  //for (auto& v : randomSeedLaggedFibonacciGenerator_)
55  // is >> v;
56 }
type
Definition: compute_granudrum_aor.py:141
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286

References a_, c_, m_, p_, q_, randomSeedLinearCongruentialGenerator_, seedLaggedFibonacciGenerator(), oomph::Global_string_for_annotation::string(), compute_granudrum_aor::type, and type_.

Referenced by DPMBase::read().

◆ seedLaggedFibonacciGenerator()

void RNG::seedLaggedFibonacciGenerator ( )
private

This seed the LFG.

234 {
235  for (unsigned int i = 0; i < p_; i++)
236  {
238  }
239 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9

References getRandomNumberFromLinearCongruentialGenerator(), i, p_, and randomSeedLaggedFibonacciGenerator_.

Referenced by randomise(), read(), RNG(), setLaggedFibonacciGeneratorParameters(), and setRandomSeed().

◆ setLaggedFibonacciGeneratorParameters()

void RNG::setLaggedFibonacciGeneratorParameters ( const unsigned int  p,
const unsigned int  q 
)

This function sets the parameters for the LFG random number generator.

319 {
320  //p must be greater than q so makes sure this is true. Not sure what happens if you set p=q, in the LFG alogrithm.
321  if (p < q)
322  {
323  p_ = q;
324  q_ = p;
325  }
326  else
327  {
328  p_ = p;
329  q_ = q;
330  }
331 
334 }
float * p
Definition: Tutorial_Map_using.cpp:9
EIGEN_DEVICE_FUNC const Scalar & q
Definition: SpecialFunctionsImpl.h:2019

References p, p_, Eigen::numext::q, q_, randomSeedLaggedFibonacciGenerator_, and seedLaggedFibonacciGenerator().

◆ setLinearCongruentialGeneratorParmeters()

void RNG::setLinearCongruentialGeneratorParmeters ( const unsigned int  a,
const unsigned int  c,
unsigned int  m 
)

This functions set the parameters for the LCG random number generator. It goes multiplier, addition, mod.

72 {
73  a_ = a;
74  c_ = c;
75  m_ = m;
76 }
const Scalar * a
Definition: level2_cplx_impl.h:32
int * m
Definition: level2_cplx_impl.h:294
int c
Definition: calibrate.py:100

References a, a_, calibrate::c, c_, m, and m_.

◆ setRandomNumberGenerator()

void RNG::setRandomNumberGenerator ( RNGType  type)

Allows the user to set which random number generator is used.

119 {
120  type_ = type;
121 }

References compute_granudrum_aor::type, and type_.

◆ setRandomSeed()

void RNG::setRandomSeed ( unsigned long int  new_seed)

This is the seed for the random number generator (note the call to seed_LFG is only required really if using that type of generator, but the other one is always required)

References randomSeedLinearCongruentialGenerator_, and seedLaggedFibonacciGenerator().

Referenced by DPMBase::constructor(), main(), PSD::PSD(), randomise(), and PSD::setFixedSeed().

◆ test()

Mdouble RNG::test ( )

This function tests the quality of random numbers, based on the chi-squared test.

This function tests the quality of random numbers, based on the chi-squared test. It reports a probability that the random number being generated are coming from a uniform distributed. If this number is less than 0.95, it is strongly advised that you change the parameters being used

270 {
271  //This are the fixed parameters that define the test
272  static unsigned int num_of_tests = 100000;
273  static Mdouble max_num = 100.0;
274  static unsigned int num_of_bins = 10;
275 
276  //This is the generated random_number
277  Mdouble rn;
278  //This is the bin the random number will lie in
279  unsigned int bin = 0;
280  //This is a vector of bins
281  std::vector<int> count;
282  count.resize(num_of_bins);
283 
284  //Initialisation of the bins
285  for (unsigned int i = 0; i < num_of_bins; i++)
286  {
287  count[bin] = 0;
288  }
289 
290  //Loop over a number of tests
291  for (unsigned int i = 0; i < num_of_tests; i++)
292  {
293  rn = getRandomNumber(0.0, max_num);
294  bin = static_cast<unsigned int>(std::floor(rn * num_of_bins / max_num));
295 
296  //Add one to the bin count
297  count[bin]++;
298 
299  }
300 
301  //Final post-process the result and report on the random number
302  Mdouble chi_cum = 0.0;
303  Mdouble expected = num_of_tests / num_of_bins;
304 
305  for (unsigned int i = 0; i < num_of_bins; i++)
306  {
307  chi_cum = chi_cum + (count[i] - expected) * (count[i] - expected) / expected;
308  logger(INFO, "% : % : %\n", Flusher::NO_FLUSH, i, count[i], (count[i] - expected) * (count[i] - expected) /
309  expected);
310  }
311  //end for loop over computing the chi-squared value.
312  logger(INFO, "chi_cum %", chi_cum);
313 
314  return mathsFunc::chi_squared_prob(chi_cum, num_of_bins);
315 }
@ INFO
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 floor(const bfloat16 &a)
Definition: BFloat16.h:643
Mdouble chi_squared_prob(Mdouble x, unsigned int k)
This is the function which actually gives the probability back using a chi squared test.
Definition: ExtendedMath.cc:167

References mathsFunc::chi_squared_prob(), Eigen::bfloat16_impl::floor(), getRandomNumber(), i, INFO, logger, and NO_FLUSH.

◆ write()

void RNG::write ( std::ostream &  os) const
59 {
60  os << " " << static_cast<unsigned int>(type_);
61  os << " " << a_;
62  os << " " << c_;
63  os << " " << m_;
64  os << " " << p_;
65  os << " " << q_;
67  //for (auto v : randomSeedLaggedFibonacciGenerator_)
68  // os << " " << v;
69 }

References a_, c_, m_, p_, q_, randomSeedLinearCongruentialGenerator_, and type_.

Referenced by DPMBase::write().

Member Data Documentation

◆ a_

unsigned long int RNG::a_
private

This are the two parameters that control the LCG random generated.

Referenced by getRandomNumberFromLinearCongruentialGenerator(), randomise(), read(), RNG(), setLinearCongruentialGeneratorParmeters(), and write().

◆ c_

◆ haveSavedBoxMuller_

bool RNG::haveSavedBoxMuller_
private

A flag that keeps track of whether or not to generate a new pair of normal variates (using Box–Muller)

Referenced by getNormalVariate(), and RNG().

◆ m_

◆ p_

unsigned long int RNG::p_
private

This are the parameters that control the LFG random generator.

Referenced by getRandomNumberFromLaggedFibonacciGenerator(), randomise(), read(), RNG(), seedLaggedFibonacciGenerator(), setLaggedFibonacciGeneratorParameters(), and write().

◆ q_

◆ randomSeedLaggedFibonacciGenerator_

std::vector<Mdouble> RNG::randomSeedLaggedFibonacciGenerator_
private

◆ randomSeedLinearCongruentialGenerator_

unsigned long int RNG::randomSeedLinearCongruentialGenerator_
private

This is the initial seed of the RNG.

Referenced by getRandomNumberFromLinearCongruentialGenerator(), randomise(), read(), RNG(), setRandomSeed(), and write().

◆ savedBoxMuller_

Mdouble RNG::savedBoxMuller_
private

A storage space for the so-far-unused variate from the pair generated by Box–Muller.

Referenced by getNormalVariate(), and RNG().

◆ type_

RNGType RNG::type_
private

This is the type of random number generator.

Referenced by getRandomNumber(), randomise(), read(), RNG(), setRandomNumberGenerator(), and write().


The documentation for this class was generated from the following files: