Math & ScienceCreating random Math quizzes

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
chad
Posts: 1
Joined: Sat Aug 02, 2014 2:47 pm

Creating random Math quizzes

Post by chad »

Below is some code that I have been playing with to create random math quizzes. What I would like help doing is randomly changing the letter from 'x' to any of the 26 letters as well as the greek letters. It is also necessary that when the random letter is generated, that the answer can also refer to the same letter.

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}
Last edited by Stefan Kottwitz on Sat Aug 02, 2014 3:09 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Post Reply