vendredi 27 mars 2015

Why is C#'s random lower limit inclusive, but upper limit exclusive?

Take this code for example:



Random rnd = new Random();
int rndNumber = rnd.Next(0,101);


One would expect that either one of the following would happen:

-rndNumber contains a random integer between 0 and 101

-rndNumber contains a random integer between 1 and 100


What actually happens though, is that rndNumber contains a random integer between 0 and 100. Why is this the case?


I understand that the upper limit is exclusive, but then why is the lower limit inclusive? Why is this not consistent?





Aucun commentaire:

Enregistrer un commentaire