mm_expand 1.5.2 → 1.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +13 -1
- package/package.json +1 -1
- package/test.js +18 -7
package/index.js
CHANGED
|
@@ -647,12 +647,24 @@ if (typeof($) === "undefined") {
|
|
|
647
647
|
|
|
648
648
|
/**
|
|
649
649
|
* @description 随机数
|
|
650
|
-
*
|
|
650
|
+
* @param {Number} min 最小值
|
|
651
651
|
* @return {Number} 返回一个数值
|
|
652
652
|
*/
|
|
653
653
|
Number.prototype.rand = function(min = 1) {
|
|
654
654
|
return Math.floor(Math.random() * (this - min + 1) + min);
|
|
655
655
|
};
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* @description 随机数
|
|
659
|
+
* @param {Number} margin 上下幅度
|
|
660
|
+
* @return {Number} 返回一个数值
|
|
661
|
+
*/
|
|
662
|
+
Number.prototype.range = function(margin = 5) {
|
|
663
|
+
var min = this - margin;
|
|
664
|
+
var max = this + margin;
|
|
665
|
+
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
666
|
+
};
|
|
667
|
+
|
|
656
668
|
})();
|
|
657
669
|
|
|
658
670
|
/* == 时间原型函数 == */
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -2,13 +2,24 @@ require('./index.js');
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
var num = 5;
|
|
5
|
-
|
|
6
|
-
console.log(num.rand());
|
|
7
|
-
console.log(num.rand());
|
|
8
|
-
console.log(num.rand());
|
|
9
|
-
console.log(num.rand());
|
|
10
|
-
console.log(num.rand());
|
|
11
|
-
console.log(num.rand());
|
|
5
|
+
// 随机一个1-5数值
|
|
6
|
+
// console.log(num.rand(1));
|
|
7
|
+
// console.log(num.rand(1));
|
|
8
|
+
// console.log(num.rand(1));
|
|
9
|
+
// console.log(num.rand(1));
|
|
10
|
+
// console.log(num.rand(1));
|
|
11
|
+
// console.log(num.rand(1));
|
|
12
|
+
// console.log(num.rand(1));
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
// 随机一个上下浮动10的数值
|
|
16
|
+
console.log(num.range(10));
|
|
17
|
+
console.log(num.range(10));
|
|
18
|
+
console.log(num.range(10));
|
|
19
|
+
console.log(num.range(10));
|
|
20
|
+
console.log(num.range(10));
|
|
21
|
+
console.log(num.range(10));
|
|
22
|
+
console.log(num.range(10));
|
|
12
23
|
|
|
13
24
|
// /**
|
|
14
25
|
// * 测试重载模块
|