samedi 14 octobre 2017

Uniform random numbers are the same in all runs

I find a method of generating uniform random number in range(aa,bb) as below:

#include <random>
double randnum (double aa, double bb)  //defining a function to create random numbers
{
  static std::default_random_engine generator;
  std::uniform_real_distribution<double> distribution (aa,bb);
  return distribution(generator);
}

For example, randnum(0,1); creates a random number between 0 and 1. The problem is that, during different runs, the random sequence which I create in for loop is exactly the same. How can I create different random numbers during different runs?




Aucun commentaire:

Enregistrer un commentaire