logo
g Text Version
Auto
Beauty & Self
Books & Music
Career
Computers
Education
Family
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
Money
News & Politics
Relationships
Religion & Spirituality
Society & Culture
Sports
Travel & Leisure
TV & Movies

dailyclick
Bored? Games!
Postcards
Astrology
Take a Quiz
Rate My Photo

new
Jokes & Riddles
Astronomy
Philosophy
Public Health
Canadian Culture


dailyclick
All times in EST

Low Carb: 8:00 PM

Full Schedule
g
g ASP Site
Editor Wanted
BellaOnline's ASP Editor

g

Random Numbers in ASP
Guest Author - Lisa Shea

There are many situations in which you'll want to have a random number in your ASP script. This can be used to change ads, to generate greetings, and much more.

First, a computer needs to know where to 'start' in generating its random number. Otherwise it'll generate the same sequence of numbers. It's only a computer after all and can't think - it can just follow instructions. So before you do anything else, you must issue the command

Randomize()

That starts your random number generator off at a spot based on the system timer, so it'll always be different.

Next, any time you reference the RND variable, it'll be set to a random value between 0 and 1. So it could be .3, .6, 0, 1, or any other number in that range.

So your aim is to get that number into the range you want it in, and to then use INT to chop off any decimal points. Let's say you want a number between 1 and 10. You would multiply that starting number by 9, and add 1 so that a 0 turned into a 1, a 1 into a 2 and so on. The lowest number it could create would be 1 (0 + 1), and the highest number would be 10 (9 + 1). Your formula would look like

RandNumb = Int((9 * Rnd) + 1)

You can use random numbers to display different ads, to change greetings, to generate random tips or fortune cookies. Have fun!

Introduction to ASP Ebook

Download this ebook to get everything you need to know about learning ASP - from a step by step tutorial to function lists, sample code, common errors and solutions, and much more! 101 pages.

This site needs an editor - click to learn more!

RSS | Related Articles | Previous Features | Site Map


Content copyright © 2008 by Lisa Shea. All rights reserved.
This content was written by Lisa Shea. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.

Digg! g delicious Save to Del.icio.us

g


For FREE email updates, subscribe to the ASP Newsletter


Past Issues


print
Printer Friendly
bookmark
Bookmark
tell friend
Tell a Friend
forum
Forum
email
Email Editor

g features
Best uses for RSS

RSS and its future.

Force Download Dialog box with ASP

Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Driving Amount
Much more
Slightly more
Slightly less
Much less

g


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2008 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor