Solved

find a random number in a range ( between 2 numbers)

Posted on 2006-07-17
4
166 Views
Last Modified: 2010-04-30

I need use VB to generate a random number between 2 numbers. for example:

generate a random number between 103 and 205, the program return me 165. something like this.

0
Comment
Question by:rmtogether
[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
  • 2
  • 2
4 Comments
 
LVL 37

Accepted Solution

by:
Harisha M G earned 500 total points
ID: 17124686
Hi PeterdeB,

LowerNo + Rnd() * (UpperNo - LowerNo)

---
Harish
0
 
LVL 37

Expert Comment

by:Harisha M G
ID: 17124697
rmtogether, you might also want to add Int or Round if you want it to be integer..

LowerNo + Int(Rnd() * (UpperNo - LowerNo))
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 17124699
Randomize

Dim iYourNumber As Integer
iYourNumber = CInt((205 - 103) * Rnd) + 103
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 17124704
{too slow...}
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

730 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