Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to obtain a ramdom number between 1 and 50

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

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Independent Software Vendors: 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!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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

579 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