Math.random()
:
The Math.random() function returns a floating-point, pseudo-random number in the range [0, 1); that is, from 0 (inclusive) up to but not including 1 (exclusive)
The random number is either in the range [0,0.5)
or [0.5,1)
. So you should use return Math.random() < 0.5;
to have a (theoretical) 50/50 chance.