add: random()

This commit is contained in:
hyb1996 2017-07-30 15:55:22 +08:00
parent 99d9d4b7a8
commit b3bc83d1a2
2 changed files with 21 additions and 3 deletions

View File

@ -63,9 +63,18 @@ launchApp("微信");
当脚本处于应当停止运行的状态时返回true, 否则返回false。
由于脚本引擎的关系有时即使强制停止正在运行的脚本也不会生效此时会出现isStopped()为true但脚本仍在运行的情况。
### notStopped()
当脚本处于应当停止运行的状态时返回false, 否则返回false。
### isRunning()
当脚本处于正在运行的状态时返回true, 否则返回false。
### stop()
### exit()
立即停止脚本运行。
### random(min, max)
* min \<Number\> 随机数产生的区间下界
* max \<Number\> 随机数产生的区间上界
返回一个在\[min...max\]之间的随机数。例如random(0, 2)可能产生0, 1, 2.
### random()
返回在[0, 1)的随机浮点数。

View File

@ -19,6 +19,8 @@ module.exports = function(__runtime__, scope){
return !isStopped();
}
scope.isRunning = scope.notStopped;
scope.exit = function(){
__runtime__.exit();
}
@ -55,5 +57,12 @@ module.exports = function(__runtime__, scope){
}
}
scope.random = function(min, max){
if(arguments.length == 0){
return Math.random();
}
return Math.floor(Math.random() * (max - min + 1)) + min;
}
scope.setScreenMetrics = __runtime__.setScreenMetrics.bind(__runtime__);
}