Random with JS | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Random with JS

How can i bring things like "randint" (from python) to JS in a easy way?

6th Feb 2017, 2:01 AM
IgorSM
IgorSM - avatar
2 Answers
+ 6
Math.random() will return a number in the range [0, 1) so if you want a random number in a specific (min, max) range you can create your own function function randVal(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); }
6th Feb 2017, 7:35 AM
Burey
Burey - avatar
+ 4
Is it Math.random()?
6th Feb 2017, 3:41 AM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar