vendredi 28 août 2015

Random Number Generator C++ Error in CMD

I'm trying to make a random number generator, to generate a number between 0 and 999.

I did originally have it running where the seed for mt19937 was generated from time(null), but found that this would cause the number to change once per second, and was not fast enough for when I called it again from within the for loop.

I'm using code::blocks to compile my code, and it compiles with no errors, but when I run the code I an error in cmd.

Error: terminate called after throwing an instance of 'std::runtime_error'
  what():  random_device::random_device(const std::string&)

Am I doing something horribly wrong?

#include <iostream>
#include <random>

using namespace std;

//Random Number Generator
int numGen() {

    //Random Number Generator
    random_device rd;
    mt19937 mt(rd());
    uniform_int_distribution<int> dist(0, 999);

    for (int I = 0; I < 6; i++) {
        cout <<dist(mt) << " ";
    }

    cout <<endl;
}

Aucun commentaire:

Enregistrer un commentaire