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!

Generate a New Random Number Each Day

Status
Not open for further replies.

Krus1972

Programmer
Mar 18, 2004
145
US
Hello,

Could someone help me with a small ASP script that will:

1. Generate a new random number everyday. A new number will be generated when the server date changes to the next day. The new number will always replace the number from the day before. The number will always stay constant for each (visitor) to my site for the entire day. I do not want to store the day's number in my MSSQL Database unless I have too.

2. The Random number will be between a lower and upper bound determine by me. The upper & lower bound can always be changed by me.


Thanks,
Jeff


 
If you use the date as a seed for Randomize, then call Rnd(), you'll get a different number each day, but the random number will remain the same until the server's date changes.

Code:
Randomize Date

MsgBox CInt(Rnd() * 10000)

Lee
 
I need to be able to pick the upper & lower bounds of the number before the server piucks the number. The number won't change until the next day.

Thanks,

Jeff
 
I arbitrarily put in 10,000 just as an example, but you can change that to whatever you want. Choosing a number in a range is basically:

randnumber = CInt(Rnd() * ((upperlimit + 1) - lowerlimit))) + lowerlimit

This will give you a range of numbers that will include the lower and upper limits as possible values returned.

Setting the seed for the random number generator to the date will provide the same sequence the entire day.

If you do a search on Google for generating numbers with VBScript, you should find answers to any other questions you have, too.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top