I am trying to make some math fact equation sheets that are based on random number generation. I have quite a bit of learning to do... but this is where I think should start: Use random numbers to make LaTeX generate a string of equations for me.
Right now, the basic idea is that: I first have \pgfmathsetmacro{\A}{random(1,4)} set \A as 1,2, 3 or 4.
- If \A=1, then I want 1+2=3 to appear.
- If \A=2, then I want 2+1=3 to appear.
- If \A=3, then I want 3=2+1 to appear.
- If \A=4, then I want 3=1+2 to appear.
This is what I've got so far, but the nested \ifthen structure seems very inelegant and will basically not scale to when I have, say, 100 different equations to choose from instead of just 4.
What's a better way?
\documentclass{article}
\usepackage{pgf}
\usepackage{pgffor}
\usepackage{ifthen}
\pagestyle{empty}
\setlength{\parindent}{0pt}
% THE FOUR EQUATIONS
% 1. 1+2=3
% 2. 2+1=3
% 3. 3=2+1
% 4. 3=1+2
\pgfmathsetseed{\number\pdfrandomseed}
\newcommand{\InitVariables}
{\pgfmathsetmacro{\A}{random(1,4)}}
\newcommand*{\onefact}
{
\InitVariables
\ifthenelse
{\equal{\A}{1}}{1+2=3}
{
\ifthenelse{\equal{\A}{2}}{3=2+1}
{
\ifthenelse{\equal{\A}{3}}{3=2+1}{3=1+2}
}
}
}
\newcommand{\myequations}[1]
{
\foreach \x in {1,...,#1}
{\onefact\\}
}
\begin{document}
\myequations{10}
\end{document}

