I'm trying to create exercise sheets with random numbers and xsim. Each time I generate random numbers, though, the variables are overwritten to create new exercises (desired), but also overwritten so that all solutions only contain values from the final exercise (not desired).
How do I "save" the values of the solutions as they're generated?
I am aware that this maybe somewhat similar to one of my prior threads, but I tried to follow the \edef... syntax advice from there and it did not seem to work.
\documentclass{article}
\usepackage{multicol}
\usepackage{pgf}
\usepackage{pgffor}
\pgfmathsetseed{\number\pdfrandomseed}
\usepackage{xsim}
\setlength{\parindent}{0pt}
\newcommand{\InitVariables}
{ \pgfmathrandominteger{\PartA}{0}{10}
\edef\PartA{\PartA}
\pgfmathrandominteger{\PartB}{0}{10}
\edef\PartB{\PartB}
\pgfmathsetmacro{\Sum}{int(\PartA + \PartB)}
\edef\Sum{\Sum}
}
\newcommand{\Exercise}{$\PartA+\PartB=?$}
\newcommand{\Solution}{$\PartA+\PartB=\Sum$}
\begin{document}
\begin{multicols}{2}
\InitVariables
\begin{exercise}
\Exercise
\end{exercise}
\begin{solution}
\Solution
\end{solution}
\InitVariables
\begin{exercise}
\Exercise
\end{exercise}
\begin{solution}
\Solution
\end{solution}
\printallsolutions
\end{multicols}
\end{document}


xsimtries very hard to write verbatim the contents of thesolutionenvironment. – egreg May 26 '20 at 16:50\Solutionas a string and havexsimprint that? If yes, how do I do that? – WeCanLearnAnything May 26 '20 at 16:59