Utilisation d'un alias / variable comme entrée pour une nouvelle commande
J'essaie actuellement de configurer une instruction conditionnelle qui prend un entier attribué au hasard et fournit une sortie spécifique selon que l'entier est pair ou impair. J'ai écrit ça jusqu'à présent
\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}
Le but de ce code, pour l'instant, est d'avoir mon expression entre des barres de valeur absolue si la puissance est impaire et entre parenthèses si la puissance est paire. Cependant, les commandes \Oddleftet \Oddrightn'interprètent pas ma commande \firstpowercomme un nombre, donc l'entrée est traitée comme étant zéro. Comment puis-je avoir un nombre aléatoire déclaré / aliasé afin qu'il puisse être utilisé comme entrée d'une autre commande?
Réponses
Vous devez d'abord enregistrer l'exposant en tant que valeur qui peut être alimentée \Oddleftou \Oddright(même si vous utilisez \firstpowerworking, cela calculera différentes valeurs à chaque utilisation).
Voici une approche différente avec 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}
vous pouvez utiliser
\ExplSyntaxOn
\newcommand{\firstpower}{\int_rand:nn{2}{5}}
\ExplSyntaxOff
c'est un nombre extensible
Plusieurs problèmes doivent être pris en considération:
Les plus remarquables sont:
Votre code est destiné à créer et générer un ensemble de nombres aléatoires avec chaque exécution LaTeX.
Mais souvent plusieurs exécutions LaTeX sont nécessaires jusqu'à ce que tout (références croisées, table des matières, etc.) corresponde.
Je pense qu'un mécanisme est une bonne idée qui crée des nombres aléatoires uniquement s'ils ne peuvent pas être récupérés à partir de la précédente exécution LaTeX via le fichier .aux. Sinon, vous pourriez avoir besoin d'un très long cercle de compilations jusqu'à ce que tout corresponde par accident:- La modification des variables aléatoires modifie le texte du document.
- La modification du texte du document peut modifier la façon dont le texte est divisé en pages.
- Changer la façon dont le texte est divisé en pages peut entraîner des références croisées et des numéros de page de la table des matières, etc., ne correspondant pas.
- Les références croisées et les numéros de page de la table des matières, etc. qui ne correspondent pas, nécessitent une autre exécution LaTeX.
- Avec cette exécution LaTeX, les variables aléatoires sont modifiées.
- La modification des variables aléatoires modifie le texte du document.
- ...
Dans l'exemple ci-dessous, une étiquette de référencement est écrite dans le fichier .aux à partir des nombres / coefficients utilisés avec un exercice. Les nombres utilisés avec un exercice sont créés de manière aléatoire uniquement s'ils ne peuvent pas être récupérés à partir de l'étiquette de référencement du fichier .aux.
Vous souhaitez probablement empêcher la création du même exercice / expression de fonction deux fois. Par conséquent, une macro
\expressionlistest maintenue qui contient une liste d'arguments non délimités, chaque argument contenant l'ensemble des nombres / coefficients utilisés avec un exercice. La création de nombres aléatoires est répétée jusqu'à ce qu'une constellation soit obtenue qui n'est pas déjà dans la liste. (Si vous n'avez pas de chance, ce ne sera jamais le cas. ;-))Vous souhaitez probablement que la liste des valeurs pour lesquelles la sortie de la fonction doit être fournie ne contienne pas deux fois la même valeur. La sélection d'une valeur aléatoire pour cette liste est répétée jusqu'à ce qu'elle en trouve une qui ne figure pas déjà dans la liste. (Si vous n'avez pas de chance, ce ne sera jamais le cas. ;-))
Vous souhaitez probablement que la liste des valeurs pour lesquelles la sortie de la fonction doit être fournie soit triée par ordre croissant.
Avec une expression de motif 𝑎 (𝑥 + 𝑏) (2𝑛) respective 𝑎 | 𝑥 + 𝑏 | (2𝑛 + 1) vous souhaitez probablement éviter les cas / exercices où 𝑎 = 0. C'est pourquoi, dans l'exemple ci-dessous, le coefficient 𝑎 n'est pas choisi comme un nombre aléatoire dans la plage -20..20 mais est choisi en deux étapes: Le signe de 𝑎 provient d'un nombre aléatoire dans la plage 0..1. La valeur absolue de 𝑎 provient d'un nombre aléatoire compris entre 1 et 20. De cette façon, le cas 𝑎 = 0 n'est pas possible.
J'ai utilisé deux fois la phrase "Si vous n'avez pas de chance, ce ne sera jamais le cas".
Probablement - au lieu de choisir des nombres aléatoires un par un - il est plus sûr de choisir un (sous-ensemble d'une) permutation aléatoire. Des algorithmes comme Fisher-Yates-Shuffle et Lehmer code me viennent à l'esprit. La durée de la compilation du document deviendrait plus prévisible. ;-)
\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}
Lorsque j'ai compilé l'exemple ci-dessus, j'ai obtenu un document qui ressemblait à ceci - en raison du caractère aléatoire des nombres, la probabilité que vous obteniez quelque chose de différent est élevée:
Cette «réponse» n'apporte pas de solution au problème.
Comme dans votre question, le package lcg est utilisé, mentionnons que le package lcg (Le package lcg, 2013/08/09 (v1.3), CTAN: https://www.ctan.org/pkg/lcg) produit de faux jetons d'espace.
(J'ai déjà essayé de contacter l'auteur du package à ce sujet via l'adresse e-mail fournie dans la documentation du package. Le courrier n'a pas non plus rebondi et je n'ai eu aucune réaction. Nous vivons à une époque turbulente. Il serait peut-être bon de mettre ces choses. dans l'ordre. Mais je ne veux pas détourner / reprendre le paquet, car ce serait probablement impoli.)
Vous pouvez facilement reproduire ce phénomène:
\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}
\randet \chgrandainsi de suite ne doivent pas produire de sortie visible.
Ainsi, je m'attendais à ce que la sortie visuelle de l'exemple minimal ci-dessus soit quelque chose comme ceci:
XX
XX
XX
Mais les X sont entrecoupés d'espaces et vous obtenez quelque chose comme ceci:
X X
X X
XX
La raison en est que le texte de définition de la clé quietet le texte de définition de la macro \r@ndproduisent des jetons d'espace parasites.
Dans ce qui suit, j'ai copié ces définitions et marqué avec <-!!!!!les endroits où les faux jetons d'espace apparaissent:
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
Je suggère les changements suivants:
\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