Here's a bit of a puzzler: Random.Next()
has an overload that accepts a minimum value and a maximum value. This overload returns a number that is greater than or equal to the minimum value (inclusive) and less than the maximum value (exclusive).
I would like to include the entire range including the maximum value. In some cases, I could accomplish this by just adding one to the maximum value. But in this case, the maximum value can be int.MaxValue
, and adding one to this would not accomplish what I want.
So does anyone know a good trick to get a random number from int.MinValue
to int.MaxValue
, inclusively?
Aucun commentaire:
Enregistrer un commentaire