我在lua中製作了一個隨機生成1到10的數字的遊戲,玩家需要猜測數字。這似乎是產生,但是,是9。這裏的唯一數是代碼:lua中的math.random只生成一個數字
number = math.random(1, 10)
function guess(number)
print("Please input a number between 1 and 10: ")
input = io.read()
if tonumber(input) < number then
print("Too low!")
guess(number)
elseif tonumber(input) > number then
print("Too high!")
guess(number)
elseif tonumber(input) == number then
print("You got it!")
end
end
guess(number)
1和10之間的隨機數應與的Math.random()被創建並存儲在數可變的,但看起來生成的數字總是9.可能是什麼原因造成的,我該如何解決?
可能有助於[Lua的隨機數重複(http://stackoverflow.com/questions/21806787/lua-random-number) –
可能的重複[ Lua隨機數?](http://stackoverflow.com/questions/21806787/lua-random-number) – hjpotter92
我同意它是重複的。有趣的是,鏈接的問題也是重複的... Dupliception? – Josh