0

# Can Math.random() returns 0 or 1?

Can Math.random() returns 0 or 1?

2 Answers

+ 2

0 yes but not 1
if you want , you just have to modify the value(floor/multiply/etc)

+ 1

I wrote a function that does that
function boolRand() {
return Math.round(Math.random());
}
Test it
for (let _ = 0; _ < 10; _++) {
console.log(boolRand());
}