?
Solved

How to obtain a ramdom number between 1 and 50

Posted on 2003-03-06
7
Medium Priority
?
169 Views
Last Modified: 2010-05-01
How can I obtain a random number between 1 and 50?
0
Comment
Question by:Gmoney
[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 1

Expert Comment

by:Fischermaen
ID: 8086580
of course, try

Int(Rnd() * 50) + 1

and you'll be happy !

Andy
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 8086592
Remeber to put Randomize on before the line:
i = Int(Rnd() * 50) + 1

cheers
0
 

Expert Comment

by:fathimasulthan
ID: 8086593

Hi,

U can use the following function to get randam number between 1 & 50.

Pass the number 1 & 50 to the following function, the function will return u the random numbers.


Public Function CreateRandNumber(int1stnumber As Integer, int2ndnumber As Integer) As Integer

Randomize Timer
CreateRandNumber = Int(Rnd * (int2ndnumber - int1stnumber)) + int1stnumber

End Function


CHEERS,
Fathima
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Accepted Solution

by:
PlanetCpp earned 200 total points
ID: 8086595
in form load event (or anywhere where this can be called once and only once before you get the random number)
write
Randomize
or
call Randomize()
whichever
that seeds the random number generator with a unique value so that you don't get the same numbers each time
then to get a random number you use
Rnd
this returns a value between 0 and 1
to use this you write (for 1 to 50)
randomnumber = Int(Rnd * 50) + 1
Int(Rnd * 50) gives you 0-49, then adding one makes it 1-50
0
 
LVL 6

Expert Comment

by:PlanetCpp
ID: 8086598
? i didn't see any posts when i started answering lol
0
 

Expert Comment

by:girish_its
ID: 8087583
hi,

   U can use the code


Randomize
dim rNo
rNo=CInt(Rnd()*50) +1

this results in the variable rNo set to a random number (not a decimal or float). if u want in decimal u donot put 'CInt'.

BYE.
0
 

Author Comment

by:Gmoney
ID: 8098907
Thanks for your help
0

Featured Post

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.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

765 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