samedi 13 mai 2017

mt19937 and normal distribution

Helo there! I am just starting to code in C++ and I'm not sure how to use random numbers generators properly. For example I need numbers from range [0,30000], how to make sure that I won't get only small numbers from my range. My function:

std::random_device rd;
std::mt19937 rng(rd());
int myRand(int i) {
    std::normal_distribution<double> distribution(30, 1500);
    double temp=distribution(rng);
    if(temp<0){
        temp*=(-1);
    }
    return (int) std::round(temp)%i;
}

Would you mind helping me to configure normal_distribution properly?




Aucun commentaire:

Enregistrer un commentaire