Skip to content

Function: randomBoolean() ​

ts
function randomBoolean(probability?): boolean;

Generates a random boolean value. 生成随机布尔值。

Parameters ​

ParameterTypeDefault valueDescription
probabilitynumber0.5Probability of returning true (0-1, default: 0.5) / 返回true的概率(0-1,默认:0.5)

Returns ​

boolean

A random boolean / 随机布尔值

Example ​

typescript
randomBoolean() // 50% chance of true
randomBoolean(0.7) // 70% chance of true
randomBoolean(0.1) // 10% chance of true

Since ​

1.0.0

Released under the MIT License.