random:容错

This commit is contained in:
ckcz123 2021-08-07 12:00:19 +08:00
parent 3c05ab3ba9
commit 85638ee875

View File

@ -866,7 +866,7 @@ utils.prototype.rand = function (num) {
////// 生成随机数(录像方法) ////// ////// 生成随机数(录像方法) //////
utils.prototype.rand2 = function (num) { utils.prototype.rand2 = function (num) {
num = num || 2147483648; num = num || 2147483648;
if (num <= 0) num = 1; num = Math.abs(num);
var value; var value;
if (core.isReplaying()) { if (core.isReplaying()) {
@ -874,8 +874,8 @@ utils.prototype.rand2 = function (num) {
if (action.indexOf("random:") == 0) { if (action.indexOf("random:") == 0) {
value = parseInt(action.substring(7)); value = parseInt(action.substring(7));
if (isNaN(value) || value >= num || value < 0) { if (isNaN(value) || value >= num || value < 0) {
core.control._replay_error(action); console.warn('错误当前random:项超过范围。将重新随机生成!');
return 0; value = Math.floor(Math.random() * num);
} }
} }
else { else {