所以我有一个有趣的问题。我在函数下面有一个代码片段,它接受两个整数并返回两个整数(x y坐标)。我在循环中为它生成了5个对象。在Mac上,它返回两个与其他数字不同的随机数。在PC上它总是返回两个确切的数字,即使我每次都播种它。有什么想法吗?
local randomSeed = 60
randomCoord = function(bufferX,bufferY)
-- randomCoord
-- int, int - get a buffer from the edge
-- returns two random coordinates that are within background Plane space
print( randomSeed )
math.randomseed(randomSeed + os.time())
randomSeed = randomSeed + os.time()
local x = math.random(backgroundBounds.xMin + bufferX,backgroundBounds.xMax - bufferX)
local y = math.random(backgroundBounds.yMin + bufferY,backgroundBounds.yMax - bufferY)
print('random x '..x..' random y '..y)
return x, y
end
backgroundBounds只是一个带整数的表(是backgroundBox的大小)。
答案 0 :(得分:0)
大多数时候,在大多数语言中,随机数设施只能播种一次。再次播种它们会产生意想不到的结果,例如返回相同的数字序列。