Generating a worksheet

My objective is to be able to generate worksheets in categories like:

1. Laws of Indices
2. Simultaneous Linear equations and

When I say generate is to generate for example 20 different problems. I believe I have addressed that with:

\newcommand{\questiontype}{%
\foreach \i in {1,...,#1}
{
\item $my question type$
}}

Somehow I believe that it is related to the question Creating random problems by using rand option.

The only difference is the restrictions that would be needed in code. For example, considering quadratic equations, there are three categories that is problems with equal roots, distinct and imaginary.

I am not an expert in pgf nor the random parameters. I am in the learning process here and I hope you the experts can assist me. I got the inspiration from Calculs et Programmation.

I haven't developed any code as yet but am ready to learn.

EDIT

To better understand my question see the code below.

For example:

\usepackage{lcg,calc,ifthen}

% Une variable qui va servir
\newcounter{det}

\newcommand{\randomsys}{
% Génerer 6 entiers dans [-20,20]
\reinitrand[first=-20, last=20, counter=a] \rand
\chgrand[counter=b] \rand
\chgrand[counter=c] \rand
\chgrand[counter=d] \rand
\chgrand[counter=e] \rand
\chgrand[counter=f] \rand
% Remplacer 0 par 1000
\ifthenelse{\value{a}=0}{\setcounter{a}{1000}}{}
\ifthenelse{\value{b}=0}{\setcounter{b}{1000}}{}
\ifthenelse{\value{d}=0}{\setcounter{d}{1000}}{}
\ifthenelse{\value{e}=0}{\setcounter{e}{1000}}{}

% Un énoncé selon la valeur du dét
\setcounter{det}{\value{a}*\value{e}-\value{b}*\value{d}}
\ifthenelse{\value{det}=0}%
{Expliquer pourquoi le système suivant
n'admet pas une unique solution :}%
{Résoudre le système suivant :}
$\left\lbrace \begin{array}{rcl} \thea x+\theb y &=& \thec \\ \thed x+\thee y &=& \thef \end{array} \right.$}

\randomsys \randomsys \randomsys \randomsys
\randomsys \randomsys \randomsys \randomsys

The code above should generate random simultaneous equations. Thus my objective is to understand what each line is saying, an alternative to this like using the pgfmath from tikz, and what each definition in the code means.

Ultimately I want to learn how I can create random problems based on the above principle. The above topics mentioned (laws of indices, quad equations and simultaneous equations) are just samples to reference from.

• This looks like quite an open-ended question. It isn't clear what would constitute a good answer to this question. Could you make it clearer what you are asking? A good start would be to explain why the answer you linked to doesn't solve your problem and to show us what you have tried so far. – Seamus Jan 24 '12 at 18:22
• I want to learn how to use the pgf features or an explanation of these features and their implementation. – azetina Jan 24 '12 at 18:27

Without more details I don't know how to help any more than this. Here is an explanation of what is going on:

1. I define \newcommand*{\Difficulty}{10}. This number is used to determine the range of the random numbers that are generated. In this case with it set to 10, the random numbers will be real numbers in the range 1...10.

2. \pgfmathtruncatemacro is used to set a macro with the integer value of the computed expression. So \pgfmathtruncatemacro{\DenomDifficulty}{2*\Difficulty} set the macro \DenomDifficulty to be twice that of the value specified in \Difficulty. Similarily, \pgfmathtruncatemacro{\Neum}{random(\Difficulty)} set the macro \Neum to the value returned by random(\Difficulty). Since random() provides a real valued random number from 1..10 and (assuming here) we only want integer numbers, this necessitated the use of \pgfmathtruncatemacro, instead of the usual \pgfmathsetmacro.

3. Similarly for the \LinearSystem and \QuadraticEquations macros, it is just a matter of generating more random numbers and using them in the math expressions.

4. You mention in your question that there are three cases for quadratic: equal roots, distinct and imaginary. If you want to only generate equations sets of equations that have the same type of roots you would need to provide an algorithm for ensuring that type of root.

If you do not require a restriction of integer values then this is fairly simple case. For example to get equal roots you could just randomly generate \A, \B and then use \C = (\B*\B)/(4*\A). However this won't necessarily be an integer, so you'd have to include extra logic here of that is desired. Further Improvements:

• Complete macros to generate only quadratic equations with distinct real and imaginary roots.
• Generate negative numbers as well. In this case it would be advisable to include some logic so that we do not end up with + - as in the linked to example in the question. One way would be just to generate another random number from 0..1 and use a - sign instead of a + sign (or no sign as in the leading numbers) if the random number generated was greater than 0.6 (assuming you wanted approximately 40% of the questions to have negative signs, which also controls the level of difficulty dependent on the grade level).
• Automatically convert decimals to reduced fractions. For this refer to this question from the future Random quadratic equation, which enhances the solution presented here.

Code:

\documentclass{article}
\usepackage{mathtools}
\usepackage{enumitem}
\usepackage{tikz}

\newcommand*{\Difficulty}{10}%

\newcommand{\FracQuestion}{%
\foreach \i in {1,...,#1}{%
\pgfmathtruncatemacro{\DenomDifficulty}{2*\Difficulty}%
\pgfmathtruncatemacro{\Neum}{random(\Difficulty)}
\pgfmathtruncatemacro{\Denom}{random(\DenomDifficulty)}
\item $\dfrac{\Neum}{\Denom}$%
}%
}%

\newcommand{\LinearSystem}{%
\foreach \i in {1,...,#1}{%
\pgfmathtruncatemacro{\Xa}{random(\Difficulty)}%
\pgfmathtruncatemacro{\Ya}{random(\Difficulty)}%
\pgfmathtruncatemacro{\Za}{random(\Difficulty)}%
\pgfmathtruncatemacro{\Xb}{random(\Difficulty)}%
\pgfmathtruncatemacro{\Yb}{random(\Difficulty)}%
\pgfmathtruncatemacro{\Zb}{random(\Difficulty)}%
\item \begin{cases}\begin{aligned}% \Xa x + \Ya y &= \Za \\% \Xb x + \Yb y &= \Zb \\% \end{aligned}\end{cases}%
}%
}%

\foreach \i in {1,...,#1}{%
\pgfmathtruncatemacro{\A}{random(\Difficulty)}%
\pgfmathtruncatemacro{\B}{random(\Difficulty)}%
\pgfmathtruncatemacro{\C}{random(\Difficulty)}%
\item $\A x^2 + \B x + \C = 0$%
}%
}%

\foreach \i in {1,...,#1}{%
\pgfmathtruncatemacro{\A}{random(\Difficulty)}%
\pgfmathtruncatemacro{\B}{random(\Difficulty)}%
\pgfmathsetmacro{\C}{(\B*\B)/(4*\A)}%
\item $\A x^2 + \B x + \C = 0$%
}%
}%

\begin{document}
\section{Random Fractions:}
\begin{enumerate}
\FracQuestion{3}
\end{enumerate}
%
\section{Random 2x2 Linear Equations:}
\begin{enumerate}
\LinearSystem{3}
\end{enumerate}
%