dimanche 13 septembre 2020

I encoutered a problem when I used mt19937 to generate random numbers in C++

I was trying the generate random numbers using mt19937 in c++ as shown in the code but I encounterd some weired behaviour.

#include <bits/stdc++.h>
using namespace std;

int main() {
    mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
    int n = rng() % 10 + 2;
    cout << n << endl;
    for (int i = 0; i < n; i++) {
        int x = rng() % 10 + 1;
        int y = rng() % 10 + 1;
        cout << x << " " << y << " " << endl;
    }
}

When I run my code in "CLion", It runs and behaves as expected;however, when trying to run the code using the terminal, It doesn't compile and I recieve 'mt19937' was not declared in this scope as an error message. Here is the Error message screenshot




Aucun commentaire:

Enregistrer un commentaire