Home  |  Latest News  |  Contribute  |  F.A.Q.  |  Account  |  Scripts | About
Search ASPNut:
 
ASP Reference
Server Variables
ASP Glossary
Related Sites

Free Components

Web Colors
Entities
CSS Level 1
Encode/Decode
Glossary

Our Sponsors
ASP Nuke CMS
Free Auctions
PHP 5 Script
Funktastic Blog
ULost Directory
Team Task

 

 

 

 

 

 

 

 

 

 

 

 

Rnd

The Rnd function generates a random number between 0 and 1. Actually, it will generate a number that is greater than or equal to zero and less than 1. It is important to note that the random function will never return the value 1.

As you may notice, the random function returns a floating point value. You can use the Int function along with some simple math to convert this floating value into a random integer.

Before you call this function, you should always seed the random number generator with a call to Randomize first. This will ensure that the numbers generated by Rnd are truly random. Or at least, as random as a random number generator can create.

' always call the following function before using Rnd Randomize
Dim I
' first display 100 randoms Response.Write "100 Randoms<BR>"
For I = 1 To 100
    Response.Write "Random(" & I & "): " & Rnd() & "<BR>"
Next

' now display 100 random integers (1-100) Response.Write "100 Random Integers<BR>"
For I = 1 To 100
    Response.Write "Random(" & I & "): " & CStr(Int(Rnd() * 100) + 1) & "<BR>"
Next

Orvado, San Diego Web Design

ASP Nuke CMS
Free Open Source
Content Manager
GoSwap Auctions
Buy, Sell
No Fees!

Contact Us | Contribute | About | Site Map



"LSD melts your mind, not in your hand." - Anon.

©2012 San Diego Web Design - Orvado Technologies, All Rights Reserved
ASP Nut provides articles and reference documentation for Active Server Page developers.