Generates a random boolean value.
- Use
Math.random()
to generate a random number and check if it is greater than or equal to0.5
.
代码实现
const randomBoolean = () => Math.random() >= 0.5;
randomBoolean(); // true
Generates a random boolean value.
Math.random()
to generate a random number and check if it is greater than or equal to 0.5
.
const randomBoolean = () => Math.random() >= 0.5;
randomBoolean(); // true