Link to home
Start Free TrialLog in
Avatar of CRIIT
CRIITFlag for Afghanistan

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
Avatar of S-Twilley
S-Twilley

the random class works around integer values.... the function MaxValue returns an integer value

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
Random R = new Random();
Random.Next(1,100);
 

will generate a random number between 1 and 100.

Avatar of Mike Tomlinson
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."



ASKER CERTIFIED SOLUTION
Avatar of jrscherer
jrscherer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CRIIT

ASKER

Thanks a lot