vendredi 26 mai 2017

discreet distribution of a specified range of random numbers

I know I can use std::discreet_distribution like this:

  std::default_random_engine generator;
  std::discrete_distribution<int> distribution {2,2,1,1,2,2,1,1,2,2};

  int p[10]={};

  for (int i=0; i<100; ++i) {
    int number = distribution(generator);
    ++p[number];
  }

However, this is going to generate the numbers in the range of 0-9 as per the weight specified.

What can I do to generate the numbers within a user specified range, say for example, 24-33 or 95-104 etc but still using the distribution specified in discrete_distribution ?

Appreciate any advice!




Aucun commentaire:

Enregistrer un commentaire