小编mog*_*ogo的帖子

Lua 5.1.4 math.random实际上并不是随机的

我的问题是,当我写math.random(10)它不是实际上随机它总是给我输出:

1 6 2 9

如果我用过例如:

local colors = {"ORANG","BLUE","RED","YELLOW","BLACK"}
print(colors[math.random(#colors)])
print(colors[math.random(#colors)])
print(colors[math.random(#colors)])
print(colors[math.random(#colors)])
print(colors[math.random(#colors)])
print(colors[math.random(#colors)])
print(colors[math.random(#colors)])
print(colors[math.random(#colors)])
os.execute 'pause'
Run Code Online (Sandbox Code Playgroud)

输出总是:

ORANGE
RED
ORANGE
BLACK
RED
RED
BLUE BLACK
Run Code Online (Sandbox Code Playgroud)

这总是输出,怎么可能是随机的????

random math lua function

2
推荐指数
1
解决办法
364
查看次数

标签 统计

function ×1

lua ×1

math ×1

random ×1