mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-09-23 20:44:42 +08:00
新增数学计算和随机数
This commit is contained in:
@@ -4,6 +4,7 @@ const string = require("./string");
|
||||
const crypto = require("./crypto");
|
||||
const buffer = require("./buffer");
|
||||
const zlib = require("./zlib");
|
||||
const random = require("./random");
|
||||
|
||||
module.exports = {
|
||||
...encoder,
|
||||
@@ -12,4 +13,5 @@ module.exports = {
|
||||
...crypto,
|
||||
buffer,
|
||||
zlib,
|
||||
random,
|
||||
};
|
||||
|
23
plugin/lib/quickcomposer/data/random.js
Normal file
23
plugin/lib/quickcomposer/data/random.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const randomInt = (start, end) => {
|
||||
return Math.round(Math.random() * (end - start) + start);
|
||||
};
|
||||
|
||||
const random = (isInt = false, start, end) => {
|
||||
if (!start && !end) {
|
||||
return isInt ? randomInt(0, 1000000) : Math.random();
|
||||
}
|
||||
|
||||
if (!end) {
|
||||
end = Math.abs(randomInt(0, 1000000) - start);
|
||||
}
|
||||
|
||||
if (!start) {
|
||||
start = 0;
|
||||
}
|
||||
|
||||
// 有start和end:返回区间随机数
|
||||
const random = Math.random() * (end - start) + start;
|
||||
return isInt ? Math.round(random) : random;
|
||||
};
|
||||
|
||||
module.exports = random;
|
Reference in New Issue
Block a user