通常第一个随机值不是真正随机的(但它从来都不是真正随机的,它是一个伪随机数生成器)。先设置一个randomseed,然后随机生成几次。试试这个代码,例如:
math.randomseed( os.time() )
math.random() math.random() math.random()
for i = 1, 1000 do
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
但是,您可以从http://lua-users.org/wiki/MathLibraryTutorial试试这个:
-- improving the built-in pseudorandom generator
do
local oldrandom = math.random
local randomtable
math.random = function ()
if randomtable == nil then
randomtable = {}
for i = 1, 97 do
randomtable[i] = oldrandom()
end
end
local x = oldrandom()
local i = 1 + math.floor(97*x)
x, randomtable[i] = randomtable[i], x
return x
end
end