-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp~
More file actions
51 lines (41 loc) · 1.28 KB
/
test.cpp~
File metadata and controls
51 lines (41 loc) · 1.28 KB
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
#include <iostream>
#include <vector>
#include <random>
#include <fstream>
#include <math.h>
int main()
{
/*
std::default_random_engine generator;
double a = 1; // a^2 = kT/m
std::normal_distribution<double> distribution(0,a);
std::ofstream output("test.dat");
int numSample = 1000000;
for (int i=0;i<numSample;i++)
output << distribution(generator) << std::endl;
*/
std::ofstream prob("test.dat");
const double nrolls=10; // number of experiments
std::default_random_engine generator;
std::normal_distribution<double> distribution(0.0,.5);
double p[1000]={};
int counter = 0;
for (int i=0; i<nrolls; ++i) {
double number = distribution(generator);
// int num = (int)floor(number*100)+500;
// if (num < 0 || num > 1000) std::cout << "out of bounds" << std::endl;
if ((number>=-5.0)&&(number<5.0))
{
p[(int)floor(number*100)+500]++;
counter++;
}
else std::cout << "out of bounds" << std::endl;
}
std::cout << "counter - numrolls = " << counter-nrolls << std::endl;
// std::cout << "normal_distribution (5.0,2.0):" << std::endl;
for (int i=0; i<1000; i++) {
// std::cout << i << "-" << (i+1) << ": ";
prob << ((double)i-500.0)/100 << " " << p[i]/nrolls << std::endl;
}
return 0;
}