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

According to the MSDN docs method, Random.Next() returns a non-negative random number. Why is this happening? int instead of uint ?

It seems that returning a value that will be evenly distributed over the range of the type used will make the most sense. In terms of use, if you use int , it should cover the range of int , and if you use uint , it should also return a uniform distribution by type. Isn't that a type use point?

+4
source share
2 answers

uint is not compatible with CLS.

Here are some great readings on the topic:

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

+16
source

It is impossible to talk about why MSFT did this.
But if you need a random UInt32, it's simple enough.

 Random ran = new Random(); Debug.WriteLine(Int32.MaxValue.ToString()); Debug.WriteLine(((UInt32)ran.Next(Int32.MinValue, Int32.MaxValue)).ToString()); 
0
source

Source: https://habr.com/ru/post/1488147/


All Articles