# Random Numbers in \for loop

I'm slowly progressing towards understanding the code for creating random arithmetic questions for young students.

At this point, I'm trying to create ten random addition questions.

Why does this not compile? The error message says that \TenRandomQuestions is not defined, but I thought I did define it...

\documentclass{article}

\usepackage{pgf}

\pgfmathsetseed{\number\pdfrandomseed}

\newcommand*\initVariables
{
\pgfmathsetmacro{\A}{random(0,10)}
\pgfmathsetmacro{\B}{random(0,10)}
}

\newcommand*\OneEquation % This macro compiles.
{
\initVariables
$\A+\B=\answer$}
}

\newcommand{\TenRandomQuestions} % This macro does NOT compile. The error message says that this command is undefined.
{%
\foreach \x in {0,1,2,...,10}%
{%
\OneEquation \\   % How do I incorporate \x into this? Or do I not need to?
}%
}%

\begin{document}

\TenRandomQuestions

\end{document}

• \usepackage{pgffor} is missing.
– user31729
Aug 6, 2016 at 21:02
• Wow. Ok, is there a list/explanation of packages related to TikZ and PGF that I should know about? Aug 6, 2016 at 21:47
• I am sure there are questions about this here on TeX.SX already. In doubt, look into pgfmanual.pdf (the tikz manual)
– user31729
Aug 6, 2016 at 21:49

\documentclass{article}

\usepackage{pgffor}

\pgfmathsetseed{\number\pdfrandomseed}

\newcommand*\initVariables
{
\pgfmathsetmacro{\A}{random(0,10)}
\pgfmathsetmacro{\B}{random(0,10)}
}

\newcommand*\OneEquation % This macro compiles.
{
\initVariables
$\A+\B=\answer$}
}

\newcommand{\TenRandomQuestions} % This macro does NOT compile. The error message says that this command is undefined.
{%
\foreach \x in {0,1,2,...,10}%
{%
\OneEquation \\   % How do I incorporate \x into this? Or do I not need to?
}%
}%

\begin{document}

\TenRandomQuestions

\end{document}

• The pgfforce is strong in you ;-) (+1)
– user31729
Aug 6, 2016 at 21:21
• haha. You should be getting the credit since you got here first, but it's answer the unanswered questions time.... ;-)
– JPi
Aug 6, 2016 at 21:22
• I don't need the rep (any longer, my 'hunt' is over) ... and you've misunderstood 'answer the unanswered', that's more for older questions :D
– user31729
Aug 6, 2016 at 21:24
• Indeed, I did not know that.
– JPi
Aug 6, 2016 at 21:29