我想创造一些东西,一直在寻找生成随机数的方法,但是无论我在哪里测试我的代码,结果总是出现非随机数。 这是我写的一个例子。
local lowdrops = {"Wooden Sword","Wooden Bow","Ion Thruster Machine Gun Blaster"}
local meddrops = {}
local highdrops = {}
function randomLoot(lootCategory)
if lootCategory == low then
print(lowdrops[math.random(3)])
end
if lootCategory == medium then
end
if lootCategory == high then
end
end
randomLoot(low)
无论在哪里测试我的代码,我都得到相同的结果。例如,当我在这里测试代码http://www.lua.org/cgi-bin/demo时,它总是以“离子推进器机枪炮”结束,不会随机化。就这样简单地测试。
random = math.random (10)
print(random)
给了我9,我是否遗漏了什么?
math.randomseed()
后立即调用math.random()
一次,看看是否固定。 - Yu Hao