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
12Generator RandomNumberGenerator::gen_;
13
15 gen_.seed(si.seed);
16
17 CLOG(LEV_INFO1) << "Pseudo random number generator initialized with seed: "
18 << 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&,
33 boost::random::uniform_int_distribution<>>
34 rn(gen_, dist);
35 return rn();
36}
37
38double RandomNumberGenerator::random_uniform_real(double low, double high) {
39 boost::random::uniform_real_distribution<> dist(low, high);
40 boost::random::variate_generator<Generator&,
41 boost::random::uniform_real_distribution<>>
42 rn(gen_, dist);
43 return rn();
44}
45
46double RandomNumberGenerator::random_normal_real(double mean, double std_dev,
47 double low, double high) {
48 boost::random::normal_distribution<> dist(mean, std_dev);
49 boost::random::variate_generator<Generator&,
50 boost::random::normal_distribution<>>
51 rn(gen_, dist);
52 double val = rn();
53 while (val < low || val > high) {
54 val = rn();
55 }
56 return val;
57}
58
59int RandomNumberGenerator::random_normal_int(double mean, double std_dev,
60 int low, int high) {
61 boost::random::normal_distribution<> dist(mean, std_dev);
62 boost::random::variate_generator<Generator&,
63 boost::random::normal_distribution<>>
64 rn(gen_, dist);
65 double val = rn();
66 while (val < low || val > high) {
67 val = rn();
68 }
69 int rounded_val = std::lrint(val);
70 return rounded_val;
71}
72
73//
74// Distributions
76 double val = dist(RandomNumberGenerator::gen_);
77 while (val < min_ || val > max_) {
78 val = dist(RandomNumberGenerator::gen_);
79 }
80 return val;
81}
82
84 double val = dist(RandomNumberGenerator::gen_);
85 while (val < min_ || val > max_) {
86 val = dist(RandomNumberGenerator::gen_);
87 }
88 return std::lrint(val);
89}
90} // namespace cyclus
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:49
uint64_t seed
Seed for random number generator.
Definition context.h:126
Code providing rudimentary logging capability for the Cyclus core.
#define CLOG(level)
Definition logger.h:40
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.
Definition logger.h:60