Solved

Most efficient way to code 20 random numbers with different max values?

Posted on 2009-05-10
3
186 Views
Last Modified: 2012-05-06
I need to get 20 random whole numbers, all with a bottom limit of 1 and a max limit that is unique for all 20.

Once i get all 20 random numbers, I need to store them in a simple array:   mynumber(X)

Here are all 20 max limits:

10,13,18,23,30
17,62,8,27,38
102,78,66,98,73
33,70,80,111,85

What is the most efficient way to code my task, using the least amount of code and processing power?  I know how to code this, but I already know my code will be heavy-handed, and I have the feeling some wizard out there would know how to do this clean and efficient

The application is a visual ASP.NET application so code should be VB compatible for ASP.NET and will be executed on a web server.

Thank you!
0
Comment
Question by:arthurh88
[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
3 Comments
 
LVL 15

Expert Comment

by:OMC2000
ID: 24349648
    ' make array of values
      Dim myArray(20) As New Integer;
      ' Initialize random number generator.
      Dim rnd As New Random()

' fill it with the value from own interval for each one
         myArray(0) = rnd.Next(1, 10)
         myArray(1) = rnd.Next(1, 13)
         myArray(2) = rnd.Next(1, 18)
         myArray(3) = rnd.Next(1, 23)
...
         myArray(18) = rnd.Next(1, 111)
          myArray(19) = rnd.Next(1, 85)
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 24350373
How about:

        Dim R As New Random
        Dim maxLimits() As Integer = {10, 13, 18, 23, 30, 17, 62, 8, 27, 38, 102, 78, 66, 98, 73, 33, 70, 80, 111, 85}
        Dim myNumbers(maxLimits.Length - 1) As Integer
        For i As Integer = 0 To maxLimits.Length - 1
            myNumbers(i) = R.Next(1, maxLimits(i) + 1)
        Next

0
 

Author Comment

by:arthurh88
ID: 24351004
excellent!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
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: …

635 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