需要生成两个值不重复的Lua表。此外,该表不应包含 (a,b) 和 (b,a) 之类的行。这样的字符串将被认为是相同的 (a,b) = (b,a)。
有一个示例(如 Mike V. 的示例)生成一个包含一列非重复值的表:
math.randomseed(os.time()) -- first, sets a seed for the pseudo-random generator
math.random(); math.random(); math.random();
local function my_random(t, from, to) -- second, exclude duplicates
local num = math.random (from, to)
if t[num] then num = my_random(t, from, to) end
t[num] = num
return num
end
local t = {} -- initialize table with not duplicate values
for i =1, 30 do
X = my_random (t, 1, 50)
print (i, "=" ,X)
end
我需要类似的,但是两列(最好立即驱动到 Lua 表中):
1 - 1,3
2 - 2,4
3 - 4,3
4 - ...
先感谢您。