Skip to content

Latest commit

 

History

History
29 lines (18 loc) · 864 Bytes

random-boolean.md

File metadata and controls

29 lines (18 loc) · 864 Bytes
标题 标签
randomBoolean(随机布尔值) math,random(数学,随机数)

生成一个随机布尔值。

  • 使用 Math.random() 生成随机数并检查它是否大于或等于 0.5。
const randomBoolean = () => Math.random() >= 0.5;

调用方式:

randomBoolean(); // true / false

应用场景

以下是一个实战示例:

结果如下:

<iframe src="codes/javascript/html/random-boolean.html"></iframe>