Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Max value from System.Random

Posted on 2005-03-25
Medium Priority
Last Modified: 2010-04-23

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,

Question by:CRIIT
LVL 12

Expert Comment

ID: 13631152
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

Expert Comment

ID: 13631177
Random R = new Random();

will generate a random number between 1 and 100.

LVL 86

Expert Comment

by:Mike Tomlinson
ID: 13631313

You are almost correct.


This will return a value between 1 and 99 inclusive.


"Return Value = A 32-bit signed integer greater than or equal to zero and less than MaxValue."


Accepted Solution

jrscherer earned 200 total points
ID: 13635173
Your question is: Can anyone explain why the max value looks like this.

The answer to your question is:
the System.Random function returns a Integer data type.
The statement  "Dim myMax As Double = myRandom.Next().MaxValue"  has nothing to do with randomization. It returns simply the value .MaxValue of a 32 bit integer, which is a constant of 2147483647, equals to (2 ^ 31) -1

If you want to see the maximum value a randomizer produces, you have to program a randomizer in a loop, run it for some time and memorize the highest value the randomizer did produce.



Author Comment

ID: 13644014
Thanks a lot

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question