Solved

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

Posted on 2009-05-10
3
181 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
3 Comments
 
LVL 15

Expert Comment

by:OMC2000
Comment Utility
    ' 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 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
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
Comment Utility
excellent!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now