add: example of random()
This commit is contained in:
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__);
|
scope.setScreenMetrics = __runtime__.setScreenMetrics.bind(__runtime__);
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user