int nextInt(int n) {
return rand() / static_cast<double>(RAND_MAX) * n;
}
I find someone write the above function(nextInt
) and he said nextInt
returns a random int in [0, n - 1], but I think nextInt
returns a random int in [0, n]. I wonder who is right and why?
Aucun commentaire:
Enregistrer un commentaire