local fmt = require "fmt" local function knuth_shuffle(a) for i = #a, 2, -1 do local j = math.random(i) a[i], a[j] = a[j], a[i] end end local tests = { {}, {10}, {10, 20}, {10, 20, 30}, {10, 20, 30, 40} } for tests as a do local b = a:clone() knuth_shuffle(a) print($"{fmt.swrite(b)} -> {fmt.swrite(a)}") end