Solved

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

Posted on 2006-07-17
4
162 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
  • 2
  • 2
4 Comments
 
LVL 37

Accepted Solution

by:
Harisha M G earned 500 total points
Comment Utility
Hi PeterdeB,

LowerNo + Rnd() * (UpperNo - LowerNo)

---
Harish
0
 
LVL 37

Expert Comment

by:Harisha M G
Comment Utility
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
Comment Utility
Randomize

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

Expert Comment

by:Jim Horn
Comment Utility
{too slow...}
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

762 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

9 Experts available now in Live!

Get 1:1 Help Now