JohnPaul
Based on the answer https://tex.stackexchange.com/a/582183/18545
```
\documentclass[12pt,a4paper]{article}
\usepackage{xsim}
\usepackage{tasks}
\NewTasksEnvironment[
label = \textbf{\Alph*.} ,
label-width = 15pt
]{choice}[\choice](4)
\DeclareExerciseEnvironmentTemplate{item}
{\description\item[\GetExerciseName~\GetExerciseProperty{counter}]}
{\enddescription}
\DeclareExerciseEnvironmentTemplate{space}
{\textbf{\GetExerciseProperty{counter}} }
{\quad}
\newcommand*\answer[1]{%
\XSIMexpandcode{%
\SetExerciseProperty{solution-body}
{\noexpand{\Alph{task}}}}%
#1%
}
\DeclareExerciseCollection{part-A}
\xsimsetup{
exercise/template = item ,
solution/template = space ,
exercise/name = Q. ,
exercise/the-counter = \arabic{exercise}. ,
exercise/collect ,
random/sort = false
}
\begin{document}
\collectexercises{part-A}
\begin{exercise}
What is the product of $-2$ and $3$?
\begin{choice}
\choice \answer{$-6$}
\choice $6$
\choice $5$
\choice $-5$
\end{choice}
\end{exercise}
\begin{exercise}
What is the sum of the sides of a polygon called?
\begin{choice}(2)
\choice Leg
\choice \answer{Perimeter}
\choice Area
\choice Volume
\end{choice}
\end{exercise}
\begin{exercise}
What is the sum of $-2$ and $-3$?
\begin{choice}
\choice $-6$
\choice $6$
\choice $5$
\choice \answer{$-5$}
\end{choice}
\end{exercise}
\begin{exercise}
Number four
\end{exercise}
\begin{exercise}
Number five
\end{exercise}
\collectexercisesstop{part-A}
\section{Problems}
\printrandomexercises[collection=part-A]{5}
\section{Answers}
\printsolutions[headings=false]
\end{document}
```
I have 5 multiple-choice questions. How can I generate multiple versions of an exam from these questions so that, in each version, both the order of the questions and the order of the answer choices are randomized?
Top Answer
CarLaTeX
Try with `randomlist`:
```
\documentclass[12pt,a4paper]{article}
\usepackage{xsim}
\usepackage{tasks}
\NewTasksEnvironment[
label = \textbf{\Alph*.} ,
label-width = 15pt
]{choice}[\choice](4)
\DeclareExerciseEnvironmentTemplate{item}
{\description\item[\GetExerciseName~\GetExerciseProperty{counter}]}
{\enddescription}
\DeclareExerciseEnvironmentTemplate{space}
{\textbf{\GetExerciseProperty{counter}} }
{\quad}
\newcommand*\answer[1]{%
\XSIMexpandcode{%
\SetExerciseProperty{solution-body}
{\noexpand{\Alph{task}}}}%
#1%
}
\DeclareExerciseCollection{part-A}
\xsimsetup{
exercise/template = item ,
solution/template = space ,
exercise/name = Q. ,
exercise/the-counter = \arabic{exercise}. ,
exercise/collect ,
random/sort = false
}
\usepackage{randomlist}
\begin{document}
\collectexercises{part-A}
\begin{exercise}
What is the product of $-2$ and $3$?
\NewList{MyList}
\InsertLastItem{MyList}{\answer{$-6$}}
\InsertLastItem{MyList}{$6$}
\InsertLastItem{MyList}{$5$}
\InsertLastItem{MyList}{$-5$}
\ExtractRandomItem{MyList}{First}
\ExtractRandomItem{MyList}{Second}
\ExtractRandomItem{MyList}{Third}
\ExtractRandomItem{MyList}{Fourth}
\begin{choice}
\choice \First
\choice \Second
\choice \Third
\choice \Fourth
\end{choice}
\end{exercise}
\begin{exercise}
What is the sum of the sides of a polygon called?
\NewList{MyList}
\InsertLastItem{MyList}{Leg}
\InsertLastItem{MyList}{\answer{Perimeter}}
\InsertLastItem{MyList}{Area}
\InsertLastItem{MyList}{Volume}
\ExtractRandomItem{MyList}{First}
\ExtractRandomItem{MyList}{Second}
\ExtractRandomItem{MyList}{Third}
\ExtractRandomItem{MyList}{Fourth}
\begin{choice}(2)
\choice \First
\choice \Second
\choice \Third
\choice \Fourth
\end{choice}
\end{exercise}
\begin{exercise}
What is the sum of $-2$ and $-3$?
\NewList{MyList}
\InsertLastItem{MyList}{\answer{$-6$}}
\InsertLastItem{MyList}{$6$}
\InsertLastItem{MyList}{$5$}
\InsertLastItem{MyList}{\answer{$-5$}}
\ExtractRandomItem{MyList}{First}
\ExtractRandomItem{MyList}{Second}
\ExtractRandomItem{MyList}{Third}
\ExtractRandomItem{MyList}{Fourth}
\begin{choice}
\choice \First
\choice \Second
\choice \Third
\choice \Fourth
\end{choice}
\end{exercise}
\begin{exercise}
Number four
\end{exercise}
\begin{exercise}
Number five
\end{exercise}
\collectexercisesstop{part-A}
\section{Problems}
\printrandomexercises[collection=part-A]{5}
\section{Answers}
\printsolutions[headings=false]
\end{document}
```
A first compilation:

A second compilation (from scratch):
