?
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
Medium Priority
?
199 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
[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
7 Comments
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

777 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