Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random Numbers

Status
Not open for further replies.

Krus1972

Programmer
Mar 18, 2004
145
US
I have the following small script that chooses a new random number each day:

Dim myvar(100)

theDate = (Left(Right(Date(),7),2))
theDate = replace (theDate, "/", "")

Randomize theDate
randnumber = Int((UBound(myvar) - 0 + 1) * Rnd + 0)

By using Ubound(myvar) the server will pick a Random number between 0-100. What I would like to do is modify the above script so I can manually input numbers of which the server will randoomly pick any one.

For example each day I would like the server to pick only one number from the following numbers of MY choosing:

10
20
30
32

I will change these numbers and add or subject the qunaityt of numbers now and then.

Any help would be well appreciated.

Jeff


 
How about something like this?
Code:
Dim numbers, randnumber, theDate

theDate = (Left(Right(Date(),7),2))
theDate = replace (theDate, "/", "")

Randomize theDate

numbers = Array(10, 20, 30, 32)

randnumber = Int(Rnd((UBound(numbers) + 1)))

Lee
 
Close but I am not saure if that will work.

the randumber varaible will be a number between 0 and the Upper Bound of the numbers array. In this case the ranom number will be between 0 and 4

The Random Number needs to be 10,20,30, or 32


 
Sorry, I forgot part of the last line, but you SHOULD have been able to make the conversion.

Code:
randnumber = numbers(Int(Rnd((UBound(numbers) + 1))))

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top