update
This commit is contained in:
49
websocket/utils/index.js
Normal file
49
websocket/utils/index.js
Normal file
@@ -0,0 +1,49 @@
|
||||
export default {
|
||||
// 生成随机数
|
||||
randomNum({ min, max }, isFloat = false) {
|
||||
if (isFloat) return (Math.random() * (max - min) + min).toFixed(2);
|
||||
return Math.floor(Math.random() * (max - min + 1) + min);
|
||||
},
|
||||
getMinmax(type) {
|
||||
// : '*' | '.' | '+' | '$'
|
||||
let min, max;
|
||||
switch (type) {
|
||||
case "*":
|
||||
min = 30;
|
||||
max = 150;
|
||||
break;
|
||||
case ".":
|
||||
min = 60;
|
||||
max = 200;
|
||||
break;
|
||||
case "+":
|
||||
min = 20;
|
||||
max = 70;
|
||||
break;
|
||||
case "$":
|
||||
min = 1;
|
||||
max = 100;
|
||||
break;
|
||||
}
|
||||
return { min, max };
|
||||
},
|
||||
getRandom(value) {
|
||||
value = value.replace(
|
||||
"***",
|
||||
"" + this.randomNum({ ...this.getMinmax("*") })
|
||||
);
|
||||
value = value.replace(
|
||||
"...",
|
||||
"" + this.randomNum({ ...this.getMinmax(".") })
|
||||
);
|
||||
value = value.replace(
|
||||
"+++",
|
||||
"" + this.randomNum({ ...this.getMinmax("+") })
|
||||
);
|
||||
value = value.replace(
|
||||
"$$$",
|
||||
"" + this.randomNum({ ...this.getMinmax("$") }, true)
|
||||
);
|
||||
return value;
|
||||
},
|
||||
};
|
||||
@@ -1,7 +0,0 @@
|
||||
function rand(min: number, max: number) {
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
}
|
||||
|
||||
export default {
|
||||
rand,
|
||||
};
|
||||
@@ -1,48 +0,0 @@
|
||||
export default {
|
||||
// 生成随机数
|
||||
randomNum({ min, max }: { min: number; max: number }, isFloat = false) {
|
||||
if (isFloat) return (Math.random() * (max - min) + min).toFixed(2);
|
||||
return Math.floor(Math.random() * (max - min + 1) + min);
|
||||
},
|
||||
getMinmax(type: '*' | '.' | '+' | '$') {
|
||||
let min: number, max: number;
|
||||
switch (type) {
|
||||
case '*':
|
||||
min = 30;
|
||||
max = 150;
|
||||
break;
|
||||
case '.':
|
||||
min = 60;
|
||||
max = 200;
|
||||
break;
|
||||
case '+':
|
||||
min = 20;
|
||||
max = 70;
|
||||
break;
|
||||
case '$':
|
||||
min = 1;
|
||||
max = 100;
|
||||
break;
|
||||
}
|
||||
return { min, max };
|
||||
},
|
||||
getRandom(value: string) {
|
||||
value = value.replace(
|
||||
'***',
|
||||
'' + this.randomNum({ ...this.getMinmax('*') }),
|
||||
);
|
||||
value = value.replace(
|
||||
'...',
|
||||
'' + this.randomNum({ ...this.getMinmax('.') }),
|
||||
);
|
||||
value = value.replace(
|
||||
'+++',
|
||||
'' + this.randomNum({ ...this.getMinmax('+') }),
|
||||
);
|
||||
value = value.replace(
|
||||
'$$$',
|
||||
'' + this.randomNum({ ...this.getMinmax('$') }, true),
|
||||
);
|
||||
return value;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user