?
Solved

Max value from System.Random

Posted on 2005-03-25
5
Medium Priority
?
201 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

762 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