From 01b0e12ba27b5069248fd09235e9a7143915ee30 Mon Sep 17 00:00:00 2001 From: Irvin Date: Wed, 16 Feb 2022 02:02:49 +0800 Subject: remove `notranslate` class in zh-CN --- .../javascript/reference/global_objects/math/random/index.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'files/zh-cn/web/javascript/reference/global_objects/math/random') diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/random/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/random/index.html index e25608ec05..91796ae506 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/random/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/math/random/index.html @@ -21,7 +21,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/random

语法

-
Math.random()
+
Math.random()

返回值

@@ -33,7 +33,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/random

得到一个大于等于0,小于1之间的随机数

-
function getRandom() {
+
function getRandom() {
   return Math.random();
 }
@@ -41,7 +41,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/random

这个例子返回了一个在指定值之间的随机数。这个值不小于 min(有可能等于),并且小于(不等于)max

-
function getRandomArbitrary(min, max) {
+
function getRandomArbitrary(min, max) {
   return Math.random() * (max - min) + min;
 }
 
@@ -50,7 +50,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/random

这个例子返回了一个在指定值之间的随机整数。这个值不小于 min (如果 min 不是整数,则不小于 min 的向上取整数),且小于(不等于)max

-
function getRandomInt(min, max) {
+
function getRandomInt(min, max) {
   min = Math.ceil(min);
   max = Math.floor(max);
   return Math.floor(Math.random() * (max - min)) + min; //不含最大值,含最小值
@@ -64,7 +64,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/random
 
 

上一个例子提到的函数 getRandomInt() 结果范围包含了最小值,但不含最大值。如果你的随机结果需要同时包含最小值和最大值,怎么办呢?  getRandomIntInclusive() 函数可以实现。

-
function getRandomIntInclusive(min, max) {
+
function getRandomIntInclusive(min, max) {
   min = Math.ceil(min);
   max = Math.floor(max);
   return Math.floor(Math.random() * (max - min + 1)) + min; //含最大值,含最小值 
-- 
cgit v1.2.3-54-g00ecf