+ 5

How generate random number in js?

please help me...

7th Jan 2018, 8:54 AM
Hardik Jogani
Hardik Jogani - avatar
5 Answers
+ 10
var x = Math.random(); this will generate a random number between 0 to 1 you can use this accordingly by add or multiplyingšŸ˜Š
7th Jan 2018, 9:16 AM
Jaydeep Khatri
Jaydeep Khatri - avatar
+ 6
Math.random method would generate output number range from 0.0 to 0.9999.
7th Jan 2018, 9:08 AM
CalviÕ²
CalviÕ² - avatar
+ 3
So Math.random()*(x - y) + y will generate a random number from y to x
7th Jan 2018, 9:14 AM
Ī‘Ī·Ļ„ĪæĪ¹Ļ€e
Ī‘Ī·Ļ„ĪæĪ¹Ļ€e - avatar
+ 3
To generate any range of random number, use below function function getARandomNumber(min, max) { return Math.random() * (max - min) + min; } // number from min to max (not inclusive max) Please note that Math.random() only output positive number that less then 1 (not inclusive 1).
7th Jan 2018, 9:22 AM
CalviÕ²
CalviÕ² - avatar
15th Jan 2018, 4:08 PM
Matthias Bohn
Matthias Bohn - avatar