0

Js random number generator

How to choose a random number from a highest / lowest range?

23rd Dec 2018, 3:05 AM
Ayn234
Ayn234 - avatar
4 ответов
+ 2
[theory] Math.random() returns a floating-point value between 0 and 1 (or 0% and 100%). Multiply the range by this "percentage", then shift the answer by the lowest number. Math.random() * range + lowest_permissable_number
23rd Dec 2018, 3:13 AM
Kirk Schafer
Kirk Schafer - avatar
+ 2
MATH ISNT DEFINED
1st Jan 2019, 8:48 PM
YeetusYeetus
YeetusYeetus - avatar
+ 1
You can use Math.random() which returns a random number between 0 and1 Use Math.floor((Math.random() * 100) + 1) to get random number between 1 and 100
23rd Dec 2018, 3:09 AM
Mayank Dhillon
Mayank Dhillon - avatar
+ 1
thanks guys
23rd Dec 2018, 3:14 AM
Ayn234
Ayn234 - avatar