-
Notifications
You must be signed in to change notification settings - Fork 0
/
NormalGenerator.cpp
52 lines (41 loc) · 969 Bytes
/
NormalGenerator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// This is a source file for Normal Generator and Printer Functions
#include "MCOptionData.hpp"
#include <boost/random.hpp>
#include <boost/random/normal_distribution.hpp>
#include<iostream>
using namespace std;
boost::mt19937 rng; // random generator
double getz()
{
// boost::mt19937 rng; // random generator
boost::normal_distribution<> StdNorm(0.0, 1.0); //standard normal
double out;
out = StdNorm(rng);
return(out);
}
vector<double> getz(long N)
{
boost::normal_distribution<> StdNorm(0.0, 1.0); //standard normal
vector<double> out(N);
for(long i = 0; i<N; i++){
out[i] = StdNorm(rng);
}
return(out);
}
void Print1d (const vector<double>& v) // Print a double vector
{
for(int i = 0; i < v.size(); i++){
cout << v[i] << " ";
}
}
void Print2d (const vector<vector<double> >& v) // Print a matrix
{
for(int j = 0; j < v[0].size(); j++)
{
for (int i = 0; i < v.size(); i++)
{
cout << v[i][j] << " ";
}
cout << endl;
}
}