ASP 101 - Active Server Pages 101 - Web05
The Place ASP Developers Go!



Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates
ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash



 Top ASP 101 Stories Top ASP 101 Stories
Connections, Commands, And Procedures
What is ASP?
VBScript Classes: Part 1 of N

QUICK TIP:
Scope out your variables
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates


Quick Tips


Be Sure To Randomize Your Random Numbers

I recently got an email from a user who was complaining that his computer couldn't generate a random number. He had used the Rnd() function to generate a number between 0 and 1 and then done the calculations to get a number in the range he needed, but no matter what he tried it was always giving him the same value.

Well the problem is that computers really aren't very good at picking random numbers. They actually create sequences of pseudo-random numbers by using a formula. The problem is this formula needs a value to get started. It's called a seed value and, unless you tell it otherwise, your computer always starts with the same seed value when it's asked for a random number. The result is that the computer always generates the same sequence of "random" numbers. (So much for them being random!)

The solution is to call the Randomize() statement before making your first call to Rnd(). This causes the computer to initialize the random number generator using a seed value based on the system timer and will give you numbers that are a little less predictable.


Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to: webmaster@asp101.com.


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers