# Printing Solutions on Different Page

I have the following source code that generates random questions regarding conversions from Arabic to Roman Numerals. I would like the solutions to be printed on a new page after the exercises end. I have tried inserting the \printsolutions commmand inside and outside of the loop. Outside of the loop it prints the solution to the last exercise repeatedly. I'm guessing this is because this is the last number stored in memory after the loop ends. Here is my code:

\documentclass[12pt,leqno]{article}
\usepackage{amsmath, amsfonts, amssymb,amsthm}
\usepackage{forloop}
\usepackage[first=1, last=100]{lcg}
\newcommand{\random}{\rand\arabic{rand}}
\usepackage[auto-label=true]{exsheets}

\title{\textbf{Converting Arabic to Roman Numerals}}
\begin{document}
\maketitle

\newcounter{s}
\forloop[1]{s}{1}{\value{s}< 10}
{
\begin{question}
Convert \random \ to a Roman Numeral
\end{question}
\begin{solution}
\MakeUppercase{\textbf{\roman{rand}}
}
\end{solution}
}
\printsolutions

\end{document}


Here is a solution. Save the answer in a macro using the id of each question.

\documentclass[12pt,leqno]{article}
\usepackage{amsmath, amsfonts, amssymb,amsthm}
\usepackage{forloop}
\usepackage[first=1, last=100]{lcg}
\newcommand{\random}{\rand\arabic{rand}}
\usepackage[auto-label=true]{exsheets}

\title{\textbf{Converting Arabic to Roman Numerals}}
\begin{document}
\maketitle

\newcounter{s}
\forloop[1]{s}{1}{\value{s}< 10}
{
\begin{question}
Convert \random\ to a Roman Numeral
\roman{rand}}
\end{question}
\begin{solution}
\end{solution}
}

\newpage
\printsolutions

\end{document}


It's an expansion problem; with your code, just \roman{rand} is stored, not its current expansion.

\documentclass[twocolumn]{article}
\usepackage{amsmath, amsfonts, amssymb,amsthm}
\usepackage[first=1, last=100]{lcg}
\newcommand{\random}{\rand\arabic{rand}}
\usepackage[auto-label=true]{exsheets}

\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\replicate}{mm}% I prefer this to \forloop
{
\prg_replicate:nn { #1 } { #2 }
}
\ExplSyntaxOff

\begin{document}

\title{Converting Arabic to Roman Numerals}
\author{1028}

\maketitle

\replicate{10}{%
\begin{question}
Convert \random \ to a Roman Numeral
\end{question}
\begingroup\edef\x{\endgroup
\noexpand\begin{solution}
\noexpand\textbf{\Roman{rand}}
\noexpand\end{solution}
}\x
}

\newpage
\printsolutions

\end{document}


I used twocolumn just for reducing the size of the output.