mardi 13 juin 2017

using std::uniform_real_distribution in a function that is called in main

I'm trying to use the std::uniform_real_distribution in a function that is called in main().

I seed the generator as follows in main():

 unsigned seed = 
 std::chrono::system_clock::now().time_since_epoch().count();
 std::default_random_engine generator (seed);
 std::uniform_real_distribution<double> distribution(0.0,1.0);

further on in main i call:

double number = distribution(generator)

when i need a random number.

The problem is that i also need ( many millions ) of random numbers in a function.

imagine a function that i call in main():

int main(){

  void function(){

    number = distribution(generator)
  }

  return 0;
}

how to do this? how to "access" the random number generator in a function.

many thanks!




Aucun commentaire:

Enregistrer un commentaire