감동, 마음이 움직이는 것
[c++] random variable form Gaussian dist. 본문
[c++] random variable form Gaussian dist.
Struggler J. 2018. 11. 10. 00:23http://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.
'Tips (Utility, Computer Language, and etc.)' 카테고리의 다른 글
[Latex] multiple ailgnment (0) | 2018.11.16 |
---|---|
[Latex] xarrow에서 화살표 width 고정시키기 (0) | 2018.11.16 |
[python] parallel computing (multiprocessing) (0) | 2018.11.08 |
[gnuplot] w boxes options (histogram 그릴 때 막대기 종류) (0) | 2018.11.03 |
[gnuplot] std with filledcurve 편차 예쁘게 그리기 (0) | 2018.11.03 |