\documentclass{article}
\usepackage{xsim}

\xsimsetup{collect}

\begin{document}

\begin{exercise}[ID=A]
  exercise A
\end{exercise}
\begin{solution}
  solution A
\end{solution}
\begin{exercise}[ID=B]
  exercise B
\end{exercise}
\begin{solution}
  solution B
\end{solution}
\begin{exercise}[ID=C]
  exercise C
\end{exercise}
\begin{solution}
  solution C
\end{solution}
\begin{exercise}[ID=D]
  exercise D
\end{exercise}
\begin{solution}
  solution D
\end{solution}
\begin{exercise}[ID=E]
  exercise E
\end{exercise}
\begin{solution}
  solution E
\end{solution}
\begin{exercise}[ID=F]
  exercise F
\end{exercise}
\begin{solution}
  solution F
\end{solution}

\section*{Exercises}
\printrandomexercises[collection=all exercises,exclude=D]{3}

\printsolutions

\end{document}
