CYCLUS
Loading...
Searching...
No Matches
random_number_generator.cc
Go to the documentation of this file.
2
3#include <iostream>
4#include <string>
5
6#include "logger.h"
7#include "sim_init.h"
8#include "context.h"
9
10namespace cyclus{
11
12 Generator RandomNumberGenerator::gen_;
13
15
16 gen_.seed(si.seed);
17
18 CLOG(LEV_INFO1) << "Pseudo random number generator initialized with seed: " << si.seed;
19 }
20
22 return gen_();
23 }
24
26 boost::random::uniform_01<> dist;
27 return dist(gen_);
28 }
29
31 boost::random::uniform_int_distribution<> dist(low, high);
32 boost::random::variate_generator<Generator&, boost::random::uniform_int_distribution<> > rn(gen_, dist);
33 return rn();
34 }
35
37 boost::random::uniform_real_distribution<> dist(low, high);
38 boost::random::variate_generator<Generator&, boost::random::uniform_real_distribution<> > rn(gen_, dist);
39 return rn();
40 }
41
42 double RandomNumberGenerator::random_normal_real(double mean, double std_dev, double low, double high){
43 boost::random::normal_distribution<> dist(mean, std_dev);
44 boost::random::variate_generator<Generator&, boost::random::normal_distribution<> > rn(gen_, dist);
45 double val = rn();
47 val = rn();
48 }
49 return val;
50 }
51
53 boost::random::normal_distribution<> dist(mean, std_dev);
54 boost::random::variate_generator<Generator&, boost::random::normal_distribution<> > rn(gen_, dist);
55 double val = rn();
57 val = rn();
58 }
59 int rounded_val = std::lrint(val);
60 return rounded_val;
61 }
62
63 //
64 // Distributions
66 double val = dist(RandomNumberGenerator::gen_);
67 while (val < min_ || val > max_){
68 val = dist(RandomNumberGenerator::gen_);
69 }
70 return val;
71 }
72
74 double val = dist(RandomNumberGenerator::gen_);
75 while (val < min_ || val > max_){
76 val = dist(RandomNumberGenerator::gen_);
77 }
78 return std::lrint(val);
79 }
80}
double random_01()
wrappers for boost::random distributions
int random_uniform_int(int low, int high)
generate a random integer between [low, high)
double random_uniform_real(double low, double high)
generate a random real number between [low, high)
void Initialize(SimInfo si)
Initialize from seed.
double random_normal_real(double mean, double std_dev, double low=0, double high=std::numeric_limits< double >::max())
generate a double from a normal distribution, with truncation at low and high
int random_normal_int(double mean, double std_dev, int low=0, int high=std::numeric_limits< int >::max())
generates an integer from a normal distribution, with truncation uses rounding to convert double to i...
Container for a static simulation-global parameters that both describe the simulation and affect its ...
Definition context.h:45
Code providing rudimentary logging capability for the Cyclus core.
#define CLOG(level)
Definition logger.h:39
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
boost::random::mt19937 Generator
@ LEV_INFO1
Information helpful for simulation users and developers alike - least verbose.
Definition logger.h:53
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters