Files
30-seconds-of-code/snippets/randomBoolean.md
2022-03-22 12:58:05 +02:00

405 B

title, tags, expertise, author, firstSeen, lastUpdated
title tags expertise author firstSeen lastUpdated
Random boolean value math,random beginner chalarangelo 2021-01-20T16:20:08+02:00 2021-01-20T16:20:08+02:00

Generates a random boolean value.

  • Use 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