JavaScript Random
In this tutorial, you will learn about random() is as follows:
Example
Output
Shifting and Scaling
The range of the values produced directly by a random variable is often different from what is needed in a specific application.
e.g.,
Math.floor(1+ Math.random()0*6)
Here, Math.random is multiplied with 6, so that we get a range from 0.0 6.0. This is called scaling.
Adding 1(here) to the obtained value is called shifting.
Math.floor() is used to determine the doset integer not greater than the argument value
Example1- Program
Displaying Random Images
Web content that varies randomly can add dynamic, interesting effects to a page.
1. alert()
2. prompt()
In Both methods has limited features in receiving input from the user
Script is often used to respond to user initiated events.