//My trial program
#include<iostream>
#include<random>
using namespace std;
int main(){
//USed to initialize (seed) the random number generator
random_device sd{};
// The random number generator
mt19937 engine {sd()};
//Uniformly distribute random numbers in [1...10]
uniform_int_distribution <> dis{1, 50};
//Generate a random integer
int x {dis(engine)};
//Print it
cout<<x<<"\n";
return 0;
}
I have used the code above to a generate random number between 1 to 50. But whenever I run the program, the random number generated is the same. An online course that I am taking has this code and it works perfectly fine on the instructor's clang compiler. I am using gcc compiler. Can anyone tell me what needs to be done please? thank you!!
Aucun commentaire:
Enregistrer un commentaire