0

Can Math.random() returns 0 or 1?

Can Math.random() returns 0 or 1?

5th Dec 2020, 6:07 PM
maazulhaq
maazulhaq - avatar
2 ответов
+ 2
0 yes but not 1 if you want , you just have to modify the value(floor/multiply/etc)
5th Dec 2020, 6:28 PM
durian
durian - avatar
+ 1
I wrote a function that does that function boolRand() { return Math.round(Math.random()); } Test it for (let _ = 0; _ < 10; _++) { console.log(boolRand()); }
5th Dec 2020, 6:40 PM
Ore
Ore - avatar