With the code as it stands, when I enter a negative range for the random numbers I get unusual output. I have subsequently only used positive numbers but would like to know how to fix this issue.
Finally, I would like to know how to generate multiple questions from the same code without copy and pasting several times as I have done. That way I only need to nominate the number of subquestions with each question and the compilation does the rest. The ideal resulting format would be:
Question 1
a) x^2 + 2x +1
b) u^2 + 5x + 6
...
Question 2
a) (x+2)(x-5)
b) (2-t)(t+5)
...
Thanks in advance,
Chad
Code: Select all
\documentclass{article}
\usepackage{amsmath, amssymb, datetime, calculator, enumitem, tikz}
\usepackage[top=2cm, bottom=1.5cm, left=1.7cm, right=1.7cm]{geometry}
\usepackage{pgf, fp}
\def\TotalSecondsMinute{}%
\def\TotalSeconds{}%
\MULTIPLY{\currentminute}{60}{\TotalSecondsMinute}%
\ADD{\TotalSecondsMinute}{\currentsecond}{\TotalSeconds}%
\pgfmathsetseed{\TotalSeconds}%
\newcommand\initVariables{
\pgfmathsetmacro{\A}{random(1,12)}
\pgfmathsetmacro{\B}{random(1,12)}
\FPtrunc\A{\A}{0}
\FPtrunc\B{\B}{0}
}
\newcommand\answer{$x^2$+\pgfmathprint{int(\A + \B)}$x$+\pgfmathprint{int(\A * \B)}} % define command to calculate result
\title{
\bf Binomial Expansion Quiz
}
\begin{document}
\date{\vspace{-8ex}}
\maketitle
\begin{enumerate}
\initVariables % initialize variables (do this every time you need new numbers)
\item
\noindent What is $\left(x+\A\right)$$\cdot$$\left(x+\B\right)$?
\\
Result is \answer
\initVariables % initialize variables (do this every time you need new numbers)
\\
\item
What is $\left(x+\A\right)$$\cdot$$\left(x+\B\right)$?
\\
Result is \answer
\initVariables % initialize variables (do this every time you need new numbers)
\item
\noindent What is $\left(x+\A\right)$$\cdot$$\left(x+\B\right)$?
\\
Result is \answer
\initVariables % initialize variables (do this every time you need new numbers)
\\
\item
What is $\left(x+\A\right)$$\cdot$$\left(x+\B\right)$?
\\
Result is \answer
\initVariables % initialize variables (do this every time you need new numbers)
\item
\noindent What is $\left(x+\A\right)$$\cdot$$\left(x+\B\right)$?
\\
Result is \answer
\initVariables % initialize variables (do this every time you need new numbers)
\\
\item
What is $\left(x+\A\right)$$\cdot$$\left(x+\B\right)$?
\\
Result is \answer
\initVariables % initialize variables (do this every time you need new numbers)
\item
\noindent What is $\left(x+\A\right)$$\cdot$$\left(x+\B\right)$?
\\
Result is \answer
\initVariables % initialize variables (do this every time you need new numbers)
\\
\item
What is $\left(x+\A\right)$$\cdot$$\left(x+\B\right)$?
\\
Result is \answer
\initVariables % initialize variables (do this every time you need new numbers)
\item
\noindent What is $\left(x+\A\right)$$\cdot$$\left(x+\B\right)$?
\\
Result is \answer
\initVariables % initialize variables (do this every time you need new numbers)
\\
\item
What is $\left(x+\A\right)$$\cdot$$\left(x+\B\right)$?
\\
Result is \answer
\end{enumerate}
\end{document}