Solved

I am trying to find out how to make a random number between 1 - 500 in vb.net 2005

Posted on 2007-11-14
7
181 Views
Last Modified: 2013-11-26
Hi,

I am trying to find a function that will produce a random number between 1 - 500 when a button is pressed then send it to a msgbox please.

Many Thanks
Lee
0
Comment
Question by:ljhodgett
7 Comments
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 20279430
Hi ljhodgett,

Use something like this....

        Dim r As New Random
        MsgBox(Convert.ToInt32(r.NextDouble * 500))

Regards,

Wayne
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 20279434
Try this:

Dim rnd As New Random
MsgBox("This is an random number:" & rnd.Next(1, 500))

jpaulino
0
 
LVL 5

Expert Comment

by:administradores
ID: 20279437
I give you a function below

Usage: GetRandomNumber(1, 500)



    Private Function GetRandomNumber(ByVal vnMinimumNumber As Integer, ByVal vnMaximumNumber As Integer)
        Randomize()
        GetRandomNumber = CInt(Int((vnMaximumNumber - vnMinimumNumber + 1) * Rnd() + vnMinimumNumber))
    End Function

0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 28

Expert Comment

by:iboutchkine
ID: 20279445
Dim generator As New Random
        Dim randomValue As Integer

        ' Generates numbers between 1 and 500, inclusive.
        randomValue = generator.Next(1, 501)
        MsgBox(randomValue)
0
 
LVL 8

Expert Comment

by:Autoeforms
ID: 20279956
iboutchkine is correct in the best way to do this. however if you always generate a new generator (ie, generator As New Random) your number will not be truly random. It is better to create the random class that will persist for the entire time you need random numbers.

greg
 
0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 20280068
you define a new Random on the top of the form and in the event where you generate you number you will get the random number
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 20280738
Any luck Lee ???
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Function after success of Jquery/AJAX action 9 29
Iteration Help (Asp.net VB) 5 25
Error message when using PrintSocket.Send 7 19
Code enhancement 4 22
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

820 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