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
Medium Priority
170 Views
How can I obtain a random number between 1 and 50?
0
Question by:Gmoney

LVL 1

Expert Comment

ID: 8086580
of course, try

Int(Rnd() * 50) + 1

and you'll be happy !

Andy
0

LVL 55

Expert Comment

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

cheers
0

Expert Comment

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

LVL 6

Accepted Solution

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

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

Expert Comment

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

ID: 8098907
0

## Featured Post

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
Course of the Month12 days, 13 hours left to enroll