% makeindex < aebpro_man.idx > aebpro_man.ind \documentclass[12pt]{article} \usepackage[fleqn]{amsmath} \usepackage[ web={centertitlepage,designv,tight*,forcolorpaper, % usesf, latextoc,pro}, aebxmp,exerquiz, dljslib={equations,ImplMulti,indefIntegral,limitArith,nodec} ]{aeb_pro} \usepackage{multicol} \usepackage{array} %\usepackage{myriadpro} %[usecmtt] \usepackage[altbullet]{lucidbry} \usepackage[quiet,testmode]{rangen} % testmode %\usepackage[quiet,seed=98]{rangen} % 128 %\usepackage[quiet,seed=135]{rangen} % \DeclareInitView {% layoutmag={mag=100}, % windowoptions={fit} } %\usepackage{makeidx}\makeindex \usepackage{acroman} \usepackage[active]{srcltx} \def\expath{../examples} \urlstyle{tt} %\def\tutpath{doc/tutorial} %\def\tutpathi{tutorial} \DeclareDocInfo { university={\AcroTeX.Net}, title={The \texorpdfstring{\pkg{rangen} Package\\[1em]}{: } Random Generation of Integer, Rational, and Real Numbers with Applications to the \texttt{exercise}, \texttt{quiz}, and \texttt{shortquiz} Environments of \textsf{Exerquiz}}, author={D. P. Story}, email={dpstory@acrotex.net}, subject={Documentation for annot\textunderscore pro from AcroTeX}, talksite={\url{www.acrotex.net}}, version={1.4}, copyrightStatus=True, copyrightNotice={Copyright (C) \the\year, D. P. Story}, copyrightInfoURL={http://www.acrotex.net} } \def\anglemeta#1{\ensuremath{\langle\textit{\texttt{#1}}\rangle}} \def\meta#1{\textit{\texttt{#1}}} \let\meta\anglemeta \def\darg#1{\texttt{\{#1\}}} \def\takeMeasure{\bgroup\obeyspaces\takeMeasurei} \def\takeMeasurei#1{\global\setbox\webtempboxi\hbox{\ttfamily#1}\egroup} \def\bxSize{\wd\webtempboxi+2\fboxsep+2\fboxrule} \let\pkg\textsf \let\env\texttt \let\opt\texttt \let\app\textsf \let\amtIndent\leftmargini \def\SUB#1{${}_{\text{#1}}$} \newdimen\aebdimen \aebdimen 0pt %\advance\aebdimen\partopsep \newcommand\bVerb[1][]{\begingroup#1\vskip\aebdimen\parindent0pt}% \def\eVerb{\vskip\aebdimen\endgroup\noindent} \makeatletter \renewcommand{\paragraph} {\@startsection{paragraph}{4}{0pt}{6pt}{-3pt}{\bfseries}} \renewcommand*\l@subsection{\@dottedtocline{2}{1.5em}{2.5em}} \renewcommand*\descriptionlabel[1]{\hspace\labelsep \normalfont #1} \newcommand{\aebDescriptionlabel}[1]{% \setlength\dimen@{\amtIndent+\labelsep}% {\hspace*{\dimen@}#1}} \makeatother \newenvironment{aebDescript} {\begin{list}{}{\setlength{\labelwidth}{0pt}% \setlength{\leftmargin}{\leftmargin}% \setlength{\leftmargin}{\leftmargin+\amtIndent}% \setlength\itemindent{-\leftmargin}% \let\makelabel\aebDescriptionlabel }}{\end{list}} \def\dps{$\hbox{$\mathfrak D$\kern-.3em\hbox{$\mathfrak P$}% \kern-.6em \hbox{$\mathcal S$}}$} \universityLayout{fontsize=Large} \titleLayout{fontsize=LARGE} \authorLayout{fontsize=Large} \tocLayout{fontsize=Large,color=aeb} \sectionLayout{indent=-62.5pt,fontsize=large,color=aeb} \subsectionLayout{indent=-31.25pt,color=aeb} \subsubsectionLayout{indent=0pt,color=aeb} \subsubDefaultDing{\texorpdfstring{$\bullet$}{\textrm\textbullet}} \newenvironment{eqComments}[1][\strut]{\smallskip\leftskip-\labelwidth \item[]\textbf{\textcolor{blue}{#1}}}{\par\smallskip} \renewcommand\nodecAlertMsg{% "A decimal answer is not acceptable here. Please express your answer using a fraction."} %\previewtrue %\pagestyle{empty} %\parindent0pt\parskip\medskipamount \definePath\bgPath{"C:/Users/Public/Documents/% ManualBGs/Manual_BG_Print_AeB.pdf"} \begin{docassembly} \addWatermarkFromFile({% bOnTop: false, cDIPath: \bgPath }) \executeSave() \end{docassembly} \begin{document} \maketitle \selectColors{linkColor=black} \tableofcontents \selectColors{linkColor=webgreen} \section{Introduction}\label{s:intro} This is a package that I began back in the year 2000 AD; at that time, I managed to obtain a working version up and running with many bugs, then forgot about it. Now, in my retirement, I stumbled across the work and decided to give it another go. The \pkg{rangen} package, as the title implies, can (pseudo-)randomly generate integers, rationals, and real numbers. Generate said numbers using the \cs{RandomZ}, \cs{RandomQ}, and \cs{RandomR} commands, respectively; in addition to these, there is \cs{RandomL} for creating a list of numbers, from which one number is selected at random, and \cs{RandomI} for generating a random index value that can be used in conjunction with \cs{RandomL}. The \AcroTeX{} eDucation Bundle (AeB) contains a package called \textsf{exerquiz} that is used to create exercises and quizzes. My goal in writing the \pkg{rangen} package was to integrate it with the quiz system of \textsf{exerquiz} so that quiz questions could be composed using the ``natural'' syntax of \pkg{rangen}, each time the source file is {\LaTeX}ed, new random numbers populate the question. To get your interest, here is an example, \begingroup\parskip0pt %\previewtrue \def\aftershortquizskip{} \setlength{\multicolsep}{0pt} \begin{shortquiz}*[answer] \textbf{\textcolor{blue}{Arithmetic.}} A simple arithmetic problem, I've created one problem, then copied it to make two problems. \vskip6pt \begin{multicols}{2} \begin{questions} % subtraction \RandomQ{\a}[16]{1/8}{15/16}\RandomQ[ne=\a]{\b}[16]{1/8}{15/16} \item $\displaystyle \ds\a - \ds\b = \RespBoxMath[\rectW{.5in}]{ (\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[\rectW{.5in}]{ (\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 \pushquestions \end{multicols} \popquestions \vskip-6pt \begin{eqComments}[Indefinite Integration.] There are two integration problems, again, the second question is a copy and paste of the first. The parameters of the problem were, of course, populated by different random numbers. \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 + \cds\b x + \ds\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/6}{3/2} \RandomQ{\b}{1/6}{3/2} \RandomZ{\c}{1}{3} \item $\displaystyle\int \cds\a x^2 + \cds\b x + \ds\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 %\vskip-6pt \vskip-6pt \begin{eqComments} Definite integration can also be posed, but is not illustrated here. \end{eqComments} \vskip-6pt \begin{eqComments}[Analytic Geometry.] Find the equation of the line that passes through $P$ and $Q$. \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))} \item $P(\,\a, \b\,)$, $Q(\,\c, \d\,)$: \RespBoxMath{y = \m*x + (\b - \a*\m) }(xy){3}{.0001}{[0,2]x[0,2]}*{ProcRespEq}\hfill \CorrAnsButton{y = \js\m\space x + rFrac((rEval( \b * \dOf\m - \a*\nOf\m ))/(rEval(\dOf\m)))}*{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))} \item $P(\,\a, \b\,)$, $Q(\,\c, \d\,)$: \RespBoxMath{y = \m*x + (\b - \a*\m) }(xy){3}{.0001}{[0,2]x[0,2]}*{ProcRespEq}\hfill \CorrAnsButton{y = \js\m\space x + rFrac((rEval( \b * \dOf\m - \a*\nOf\m ))/(rEval(\dOf\m)))}*{rngCorrAnsButton}% \kern1bp\sqTallyBox\par\kern2pt \end{questions} \end{shortquiz}\hfill\sqClearButton\kern1bp\sqTallyTotal \par\endgroup \newtopic\noindent Each time the manual is compiled, a new set of problems of the same type is generated. This package is pretty impressive, I'm sure you'll agree. \dps These examples were taken from the demo file \texttt{rangen\_tst.tex}. \section{Requirements} The requirements for your {\LaTeX} system, and well as any other software, is highlighted in this section. \subsection{{\LaTeX} Package Requirements} The following packages, in addition to the standard {\LaTeX} distribution, are required: \begin{enumerate} \item The \textsf{lcg} package (2008/09/10 v1.2) by Erich Janka. \item The \textsf{hyperref} package, a recent version. \item If you want to use \pkg{rangen} to create quizzes, then \textsf{exerquiz} of \textcolor{blue}{AeB} is required.\footnote{AeB: \url{http://www.math.uakron.edu/~dpstory/webeq.html}} \end{enumerate} \subsection{PDF Creator Requirements} The package works for all PDF creators: Acrobat Distiller, pdftex, and dvipdfm. \section{Installation} Unzip \texttt{rangen.zip} into your {\LaTeX} tree, the folder \texttt{rangen} is constructed with to contain the installation. \section{Package Options} Currently, there is only one option, \opt{testmode}. Then this option is used, each time the file is run, the random number generator of \pkg{lcd} is re-seeded Normally, the seed is based on the time, the date and other factors; the clock of the {\TeX} compiler gives the time to the nearest minute, so one must wait at least a minute before getting a new seed, this is not acceptable when testing a package. When \opt{testmode} is used, the initial seed is \texttt{seed=1}, and increments by one thereafter; after the increment, this value is saved to the file \cs{jobname.seed} and input back in on the next compile. Any other options that are passed to \pkg{rangen}, are passed on to the \textsf{lcg} package. Useful options for \pkg{lcg} are \texttt{quiet} and \texttt{seed=\meta{number}}. \section{Basic Commands} This package defines the commands \cs{RandomZ}, \cs{RandomQ}, and \cs{RandomR}, \cs{RandomL}, and \cs{RandomI}. We describe these commands in this section. For convenience of terminology, a number created by one of the above commands will be referred to as a RV (random variable). \cs{RandomZ} and \cs{RandomQ} use the count registers, so there is a restriction on the size of any RV generated by these two commands, we must have \begin{equation*} -2^{31}+1 \leq \text{RV} \leq 2^{31}-1\implies -2147483647 \leq \text{RV} \leq 2147483647 \end{equation*} For simple applications envisioned for \pkg{rangen}, this range should be plenty enough. The \cs{RandomR} command uses the dimension registers, so a RV generated by \cs{RandomR} is restricted to \begin{equation*} -2^{14} < \text{RV} < 2^{14}\implies -16384 < \text{RV} < 16384 \end{equation*} Again, this is not a package for making floating point calculations, it is a package for generating integers, rationals, and decimal numbers with an eye towards application to academic problem generation. Floating point arithmetic can be accomplished using the \textsf{fp} package; \pkg{rangen} and \textsf{fp} seem to be compatible. \subsection{\texorpdfstring{\protect\cs{RandomZ}}{\CMD{RandomZ}}} The command \Com{RandomZ} defines a random integer, the syntax is \takeMeasure{\string\RandomZ[\meta{key-values}]\darg{\cs{\meta{name}}}\darg{\meta{zLEP}}\darg{\meta{zUEP}}} \begin{dCmd*}[commandchars=!()]{\bxSize} \RandomZ[!meta(key-values)]{!cs(!meta(name))}{!meta(zLEP)}{!meta(zUEP)} \end{dCmd*} \PD \begin{description} \item [\texttt{\meta{key-values}}] The key-value pairs that modify the choice of the variable. The key-value pairs recognize are \begin{description} \item [\texttt{ne=\meta{value}}] Restrict the choice of the random integer by requiring it \emph{not be equal} to another number, for example, \texttt{ne=0} or \texttt{ne=\cs{b}}. In the latter case, \cs{b} is a number defined already by either an earlier \cs{RandomZ} call, or by \Com{defineZ}, discussed later. Multiple restrictions can be placed as well, for example, if \verb!ne={0,-1}!, \pkg{rangen} selects an integer different from 0 or -1. % \item \texttt{formatOne}: A Boolean formatting key for formatting the number 1; % for example, instead of typesetting \texttt{1x} the correct syntax is to typeset \texttt{x}. % To obtain this special formatting, you must use % \cs{fmt} or \cs{ds}, for example \verb!\fmt\a!. Details are described below. % \item \texttt{formatPMOne}: A Boolean formatting key for formatting the numbers 1 and -1; % in addition to formatting of the number 1, if the random integer is -1 we want to % typeset \texttt{-x} not \texttt{-1x}. To obtain this special formatting, you must use % \cs{fmt} or \cs{ds}, for example \verb!\fmt\a!. Details are described below. \end{description} \item[\cs{\meta{name}}] The name of the random integer. For example, \cs{a}, \cs{b}, etc. \item [\meta{zLEP}] An integer that is the lower endpoint of the interval from which the number is randomly selected. The lower endpoint may be an integer previously calculated by an earlier \cs{RandomZ} call, for example, \verb!\RandomZ{\b}{\a}{5}!, this will generate an integer \cs{b} such that $\cs{a}\le\cs{b}\le5$. To get strict inequality, append an asterisk (\texttt{*}), for example, if the syntax \verb!\RandomZ{\b}{\a*}{5}! is used, then \pkg{rangen} attempts to satisfy $\cs{a}<\cs{b}\le5$. The range of \cs{a} should be such that the upper limit for \cs{a} is less than the upper limit of \cs{b}. When the endpoint is a number, the \texttt{*} is ignored.\smallskip When the lower endpoint is a command created by the commands \cs{Random\meta{\upshape{Z|Q|R|L}}} or by \cs{define\meta{\upshape{Z|Q|R}}}, the endpoint is converted to a real number. \item [\meta{zUEP}] An integer that is the upper endpoint of the interval from which the number is randomly selected. The upper endpoint may be an integer previously calculated by an earlier \cs{RandomZ} call, for example, \verb!\RandomZ{\b}{-5}{\a}!, this will generate an integer \cs{b} such that $-5\le\cs{b}\le\cs{a}$. To get strict inequality, use the syntax $-5\le\cs{b}\le\cs{a}*$, then \pkg{rangen} attempts to satisfy $-5\le\cs{b}<\cs{a}$. The range of \cs{a} should be such that the lower limit for \cs{a} is greater than the lower limit of \cs{b}. When the endpoint is a number, the \texttt{*} is ignored.\smallskip When the upper endpoint is a command created by the commands \cs{Random\meta{\upshape{Z|Q|R|L}}} or by \cs{define\meta{\upshape{Z|Q|R}}}, the endpoint is converted to a real number. \end{description} \noindent \textbf{Examples:} \begin{enumerate} \item \verb!\RandomZ{\a}{-5}{5}!: \RandomZ{\a}{-5}{5}\cs{a}=\a. To get another random integer, we repeatedly execute \verb!\RandomZ{\a}{-5}{5}! followed by \cs{a}, for example, we copy and paste \verb!\RandomZ{\a}{-5}{5}\a! three times to get \RandomZ{\a}{-5}{5}\a, \RandomZ{\a}{-5}{5}\a, \RandomZ{\a}{-5}{5}\a. \item Illustrate \texttt{ne}: Consider \verb!\RandomZ[ne={0,-1}]{\a}{-5}{5}\a!, copy and paste repeatedly: \RandomZ[ne={0,-1}]{\a}{-5}{5}\a, \RandomZ[ne={0,-1}]{\a}{-5}{5}\a, \RandomZ[ne={0,-1}]{\a}{-5}{5}\a, \RandomZ[ne={0,-1}]{\a}{-5}{5}\a, and \RandomZ[ne={0,-1}]{\a}{-5}{5}\a. If \pkg{rangen} worked as it should, the list of five number should not contain a 0 or a -1, does it? \item Illustrate $\cs{a}\le\cs{b}$: We use the code \begin{Verbatim} \RandomZ{\a}{-5}{5}\RandomZ{\b}{\a}{10}$\a \le \b$ \end{Verbatim} We now copy and paste this code: \RandomZ{\a}{-5}{5}\RandomZ{\b}{\a}{10}$\a \le \b$, \RandomZ{\a}{-5}{5}\RandomZ{\b}{\a}{10}$\a \le \b$. To get strict inequality we execute \begin{Verbatim} \RandomZ{\a}{-5}{5}\RandomZ{\b}{\a*}{10}$\a < \b$ \end{Verbatim} We now copy and paste this code: \RandomZ{\a}{-5}{5}\RandomZ{\b}{\a*}{10}$\a < \b$, \RandomZ{\a}{-5}{5}\RandomZ{\b}{\a*}{10}$\a < \b$ %\item\texttt{formatOne}: We execute the code %\begin{Verbatim} %\RandomZ[formatOne]{\a}{1}{3}$\fmt\a x$ %\end{Verbatim} % to get \RandomZ[formatOne]{\a}{1}{3}$\fmt\a x$, \RandomZ[formatOne]{\a}{1}{3}$\fmt\a x$, % \RandomZ[formatOne]{\a}{1}{3}$\fmt\a x$, \RandomZ[formatOne]{\a}{1}{3}$\fmt\a x$. % Notice the use of the command \cs{fmt}. When \cs{fmt} is present, the special formatting % is used; there are times when you want the formatting, and other times when you don't it. For example, % suppose we want \cs{a} to be a constant term, we want $ 1 + x $ not $\phantom{1}+x$, to get this % we use create \cs{a} as before \verb!\RandomZ[formatOne]{\a}{1}{3}$\a+\fmt\a x$!, but do not use % the \cs{fmt} on the first term. This gets us \RandomZ[formatOne]{\a}{1}{3}$\a+\fmt\a x$, % \RandomZ[formatOne]{\a}{1}{3}$\a+\fmt\a x$, \RandomZ[formatOne]{\a}{1}{3}$\a+\fmt\a x$. % %\item\texttt{formatPMOne}: We execute the code %\begin{Verbatim} %\RandomZ[ne=0,formatPMOne]{\a}{-2}{2}$\fmt\a x$ %\end{Verbatim} %to obtain \RandomZ[ne=0,formatPMOne]{\a}{-2}{2}$\fmt\a x$, \RandomZ[ne=0,formatPMOne]{\a}{-2}{2}$\fmt\a x$, %\RandomZ[ne=0,formatPMOne]{\a}{-2}{2}$\fmt\a x$, \RandomZ[ne=0,formatPMOne]{\a}{-2}{2}$\fmt\a x$. Let us hope %we get a -1 in one of those generations. \end{enumerate} \paragraph*{Data Type Properties.}\label{dtProperties}When a random number is created, there are several auxiliary commands that are defined. \takeMeasure{\string\nOf\darg{\cs{\meta{name}}}\quad\string\dOf\darg{\cs{\meta{name}}}} \begin{dCmd*}[commandchars=!()]{\bxSize} \nOf{!cs(!meta(name))}!quad\dOf{!cs(!meta(name))} \fmt{!cs(!meta(name))}!quad\ds{!cs(!meta(name))} \end{dCmd*} \CmdDescription \begin{description}\def\1{\hspace{-\labelsep}} \item\1 \cs{nOf\darg{\cs{\meta{name}}}} is the numerator for the number \cs{\meta{name}}. For an integer this is just \cs{\meta{name}}. This function becomes important for rational numbers. If \cs{a} is the rational number 2/3, then \verb!\nOf{\a}=2!. \item\1 \cs{dOf\darg{\cs{\meta{name}}}} is the denominator for the number \cs{\meta{name}}. For an integer this is just \texttt{1}. This function becomes important for rational numbers. If \cs{a} is the rational number 2/3, then \verb!\dOf{\a}=3!. \item\1 \cs{fmt\darg{\cs{\meta{name}}}} allows for special formatting for in-line numbers. Without one of the special formatting options, \cs{fmt}\cs{a} is the same as \cs{a}. \item\1 \cs{ds\darg{\cs{\meta{name}}}} allows for special formatting for display style number. \cs{ds} is relevant for rational numbers. If \cs{a} represents the rational 1/2, the \cs{a} expanded is 1/2, while \cs{ds}\cs{a} expanded is $\frac{1}{2}$. The \cs{ds} command also obeys the formatting options. \end{description} \subsection{\texorpdfstring{\protect\cs{RandomQ}}{\CMD{RandomQ}}} The command \Com{RandomQ} defines a random rational, the syntax is \takeMeasure{\small\string\RandomQ[\meta{key-values}]\darg{\cs{\meta{name}}}% [\meta{max\_denom}]\darg{\meta{qLEP}}\darg{\meta{qUEP}}} \begin{dCmd*}[commandchars=!(),fontsize=\small]{\bxSize} \RandomQ[!meta(key-values)]{!cs(!meta(name))}[!meta(max_denom)]{!meta(qLEP)}{!meta(qUEP)} \end{dCmd*} \PD \begin{description}\def\1{\hspace{-\labelsep}} \item [\meta{key-values}] The key-value pairs that modify the choice of the variable. The key-value pairs recognize are \begin{description} \item [\texttt{ne=\meta{value}}] Restrict the choice of the random rational by requiring it \emph{not be equal} to another number, for example, \texttt{ne=0} or \texttt{ne=\cs{b}}. In the latter case, \cs{b} is a number defined already by either an earlier \cs{RandomQ} call, or by \Com{defineQ}, discussed later. Multiple restrictions can be placed as well, for example, if \verb!ne={0,-1}!, \pkg{rangen} selects an integer different from 0 or -1. % \item \texttt{formatOne}: A Boolean formatting key for formatting the number 1; % for example, instead of typesetting \texttt{1x} the correct syntax is to typeset \texttt{x}. % To obtain this special formatting, you must use % \cs{fmt} or \cs{ds}, for example \verb!\fmt\a!. Details are described below. % \item \texttt{formatPMOne}: A Boolean formatting key for formatting the numbers 1 and -1; % in addition to formatting of the number 1, if the random integer is -1 we want to % typeset \texttt{-x} not \texttt{-1x}. To obtain this special formatting, you must use % \cs{fmt} or \cs{ds}, for example \verb!\fmt\a!. Details are described below. \end{description} \item\1\cs{\meta{name}} is the name of the random rational. For example, \cs{a}, \cs{b}, etc. \item\1\meta{max\_denom} is the largest denominator you want your random rational to have. For example, \verb!\RandomQ{\a}[9]{1/2}{7/2}!: The value of \cs{a} is a rational number between 1/2 and 7/2 having a maximum denominator of 9. If this parameter is not specified, the least common denominator is used; for the example, that would be 2. To contrast the two, consider the following examples: \begin{enumerate} \item \verb!\RandomQ{\a}[9]{1/2}{7/2}\a!: \RandomQ{\a}[9]{1/2}{7/2}\a, \RandomQ{\a}[9]{1/2}{7/2}\a, \RandomQ{\a}[9]{1/2}{7/2}\a, and \RandomQ{\a}[9]{1/2}{7/2}\a. \item \verb!\RandomQ{\a}{1/2}{7/2}\a!: \RandomQ{\a}{1/2}{7/2}\a, \RandomQ{\a}{1/2}{7/2}\a, \RandomQ{\a}{1/2}{7/2}\a, \RandomQ{\a}{1/2}{7/2}\a. \end{enumerate} The fractions are reduced to lowest terms, and represented as an integer if needed. Here is more detail on the algorithm used to generate a rational: We illustrate using the example, \verb!\RandomQ{\a}[9]{1/2}{7/2}!, the details are simplified slightly. \begin{enumerate} \item Convert the range so that the endpoints have a denominator of~9. \begin{alignat*}{2} &\texttt{LEP}: \frac{1}{2}= \frac{9/2}{9}=\frac{4.5}{9}< \frac{5}{9}&&\quad\text{round up} \\[1em] &\texttt{UEP}: \frac{7}{2}= \frac{63/2}{9}=\frac{31.5}{9}>\frac{31}{9}&&\quad\text{round down} \end{alignat*} \item We randomly choose an integer between 5 and 31, call it \cs{z}; our random rational is then \texttt{\cs{z}/9}, unless there is an \texttt{*} affixed to one of both endpoints. \item If one or both endpoints is itself a random rational (or integer) and the \texttt{*} character is used, then the lower end of the range is incremented (from 5 to 6) and/or the upper end is decremented (from 31 to 30). \item Reduce the fraction obtained in the previous step. \end{enumerate} You can see from this example, there are a lot of choices for the random integer, there are 27 possibilities between 5 and 32. \item\1 \meta{qLEP} is a rational (of the form a/b) that is the lower endpoint of the interval from which the number is randomly selected. The lower endpoint may be a rational (or integer) previously calculated by an earlier \cs{RandomQ} call, for example, \verb!\RandomQ{\b}{\a}{4/3}!, this will generate an integer \cs{b} such that $\cs{a}\le\cs{b}\le4/3$. To get strict inequality, use the syntax \verb!\RandomZ{\b}{\a*}{4/3}!, then \pkg{rangen} attempts to satisfy $\cs{a}<\cs{b}\le4/3$. The range of \cs{a} should be such that the upper limit for \cs{a} is less than the upper limit of \cs{b}. When the endpoint is a number, the \texttt{*} is ignored.\smallskip When the lower endpoint is a command created by any of the commands \cs{Random\meta{\upshape{Z|Q|R|L}}} or \cs{define\meta{\upshape{Z|Q|R}}}, the endpoint is converted to a real number. \item\1\meta{qUEP} is a rational that is the upper endpoint of the interval from which the number is randomly selected. The upper endpoint may be a rational (or integer) previously calculated by an earlier \cs{RandomQ} call, for example, \verb!\RandomQ{\b}{-4/3}{\a}!, this will generate an integer \cs{b} such that $-4/3\le\cs{b}\le\cs{a}$. To get strict inequality, use the syntax $-4/3\le\cs{b}\le\cs{a}*$, then \pkg{rangen} attempts to satisfy $-4/3\le\cs{b}<\cs{a}$. The range of \cs{a} should be such that the lower limit for \cs{a} is greater than the lower limit of \cs{b}. When the endpoint is a number, the \texttt{*} is ignored.\smallskip When the upper endpoint is a command created by any of the commands \cs{Random\meta{\upshape{Z|Q|R|L}}} or \cs{define\meta{\upshape{Z|Q|R}}}, the endpoint is converted to a real number. \end{description} \paragraph*{Examples} \begin{enumerate} \item \verb!\RandomZ{\a}{-5}{5}!: \RandomZ{\a}{-5}{5}\cs{a}=\a. To get another random integer, we repeatedly execute \verb!\RandomZ{\a}{-5}{5}! followed by \cs{a}, for example, we copy and paste \verb!\RandomZ{\a}{-5}{5}\a! three times to get \RandomZ{\a}{-5}{5}\a, \RandomZ{\a}{-5}{5}\a, \RandomZ{\a}{-5}{5}\a. \item Illustrate \texttt{ne}: Copy and paste \begin{Verbatim} \RandomZ[ne={0,-1}]{\a}{-5}{5}\a \end{Verbatim} repeatedly to obtain: \RandomZ[ne={0,-1}]{\a}{-5}{5}\a, \RandomZ[ne={0,-1}]{\a}{-5}{5}\a, \RandomZ[ne={0,-1}]{\a}{-5}{5}\a, \RandomZ[ne={0,-1}]{\a}{-5}{5}\a, and \RandomZ[ne={0,-1}]{\a}{-5}{5}\a. If \pkg{rangen} worked as it should, the list of five number should not contain a 0 or a -1, does it? \item Illustrate $\cs{a}\le\cs{b}$: We use the code \begin{Verbatim} \RandomZ{\a}{-5}{5}\RandomZ{\b}{\a}{10}$\a \le \b$ \end{Verbatim} We now copy and paste this code: \RandomZ{\a}{-5}{5}\RandomZ{\b}{\a}{10}$\a \le \b$, \RandomZ{\a}{-5}{5}\RandomZ{\b}{\a}{10}$\a \le \b$. To get strict inequality we execute \begin{Verbatim} \RandomZ{\a}{-5}{5}\RandomZ{\b}{\a*}{10}$\a < \b$ \end{Verbatim} We now copy and paste this code: \RandomZ{\a}{-5}{5}\RandomZ{\b}{\a*}{10}$\a < \b$, \RandomZ{\a}{-5}{5}\RandomZ{\b}{\a*}{10}$\a < \b$ %\item\texttt{formatOne}: We execute the code %\begin{Verbatim} %\RandomZ[formatOne]{\a}{1}{3}$\fmt\a x$ %\end{Verbatim} % to get \RandomZ[formatOne]{\a}{1}{3}$\fmt\a x$, \RandomZ[formatOne]{\a}{1}{3}$\fmt\a x$, % \RandomZ[formatOne]{\a}{1}{3}$\fmt\a x$, \RandomZ[formatOne]{\a}{1}{3}$\fmt\a x$. % Notice the use of the command \cs{fmt}. When \cs{fmt} is present, the special formatting % is used; there are times when you want the formatting, and other times when you don't it. For example, % suppose we want \cs{a} to be a constant term, we want $ 1 + x $ not $\phantom{1}+x$, to get this % we use create \cs{a} as before \verb!\RandomZ[formatOne]{\a}{1}{3}$\a+\fmt\a x$!, but do not use % the \cs{fmt} on the first term. This gets us \RandomZ[formatOne]{\a}{1}{3}$\a+\fmt\a x$, % \RandomZ[formatOne]{\a}{1}{3}$\a+\fmt\a x$, \RandomZ[formatOne]{\a}{1}{3}$\a+\fmt\a x$. % %\item\texttt{formatPMOne}: We execute the code %\begin{Verbatim} %\RandomZ[ne=0,formatPMOne]{\a}{-2}{2}$\fmt\a x$ %\end{Verbatim} %to obtain \RandomZ[ne=0,formatPMOne]{\a}{-2}{2}$\fmt\a x$, \RandomZ[ne=0,formatPMOne]{\a}{-2}{2}$\fmt\a x$, %\RandomZ[ne=0,formatPMOne]{\a}{-2}{2}$\fmt\a x$, \RandomZ[ne=0,formatPMOne]{\a}{-2}{2}$\fmt\a x$. Let us hope %we get a -1 in one of those generations. \item \verb!\RandomQ{\a}{-5/2}{5/2}!: \RandomQ{\a}{-5/2}{5/2}\cs{a}=\a. We repeatedly copy and paste \verb!\RandomQ{\a}{-5/2}{5/2}\a! three times to get \RandomQ{\a}{-5/2}{5/2}\a, \RandomQ{\a}{-5/2}{5/2}\a, \RandomQ{\a}{-5/2}{5/2}\a. \item Illustrate \texttt{ne}: \verb!\RandomQ[ne={0,-1}]{\a}{-5/2}{5/2}\a!, copy and paste this code repeatedly: \RandomQ[ne={0,-1}]{\a}{-5/2}{5/2}\a, \RandomQ[ne={0,-1}]{\a}{-5/2}{5/2}\a, \RandomQ[ne={0,-1}]{\a}{-5/2}{5/2}\a, \RandomQ[ne={0,-1}]{\a}{-5/2}{5/2}\a, and \RandomQ[ne={0,-1}]{\a}{-5/2}{5/2}\a. If \pkg{rangen} worked as it should, the list of five number should not contain a 0 or a -1, does it? \item Illustrate $\cs{a}\le\cs{b}$: We use the code \begin{Verbatim}[fontsize=\small] \RandomQ{\a}{-5/2}{5/2}\RandomQ{\b}[4]{\a}{10}$\a \le \b$ \end{Verbatim} and copy and paste: \RandomQ{\a}{-5/2}{5/2}\RandomQ{\b}[4]{\a}{10}$\a \le \b$, \RandomQ{\a}{-5/2}{5/2}\RandomQ{\b}[4]{\a}{10}$\a \le \b$. To get strict inequality we execute \begin{Verbatim}[fontsize=\small] \RandomQ{\a}{-5/2}{5/2}\RandomQ{\b}[4]{\a*}{10}$\a < \b$ \end{Verbatim} to get \RandomQ{\a}{-5/2}{5/2}\RandomQ{\b}[4]{\a*}{10}$\a < \b$, \RandomQ{\a}{-5/2}{5/2}\RandomQ{\b}[4]{\a*}{10}$\a < \b$ %\item\texttt{formatOne}: We execute the code %\begin{Verbatim} %\RandomQ[formatOne]{\a}{2/3}{4/3}$\ds\a x$ %\end{Verbatim} % to get \RandomQ[formatOne]{\a}{2/3}{4/3}$\ds\a x$, \RandomQ[formatOne]{\a}{2/3}{4/3}$\ds\a x$, % \RandomQ[formatOne]{\a}{2/3}{4/3}$\ds\a x$, \RandomQ[formatOne]{\a}{2/3}{4/3}$\ds\a x$. % Notice the use of the command \cs{ds}. When \cs{ds} is present, the special formatting % is used; there are times when you want the formatting, and other times when you don't it. For example, % suppose we want \cs{a} to be a constant term, we want $ 1 + x $ not $\phantom{1}+x$, to get this % we use create \cs{a} as before\\[3pt] % \verb!\RandomQ[formatOne]{\a}{2/3}{4/3}$\a+\ds\a x$!,\\[3pt] % but do not use % the \cs{ds} on the first term. This gets us \RandomQ[formatOne]{\a}{2/3}{4/3}$\a+\ds\a x$, % \RandomQ[formatOne]{\a}{2/3}{4/3}$\a+\ds\a x$, \RandomQ[formatOne]{\a}{2/3}{4/3}$\a+\ds\a x$. % %\item\texttt{formatPMOne}: We execute the code %\begin{Verbatim} %\RandomQ[formatPMOne]{\a}{-6/5}{-4/5}$\ds\a x$ %\end{Verbatim} %to obtain \RandomQ[formatPMOne]{\a}{-6/5}{-4/5}$\ds\a x$, \RandomQ[formatPMOne]{\a}{-6/5}{-4/5}$\ds\a x$, %\RandomQ[formatPMOne]{\a}{-6/5}{-4/5}$\ds\a x$, \RandomQ[formatPMOne]{\a}{-6/5}{-4/5}$\ds\a x$. Let us hope %we get a -1 in one of those generations. \end{enumerate} For a rational number, the commands \cs{nOf}, \cs{dOf}, \cs{fmt}, and \cs{ds} are also defined, see \Nameref{dtProperties}. \subsection{\texorpdfstring{\protect\cs{RandomR}}{\CMD{RandomR}}} The command \Com{RandomR} defines a random real number, the syntax is \takeMeasure{\string\RandomR[\meta{key-values}]\darg{\cs{\meta{name}}}% \darg{\meta{rLEP}}\darg{\meta{rUEP}}} \begin{dCmd*}[commandchars=!()]{\bxSize} \RandomR[!meta(key-values)]{!cs(!meta(name))}{!meta(rLEP)}{!meta(rUEP)} \end{dCmd*} \PD \begin{description}\def\1{\hspace{-\labelsep}} \item [\meta{key-values}] The key-value pairs that modify the choice of the variable. The key-value pairs recognize are \begin{description} \item [\texttt{round=\meta{value}}] Round the generated real number so that number of decimal places equals the \meta{value}, the value of the \texttt{round} key; for example, \texttt{round=2} rounds the result to 2 decimal places. \item [\texttt{showzeros=\meta{\upshape{true|false}}}] Show trailing zeros, only valid when the \texttt{round} key is used. For example, \texttt{round=4,showzeros} might yield a result of 3.2300, whereas without the \texttt{showzeros} key (or with \texttt{showzeros=false}), the same result would be 3.23. \item [\texttt{ne=\meta{value}}] Restrict the choice of the random real by requiring it \emph{not be equal} to another number real, for example, \texttt{ne=-1} or \texttt{ne=\cs{b}}. In the latter case, \cs{b} is a number defined already by either an earlier \cs{RandomR} call, or by \Com{defineR}, discussed later. Multiple restrictions can be placed as well, for example, if \verb!ne={0,-1}!, \pkg{rangen} selects an integer different from 0 or -1.\smallskip Note, comparisons are made \emph{after} rounding. \end{description} \item\1\cs{\meta{name}} is the name of the random rational. For example, \cs{a}, \cs{b}, etc. \item\1 \meta{rLEP} is a real number (or integer) that is the lower endpoint of the interval from which the number is randomly selected. The lower endpoint may be a number previously calculated by an earlier \cs{RandomR} call, for example, \verb!\RandomR{\b}{\a}{1.3}!, this will generate an integer \cs{b} such that $\cs{a}\le\cs{b}\le1.3$. To get strict inequality, use the syntax \verb!\RandomZ{\b}{\a*}{1.3}!, then \pkg{rangen} attempts to satisfy $\cs{a}<\cs{b}\le4/3$. The range of \cs{a} should be such that the upper limit for \cs{a} is less than the upper limit of \cs{b}. When the endpoint is a number, the \texttt{*} is ignored.\smallskip When the lower endpoint is a command created by ant if the command \cs{Random\meta{\upshape{Z|Q|R|L}}}, or by \cs{define\meta{\upshape{Z|Q|R}}}, the endpoint is converted to a real number. \item\1 \meta{rUEP} is a real number that is the upper endpoint of the interval from which the number is randomly selected. The upper endpoint may be a number previously calculated by an earlier \cs{RandomR} call, for example, \verb!\RandomR{\b}{-1.3}{\a}!, this will generate an integer \cs{b} such that $-1.3\le\cs{b}\le\cs{a}$. To get strict inequality, use the syntax $-1.3\le\cs{b}\le\cs{a}*$, then \pkg{rangen} attempts to satisfy $-1.3\le\cs{b}<\cs{a}$. The range of \cs{a} should be such that the lower limit for \cs{a} is greater than the lower limit of \cs{b}. When the endpoint is a number, the \texttt{*} is ignored.\smallskip When the upper endpoint is a command created by ant if the command \cs{Random\meta{\upshape{Z|Q|R|L}}}, or by \cs{define\meta{\upshape{Z|Q|R}}}, the endpoint is converted to a real number. \end{description} The \cs{RandomR} command divides range ($\meta{rUEP}-\meta{rLEP}$) into equal sub-intervals, and randomly chooses node (an endpoint of one of the sub-intervals). The number of subdivisions is determined by \cs{RNGpowerOfTen}, and can be set by \cs{nDivisionsPowerOfTen}. This latter command takes an integer argument, $n$, $1\le n\le 4$, the number of subdivisions is then $10^n$. Strictly speaking \cs{RNGpowerOfTen} does not have to be a power of 10, you can make the definition \verb!\def\RNGpowerOfTen{16}!, and that should work as well. The default is \verb!\nDivisionsPowerOfTen{2}!, that is, divide the range into 100 equal subdivisions. \paragraph*{Examples:} \begin{enumerate} \item \verb!\RandomR{\a}{-2.3}{2.3}!: \RandomR{\a}{-2.3}{2.3}\cs{a}=\a. To obtain more random real numbers, repeatedly execute \verb!\RandomR{\a}{-2.3}{2.3}! followed by \cs{a}; for example, \verb!\RandomR{\a}{-2.3}{2.3}\a! repeated three times yields the following: \begin{equation*} \RandomR{\a}{-2.3}{2.3}\a,\ \RandomR{\a}{-2.3}{2.3}\a,\ \RandomR{\a}{-2.3}{2.3}\a \end{equation*} \item \texttt{round}: We use \verb!\RandomR[round=4]{\a}{-2}{2}\a! to get \begin{equation*} \RandomR[round=4]{\a}{-2}{2}\a,\ \RandomR[round=4]{\a}{-2}{2}\a,\ \RandomR[round=4]{\a}{-2}{2}\a \end{equation*} \item \texttt{showzeros}: \verb!\RandomR[round=4,showzeros]{\a}{-2}{2}\a!: \begin{equation*} \RandomR[round=4,showzeros]{\a}{-2}{2}\a,\ \RandomR[round=4,showzeros]{\a}{-2}{2}\a,\ \RandomR[round=4,showzeros]{\a}{-2}{2}\a,\ \RandomR[round=4,showzeros]{\a}{-2}{2}\a,\ \RandomR[round=4,showzeros]{\a}{-2}{2}\a \end{equation*} \item Illustrate $\cs{a}\le\cs{b}$: We use the code \begin{Verbatim} \RandomR{\a}{-5}{5}\RandomR{\b}{\a}{10}$\a \le \b$ \end{Verbatim} We now copy and paste this code twice: \begin{equation*} \RandomR{\a}{-5}{5}\RandomR{\b}{\a}{10}\a \le \b,\ \RandomR{\a}{-5}{5}\RandomR{\b}{\a}{10}\a \le \b \end{equation*} To get strict inequality we execute \begin{Verbatim} \RandomR{\a}{-5}{5}\RandomR{\b}{\a*}{10}$\a < \b$ \end{Verbatim} We now copy and paste this code a couple of times: \begin{equation*} \RandomR{\a}{-5}{5}\RandomR{\b}{\a*}{10} \a < \b,\ \RandomR{\a}{-5}{5}\RandomR{\b}{\a*}{10} \a < \b \end{equation*} For real numbers, there is little chance the two values are equal, but just in case, strict inequality may be specified in this way. \end{enumerate} \subsection{\texorpdfstring{\protect\cs{RandomL}}{\CMD{RandomL}}} The command \Com{RandomL} defines a list of numbers (integer, rational, decimal), and randomly selects a number from the list. \takeMeasure{\string\RandomR[\meta{key-values}]\darg{\cs{\meta{name}}}% \darg{\meta{n\SUB{1},n\SUB{2},n\SUB{3},...}}}% \begin{dCmd*}[commandchars=!()]{\bxSize} \RandomL[!meta(key-values)]{!cs(!meta(name))}{!meta(n!SUB(1),n!SUB(2),n!SUB(3),...)} \end{dCmd*} \PD \begin{description}\def\1{\hspace{-\labelsep}} \item [\texttt{\meta{key-values}}] The only key-value pairs recognized is \texttt{index=\meta{posZ}}. The index is a base-1 index, thus \texttt{index=1} references the first number in the list. The \texttt{index} key can be used to retrieve a particular number from this list; for example, declaring \verb!\RandomL[index=2]{\a}{17,1/2,1.3}!, the value of \cs{a} is 1/2. The value of \texttt{index} can be any positive integer, even one generated using \cs{RandomI}. If the value of \texttt{index} is greater than the number of items in the list, modular arithmetic is performed to put the index back into the proper range. When the \texttt{index} key is not present, a number is randomly selected from the list. \item\1\cs{\meta{name}} is the name of the number generated. The number generated will be defined as integer, rational, or real; consequently \cs{nOf}, \cs{dOf}, \cs{fmt}, and \cs{ds} are defined. \item \meta{n\SUB{1},n\SUB{2},n\SUB{3},...} A (possibly mixed) list of numbers. The numbers can be literal (12, 1.2, 3/4), or control sequences of numbers (commands) defined earlier by \cs{Random\meta{\upshape{Z|Q|R|L}}} or by \cs{define\meta{\upshape{Z|Q|R}}}. \end{description} \paragraph*{Examples} \begin{enumerate} \item After declaring \verb!\RandomL{\a}{17,3.14,88,3/4,1/2}!, the value of \cs{a} is \RandomL{\a}{17,3.14,88,3/4,1/2}\texttt{\cs{a} = \a}, Select a number from this list at random \RandomL{\a}{17,3.14,88,3/4,1/2}\texttt{\string\a=\a}, again \RandomL{\a}{17,3.14,88,3/4,1/2}\texttt{\string\a=\a}, and again \RandomL{\a}{17,3.14,88,3/4,1/2}\texttt{\string\a=\a}. \item \verb!\RandomL[index=3]{\a}{17,3.14,88,3/4,1/2}\a!, \RandomL[index=3]{\a}{17,3.14,88,3/4,1/2}\texttt{\string\a=\a}. \end{enumerate} \subsection{\texorpdfstring{\protect\cs{RandomI}}{\CMD{RandomI}}} The command \Com{RandomI} defines a list of integers, \verb!{1,2,3...n}! and randomly selects an integer, thought of as an index value, from the list. \takeMeasure{\string\RandomI\darg{\cs{\meta{name}}}\darg{\meta{n}}}% \begin{dCmd*}[commandchars=!()]{\bxSize} \RandomI{!cs(!meta(name))}{!meta(n)} \end{dCmd*} \PD \begin{description}\def\1{\hspace{-\labelsep}} \item\1\cs{\meta{name}} is the name of the number generated, the number will be defined as an integer number. \item\1 \meta{n} is a positive number greater than 1. The list \verb!{1,2,3...n}! is implicitly created. \end{description} \paragraph*{Example:} \verb!\RandomI{\indx}{20}\indx! yields \RandomI{\indx}{20}\indx, \RandomI{\indx}{20}\indx, \RandomI{\indx}{20}\indx, \RandomI{\indx}{20}\indx, when copied and pasted four times. \newtopic\noindent My thought in creating \cs{RandomI} is to use it in conjunction with \cs{RandomL} (using the \texttt{index} key). For example, \begin{Verbatim} \RandomI{\indx}{4} \RandomL[index=\indx]{\a}{1/2,1/3,1/4,1/5} \RandomL[index=\indx]{\b}{5/3,6/5,7/2,5/6} \begin{equation*} (\a)+(\b) = \end{equation*} \end{Verbatim} \RandomI{\indx}{4} \RandomL[index=\indx]{\a}{1/2,1/3,1/4,1/5} \RandomL[index=\indx]{\b}{5/3,6/5,7/2,5/6} \noindent This code results in the following arithmetic problem: \begin{equation*} (\a)+(\b) = \end{equation*} This is probably not a good example of the usage of \cs{RandomI}. See the next section on \cs{RandomP}. \subsection{\texorpdfstring{\protect\cs{RandomP}}{\CMD{RandomP}}} The command \Com{RandomP} defines a list of strings (literal expressions), and randomly selects one from the list. (The ``P'' in \cs{RandomP} stands for ``Problem.'') \takeMeasure{\string\RandomP[\meta{key-values}]\darg{\cs{\meta{name}}}\darg{\meta{list of literals}}}% \begin{dCmd*}[commandchars=!()]{\bxSize} \RandomP[!meta(key-values)]{!cs(!meta(name))}{!meta(list of literals)} \end{dCmd*} \PD \begin{description}\def\1{\hspace{-\labelsep}} \item [\texttt{\meta{key-values}}] The only key-value pairs recognized is \texttt{index=\meta{posZ}}. The index is a base-1 index, thus index=1 references the first number in the list. The \texttt{index} key can be used to retrieve a particular literal from this list; for example, by executing \verb!\RandomP[index=2]{\a}{d,p,s}!, the value of \cs{a} is \texttt{p}. The value of \texttt{index} can be any positive integer, even one generated using \cs{RandomI}, or by another list. If the value of \texttt{index} is greater than the number of items in the list, modular arithmetic is performed to put the index back into the proper range. When the \texttt{index} key is not present, a number is randomly selected from the list. \item\1\cs{\meta{name}} is the name of the literal generated. \item\1\meta{list of literals} is a comma-delimited list of literal strings, selected literal is not interpreted as a number, but is passed into the definition of \cs{\meta{name}}. \end{description} \paragraph*{Examples} \begin{enumerate} \item Executing \verb!\RandomP{\a}{1+16,\cos(\pi),%!\\ \verb! \frac{d}{dx}\frac{1}{2}x^2,{\int \cos(x)\,dx}}!\\ \verb!$\texttt{\string\a} = \a$!, we get \RandomP[index=5]{\a}{1+16,\cos(\pi),\frac{d}{dx}\frac{1}{2}x^2}% $\texttt{\string\a} = \a $, and then again, \RandomP{\a}{1+16,\cos(\pi),\frac{d}{dx}\frac{1}{2}x^2}% $ \texttt{\string\a} = \a $. \item Use \cs{RandomI} with \cs{RandomP}. You can create a series of questions and answers using these two: \begin{Verbatim}[fontsize=\small] \RandomI{\indx}{5} \RandomP[index=\indx]{\q}{1+16,\cos(\pi),\pi\sin(\pi),% \frac{d}{dx}\frac{1}{2}x^2,{\int \cos(x)\,dx}} \RandomP[index=\indx]{\a}{17,-1,0,x,\sin(x)+C} \begin{equation*} \q = \a \end{equation*} \end{Verbatim} \RandomI{\indx}{5} %\typeout{index=\iOf{\indx}}% \RandomP[index=\indx]{\q}{1+16,\cos(\pi),\pi\sin(\pi),\frac{d}{dx}\frac{1}{2}x^2,{\int \cos(x)\,dx}} \RandomP[index=\indx]{\a}{17,-1,0,x,\sin(x)+C} The execution of these lines becomes \begin{equation*} \q = \a \end{equation*} You can create a switch to include the answer or not. \item There is an alternate approach to this previous example. Random lists (\cs{RandomL} and \cs{RandomP}) define a macro \cs{iOf}, the value of which is the index of the item selected (at random). We can use \cs{iOf} in the above problem as follows: \begin{Verbatim}[fontsize=\small] \RandomP{\q}{1+16,\cos(\pi),\pi\sin(\pi),% \displaystyle\frac{d}{dx}\frac{1}{2}x^2,% {\int \cos(x)\,dx}} \RandomP[index=\iOf{\q}]{\a}{17,-1,0,x,\sin(x)+C} \begin{equation*} \q = \a \end{equation*} \end{Verbatim} The execution of these lines gives the output\dots \RandomP{\q}{1+16,\cos(\pi),\pi\sin(\pi),% \displaystyle\frac{d}{dx}\frac{1}{2}x^2,{\int \cos(x)\,dx}} \RandomP[index=\iOf{\q}]{\a}{17,-1,0,x,\sin(x)+C} \begin{equation*} \q = \a \end{equation*} Here, we select the answer to the randomly chosen question. \end{enumerate} \subsection{\texorpdfstring{\protect\cs{RandomS}}{\CMD{RandomS}}} The command \cs{RandomS} generates a random sign, either \texttt{+} or \texttt{-}. This may be useful for creating addition/subtraction problems. \takeMeasure{\string\RandomS[\meta{dec}]\darg{\cs{\meta{name}}}}% \begin{dCmd*}[commandchars=!()]{\bxSize} \RandomS[!meta(dec)]{!cs(!meta(name))} \end{dCmd*} \PD \begin{description}\def\1{\hspace{-\labelsep}} \item\1\meta{dec} is a number between 0 and 1. This command generates a \texttt{+} sign with probability \meta{dec}. The default value is 0.5. \item\1\cs{\meta{name}} is the name that references the generated random sign. \end{description} \paragraph*{Examples} \begin{enumerate} \item Random addition problem: \begin{Verbatim} \RandomZ{\a}{1}{20}\RandomZ{\b}{1}{20}\RandomS{\s} \begin{equation*} \a \s \b \end{equation*} \end{Verbatim} \RandomZ{\a}{1}{20}\RandomZ{\b}{1}{20}\RandomS{\s} This code expands to \begin{equation*} \a \s \b \end{equation*} Whether we add or subtract the summands is determined by the command \cs{s}. \item Random Differentiation problem: \begin{Verbatim} \RandomQ{\a}[8]{1}{2}\RandomQ{\b}[8]{2}{3} \RandomZ{\n}{1}{6}\RandomS{\si}\RandomS{\sii} Differentiate \begin{equation*} \frac{d}{dx}(\bigl (\a) \si (\b) x^{\sii\n}\bigr) \end{equation*} \end{Verbatim} \RandomQ{\a}[8]{1}{2}\RandomQ{\b}[8]{2}{3} \RandomZ{\n}{1}{6}\RandomS{\si}\RandomS{\sii} Differentiate \begin{equation*} \frac{d}{dx}\bigl( (\a) \si (\b) x^{\sii\n}\bigr) \end{equation*} \end{enumerate} \subsection{Commands that Operate on Numbers} Associated with each data type (integer, rational, and real) are several useful commands \cs{nOf}, \cs{dOf}, \cs{iOf}, \cs{fmt}, and \cs{ds}. \subsubsection{\texorpdfstring{\protect\cs{nOf} and \protect\cs{dOf}}{\CMD{nOf} and \CMD{dOf}}} For integer, rational, and real numbers \cs{nOf} and \cs{dOf} are the numerator and denominator, respectively. \begin{itemize} \item Integer: \cs{nOf} is the integer, and \cs{dOf} is 1; for example, define an integer by \verb!\RandomZ{\a}{-5}{5}!,\RandomZ{\a}{-5}{5} \cs{a}=\a, \verb!\nOf{\a}!=\nOf{\a}, \verb!\dOf{\a}!=\dOf{\a}, as advertised. \item Rational: \cs{nOf} is the numerator (an integer), and \cs{dOf} is the denominator (an integer) of the reduced fraction. For example, define \cs{a} by \verb!\RandomQ[ne=0]{\a}[9]{-3/2}{3/2}!,\RandomQ[ne=0]{\a}[9]{-3/2}{3/2} then \begin{equation*} \cs{a}=\a,\ \verb!\nOf{\a}!=\nOf{\a},\ \text{and}\ \verb!\dOf{\a}!=\dOf{\a}. \end{equation*} \item Real: \cs{nOf} is the numerator (an integer), and \cs{dOf} is the denominator (an integer) of the reduced fraction, after the real is converted into a rational number. For example, \verb!\RandomR{\a}{.25}{.75}!,\RandomR{\a}{.25}{.75} then \begin{equation*} \cs{a}=\a,\ \verb!\nOf{\a}!=\nOf{\a},\ \text{and}\ \verb!\dOf{\a}!=\dOf{\a} \end{equation*} If we round using with \verb!\RandomR[round=2]{\a}{.25}{.75}!, we get \begin{equation*} \RandomR[round=2]{\a}{.25}{.75}\cs{a}=\a,\ \verb!\nOf{\a}!=\nOf{\a},\ \text{and}\ \verb!\dOf{\a}!=\dOf{\a} \end{equation*} % \cs{a}=\a, \verb!\nOf{\a}!=\nOf{\a}, and \verb!\dOf{\a}!=\dOf{\a} \end{itemize} \subsubsection{Special Formatting Commands: The \texorpdfstring{\protect\cs{ds}}{\CMD{ds}} and \texorpdfstring{\protect\cs{fmt}}{\CMD{fmt}} families} When a RV, such as \cs{a}, is a rational number type, say \cs{a}=1/3, the command \cs{a} expands to 1/3. To get a display style formatting of the rational use the \Com{ds} command. The expansion of \texttt{\$\cs{ds}\cs{a}\$} is $\frac13$. We have seen in several examples in which the formatting was not always what we'd like. Expressions like $x^{1}$ should be $x$, $1x$ should be $x$, $-1x$ should be $-x$. The formatting commands \cs{cfmt} and \cs{efmt} (and their display style counterparts \cs{cds} and \cs{eds}) attempt to format the special cases of 1 and -1, as they appear in an exponent (the `e' variations) and as they appear as a coefficient (the `c' variations). All the formatting commands \cs{cfmt}, \cs{efmt}, \cs{ds}, \cs{cds}, and \cs{eds} take a RV as its argument. \cs{\meta{\upshape{c|e}}fmt}|\cs{\meta{\upshape{c|e}}ds}\cs{a} expands to \cs{a} when \cs{a} is not 1 or -1. These cases are covered below. \begin{itemize} \item For \cs{a}=1, \cs{cfmt}\cs{a}=\cs{efmt}\cs{a}=\cs{cds}\cs{a}=\cs{eds}\cs{a}=\darg{}, the empty string. Thus, \defineZ{\a}{1}if \cs{a}=\a, and we typeset \verb!$\a x^{\a}$!, we get $\a x^{\a}$, which is not the standard way of writing this expression, but if we typeset \verb!$\cfmt\a x^{\efmt\a}$! we get $\cfmt\a x^{\efmt\a}$, which is correct. Notice that we used \cs{cfmt} on the baseline, and \cs{efmt} in the exponent. It does not make any difference here, but it does if \cs{a}=-1, see the next bullet point. \item \cs{a}=-1, then \begin{align*} &\cs{cfmt}\cs{a}=\cs{cds}\cs{a}=\texttt{-}\quad\text{(minus sign)}\\ &\cs{efmt}\cs{a}=\cs{eds}\cs{a}=\texttt{-1}\quad\text{(minus one)} \end{align*} Returning to the same expression in the previous bullet, if \defineZ{\a}{-1}\cs{a}=\a, and we typeset \verb!$\a x^{\a}$!, we get $\a x^{\a}$, which is not the standard way of writing this expression, but, on the other hand, if we typeset \verb!$\cfmt\ax^{\efmt\a}$! we get $\cfmt\a x^{\efmt\a}$, which is correct. Notice the difference cases if I had typeset \verb!$\cfmt\a x^{\cfmt\a}$!, I would have gotten $\cfmt\a x^{\cfmt\a}$, not good. The `c'-variation is used for unitary signs, not binary signs. For example, \defineZ{\a}{-1}, if \cs{a}=\a, and we typeset \verb!$2 + \cfmt\a x$!, we get $2 + \cfmt\a x$, which may be fine is some situations, but most of the time it is not. As a work around, make coefficients positive, and generate a random sign using \cs{RandomS}; for example, after declaring \begin{Verbatim} \RandomS{\s}\RandomZ{\a}{1}{3} \end{Verbatim} and typeseting \verb!$2 \s \cfmt\a x$!, we get an addition half the time and subtraction the other half: \RandomS{\s}\RandomZ{\a}{1}{3}$2 \s \cfmt\a x$, \RandomS{\s}\RandomZ{\a}{1}{3}$2 \s \cfmt\a x$, \RandomS{\s}\RandomZ{\a}{1}{3}$2 \s \cfmt\a x$, \RandomS{\s}\RandomZ{\a}{1}{3}$2 \s \cfmt\a x$, \RandomS{\s}\RandomZ{\a}{1}{3}$2 \s \cfmt\a x$, \RandomS{\s}\RandomZ{\a}{1}{3}$2 \s \cfmt\a x$. Similarly, the `e'-variation is for unitary sign in the exponent, and should be used when there is a need for these special format rules. \item Random Sign: The formatting commands are defined for a random sign created by \cs{RandomS} and following the same definitions outline above. These are of marginal value in this context. % \item[] \verb!\RandomL{\a}{-1,1}\RandomS{\s}$\a \s x^{\efmt\s x}$! yields the % expression \RandomL{\a}{-1,1}\RandomS{\s}$\a \s e^{\efmt\a x}$ \end{itemize} \subsubsection{Getting the Data type with \texorpdfstring{\protect\cs{typeOf}}{\CMD{typeOf}}} There may be occasions where you want to know the data type of a RV. The \pkg{rangen} does change the data type in special cases. For example, if \cs{a} is created by \verb~\cs{RandomQ}{\a}[2]{1}{3}~, and its value happens to be an integer, \pkg{rangen} changes its type of integer. You can determine the type of a RV with the \cs{typeOf} command, which takes a RV as its argument, the value of \cs{typeOf} is a nonnegative integer. The following table gives the values of \cs{typeOf}, and associated data types. \begin{flushleft} \hspace{\amtIndent}\begin{tabular}{lc} Data type & \cs{typeOf}\\\hline Integer & 0 \\ Rational & 1 \\ Real & 2 \\ Literal & 3 \end{tabular} \end{flushleft} \paragraph*{A suggested application to \cs{typeOf}.} Suppose, \cs{a} is a rational RV (for example, \verb!\RandomQ{\a}[2]{1}{3}!), and we want to typeset the expression \verb!$\cfmt\a x$!. One instance might be \defineQ{\a}{3}{2}$\cfmt\a x$, this is not good syntax; so we typeset \verb!$(\cfmt\a) x$! to get $(\cfmt\a) x$, that's good. But if \cs{a} is an integer, such as 1, 2, or 3, we get \defineQ{\a}{2}{1}$(\cfmt\a) x$, which contains redundant parentheses. Now we come to the use of \cs{typeof}. We now typeset the expression \begin{Verbatim} $ \ifnum\typeOf\a=0\relax\cfmt\a\else(\cfmt\a)\fi x $ \end{Verbatim} If \cs{a} is \emph{not an integer} we get, \defineQ{\a}{3}{2}for \cs{a}=\a, we obtain $\ifnum\typeOf\a=0\relax\cfmt\a\else(\cfmt\a)\fi x$, but for \defineQ{\a}{2}{1}for \cs{a}=\a, we get $\ifnum\typeOf\a=0\relax\cfmt\a\else(\cfmt\a)\fi x$. \subsection{\texorpdfstring{\protect\cs{defineZ}}{\CMD{defineZ}}, \texorpdfstring{\protect\cs{defineQ}}{\CMD{defineQ}}, and \texorpdfstring{\protect\cs{defineR}}{\CMD{defineR}}} The \pkg{rangen} package internally uses \cs{defineZ}, \cs{defineQ}, and \cs{defineR} to define an integer, a rational number, and a real (decimal) number. These command may be used by the document author as well to create non-random variables. \takeMeasure{\string\defineQ\darg{\cs{\meta{name}}}\darg{\meta{zNumer}}\darg{\meta{zDenom}}}% \begin{dCmd*}[commandchars=!()]{\bxSize} \defineZ{!cs(!meta(name))}{!meta(zValue)} \defineQ{!cs(!meta(name))}{!meta(zNumer)}{!meta(zDenom)} \defineR{!cs(!meta(name))}{!meta(rValue)} \end{dCmd*} Thus, \verb!\defineZ{\a}{17}!\defineZ{\a}{17} defines \cs{a}=\a, \verb!\defineQ{\a}{-3}{2}! \defineQ{\a}{-3}{2} defines \cs{a}=\a, and \verb!\defineR{\a}{17.88}!\defineR{\a}{17.88} defines \cs{a}=\a. The various properties data types are created by \cs{defineZ}, \cs{defineQ}, and \cs{defineR}; these are \cs{nOf}, \cs{dOf}, \cs{typeOf}, \cs{ds}, \cs{eds}, \cs{cds}, \cs{efmt}, and \cs{cfmt}. \newtopic\noindent The following are other important points to remember. \begin{itemize} \item \textbf{Positive Denominators.} Notice that if \verb!\defineQ{\a}{3}{-2}!,\defineQ{\a}{3}{-2} then \cs{a}=\a, and \cs{nOf}\cs{a}=\nOf\a, and \cs{dOf}\cs{a}=\dOf\a. Thus, \pkg{rangen} does not allow a negative denominator. \item \textbf{Automatic Reduction.} If we declare \verb!\defineQ{\a}{6}{4}!,\defineQ{\a}{6}{4} then \cs{a}=\a, a rational number is automatically reduced to lowest terms. \item \textbf{Re-classification.} If we make the definition \verb!\defineQ{\a}{6}{2}!,\defineQ{\a}{6}{2} then \cs{a}={\a} is reduced to lowest terms and re-classified as an integer \cs{typeOf}\cs{a}=\typeOf\a~(an integer). \end{itemize} \section{\textsf{rangen} and \textsf{fp}} After a little bit of testing, it appears that \textsf{fp} can work with the \texttt{rangen} package. The \texttt{rangen} package does not provide any command for combining RVs using such operations as addition, subtraction, multiplication, division, etc. The \texttt{rangen} package package does provide several useful commands that \textsf{fp} does not, these are \cs{reduceFrac}, \cs{gcd}, and \cs{lcm}. \Com{reduceFrac} takes two arguments (numerator and denominator), both integers, and attempts to reduce the implied fraction to lowest terms, and returns the result in two macros \cs{rfNumer} and \cs{rfDenom}. For example, to reduce the fraction $4/12$, we execute \verb!\reduceFrac{4}{12}!, which returns\reduceFrac{4}{12} \cs{rfNumer}=\rfNumer, and \cs{rfDenom}=\rfDenom, forming the reduced fraction $\rfNumer/\rfDenom$; thus, $4/12 = \rfNumer/\rfDenom$. The \emph{greatest common divisor} command \cs{gcd} takes two integers as its arguments and returns its result in the macro \cs{thegcd}. For example, the \verb!\gcd{4,8}! is \gcd{4}{8}\thegcd, while the \verb!\gcd{4}{6}! is \gcd{4}{6}\thegcd. The \emph{least common multiple} command \cs{lcd} takes two integers as its arguments, and returns its result in the macro \cs{thelcd}. For example, \verb!\lcm{4}{5}! is \lcm{4}{5}\cs{thelcm}=\thelcm, while, \verb!\lcm{4}{6}! is \lcm{4}{6}\cs{thelcm}=\thelcm. The following example illustrates the use of the \texttt{rangen} and \texttt{fp} packages to pose a random arithmetic problem, and present a detailed solution. \begin{Verbatim}[fontsize=\footnotesize] \RandomQ{\a}[6]{2}{4}\RandomQ{\b}[6]{2}{4} \gcd{\dOf\a}{\dOf\b} \FPeval\lcd{clip((\dOf\a)*(\dOf\b)/\thegcd)} \FPeval\si{clip(\lcd/(\dOf\a))} \FPeval\sii{clip(\lcd/(\dOf\b))} \FPeval\finalnum{clip((\si)*(\nOf\a)+(\sii)*(\nOf\b))} \defineQ{\ans}{\finalnum}{\lcd} $$ \ds\a \thisop \ds\b = \frac{(\si)(\nOf\a)+(\sii)(\nOf\b)}{\lcd} = \frac{\finalnum}{\lcd}\ifnum\lcd=\dOf\ans\else =\ds\ans\fi $$ \end{Verbatim} An instance of this code might look like this: $$ \frac{8}{3}+\frac{17}{6}=\frac{(2)(8)+(1)(17)}{6}=\frac{33}{6}=\frac{11}{2} $$ If there is any reduction of the fraction (brought on by the \cs{defineQ} command), this additional expression is included. \paragraph*{Demo file.} See the demo file \texttt{rangen\_fp.tex} for a complete example. \section{\textsf{rangen} and \textsf{exerquiz}} Developing a package for randomly generating numbers that could be used as a basis for creating random quizzes (see the example back in \hyperref[s:intro]{Section~\ref*{s:intro}}, page~\pageref*{s:intro}) was my original motivation for writing the original package back in the year 2000 AD. In this section, we introduce the techniques that I've developed for creating random quizzes, and, more importantly, how to grade them and to exhibit to the user the correct answer. This system is not a computer algebra system, so, it is difficult, but not impossible to also supply a solution (a opposed to just the answer) to the problem as well. \paragraph*{Demo file.} Now, let's see how its done! Examples of this section were taken from the demo file \texttt{rangen\_tst.tex}. \subsection{Creating Quizzes using \textsf{rangen}} The \pkg{rangen} package provides three JavaScript functions that are used with \textsf{exerquiz} quizzes, these are \begin{itemize} \item \texttt{rEval(str)}: The function \texttt{rEval} evaluates its argument. The \texttt{rEval} function searches its argument for \texttt{rEval} and \texttt{rFrac}, and executes any inner nested functions first. \item \texttt{rFrac(str)}: Evaluates a rational number by evaluating the value of the numerator and denominator separately. The function \texttt{rFrac} searches its argument for \texttt{rEval} and \texttt{rFrac}, and executes any inner nested functions first. \item \texttt{rngCorrAnsButton}: A function that is used to represent the correct answer to the user. \end{itemize} The best way of illustrating these function is by discussing an example or two. \renewcommand\titleQuizfmt{\bfseries\color{red}} \titleQuiz*{Example~1. } \begin{shortquiz}*[sq1] We create two RVs, \cs{a} and \cs{b} that are rational numbers. We want to add them, and present the answer as a rational number. \begin{Verbatim}[fontsize=\small] \RandomQ{\a}[16]{1/8}{15/16}\RandomQ[ne=\a]{\b}[16]{1/8}{15/16} \end{Verbatim} \begin{questions} \RandomQ{\a}[16]{1/8}{15/16}\RandomQ[ne=\a]{\b}[16]{1/8}{15/16} \item $\displaystyle\ds\a - \ds\b = \RespBoxMath[\rectW{.5in}]{ (\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\sqClearButton \end{questions} \end{shortquiz} \vskip-.5\baselineskip The question is posed using \cs{RespBoxMath}. \begin{Verbatim}[xleftmargin=20pt,numbers=left,fontsize=\small] $\displaystyle\ds\a - \ds\b = \RespBoxMath[\rectW{.5in}]{ (\nOf\a*\dOf\b-\nOf\b*\dOf\a)/(\dOf\a*\dOf\b)} {2}{.0001}{[0,2]} [{priorParse: \Array(nodec,NoAddOrSub)}]$ \end{Verbatim} \textsf{Exerquiz} determines whether the user's answer is correct, it by evaluating the author's answer at randomly selected points. Exerquiz uses the floating point arithmetic of JavaScript to evaluate the user's answer. The author's correct answer is given in line (1), and it is just the formula for combining two fractions \cs{a} and \cs{b}; note the use of \cs{nOf} and \cs{dOf}. Line~(2) is standard parameters for \cs{RespBoxMath}, the number of random points to use, the precision, and the interval from which to select the points. Line~(3) specifies a couple of routines from the \textsf{dljslib} package, these prevent the user from using decimals and rational arithmetic to answer the question. (The latter function would, for example, prevent the user from copying the question and pasting it into the answer.) Now comes the most interesting part, at least to me: The presentation of the correct answer to the user. These is where the JavaScript functions \texttt{rEval} and \texttt{rFrac} are used. The code for the answer button is shown below. \begin{Verbatim}[xleftmargin=20pt,numbers=left,fontsize=\small] \CorrAnsButton{rFrac( rEval(\nOf\a*\dOf\b-\nOf\b*\dOf\a)/rEval(\dOf\a*\dOf\b) )}*{rngCorrAnsButton} \end{Verbatim} Here, this code is broken across several lines to fit on the page. We direct the \cs{CorrAnsButton} to use the function \texttt{rngCorrAnsButton}, as seen in line~(3). This is a special function define by \pkg{rangen} to help in the presentation of the answer to the user. Keep in mind, the inner-most \texttt{rEval} and \texttt{rFrac} functions are evaluated first; consequently, the two \texttt{rEval} functions in line~(2) are evaluated first. These two evaluations calculate the numerator and denominator separately, this results in a numerical numerator and denominator. The function \texttt{rFrac} is then executed on the resulting rational number, this function reduces the fraction to lowers terms. This final calculation is what the user sees when the correct answer button is pressed. The next example will illustrate a decimal presentation of the answer, and introduces a new command, \Com{RNGprintf}. \titleQuiz*{Example~2. } \begin{shortquiz}*[sq2] We create four RVs, \cs{a}, \cs{b}, \cs{c}, and \cs{n}, three rational and one integer. The exponent of the power is rational, hence, we represent a decimal answer to the user. \begin{Verbatim}[fontsize=\small] \RandomQ{\a}[8]{1/4}{7/6}\RandomZ{\b}{1}{3} \RandomQ{\n}[8]{1/2}{3/2}\RandomZ[ne=\zZero]{\c}{-3}{3} \end{Verbatim} \begin{questions}\setcounter{eqquestionnoi}{1} \RandomQ{\a}[8]{1/4}{7/6} \RandomZ{\b}{1}{3} \RandomQ{\n}[8]{1/2}{3/2} \RandomZ[ne=\zZero]{\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\RNGprintf{\%.4f}}\kern1bp\sqClearButton \end{questions} \end{shortquiz} \vskip-.5\baselineskip The question is posed using \cs{RespBoxMath}. \begin{Verbatim}[xleftmargin=20pt,numbers=left,fontsize=\small] $\displaystyle\int_{\a}^{\b} \cfmt\c x^{\efmt\n}\,dx = \RespBoxMath{\c((\b)^(\n+1)-(\a)^(\n+1))/(\n+1)} {3}{.0001}{[0,2]}$ \end{Verbatim} The correct answer is given on line~(2), and is based on the known form of the integrand; here, we use standard integration formulas. The code for the correct answer button has a new element in it \begin{Verbatim}[xleftmargin=20pt,numbers=left,fontsize=\small] \CorrAnsButton{rEval( \c((\b)^(\n+1)-(\a)^(\n+1))/(\n+1) )}*{rngCorrAnsButton\RNGprintf{\%.4f}}}\kern1bp\sqTallyBox \end{Verbatim} The \texttt{rEval} function evaluates the expression on line~(2), the result is a decimal number. As before, we use the \texttt{rngCorrAnsButton}, but we've added the \Com{RNGprintf} command to the end of the function name. This is a kludge that I've developed to be able to format a numerical answer. The \cs{RNGprintf} command uses the Acrobat JavaScript function \texttt{util.printf}. The argument of \cs{RNGprintf} is passed to \texttt{util.printf} as its formatting string. Here, we use \verb!\%.4f!, so the number is presented as a floating point number with four decimal places. See the documentation of \texttt{util.printf} in the \textsl{JavaScript for Acrobat API Reference.}\footnote {\url{{http://livedocs.adobe.com/acrobat_sdk/9/Acrobat9_HTMLHelp}}} The final example it the one seen in \Nameref{s:intro}, it uses another new command, \Com{defineDepQJS}. This command is used to define a new RV as a rational function of other RVs, and to define special JavaScript formatting, \cs{js}. The results of this command are used exclusively for JavaScript, and are not meant to be typeset. \takeMeasure{\string\defineDepQJS\darg{\cs{\meta{name}}}% \darg{\meta{numer}}\darg{\meta{denom}}\darg{\meta{script}}}% \begin{dCmd*}[commandchars=!()]{\bxSize} \defineDepQJS{!cs(!meta(name))}{!meta(numer)}{!meta(denom)}{!meta(script)} \end{dCmd*} \noindent This function defines \cs{\meta{name}} to be \texttt{(\meta{numer})/(\meta{denom})}. The expression \meta{numer} and \meta{denom} can be functions of RV defined earlier. The $4^{\text{th}}$ argument is JavaScript for evaluating \cs{\meta{name}}; \meta{script} is accessed by \cs{js\cs{\meta{name}}} and is used from within a \cs{CorrAnsButton}. The $4^{\text{th}}$ argument can include such commands as \cs{\meta{name}}, \cs{nOf}\cs{\meta{name}}, and \cs{dOf}\cs{\meta{name}}. An example will perhaps illustrate. \titleQuiz*{Example~3. } \begin{shortquiz}*[sq3] Find the equation of the line that passes through $P$ and $Q$. We begin by defining our variables: \begin{Verbatim}[xleftmargin=20pt,numbers=left,fontsize=\small] \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)))} \end{Verbatim} Our big problem is to compute the slope of the line, \cs{m}. I define \cs{m} as using \cs{defineDepQJS}. The numerator and denominator are those in the slope calculation, given two points. The expansion of \cs{m} is \verb!(\d-\b)/(\c-\a)!, and the JavaScript will perform the arithmetic operations. The expression that is accessed with the \cs{js} is the fourth argument, line~(4); here, we calculate slope as a rational number. We make a similar definition for the \cs{yIntercept} of the line. Below are the two points \verb!$P(\a, \b)$! and \verb!$Q(\c, \d)$!. \begin{questions}\setcounter{eqquestionnoi}{2} \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 $P(\,\a, \b\,)$, $Q(\,\c, \d\,)$: \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\sqClearButton \end{questions} \end{shortquiz} \vskip-.5\baselineskip The question is posed using \cs{RespBoxMath}. \begin{Verbatim}[xleftmargin=20pt,numbers=left,fontsize=\small] $P(\,\a, \b\,)$, $Q(\,\c, \d\,)$: \RespBoxMath{y=\m*x + \yIntercept}(xy) {3}{.0001}{[0,2]x[0,2]}*{ProcRespEq} \end{Verbatim} The answer is given in line~(2), and will be evaluated numerically, and compared numerically with the user's response. The code for the correct answer button has a new element in it \begin{Verbatim}[xleftmargin=20pt,numbers=left,fontsize=\small] \CorrAnsButton{y = \js\m\space x + \js\yIntercept} *{rngCorrAnsButton} \end{Verbatim} The display of the answer is done using \cs{js}\cs{m} and \cs{js}\cs{yIntercept} to represent the slope and intercept as a rational number. Think of \cs{defineDepQJS} a convenient way of defining (JavaScript) expressions that will appear in \cs{RespBoxMath} and for \cs{CorrAnsButton}. \subsection{Creating Solutions to Random Quizzes} Writing a solution to a question that is based on a formula or template can be difficult. {\LaTeX} is not a computer algebra system, so the possibilities are limited. Still, \pkg{rangen} supplies the \texttt{writeRVsTo} environment to support a solution. \titleQuiz*{Example~4. } \begin{shortquiz}*[sq1] We create two RVs, \cs{a} and \cs{b} that are rational numbers. We want to add them, and present the answer as a rational number. \begin{Verbatim}[fontsize=\small] \begin{writeRVsTo}{quizzes} \RandomQ{\a}[16]{1/8}{15/16}\RandomQ[ne=\a]{\b}[16]{1/8}{15/16} \end{writeRVsTo} \end{Verbatim} We make that same definitions as in \textbf{\textcolor{red}{Example~1}}, but we enclose these definitions within the \texttt{writeRVsTo}. This environment writes its contents to the quiz solutions file, and also executes its contents. This way, the definitions are make both here, and just before the solution to this problem in the solutions file. \begin{questions}\setcounter{eqquestionnoi}{3} \begin{writeRVsTo}{quizzes} \RandomQ{\a}[16]{1/8}{15/16}\RandomQ[ne=\a]{\b}[16]{1/8}{15/16} \end{writeRVsTo} \item $\displaystyle\ds\a + \ds\b = \RespBoxMath[\rectW{.5in}]{ (\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\sqClearButton \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*} Did I forget to tell you that a simple command \cs{RNGadd} for adding two rational numbers is defined by \pkg{rangen}. Sorry about that! \dps \end{solution} \end{questions} \end{shortquiz} \vskip-.5\baselineskip The verbatim listing of this quiz is \begin{Verbatim}[fontsize=\footnotesize] \item $\displaystyle\ds\a + \ds\b = \RespBoxMath[\rectW{.5in}]{ (\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\sqClearButton \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*} Did I forget to tell you that a simple command \cs{RNGadd} for adding two rational numbers is defined by \pkg{rangen}. Sorry about that! \dps \end{solution} \end{Verbatim} \newtopic\noindent The \texttt{writeRVsTo} has the following syntax \takeMeasure{\string\begin\darg{writeRVsTo}\darg{quizzes|exercises}}% \begin{dCmd*}[commandchars=!()]{\bxSize} \begin{writeRVsTo}{quizzes|exercises} !meta(rangen commands creating RVs) \end{writeRVsTo} \end{dCmd*} The argument can be either the string \texttt{quizzes} or \texttt{exercises}. In the first case, the content of the environment is written to the solutions file for quizzes, and in the latter case, to the solutions file for the exercises. \bigskip That's all for now, I simply must get back to my retirement. \dps \end{document}