[c++] random variable form Gaussian dist.
http://www.cplusplus.com/reference/random/normal_distribution/
#include <iostream>
#include <string>
#include <random>
using namespace std;
int main() {
int nrolls = 10000; //the number of sampling trial
random_device rd; //making random seed for generator
default_random_engine generator( rd() ); //making random generator using the random seed
normal_distribution<double> gaussian(5., 2.); //Gaussian distribution with mean 5 deviation 2
int p[10] = {};
double temp;
for (int i=0; i<nrolls; i++){
cout << gaussian(generator) << endl; //generating random number from the gaussian distribution
if (temp>0. && temp<10.) p[int(temp)]++;
}
//print the results
for(int i=0; i<10; i++){
cout << i << "-" << i+1 << ":";
cout << string(p[i]*nstars/nrolls,'*') << endl;
}
return 0;
}
You need -std=c++11 option to compile the code.