我正在研究隨機數字的代碼。我把math.randomseed(os.time())
放在一個循環中。代碼如下:隨機種子在LUA
for i = 1, 1000 do
math.randomseed(os.time())
j = math.random(i, row-one)
u[i], u[j] = u[j], u[i]
for k = 1, 11 do
file:write(input2[u[i]][k], " ")
end
file:write"\n"
end
而當我運行它幾次,整個輸出總是相同的。隨機種子是不是應該在重新運行時防止重複?
'os.time()'第二期間返回的值相同。 –
@EgorSkriptunoff所以當我重新運行代碼時,如何讓整個結果不同? – Rachelle
不要在一秒內運行相同的代碼兩次:-) –