Math.random
Math.random
功能
随机数。返回 0 <= n < 1 的随机浮点数。
语法
Math.random()
参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| 无 | - | 否 | 无 | 不需要参数。 |
返回值
| 类型 | 说明 |
|---|---|
| Float | 返回 0 <= n < 1 的随机浮点数。 |
示例
result = Math.random() // 输出:true print result >= 0 && result < 1
注意事项
- 随机数不是密码学安全随机数。
随机数。返回 0 <= n < 1 的随机浮点数。
Math.random()
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| 无 | - | 否 | 无 | 不需要参数。 |
| 类型 | 说明 |
|---|---|
| Float | 返回 0 <= n < 1 的随机浮点数。 |
result = Math.random() // 输出:true print result >= 0 && result < 1