1
Answer

what is randome method in js

what is randome method in js

Answers (1)
1
Shivam Payasi

Shivam Payasi

10 21.1k 27.1k 1y

In JavaScript, the `Math.random()` method is used to generate a random number between 0 (inclusive) and 1 (exclusive). It returns a random floating-point number.

Here is an example of how to use the `Math.random()` method:

var randomNumber = Math.random();
console.log(randomNumber);

This will output a random number between 0 and 1, such as 0.245678 or 0.923456.

To generate a random number within a specific range, you can use the `Math.random()` method along with some arithmetic operations. For example, to generate a random number between 1 and 10, you can multiply the result of `Math.random()` by the range and then add the minimum value:

var min = 1;
var max = 10;
var randomInRange = Math.floor(Math.random() * (max - min + 1)) + min;
console.log(randomInRange);

This will output a random number between 1 and 10, such as 5 or 9.