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


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.

rmtogetherAsked:
Who is Participating?
 
Harisha M GConnect With a Mentor Commented:
Hi PeterdeB,

LowerNo + Rnd() * (UpperNo - LowerNo)

---
Harish
0
 
Harisha M GCommented:
rmtogether, you might also want to add Int or Round if you want it to be integer..

LowerNo + Int(Rnd() * (UpperNo - LowerNo))
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Randomize

Dim iYourNumber As Integer
iYourNumber = CInt((205 - 103) * Rnd) + 103
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
{too slow...}
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.