mirror of
https://github.com/TonyJiangWJ/Auto.js.git
synced 2026-06-21 21:01:43 +08:00
add: example of random()
This commit is contained in:
parent
b3bc83d1a2
commit
fed7b97deb
24
app/src/main/assets/sample/控制台/产生随机数.js
Normal file
24
app/src/main/assets/sample/控制台/产生随机数.js
Normal file
@ -0,0 +1,24 @@
|
||||
console.show();
|
||||
|
||||
log("将产生5个1到100的随机数");
|
||||
|
||||
for(let i = 0; i < 5; i++){
|
||||
print(random(1, 100));
|
||||
print(" ");
|
||||
sleep(400);
|
||||
}
|
||||
print("\n");
|
||||
|
||||
log("将产生10个1到20的不重复随机数");
|
||||
|
||||
var exists = {};
|
||||
|
||||
for(let i = 0; i < 10; i++){
|
||||
var r;
|
||||
do{
|
||||
r = random(1, 20);
|
||||
}while(exists[r]);
|
||||
exists[r] = true;
|
||||
print(r + " ");
|
||||
sleep(400);
|
||||
}
|
||||
@ -65,4 +65,5 @@ module.exports = function(__runtime__, scope){
|
||||
}
|
||||
|
||||
scope.setScreenMetrics = __runtime__.setScreenMetrics.bind(__runtime__);
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user