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

21 lines
405 B
Markdown

---
title: Random boolean value
tags: math,random
expertise: beginner
author: chalarangelo
firstSeen: 2021-01-20T16:20:08+02:00
lastUpdated: 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`.
```js
const randomBoolean = () => Math.random() >= 0.5;
```
```js
randomBoolean(); // true
```