Usando un alias / variable como entrada para un nuevo comando
Actualmente estoy tratando de configurar una declaración condicional que toma un número entero asignado al azar y proporciona una salida específica dependiendo de si el número entero es par o impar. He escrito esto hasta ahora
\documentclass[12pt]{article}
\usepackage[first=-20, last=20]{lcg}
\usepackage{tikz}
\usepackage{calculator}
\usepackage{calculus}
\usepackage{ifthen}
\newcommand{\randi}{\rand\arabic{rand}}
\newcommand{\addsub}{\pgfmathrandomitem{\choice}{choices1}\choice}
\pgfmathdeclarerandomlist{choices1}{{+}{-}}
\newcommand{\firstpower}{\chgrand[first=2, last=5] \randi}
\newcommand{\Oddleft}[1]{
\ifodd#1
|
\else
(
\fi
}
\newcommand{\Oddright}[1]{
\ifodd#1
|
\else
)
\fi
}
\begin{document}
\section*{Problem 1}
Provide the output of the function $f(x) = \randi
\Oddleft{\firstpower}
x \addsub \chgrand[first=1, last=20] \randi
\Oddright{\firstpower} ^{\firstpower}$ for values of $x = \chgrand[last=-50, last=50]$
\\
\end{document}
El objetivo de este código, por ahora, es tener mi expresión entre barras de valor absoluto si la potencia es impar y entre paréntesis si la potencia es par. Sin embargo, los comandos \Oddlefty \Oddrightno interpretan mi comando \firstpowercomo un número, por lo que la entrada se trata como cero. ¿Cómo puedo hacer que se declare / alias un número aleatorio para que se pueda usar como entrada para otro comando?
Respuestas
Primero debe guardar el exponente como un valor que se puede alimentar \Oddlefto \Oddright(incluso si se usa \firstpower, calcularía valores diferentes en cada uso).
Aquí hay un enfoque diferente con expl3:
\documentclass[12pt]{article}
\usepackage{xfp}
\ExplSyntaxOn
\NewDocumentCommand{\expression}{}
{
% a random sign, print nothing if positive
\int_if_odd:nT { \int_rand:nn { 1 } { 2 } } { - }
% the absolute value of the coefficient
\int_rand:nn { 1 } { 20 }
% compute a random exponent
\int_set:Nn \l_tmpa_int { \int_rand:nn { 2 } { 5 } }
% if odd exponent, use |, else (
\int_if_odd:nTF \l_tmpa_int { | } { ( }
% the variable
x
% a random sign
\int_if_odd:nTF { \int_rand:nn { 1 } { 2 } } { - } { + }
% the absolute value of the summand
\int_rand:nn { 1 } { 20 }
% if odd exponent use |, else )
\int_if_odd:nTF \l_tmpa_int { | } { ) }
% the exponent
\sp { \int_use:N \l_tmpa_int }
}
% print a row of values
\NewDocumentCommand{\randomvalues}{m}
{
\int_rand:nn { -50 } { 50 }
\prg_replicate:nn { #1 - 1 } { , \int_rand:nn { -50 } { 50 } }
}
\ExplSyntaxOff
\begin{document}
Provide the output of the function $f(x) = \expression$
Provide the output of the function $f(x) = \expression$
Provide the output of the function $f(x) = \expression$
Provide the output of the function $f(x) = \expression$
Provide the output of the function $f(x) = \expression$
Provide the output of the function $f(x) = \expression$
Provide the output of the function $f(x) = \expression$ for the values $x=\randomvalues{4}$
\end{document}
puedes usar
\ExplSyntaxOn
\newcommand{\firstpower}{\int_rand:nn{2}{5}}
\ExplSyntaxOff
ese es un número expandible
Hay varias cuestiones que deben tenerse en cuenta:
Los más destacados son:
Su código está destinado a crear y generar un conjunto de números aleatorios con cada ejecución de LaTeX.
Pero a menudo se necesitan varias ejecuciones de LaTeX hasta que todo (referencias cruzadas, tabla de contenido, etc.) coincida.
Creo que es una buena idea un mecanismo que cree números aleatorios solo si no se pueden recuperar de la ejecución anterior de LaTeX a través del archivo .aux. De lo contrario, podría terminar necesitando un círculo muy largo de compilaciones hasta que todo coincida por accidente:- El cambio de variables aleatorias cambia el texto del documento.
- Cambiar el texto del documento puede cambiar la forma en que el texto se divide en páginas.
- Cambiar la forma en que se divide el texto en páginas puede provocar que las referencias cruzadas y los números de página de la tabla de contenido, etc., no coincidan.
- Las referencias cruzadas y los números de página de la tabla de contenido, etc. que no coinciden, requieren otra ejecución de LaTeX.
- Con esa ejecución LaTeX, las variables aleatorias se cambian.
- El cambio de variables aleatorias cambia el texto del documento.
- ...
En el siguiente ejemplo, se escribe una etiqueta de referencia en el archivo .aux a partir de los números / coeficientes utilizados con un ejercicio. Los números utilizados con un ejercicio se crean aleatoriamente solo si no se pueden recuperar de la etiqueta de referencia del archivo .aux.
Probablemente desee evitar que se cree dos veces el mismo ejercicio / expresión de función. Por lo tanto,
\expressionlistse mantiene una macro que contiene una lista de argumentos no delimitados, cada argumento contiene el conjunto de números / coeficientes utilizados con un ejercicio. La creación de números aleatorios se repite hasta que se obtiene una constelación que no está ya en la lista. (Si no tiene suerte, este nunca será el caso. ;-))Probablemente desee que la lista de valores para los que se proporcionará la salida de la función no contenga el mismo valor dos veces. La selección de un valor aleatorio para esta lista se repite hasta encontrar uno que aún no está en la lista. (Si no tiene suerte, este nunca será el caso. ;-))
Probablemente desee que la lista de valores para los que se proporcionará la salida de la función se clasifique en orden ascendente.
Con expresiones de patrón 𝑎 (𝑥 + 𝑏) (2𝑛) respectivo 𝑎 | 𝑥 + 𝑏 | (2𝑛 + 1) probablemente desee evitar casos / ejercicios donde 𝑎 = 0. Es por eso que en el siguiente ejemplo, el coeficiente 𝑎 no se elige como un número aleatorio en el rango -20..20 sino que se elige en dos pasos: El signo de 𝑎 es de un número aleatorio en el rango 0..1. El valor absoluto de 𝑎 proviene de un número aleatorio en el rango 1..20. De esta forma el caso 𝑎 = 0 no es posible.
Usé dos veces la frase "Si no tienes suerte, este nunca será el caso".
Probablemente, en lugar de elegir números aleatorios uno por uno, es más seguro elegir un (subconjunto de a) permutación aleatoria. Me vienen a la mente algoritmos como Fisher-Yates-Shuffle y el código Lehmer . La duración de la compilación del documento sería más predecible. ;-)
\documentclass[12pt]{article}
\usepackage[first=-20, last=20]{lcg}
\makeatletter
%========================================================================
% \CreateListsOfRandomNumbers{<macro that gets all lists of random numbers as arguments>}{%
% {{amount of random numbers}{lower bound}{upper bound}{List not in braces=0/list in braces=1}}
% {{amount of random numbers}{lower bound}{upper bound}{List not in braces=0/list in braces=1}}
% ...
% {{amount of random numbers}{lower bound}{upper bound}{List not in braces=0/list in braces=1}}
% }%
% yields:
% <macro that gets all lists of random numbers as arguments><list 1 of random numbers><list 2 of random numbers>..<list k of random numbers>
%
% Values in the lists are sorted in ascending order.
% No value occurs twice within the same list.
%
% E.g.,
%
% \CreateListsOfRandomNumbers{\foobar}{%
% {{2}{3}{17}{0}}%
% {{6}{1}{20}{1}}%
% {{4}{20}{40}{0}}
% }%
% may yield:
% \foobar{5}{17}% <-first list: 2 random numbers in range 3..17, list not in braces
% {{4}{7}{9}{12}{15}{19}}% <-second list: 6 random numbers in range 1..20, list in braces
% {20}{27}{34}{39}% <-third list: 4 random numbers in range 20..40, list not in braces
%
\@ifdefinable\CreateListsOfRandomNumbers{%
\DeclareRobustCommand\CreateListsOfRandomNumbers[2]{%
% #1 = macro that gets all lists of random numbers as arguments
% #2 = list of 4-tuples {{amount of random numbers}{lower bound}{upper bound}{List not in braces=0/list in braces=1}}
\CreateListsOfRandomNumbersLoop{#1}{}#2{}%
}%
}%
%========================================================================
\newcommand\CreateListsOfRandomNumbersLoop[3]{%
% #1 = macro that gets all lists of random numbers as arguments
% #2 = list of lists of random numbers created so far
% #3 = 4-tuple {amount of random numbers}{lower bound}{upper bound}{List not in braces=0/list in braces=1}
\ifx X#3X\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{#1#2}{%
\CreateRandomNumbersOfSameRange#3{\AppendToCreateListsOfRandomNumbersLoop{#1}{#2}}%
}%
}%
\newcommand\AppendToCreateListsOfRandomNumbersLoop[3]{\CreateListsOfRandomNumbersLoop{#1}{#2#3}}%
\newcommand\CreateRandomNumbersOfSameRange[5]{%
\ifnum\numexpr((#3)-(#2)+1)-#1\relax<0 \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{%
\GenericError{\space\@spaces\@spaces}%
{Error: Creation of list of random-numbers not possible}%
{\space\@spaces\@spaces You cannot have #1 different random numbers if according\MessageBreak
to the randomoize-ranges there are only (#3)-(#2)+1=\number\numexpr((#3)-(#2)+1)\relax\MessageBreak
different numbers available.}%
{Learn about Jean Leurechon's pigeonhole principle/Dirichlet's drawer principle.}%
\ifnum\expandafter\@firstofone\expandafter{\number#4}>0 %
\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{#5{{{0}}}}{#5{{0}}}%
}{%
\InnerCreateRandomNumbersOfSameRange{#1}{#2}{#3}{#4}{#5}%
}%
}%
\newcommand\InnerCreateRandomNumbersOfSameRange[1]{%
%#1 = amount of random numbers
\expandafter\CreateRandomNumbersOfSameRangeLoop\expandafter{\romannumeral\number\number#1 000}{}%
}%
\newcommand\CreateRandomNumbersOfSameRangeLoop[6]{%
%#1 = characters m in an amount corresponding to amount of numbers
%#2 = list of random numbers created so far
%#3 = lower bound
%#4 = upper bound
%#5 = 0/1 List not/in braces
%#6 = Tokens where to append the list of random-numbers as argument
\ifx X#1X\expandafter\@secondoftwo\else\expandafter\@firstoftwo\fi
{%
\randi[\CheckIfAlreadyInRandomlist#2{}{}\relax{#2}{#1}{#3}{#4}]{#3}{#4}%
}{%
\SortRandomNumbersLoop#2{}{}\relax{}%
}%
{#5}{#6}%
}%
\@ifdefinable\CheckIfAlreadyInRandomlist{%
\long\def\CheckIfAlreadyInRandomlist#1#2\relax#3#4#5#6#7{%
%#1 = first element of list of random numbers created so far
%#2 = remaining elements of list of random numbers created so far
%#3 = list of random numbers created so far
%#4 = characters m in an amount corresponding to amount of numbers
%#5 = lower bound
%#6 = upper bound
%#7 = random number just created
\ifx\relax#1\relax\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{\expandafter\CreateRandomNumbersOfSameRangeLoop\expandafter{\@gobble#4}{#3{#7}}{#5}{#6}}%
{%
\ifnum\expandafter\@firstofone\expandafter{\number#1}=\expandafter\@firstofone\expandafter{\number#7} %
\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{\CreateRandomNumbersOfSameRangeLoop{#4}{#3}{#5}{#6}}%
{%
\CheckIfAlreadyInRandomlist#2\relax{#3}{#4}{#5}{#6}{#7}%
}%
}%
}%
}%
\@ifdefinable\SortRandomNumbersLoop{%
\long\def\SortRandomNumbersLoop#1#2\relax#3{%
%#1 first element of list
%#2 remaining elements of list
%#3 list of sorted elements
\ifx X#1X\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{%
\ReturnSortedList{#3}%
}{%
\InsertRandomNumberLoop{#1}{#2}\relax#3{}{}\relax{}{\@firstoftwo}%
}%
}%
}%
\@ifdefinable\InsertRandomNumberLoop{%
\long\def\InsertRandomNumberLoop#1#2\relax#3#4\relax#5#6{%
%#1 first element of list
%#2 remaining elements of list
%#3 first element of list of sorted elements
%#4 remaining elements of list of sorted elements
%#5 new list of sorted elements
%#6 indicator whether element was already inserted
\ifx X#3X\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{%
#6{\SortRandomNumbersLoop#2\relax{#5{#1}}}%
{\SortRandomNumbersLoop#2\relax{#5}}%
}{%
#6{%
\ifnum\expandafter\@firstofone\expandafter{\number#3}>\expandafter\@firstofone\expandafter{\number#1} %
\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{%
\InsertRandomNumberLoop{#1}{#2}\relax#4\relax{#5{#1}{#3}}{\@secondoftwo}%
}{%
\InsertRandomNumberLoop{#1}{#2}\relax#4\relax{#5{#3}}{#6}%
}%
}{%
\InsertRandomNumberLoop{#1}{#2}\relax#4\relax{#5{#3}}{#6}%
}%
}%
}%
}%
\newcommand\ReturnSortedList[3]{%
%#1 = list of sorted elements
%#2 = 0/1 List not/ in braces
%#3 = Tokens where to append the list of random-numbers as argument
\ifnum\expandafter\@firstofone\expandafter{\number#2}>0 %
\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{#3{{#1}}}{#3{#1}}%
}%
%========================================================================
\newcommand\PassFirstToSecond[2]{#2{#1}}
\newcommand{\randi}[3][\@firstofone]{%
% #1 = token(s) where to append the random-number after nesting it in braces
% #2 = lower bound of randomize
% #3 = upper bound of randomize
\chgrand[first=#2,last=#3]%
\rand
\expandafter\PassFirstToSecond\expandafter{\number\value{rand}}{#1}%
}%
%========================================================================
% \WriteRandomNumbersLoop{<variable>}{<separator>}<List of numbers>{}
\newcommand\WriteRandomNumbersLoop[3]{%
\ifx X#3X\expandafter\@gobble\else\expandafter\@firstofone\fi
{%
#2$#1=#3$%
\WriteRandomNumbersLoop{#1}{; }% I used semicolon instead of comma because comma in many countries is decimal-separator.
}%
}%
%========================================================================
\newcounter{CreatedExpressions}
\newcommand\CreateExpression[2]{%
% #1 - variable
% #2 - amount of random values where to solve the expression for.
% As values are in range -50..50, don't request more than 101 values!
\global\stepcounter{CreatedExpressions}%
\@ifundefined{r@CreatedExpression\number\value{CreatedExpressions}}{%
\@firstoftwo
}{%
\begingroup
\expandafter\expandafter\expandafter
\CheckExpressionlabel\csname r@CreatedExpression\number\value{CreatedExpressions}\endcsname
\def\@tempb{{#1}{#2}}%
\ifx\@tempa\@tempb\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{\endgroup\@secondoftwo}{\endgroup\@firstoftwo}%
}{%
\CreateExpressionRandomNumbers{#1}{#2}%
}{%
\expandafter\expandafter\expandafter
\writeexpression\csname r@CreatedExpression\number\value{CreatedExpressions}\endcsname
}%
}%
\newcommand\CheckExpressionlabel[8]{\def\@tempa{{#7}{#8}}}%
\newcommand\CreateExpressionRandomNumbers[2]{%
\CreateListsOfRandomNumbers{\InnerCreateExpressionRandomNumbers}{%
{{1}{0}{1}{0}}%<- sign of coefficient
{{1}{1}{20}{0}}% <- abs of coefficient
{{1}{2}{5}{0}}%<- exponent
{{1}{1}{20}{0}}%<- abs of summand
{{1}{0}{1}{0}}%<- sign of summand
{{#2}{-50}{50}{1}}%<- List with values where the expression to solve for
}%
{#1}{#2}%
}%
\newcommand\expressionlist{}%
\newcommand\InnerCreateExpressionRandomNumbers[8]{%
% #1 - sign of coefficient
% #2 - abs of coefficient
% #3 - exponent
% #4 - abs of summand
% #5 - sign of summand
% #6 - List with values where the expression to solve for
% #7 - variable, usually x
% #8 - amount of values where to solve the expression for
\begingroup
\def\@tempa{{#1}{#2}{#3}{#4}{#5}}%
\expandafter\CheckExpressionListLoop\expandafter{\expandafter\@firstoftwo\expandafter}\expressionlist{}{%
\endgroup
\CreateExpressionRandomNumbers{#7}{#8}%
}{%
\endgroup
\writeexpression{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}%
}%
}%
\newcommand\writeexpression[8]{%
\immediate\write\@auxout{%
\string\newlabel{CreatedExpression\number\value{CreatedExpressions}}{{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}}%
}%
\g@addto@macro\expressionlist{{{#1}{#2}{#3}{#4}{#5}}}%
$f(#7)=\ifnum#1=0 \else-\fi#2\oddabs{#3}{#7\ifnum#5=0 +\else-\fi#4}^{#3}$%
\ifnum#8>0 \@firstofone{} for the value\ifnum#8>1 s\fi\@firstofone{} \WriteRandomNumbersLoop{#7}{}#6{}\fi.%
}%
\newcommand\oddabs[2]{%
\ifodd\expandafter\@firstofone\expandafter{\number#1} %
\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{|#2|}{(#2)}%
}%
\newcommand\CheckExpressionListLoop[2]{%
\ifx X#2X\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{#1{\@secondoftwo}{\@firstoftwo}}%
{\def\@tempb{#2}%
\ifx\@tempa\@tempb\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{\CheckExpressionListLoop{\@secondoftwo}}{\CheckExpressionListLoop{#1}}%
}%
}%
\makeatother
\begin{document}
\section*{Problem 1}
\noindent Provide the output of the function \CreateExpression{t}{7}\\
\noindent Provide the output of the function \CreateExpression{x}{3}\\
\noindent Provide the output of the function \CreateExpression{y}{1}\\
\noindent Provide the output of the function \CreateExpression{z}{0}\\
\end{document}
Cuando compilé el ejemplo anterior, obtuve un documento que se veía así: debido a la aleatoriedad de los números, la probabilidad de que obtenga algo diferente es alta:
Esta "respuesta" no proporciona una solución al problema.
Como en su pregunta se usa el paquete lcg, mencionemos que el paquete lcg (El paquete lcg, 2013/08/09 (v1.3), CTAN: https://www.ctan.org/pkg/lcg) produce tokens espaciales falsos.
(Ya intenté comunicarme con el autor del paquete sobre esto a través de la dirección de correo electrónico proporcionada en la documentación del paquete. Ni el correo rebotó ni obtuve ninguna reacción. Vivimos en tiempos turbulentos. Sería bueno poner estas cosas en orden. Pero no quiero secuestrar / apoderarse del paquete, porque eso probablemente sería descortés).
Puede reproducir fácilmente este fenómeno:
\documentclass{article}
\usepackage{lcg}
\begin{document}
\noindent X\rand X
\noindent X\chgrand[first=1,last=20,quiet=y]X
\noindent X\rand X
\end{document}
\randy \chgrandsimilares no deberían producir una salida visible.
Por lo tanto, esperaba que la salida visual del ejemplo mínimo anterior fuera algo como esto:
XX
XX
XX
Pero las X están intercaladas con espacios y obtienes algo como esto:
X X
X X
XX
La razón es que tanto el texto de definición de la clave quietcomo el texto de definición de la macro \r@ndproducen fichas de espacio falsas.
A continuación, copié estas definiciones y las marqué con <-!!!!!los lugares donde aparecen los tokens espaciales espurios:
84 \define@key{Init}{quiet}[y]{ <-!!!!!
85 \def\qui@t{\expandafter\firstletterr@nd #1\delimiter} <-!!!!!
86 \if \qui@t y% nothing to do
87 \else\if\qui@t Y \def\qui@t{y} <-!!!!! (2x)
88 \else\if\qui@t j \def\qui@t{y} <-!!!!! (2x)
89 \else\if\qui@t J \def\qui@t{y} <-!!!!! (2x)
90 \else\if\qui@t n \def\qui@t{n} <-!!!!! (2x)
91 \else\if\qui@t N \def\qui@t{n} <-!!!!! (2x)
92 \else
93 \PackageWarning{lcg}{Value of key <quiet> must be <y> or <n>} <-!!!!!
94 \def\qui@t{y} <-!!!!!
95 \fi\fi\fi\fi\fi\fi
96 }
173 \def\r@nd{%
174 \ifnum \cr@nd < \@ne% then ... initialize generator
175 \cr@nd = \the\time
176 \advance \cr@nd \inputlineno
177 \multiply \cr@nd \value{page} <-!!!!!
178 \advance \cr@nd \the\year
179 \multiply \cr@nd \the\month
180 \multiply \cr@nd \the\day
181 \advance \cr@nd \inputlineno
182 \if \qui@t y%
183 \else
184 \typeout{Random number generator initialized to \the\cr@nd}%
185 \fi
186 \r@nd%
187 \else % else ... generate new number
188 \@tempcnta = \cr@nd
189 \divide \@tempcnta 127773 % \@tempcnta = floor(z/q)
190 \@tempcntb = \@tempcnta % \@tempcntb = floor(z/q)
191 \multiply \@tempcnta -2836 % \@tempcnta = -r*floor(z/q)
192 \multiply \@tempcntb -127773 % \@tempcntb = -q*floor(z/q)
193 \advance \cr@nd \@tempcntb % cr@nd = z mod q
194 \multiply \cr@nd 16807 % cr@nd = a * (z mod q)
195 \advance \cr@nd \@tempcnta % cr@nd = a*z mod m
196 \ifnum \cr@nd < \z@%
197 \advance \cr@nd 2147483647 % cr@nd = (a*z mod m) > 0
198 \fi
199 \global\cr@nd=\cr@nd % persist the change outside current scope
200 \fi
201 }% end of \r@nd
Sugiero los siguientes cambios:
\define@key{Init}{quiet}[y]{%
\def\qui@t{\expandafter\firstletterr@nd #1\delimiter}%
\if \qui@t y% nothing to do
\else\if\qui@t Y\def\qui@t{y}%
\else\if\qui@t j\def\qui@t{y}%
\else\if\qui@t J\def\qui@t{y}%
\else\if\qui@t n\def\qui@t{n}%
\else\if\qui@t N\def\qui@t{n}%
\else
\PackageWarning{lcg}{Value of key <quiet> must be <y> or <n>}%
\def\qui@t{y}%
\fi\fi\fi\fi\fi\fi
}
\def\rand{%
\r@nd%
\@tempcnta
\@tempcntb
\@tempcnta = \f@rst
\@tempcntb = \l@st
\multiply \@tempcnta \m@ne
\advance \@tempcntb \@tempcnta
\advance \@tempcntb \@ne %l@st-f@rst+1
\@tempcnta = 2147483647
\divide \@tempcnta \@tempcntb
\multiply \@tempcnta \@tempcntb
\ifnum \cr@nd > \@tempcnta\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{\rand}%
{%
\setcounter{\r@ndcountername}{\cr@nd}%
\@tempcnta = \cr@nd
\divide \@tempcnta \@tempcntb
\multiply \@tempcnta \@tempcntb
\multiply \@tempcnta \m@ne
\addtocounter{\r@ndcountername}{\@tempcnta}%
\addtocounter{\r@ndcountername}{\f@rst}%
}%
}% end of \rand
\def\r@nd{%
\ifnum \cr@nd < \@ne\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{% then ... initialize generator
\cr@nd = \the\time
\advance \cr@nd \inputlineno
\multiply \cr@nd \value{page}%%%%%%%
\advance \cr@nd \the\year
\multiply \cr@nd \the\month
\multiply \cr@nd \the\day
\advance \cr@nd \inputlineno
\if \qui@t y%
\else
\typeout{Random number generator initialized to \the\cr@nd}%
\fi
\r@nd%
}{% else ... generate new number
\@tempcnta = \cr@nd
\divide \@tempcnta 127773 % \@tempcnta = floor(z/q)
\@tempcntb = \@tempcnta % \@tempcntb = floor(z/q)
\multiply \@tempcnta -2836 % \@tempcnta = -r*floor(z/q)
\multiply \@tempcntb -127773 % \@tempcntb = -q*floor(z/q)
\advance \cr@nd \@tempcntb % cr@nd = z mod q
\multiply \cr@nd 16807 % cr@nd = a * (z mod q)
\advance \cr@nd \@tempcnta % cr@nd = a*z mod m
\ifnum \cr@nd < \z@%
\advance \cr@nd 2147483647 % cr@nd = (a*z mod m) > 0
\fi
\global\cr@nd=\cr@nd % persist the change outside current scope
}%
}% end of \r@nd