dimanche 3 avril 2016

Random number generator repeats every time? [on hold]

I'm trying to find a random number generator that will give me a single random number each time I run it. I have spent a week trying dozens of different ones, both from this site and others. Every time I run it, it gives me the same number! The only time it changes is if I change the range, and then it just gives me the new number over and over. I am running Code::Blocks ver. 16.01 on Windows 7. Can anyone help?? I'm at my wits' end!

This code gives me a decently ramdom string of numbers, but still the same string each time!

#include <iostream>
#include <random>

int main()
{
  std::random_device rd;
  std::mt19937 eng(rd()); std::uniform_int_distribution<> distr(0, 10);

  for(int n=0; n<100; ++n)
    std::cout << distr(eng) << '\t';
}

I have tried the code on my compiler app on my phone as well.




Aucun commentaire:

Enregistrer un commentaire