\documentclass{article}
\usepackage[fleqn]{amsmath}
\usepackage[tight,designiii,usesf]{web}
\usepackage{exerquiz}
\usepackage[equations,ImplMulti,indefIntegral,limitArith,nodec]{dljslib}
\usepackage[quiet,testmode]{rangen}

\title{Experiments in Creating Random Problems}
\author{D. P. Story}
\subject{Test file for the rangen Package}
\keywords{LaTeX, rangen, quizzes, random}

\university{NORTHWEST FLORIDA STATE COLLEGE\\
   Department of Mathematics}
\email{dpstory@acrotex.net}
\version{1.0}

%\nocopyright
\norevisionLabel
\makeatletter
\def\eq@textFont{/TiRo}
\makeatother

\everyTextField{\BG{1 1 1}}
\everyCheckBox{\BG{1 1 1}}
\everyRespBoxMath{\rectW{1.9in}\textSize{0}}
\everyRespBoxTxt{\rectW{1.9in}\textSize{0}}

\newcommand{\cs}[1]{\texttt{\char`\\#1}}

\renewcommand\nodecAlertMsg{%
    "A decimal answer is not acceptable here.
     Please express your answer using a fraction."}
\newenvironment{eqComments}[1][\strut]{\smallskip\leftskip-\labelwidth
\item[]\textbf{\textcolor{blue}{#1}}}{\par\smallskip}

\begin{document}

\maketitle

\begin{shortquiz}*[sq] Answer each of the following. Passing is 100\%.

\begin{questions}

\begin{eqComments}[Arithmetic]\end{eqComments}

%% addition
\RandomQ{\a}[9]{1/8}{6/7}\RandomQ{\b}[8]{1/16}{15/16}

\item  $\displaystyle \ds\a +  \ds\b =
       \RespBoxMath{ (\nOf\a * \dOf\b + \nOf\b * \dOf\a )/( \dOf\a * \dOf\b ) }{2}{.0001}{[0,2]}[{priorParse: \Array(nodec,NoAddOrSub)}]$\hfill
       \CorrAnsButton{rFrac( rEval( \nOf\a * \dOf\b + \nOf\b * \dOf\a )/rEval( \dOf\a * \dOf\b ))}*{rngCorrAnsButton}\kern1bp\sqTallyBox

% subtraction
\RandomQ{\a}[16]{1/16}{15/16}\RandomQ[ne=\a]{\b}[16]{1/8}{15/16}

\item  $\displaystyle  \ds\a - \ds\b =
       \RespBoxMath{ (\nOf\a * \dOf\b - \nOf\b * \dOf\a )/( \dOf\a * \dOf\b ) }{2}{.0001}{[0,2]}[{priorParse: \Array(nodec,NoAddOrSub)}]$\hfill
       \CorrAnsButton{rFrac( rEval( \nOf\a * \dOf\b - \nOf\b * \dOf\a )/rEval( \dOf\a * \dOf\b ) )}*{rngCorrAnsButton}\kern1bp\sqTallyBox

% subtraction
\RandomQ{\a}[16]{1/8}{15/16}\RandomQ[ne=\a]{\b}[16]{1/8}{15/16}

\item  $\displaystyle \ds\a - \ds\b =
       \RespBoxMath{ (\nOf\a * \dOf\b - \nOf\b * \dOf\a )/( \dOf\a * \dOf\b ) }{2}{.0001}{[0,2]}[{priorParse: \Array(nodec,NoAddOrSub)}]$\hfill
       \CorrAnsButton{rFrac( rEval( \nOf\a * \dOf\b - \nOf\b * \dOf\a )/rEval( \dOf\a * \dOf\b ) )}*{rngCorrAnsButton}\kern1bp\sqTallyBox

\begin{eqComments}
This next problem illustrates the use of \cs{RandomL} and \cs{RansomAS}. The summands are
determined from a list of rational numbers. Addition or subtraction of the summands is determined
by \cs{RandomAS}.
\end{eqComments}

%% Random add/subtr using RandomL and RandomAS
\RandomL{\a}{1/2,2/3,5/3,2/5,6/5}\RandomL{\b}{4/3,3/4,8/7,3/2}\RandomS{\as}

\item $\displaystyle \ds\a \as  \ds\b =
       \RespBoxMath{ (\nOf\a * \dOf\b \as \nOf\b * \dOf\a )/( \dOf\a * \dOf\b ) }{2}{.0001}{[0,2]}[{priorParse: \Array(nodec,NoAddOrSub)}]$\hfill
       \CorrAnsButton{rFrac( rEval( \nOf\a * \dOf\b \as \nOf\b * \dOf\a )/rEval( \dOf\a * \dOf\b ) )}*{rngCorrAnsButton}\kern1bp\sqTallyBox


\begin{eqComments}
This next example illustrates how you can create a solution to a problem. This is a simple
addition problem using the built-in command \cs{qAdd}. Solutions to more advanced problems
might be obtained using the \textsf{fp} package.
\end{eqComments}

\begin{writeRVsTo}{quizzes}
\RandomQ{\a}[9]{1/8}{6/7}\RandomQ{\b}[7]{1/16}{15/16}
\end{writeRVsTo}

%% addition
\item $\displaystyle \ds\a +  \ds\b =
       \RespBoxMath{ (\nOf\a * \dOf\b + \nOf\b * \dOf\a )/( \dOf\a * \dOf\b ) }*{2}{.0001}{[0,2]}[{priorParse: \Array(nodec,NoAddOrSub)}]$\hfill
       \CorrAnsButton{rFrac( rEval( \nOf\a * \dOf\b + \nOf\b * \dOf\a )/rEval( \dOf\a * \dOf\b ) )}*{rngCorrAnsButton}\kern1bp\sqTallyBox

\begin{solution}\relax\RNGadd\a\b\defineQ{\ans}{\rfNumer}{\rfDenom}%
The solution to this problem is
\begin{equation*}
        \boxed{\ds\a +  \ds\b = \ds\ans}
\end{equation*}
\end{solution}


\newpage
\begin{eqComments}[Definite Integrals]\end{eqComments}

\RandomQ{\a}[8]{1/4}{7/6}
\RandomZ{\b}{1}{3}
\RandomQ{\n}[8]{1/2}{3/2}
\RandomZ[ne=0]{\c}{-3}{3}

\item   $\displaystyle\int_{\a}^{\b} \cfmt\c x^{\efmt\n}\,dx =
        \RespBoxMath{\c((\b)^(\n+1)-(\a)^(\n+1))/(\n+1)}{3}{.0001}{[0,2]}$\hfill
        \CorrAnsButton{rEval(\c((\b)^(\n+1)-(\a)^(\n+1))/(\n+1))}*{rngCorrAnsButton}\kern1bp\sqTallyBox


\RandomQ{\a}{1/6}{2/9}
\RandomZ{\b}{1}{10}
\RandomQ[ne={0,-1}]{\n}[5]{-1}{1}
\RandomZ[ne=0]{\c}{-3}{3}

\item   $\displaystyle\int_{\a}^{\b} \cfmt\c x^{\efmt\n}\,dx =
        \RespBoxMath{\c((\b)^(\n+1)-(\a)^(\n+1))/(\n+1)}{3}{.0001}{[0,2]}$\hfill
        \CorrAnsButton{rEval(\c((\b)^(\n+1)-(\a)^(\n+1))/(\n+1))}*{rngCorrAnsButton}\kern1bp\sqTallyBox

\RandomZ{\a}{1}{6}
\RandomZ{\b}{\a*}{8}
\RandomZ{\n}{1}{5}
\RandomZ[ne=0]{\c}{-3}{3}

\item   $\displaystyle\int_{\a}^{\b} \cfmt\c x^{\efmt\n}\,dx =
        \RespBoxMath{\c((\b)^(\n+1)-(\a)^(\n+1))/(\n+1)}{3}{.0001}{[0,2]}$\hfill
        \CorrAnsButton{rFrac(rEval(\c ( (\b)^(\n+1)-(\a)^(\n+1)))/rEval(\n+1))}*{rngCorrAnsButton}\kern1bp\sqTallyBox

\RandomZ{\a}{1}{5}
\RandomZ{\b}{\a*}{10}
\RandomQ[ne={0,-1}]{\n}{-3}{2/3}
\RandomZ[ne=0]{\c}{-3}{3}

\item   $\displaystyle\int_{\a}^{\b} \cfmt\c x^{\efmt\n}\,dx =
        \RespBoxMath{\c((\b)^(\n+1)-(\a)^(\n+1))/(\n+1)}{3}{.0001}{[0,2]}$\hfill
        \CorrAnsButton{rEval(\c((\b)^(\n+1)-(\a)^(\n+1))/(\n+1))}*{rngCorrAnsButton}\kern1bp\sqTallyBox

\RandomQ{\a}{1/4}{2/3}
\RandomQ{\b}{\a*}{7/6}
\RandomQ[ne={0,-1}]{\n}{-3}{2/3}
\RandomZ[ne=0]{\c}{-3}{3}

\item   $\displaystyle\int_{\a}^{\b} \cfmt\c x^{\efmt\n}\,dx =
        \RespBoxMath{\c((\b)^(\n+1)-(\a)^(\n+1))/(\n+1)}{3}{.0001}{[0,2]}$\hfill
        \CorrAnsButton{rEval(\c((\b)^(\n+1)-(\a)^(\n+1))/(\n+1))}*{rngCorrAnsButton}\kern1bp\sqTallyBox

\begin{eqComments}
This next problem was created from random lists of values using \cs{RandomL}.
\end{eqComments}

\RandomL{\c}{1/6,1/4,1/6,1/2}
\RandomL{\a}{1,2,3,4,5,6}
\ifnum\a=1
    \def\strAns{sin(PI/\dOf\c)}
\else
    \def\strAns{(1/\a)(sin(\a*PI/\dOf\c))}
\fi

\item $\displaystyle\int_0^{\pi/\dOf\c} \cos(\cfmt\a x) \,dx =
        \RespBoxMath{(1/\a)(sin(\a*PI/\dOf\c))}{3}{.0001}{[0,2]}$\hfill
        \CorrAnsButton{rEval(\strAns)}*{rngCorrAnsButton\RNGprintf{\%.4f}}\kern1bp\sqTallyBox


\newpage
\begin{eqComments}[Indefinite Integration]\end{eqComments}

\RandomQ{\a}{1/6}{3/2}
\RandomQ{\b}{1/6}{3/2}
\RandomZ{\c}{1}{3}

\item   $\displaystyle\int \cds\a x^2 + \ds\b x + \c\,dx =
        \RespBoxMath{(\a/3)x^3+(\b/2) x^2 + \c x}{3}{.0001}{[0,2]}$\hfill
        \CorrAnsButton{(rFrac(rEval(\nOf\a)/rEval(3*\dOf\a))) x^3
            + (rFrac(rEval(\nOf\b)/rEval(2*\dOf\b))) x^2
            + \c x + C}*{rngCorrAnsButton}\kern1bp\sqTallyBox

\RandomQ{\a}{1/3}{3}
\RandomQ{\b}{1/6}{3/2}
\RandomZ{\c}{1}{3}

\item   $\displaystyle\int \cds\a x^2 + \ds\b x + \c\,dx =
        \RespBoxMath{(\a/3)x^3+(\b/2) x^2 + \c x}{3}{.0001}{[0,2]}$\hfill
        \CorrAnsButton{(rFrac(rEval(\nOf\a)/rEval(3*\dOf\a))) x^3
            + (rFrac(rEval(\nOf\b)/rEval(2*\dOf\b))) x^2
            + \c x + C}*{rngCorrAnsButton}\kern1bp\sqTallyBox

\newpage
\begin{eqComments}[Differentiation]\end{eqComments}

\RandomQ[ne=0]{\c}[4]{-2}{2}
\RandomQ[ne=0]{\n}[1]{-3}{2}

\item   $\displaystyle \frac{d}{dx} \cds\c x^{\efmt\n} =
        \ifnum\nOf\n=\dOf\n
            \RespBoxMath{\c}{3}{.0001}{[0,2]}$\hfill
            \CorrAnsButton{rFrac(\nOf\c/\dOf\c)}*{rngCorrAnsButton}%
        \else
            \RespBoxMath{\c*\n*x^(\n-1)}{3}{.0001}{[0,2]}$\hfill
            \CorrAnsButton{rFrac(rEval(\nOf\c*\nOf\n)/rEval(\dOf\c*\dOf\n))
                x^(rFrac(rEval(\nOf\n-\dOf\n)/\dOf\n))}*{rngCorrAnsButton}%
        \fi
        \kern1bp\sqTallyBox

\begin{eqComments}
This next problem uses a random sign, defined by \cs{RandomS}.
\end{eqComments}

\RandomQ{\c}[4]{2}{3}\RandomS{\s}
\RandomQ[ne=0]{\n}[2]{-3}{2}

\item   $\displaystyle \frac{d}{dx} \cfmt\s\ds\c x^{\efmt\n} =
        \ifnum\nOf\n=\dOf\n
            \RespBoxMath{\s\c}{3}{.0001}{[0,2]}$\hfill
            \CorrAnsButton{\s\nOf\c/\dOf\c}*{rngCorrAnsButton}%
        \else
            \RespBoxMath{\s\c*\n*x^(\n-1)}{3}{.0001}{[0,2]}$\hfill
            \CorrAnsButton{rFrac(rEval(\s\nOf\c*\nOf\n)/rEval(\dOf\c*\dOf\n))
                x^(rFrac(rEval(\nOf\n-\dOf\n)/\dOf\n))}*{rngCorrAnsButton}%
        \fi
        \kern1bp\sqTallyBox


\RandomQ[ne=0]{\c}[4]{-2}{5}
\RandomQ{\n}[4]{2}{5}

\item   $\displaystyle \frac{d}{dx} \ds\c x^{\efmt\n} =
        \ifnum\nOf\n=\dOf\n
            \RespBoxMath{\c}{3}{.0001}{[0,2]}$\hfill
            \CorrAnsButton{\nOf\c/\dOf\c}*{rngCorrAnsButton}%
        \else
            \RespBoxMath{\c*\n*x^(\n-1)}{3}{.0001}{[0,2]}$\hfill
            \CorrAnsButton{rFrac(rEval(\nOf\c*\nOf\n)/rEval(\dOf\c*\dOf\n))
                x^(rFrac(rEval(\nOf\n-\dOf\n)/\dOf\n))}*{rngCorrAnsButton}%
        \fi
        \kern1bp\sqTallyBox

\newpage

\begin{eqComments}[Analytic Geometry]\end{eqComments}

\RandomZ{\a}{-10}{9}
\RandomZ{\b}{-10}{9}
\RandomZ{\c}{\a*}{10}
\RandomZ{\d}{\b*}{10}
\defineDepQJS{\m}{\d - \b}{\c - \a}{rFrac(rEval(\nOf\m)/rEval(\dOf\m))}
\defineDepQJS{\yIntercept}{\b - \a*\m}{1}{rFrac((rEval( \b * \dOf\m - \a*\nOf\m ))/(rEval(\dOf\m)))}


\item   Let $P(\,\a, \b\,)$ be a point and $Q(\,\c, \d\,)$ be a point. Find the equation of the line that
        passes through $P$ and $Q$.\par\kern3pt
        \RespBoxMath{y = \m*x + \yIntercept }(xy){3}{.0001}{[0,2]x[0,2]}*{ProcRespEq}\hfill
        \CorrAnsButton{y = \js\m\space x + \js\yIntercept}*{rngCorrAnsButton}%
        \kern1bp\sqTallyBox

\RandomZ{\a}{-10}{9}
\RandomZ{\b}{-10}{9}
\RandomZ{\c}{\a*}{10}
\RandomZ{\d}{\b*}{10}
\defineDepQJS{\m}{\d - \b}{\c - \a}{rFrac(rEval(\nOf\m)/rEval(\dOf\m))}
\defineDepQJS{\yIntercept}{\b - \a*\m}{1}{rFrac((rEval( \b * \dOf\m - \a*\nOf\m ))/(rEval(\dOf\m)))}

\item  Let $P(\,\a, \b\,)$ be a point and $Q(\,\c, \d\,)$ be a point. Find the equation of the line that
        passes through $P$ and $Q$.\par\kern3pt
        \RespBoxMath{y = \m*x + (\b - \a*\m) }(xy){3}{.0001}{[0,2]x[0,2]}*{ProcRespEq}\hfill
        \CorrAnsButton{y = \js\m\space x + \js\yIntercept}*{rngCorrAnsButton}%
        \kern1bp\sqTallyBox

\end{questions}
\end{shortquiz}
\begin{flushright}
\sqClearButton\kern1bp\sqTallyTotal
\end{flushright}
\end{document}
