I am a beginner in C++ and I am trying to explore C++11 features. Here I am trying to get familiar with the new randomness generating engines.
I summarized the following code from a tutorial on this subject and I noticed two things:
1- The uniform_real_distribution
doe not include the max value.
2- The commented line produce an error although it seems to work fine on the tutorial.
#include <iostream>
#include <chrono>
using namespace std;
int main(){
unsigned seed = 201;
//seed = chrono::steady_clock()::now().time_since_epoch().count();
default_random_engine e(seed);
uniform_real_distribution<double> u(0,9);
vector<double> v(10);
int num;
for(int i = 0; i < 400; ++i){
num = u(e);
++v[num];
}
for (int i = 0; i < 10; ++i)
cout << i << ": " << string(v[i],'*') << "\n";
}
I tried to find the reasons of these two things with no luck.
So, my questions:
1- How to include the max value?
2- Why I am getting the error when uncomment the chrono
line ?
cannot convert 'std::chrono::_V2::steady_clock' to 'unsigned int' in initialization
Note: I am using MinGW64 g++ with c++14.
Aucun commentaire:
Enregistrer un commentaire