Sowas nennt man auch [self-avoiding walk](https://en.wikipedia.org/wiki/Self-avoiding_walk).
\documentclass{article}
\usepackage{luacode}
\begin{luacode*}
function saw(n)
local list = {}
local seen = {}
while #list < n do
local x = math.random(n)
if not seen[x] then
list[#list+1] = x
seen[x] = true
end
end
tex.sprint(table.concat(list,","))
end
\end{luacode*}
\begin{document}
\directlua{saw(5)}
\end{document}
[![alt text][1]][1]
Falls man die Liste schon hat kann man auch den [Knuth Shuffle](https://en.wikipedia.org/wiki/Fisher–Yates_shuffle) machen.
\documentclass{article}
\usepackage{luacode}
\begin{luacode*}
function shuffle(list)
for i = #list,2,-1 do
local j = math.random(i)
list[i], list[j] = list[j], list[i]
end
tex.sprint(table.concat(list,","))
end
\end{luacode*}
\begin{document}
\directlua{shuffle({1,2,3,4,5})}
\end{document}
[1]: https://texwelt.de/wissen/upfiles/test_403.png