HOME

VBScript Tutorial
VB HOME
VB Introduction
VB How to
VB Where to
VB Variables
VB Procedures
VB Conditional
VB Looping

Examples
VB Examples

References
VB Functions
VB Keywords

Please visit our sponsors !

The Rnd Function

Back

The Rnd function returns a random number. The number is always less than 1 but greater or equal to 0.

Syntax

Rnd[(number)]

Parameter Description
number Optional. A valid numeric expression

If number is:

  • <0 - Rnd returns the same number every time
  • >0 - Rnd returns the next random number in the sequence
  • =0 - Rnd returns the most recently generated number
  • Not supplied - Rnd returns the next random number in the sequence

Example 1

document.write(Rnd)
Output:
0.7055475

Example 2

'If you refresh the page,
'using the code in example 1,
'the SAME random number will show over and over.
'Use the Randomize statement generate a new random number
'each time the page is reloaded!
Randomize
document.write(Rnd)
Output:
0.4758112

Example 3

'Here is how to produce random integers in a
'given range:
dim max,min
max=100
min=1
document.write(Int((max-min+1)*Rnd+min))
Output:
71


Back

Jump to: Top of Page or HOME or Printer Friendly Printer friendly page


Search W3Schools:


What Others Say About Us

Does the world know about us? Check out these places:

Dogpile Alta Vista MSN Google Excite Lycos Yahoo Ask Jeeves


We Help You For Free. You Can Help Us!


W3Schools is for training only. We do not warrant its correctness or its fitness for use. The risk of using it remains entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.

Copyright 1999-2002 by Refsnes Data. All Rights Reserved


Validate How we converted to XHTML Validate

ASPHits
Active Server Pages Resource Web Site


Your own Web Site?

Read W3Schools
Hosting Tutorial



$15 Domain Name
Registration
Save $20 / year!



Advertise
at W3Schools

Only 0.5 CPM



SELECTED LINKS

University Online
Master Degree
Bachelor Degree


Web Software

The Future of
Web Development


Jobs and Careers

Web Security
Web Statistics
Web Standards


PARTNERS

W3Schools
TopXML
VisualBuilder
XMLPitstop
DevelopersDex
DevGuru
Programmers Heaven
The Code Project
Tek Tips Forum
ZVON.ORG
TopXML Search