add: example of random()

This commit is contained in:
hyb1996 2017-07-30 16:08:56 +08:00
parent b3bc83d1a2
commit fed7b97deb
2 changed files with 25 additions and 0 deletions

View 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);
}

View File

@ -65,4 +65,5 @@ module.exports = function(__runtime__, scope){
}
scope.setScreenMetrics = __runtime__.setScreenMetrics.bind(__runtime__);
}