jeudi 24 décembre 2015

C++ Generating random numbers

srand(time(NULL));
    for (int o = 0; o < 8; o++){

        x = rand() % 126 + 33;      
        keysInNumbers[o] = x;
        cout << "Randomly generated number: " << keysInNumbers[o] << endl;
    };

This should be generating random numbers between 33 and 126 but for some reason there are a few numbers that are above 126 though never below 33. I cannot figure out why this is happening.




Aucun commentaire:

Enregistrer un commentaire