From b3bc83d1a204ab7f3c491c7a2512bb09ea07e810 Mon Sep 17 00:00:00 2001 From: hyb1996 <946994919@qq.com> Date: Sun, 30 Jul 2017 15:55:22 +0800 Subject: [PATCH] add: random() --- .../assets/help/documentation/一般常用函数.md | 15 ++++++++++++--- autojs/src/main/assets/modules/__general__.js | 9 +++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/src/main/assets/help/documentation/一般常用函数.md b/app/src/main/assets/help/documentation/一般常用函数.md index a74e205d..a1209639 100644 --- a/app/src/main/assets/help/documentation/一般常用函数.md +++ b/app/src/main/assets/help/documentation/一般常用函数.md @@ -63,9 +63,18 @@ launchApp("微信"); 当脚本处于应当停止运行的状态时返回true, 否则返回false。 由于脚本引擎的关系,有时即使强制停止正在运行的脚本也不会生效,此时会出现isStopped()为true但脚本仍在运行的情况。 -### notStopped() -当脚本处于应当停止运行的状态时返回false, 否则返回false。 +### isRunning() +当脚本处于正在运行的状态时返回true, 否则返回false。 -### stop() +### exit() 立即停止脚本运行。 +### random(min, max) +* min \ 随机数产生的区间下界 +* max \ 随机数产生的区间上界 + +返回一个在\[min...max\]之间的随机数。例如random(0, 2)可能产生0, 1, 2. + +### random() + +返回在[0, 1)的随机浮点数。 \ No newline at end of file diff --git a/autojs/src/main/assets/modules/__general__.js b/autojs/src/main/assets/modules/__general__.js index 88a25f8c..52fcecf3 100644 --- a/autojs/src/main/assets/modules/__general__.js +++ b/autojs/src/main/assets/modules/__general__.js @@ -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__); } \ No newline at end of file