This doesn't work:
for (int p = 0; p < 10; p++) {
    random_device rd;
    mt19937 gen(rd);
    uniform_real_distribution<int> dis(0, INT_MAX);
    printf("%i\n", dis(gen));
}
Any advice would be appreciated.
You have few mistakes in your code.
random_device and seeding mt19937 outside the for loop. I'll also suggest the same for uniform_real_distribution<int>mt19937 takes in the constructor value of seed not random_device so you have to call it to get seed(rd())uniform_int_distribution<int> if you are generating integersint value i'll suggest using more C++ style std::numeric_limits<int>::max()Here is working example:
#include <cstdio>
#include <random>
#include <limits>
using namespace std;
int main(){
  random_device rd;
  mt19937 gen(rd());
  uniform_int_distribution<int> dis(0, std::numeric_limits<int>::max());
  for (int p = 0; p < 10; p++) {
    printf("%i\n", dis(gen));
  }
  return 0;
}
User contributions licensed under CC BY-SA 3.0