<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">% https://tex.stackexchange.com/q/155630/
\documentclass{article}
\usepackage{xsim}

\DeclareExerciseCollection{foo}
\xsimsetup{collect}

\begin{document}

\begin{exercise}
  foo
\end{exercise}
\begin{exercise}
  bar
\end{exercise}
\begin{exercise}
  baz
\end{exercise}

% shuffle around for a different version:
\printexercise{exercise}{1}
\printexercise{exercise}{3}
\printexercise{exercise}{2}

\end{document}
</pre></body></html>