Solved

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

Posted on 2006-07-17
4
164 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
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

785 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