CRIIT
asked on
Max value from System.Random
Hi,
I need to find out the max value that the system can generate by using the following random function. I am using these codes. And it returns 2147483647. Can anyone explain why the max value looks like this.
'------------------------- ---------- ---------- ---------- ----
Dim myRandom As New System.Random
Dim myMax As Double = myRandom.Next().MaxValue
'---------myMax = 2147483647
Thank you,
Joseph
I need to find out the max value that the system can generate by using the following random function. I am using these codes. And it returns 2147483647. Can anyone explain why the max value looks like this.
'-------------------------
Dim myRandom As New System.Random
Dim myMax As Double = myRandom.Next().MaxValue
'---------myMax = 2147483647
Thank you,
Joseph
Random R = new Random();
Random.Next(1,100);
will generate a random number between 1 and 100.
Random.Next(1,100);
will generate a random number between 1 and 100.
mani_sai,
You are almost correct.
Random.Next(1,100);
This will return a value between 1 and 99 inclusive.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemRandomClassNextTopic1.asp
"Return Value = A 32-bit signed integer greater than or equal to zero and less than MaxValue."
You are almost correct.
Random.Next(1,100);
This will return a value between 1 and 99 inclusive.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemRandomClassNextTopic1.asp
"Return Value = A 32-bit signed integer greater than or equal to zero and less than MaxValue."
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot
The Integer data type is typically 32bit (i.e. when not using the other Int types)... which has ranges (from the help file):
"The Int32 value type represents signed integers with values ranging from negative 2,147,483,648 through positive 2,147,483,647."
So regardless of whether you are assigning it to a double or single, or long... that's going to be your range... I think :P