Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Random Numbers

Posted on 2011-10-01
Medium Priority
349 Views
Last Modified: 2012-06-21
I would like to generate multiple numbers between two values (Exemple: 2000 and 3000).
I wrote this program but it generate only one value at one click. I want to generate multiple integers in one click (2000, 2001, 2020, 2876...). Here is my code:

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim r As Random = New Random
MsgBox(r.Next(10, 15))
End Sub
End Class

Any idea please?
Thanks.
0
Question by:hamda000
[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 3

Expert Comment

ID: 36897759
I am assuming you want a character string that looks like "number, number, number"

Create a loop that runs "n" times according to how many random numbers you want.

Initialise a variable to store the result in and for each run through the loop, append a random number and, so long as n is less than the total of random numbers required, a comma and a space.

When the loop has finished, pass the variable back to the calling code.
0

LVL 86

Accepted Solution

Mike Tomlinson earned 2000 total points
ID: 36897930
Maybe something like this?
``````Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim rndValues As List(Of Integer)
rndValues = GetRandomValues(2000, 3000, 25)
ListBox1.DataSource = rndValues
End Sub

Private Function GetRandomValues(ByVal min As Integer, ByVal max As Integer, ByVal quantity As Integer) As List(Of Integer)
Static R As New Random
Dim values As New List(Of Integer)
For i As Integer = 1 To quantity
values.Add(R.Next(min, max + 1))
Next
Return values
End Function
End Class
``````
0

Author Closing Comment

ID: 36898109
Thanks. Now I have to work on the sorting.
0

## Featured Post

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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…
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 …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
###### Suggested Courses
Course of the Month11 days, 22 hours left to enroll

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

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