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
Journals
Folklore and Mythology
Business Coach
Marriage
Senior Living
Ethnic Beauty
Adolescence


dailyclick
All times in EST

Autism Spectrum Disorders: 4: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

Add Random+Numbers+in+ASP to Twitter Add Random+Numbers+in+ASP to Facebook Add Random+Numbers+in+ASP to MySpace Add Random+Numbers+in+ASP to Del.icio.us Digg Random+Numbers+in+ASP Add Random+Numbers+in+ASP to Yahoo My Web Add Random+Numbers+in+ASP to Google Bookmarks Add Random+Numbers+in+ASP to Stumbleupon Add Random+Numbers+in+ASP to Reddit


Content copyright © 2009 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.

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

jobs
what
job title, keywords
where
city, state or zip
jobs by job search


vote
Growing a Garden
Veggies and Flowers
Veggies Only
Flowers Only
No Garden

g


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


BellaOnline Editor