Solved

Random Numbers

Posted on 2011-10-01
3
305 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
Comment
Question by:hamda000
3 Comments
 
LVL 3

Expert Comment

by:sofsol
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 85

Accepted Solution

by:
Mike Tomlinson earned 500 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

Open in new window

0
 

Author Closing Comment

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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

14 Experts available now in Live!

Get 1:1 Help Now