math.randomseed(os.time()) local result_pos_t = {} local function result_pos(num, max) local k = num .. ',' .. max if not result_pos_t[k] then if num == 0 then result_pos_t[k] = (max - num) + 1 else result_pos_t[k] = result_pos(num - 1, max) + (max - num) + 1 end end return result_pos_t[k] end local function crazy_dice(n) local size = result_pos(n, n) local rand = math.random(size) for i = 0, n do if rand <= result_pos(i, n) then return i end end error() end local tally = {} local count = 100000 local sides = 10 for i = 1, count do local res = crazy_dice(sides) - crazy_dice(sides) if not tally[res] then tally[res] = 1 else tally[res] = tally[res] + 1 end end for i = -sides, sides do print(i, (tally[i] or 1) / count) end