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

x
?
Solved

Max value from System.Random

Posted on 2005-03-25
5
Medium Priority
?
210 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:CRIIT
5 Comments
 
LVL 12

Expert Comment

by:S-Twilley
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
0
 
LVL 8

Expert Comment

by:mani_sai
ID: 13631177
Random R = new Random();
Random.Next(1,100);
 

will generate a random number between 1 and 100.

0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 13631313
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."



0
 
LVL 9

Accepted Solution

by:
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.

Jack.net

0
 

Author Comment

by:CRIIT
ID: 13644014
Thanks a lot
0

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