Lua随机问题
1)lua隨機(jī)math.random 的結(jié)果前三個(gè)不可靠。
2)math.random(os.time())一定要寫在程序最開始的時(shí)候,不要寫在循環(huán)體內(nèi)部。寫在循環(huán)體內(nèi)部的math.random(os.time())無法起到每次運(yùn)行程序,隨機(jī)生成隨機(jī)種子的作用。
e.g.1 math.randomseed(os.time()) for i=1,10 do print(math.random(10)) end結(jié)果:2 10 5 8 6 10 6 10 3 1 [Finished in 0.1s]e.g.2for i=1,10 do math.randomseed(os.time()) print(math.random(10)) end結(jié)果:1 1 1 1 1 1 1 1 1 1 [Finished in 0.1s]
e.g.1 math.randomseed(os.time()) for i=1,10 do print(math.random(10)) end結(jié)果:2 10 5 8 6 10 6 10 3 1 [Finished in 0.1s]e.g.2for i=1,10 do math.randomseed(os.time()) print(math.random(10)) end結(jié)果:1 1 1 1 1 1 1 1 1 1 [Finished in 0.1s]
?
?轉(zhuǎn)載于:https://www.cnblogs.com/Fallever/p/6880728.html
總結(jié)
- 上一篇: (继承)virtual与访问控制
- 下一篇: parasoft Jtest 使用教程: