About This Product
FontsMadeEasy.com
 
Search This Database:
| Over 5000 Free Fonts | Tutorials | Javascript Forum | Other Javascript Resources | Cheat Sheet
Tutorial archive
General Questions
Javascript 1.2
Navigation
Numbers
Strings
Object Model
Reference Manual
Dialog
Windows
Frames
Forms
Images
Mouse Events
Colors
File Access
Control Status Bar
Dates and Time
Cookies
Client Information
Bookmarklets


Random Numbers

Question: How do I generate random numbers in JavaScript?

Answer: To generate random floating-point numbers in the range from 0 to 1, use the Math.random() method:

num = Math.random()  // num is random, from 0 to 1 
If you need random floating-point numbers in the range from A to B, use this code:
num = A + (B-A)*Math.random()  // num is random, from A to B 

BackBack