Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to generate random questions based on a random integer input. I have tried he code from a site online and tweaked it so that it generates more than one random problem but evidently it does not generate random problems. In the enumerate, the same problem appears. Any insight into the matter will be highly appreciated.

\documentclass[letterpaper]{article}
\usepackage{amsmath,amssymb,enumitem}
\usepackage{lcg,calc}
\usepackage{tikz}
\reinitrand[first=1, last=10, counter=num]  \rand
\reinitrand[first=2, last=20, counter=deno] \rand
\reinitrand[first=2, last=5, counter=coeff] \rand
\setcounter{num}{\value{coeff}*\value{num}} 
\setcounter{deno}{\value{coeff}*\value{deno}}
\newcommand{\fracquestion}[1]{%
\foreach \i in {1,...,#1}
{
\item $\dfrac{\thenum}{\thedeno}$
}}
\begin{document}
\begin{enumerate}
\fracquestion{5}
\end{enumerate}
\end{document}
share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

If you move the random number generating code within the \foreach and ajdust the seed values you get:

enter image description here

\documentclass[letterpaper]{article}
\usepackage{amsmath,amssymb,enumitem}
\usepackage{lcg,calc}
\usepackage{tikz}

\newcommand{\fracquestion}[1]{%
    \foreach \i in {1,...,#1}{%
      \reinitrand[first=\i, last=10, counter=num]  \rand
      \reinitrand[first=\i, last=20, counter=deno] \rand
      \reinitrand[first=\i, last=5, counter=coeff] \rand
      \setcounter{num}{\value{coeff}*\value{num}} 
      \setcounter{deno}{\value{coeff}*\value{deno}}
      \item $\dfrac{\thenum}{\thedeno}$
    }
}
\begin{document}
\begin{enumerate}
  \fracquestion{5}
\end{enumerate}
\end{document}

Alternatively you could just use the random number generation capability already built into PGF (which is included with tikz):

enter image description here

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

\newcommand{\fracquestion}[1]{%
    \foreach \i in {1,...,#1}{%
      \item $\dfrac{\pgfmathparse{random(10)}\pgfmathresult}{\pgfmathparse{random(20)}\pgfmathresult}$%
    }
}
\begin{document}
\begin{enumerate}
  \fracquestion{5}
\end{enumerate}
\end{document}
\begin{document}
share|improve this answer
    
Thank you. I will try to apply the same principle to simple quadratic equations to try to generate problems with equal roots, distinct roots and imaginary roots. –  azetina Jan 23 '12 at 19:01
    
I am looking at random math problems. How can I get only the quadratic equations and using the same principle as above; that is, with random problems generated? –  azetina Jan 24 '12 at 14:57
    
Huh??? Not sure exactly what you want to do. A quadratic equation just needs three random numbers \a, \b, \c, and then $\a x^2 + \b x + \c$ would be a randomly generated quadratic equation. I suspect that you are looking for something else.. If it is not related to thrust of this question (i.e., how to generate random numbers) it should probably be posted as a new question. –  Peter Grill Jan 24 '12 at 15:59
    
@PeterGrillOk I will try to post as a new question. –  azetina Jan 24 '12 at 16:04
    
Ok, you should include a link back to this question in case it is deemed a duplicate. –  Peter Grill Jan 24 '12 at 16:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.