Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Random.Next() return an int instead of uint?

Tags:

c#

.net

random

According to MSDN docs the method Random.Next() Returns a nonnegative random number. Why on earth does it return int instead of uint?

It seems that returning a value that would be evenly distributed over the range of the type used would make the most sense. From a usage standpoint - if you are using int it should cover the range of int, and if you are using uint it should also return an even distribution over the type. Isn't that the point of using a type?

like image 300
Zac Avatar asked Dec 05 '22 10:12

Zac


1 Answers

uint is not CLS-Compliant.

Here is some great reading on the topic:

http://msdn.microsoft.com/en-us/library/vstudio/bhc3fa7f(v=vs.100).aspx

like image 105
ravibhagw Avatar answered Dec 20 '22 02:12

ravibhagw