%%
%% This is file `ran_toks.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% ran_toks.dtx  (with options: `copyright,package')
%% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% ran_toks package,                                    %%
%% Copyright (C) 1999-2019  D. P. Story                 %%
%%   dpstory@uakron.edu, dpstory@acrotex.net            %%
%%                                                      %%
%% This program can redistributed and/or modified under %%
%% the terms of the LaTeX Project Public License        %%
%% Distributed from CTAN archives in directory          %%
%% macros/latex/base/lppl.txt; either version 1 of the  %%
%% License, or (at your option) any later version.      %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NeedsTeXFormat{LaTeX2e}[1997/12/01]
\ProvidesPackage{ran_toks}
 [2019/12/28 v1.2 Randomizing tokens (dps)]
\RequirePackage{verbatim}
\@ifundefined{nextrandom}{\input{random.tex}}{}
\def\nextrandom{\begingroup
  \ifnum\randomi<\@ne % then initialize with time
    \global\randomi\time
    \global\multiply\randomi388 \global\advance\randomi\year
    \global\multiply\randomi31 \global\advance\randomi\day
    \global\multiply\randomi97 \global\advance\randomi\month
    \message{Randomizer initialized to \the\randomi.}%
    \nextrandom \nextrandom \nextrandom
    \xdef\InitSeedValue{\the\randomi}%
 \fi
 \count@ii\randomi
 \divide\count@ii 127773 % modulus = multiplier * 127773 + 2836
 \count@\count@ii
 \multiply\count@ii 127773
 \global\advance\randomi-\count@ii % random mod 127773
 \global\multiply\randomi 16807
 \multiply\count@ 2836
 \global\advance\randomi-\count@
 \ifnum\randomi<\z@ \global\advance\randomi 2147483647\relax\fi
 \endgroup
}
\newtoks\rt@listIn \rt@listIn={}
\newtoks\rt@newListIn \rt@newListIn={}
\newtoks\rt@listOut \rt@listOut={}
\newcount\rt@nMax
\newcount\rt@nCnt
\newcount\rt@getRanNum
\newif\ifrtdebug \rtdebugfalse
\newif\ifwerandomize \werandomizetrue
\newif\ifsaveseed\saveseedtrue
\newwrite\rt@Verb@write
\def\rt@nameedef#1{\expandafter\edef\csname #1\endcsname}
\def\ranToksOn{\werandomizetrue}
\def\ranToksOff{\werandomizefalse}
\def\useThisSeed#1{\saveseedfalse\randomi=#1}
\@onlypreamble\useThisSeed
\def\useLastAsSeed{\rt@useLastAsSeed}
\@onlypreamble\useLastAsSeed
\def\rt@useLastAsSeed{%
  \IfFileExists{\jobname_rt.sav}{%
    \PackageInfo{ran_toks}{Inputting \jobname_rt.sav}%
    \@ifundefined{readsavfile}{\newread\readsavfile}{}%
    \openin\readsavfile=\jobname_rt.sav
    \read\readsavfile to \InitSeedValue
    \read\readsavfile to \lastRandomNum
    \closein\readsavfile
    \randomi=\lastRandomNum
        \xdef\InitSeedValue{\the\randomi}
  }{%
    \PackageInfo{ran_toks}{\jobname_rt.sav cannot
      be found, \MessageBreak
      using the random initializer}%
  }%
}
\@ifundefined{aeb@randomizeChoices}{%
    \let\inputRandomSeed\useLastAsSeed
    \let\useRandomSeed\useThisSeed}{}
\def\verbatimwrite{\@bsphack
  \let\do\@makeother\dospecials
  \catcode`\^^M\active \catcode`\^^I=12
  \def\verbatim@processline{%
    \immediate\write\verbatim@out
    {\the\verbatim@line}}%
  \verbatim@start}
\def\endverbatimwrite{\@esphack}
\def\rt@IWVO{\immediate\write\verbatim@out}
\def\InitSeedValue{\the\randomi}
\def\rt@writeSeedData{\ifsaveseed
  \@ifundefined{saveseedinfo}{\newwrite\saveseedinfo}{}
  \immediate\openout \saveseedinfo \jobname_rt.sav
  \let\verbatim@out\saveseedinfo
  \def\rt@msgi{initializing seed value}%
  \def\rt@msgii{last random number used}%
  \uccode`c=`\%\uppercase{%
  \rt@IWVO{\InitSeedValue\space c \rt@msgi}%
  \rt@IWVO{\the\randomi\space c \rt@msgii}}\immediate
  \closeout\saveseedinfo\fi}
\AtEndDocument{\rt@writeSeedData}%
\def\rt@populateList#1{\rt@listIn={}\rt@nCnt\z@
  \@whilenum\rt@nCnt<#1\do{\advance\rt@nCnt\@ne
    \edef\rt@listInHold{\the\rt@listIn\noexpand\\{\the\rt@nCnt}}%
    \rt@listIn=\expandafter{\rt@listInHold}}}
\def\rt@RandomizeList#1{\global
  \rt@listIn={}\global\rt@newListIn={}\global\rt@listOut={}%
  \rt@nMax=#1\relax\rt@populateList{\the\rt@nMax}%
  \ifwerandomize
    \expandafter\rt@randomizeList\else
    \global\rt@listOut=\expandafter{\the\rt@listIn}\fi
  \global\rt@nameedef{\rt@BaseName-List}{\the\rt@listOut}}
\def\rt@randomizeList{\let\\=\rt@processi
  \setrannum{\rt@getRanNum}{1}{\the\rt@nMax}%
\ifrtdebug\typeout{\string\rt@getRanNum=\the\rt@getRanNum}\fi
  \rt@nCnt\z@
\ifrtdebug\typeout{LISTING: \the\rt@listIn}\fi
  \the\rt@listIn
  \rt@loopTest
}
\def\rt@loopTest{\advance\rt@nMax\m@ne
  \ifnum\rt@nMax>\z@
    \def\rt@next{%
      \rt@listIn=\expandafter{\the\rt@newListIn}%
      \rt@newListIn={}\rt@randomizeList}%
  \else
    \let\rt@next\relax
    \global\rt@listOut=\expandafter{\the\rt@listOut}%
    \ifrtdebug
      \typeout{Final Result: \string\rt@listOut=\the\rt@listOut}\fi
  \fi\rt@next
}
\def\rt@processi#1{\advance\rt@nCnt\@ne
  \ifnum\rt@nCnt=\rt@getRanNum
    \edef\rt@listOutHold{\the\rt@listOut}%
    \global\rt@listOut=\expandafter{\rt@listOutHold\\{#1}}%
    \ifrtdebug\typeout{Found it: \string\\{#1}}%
    \typeout{New \string\rt@listOut: \the\rt@listOut}\fi
  \else
    \edef\rt@listInHold{\the\rt@newListIn}%
      \rt@newListIn=\expandafter{\rt@listInHold\\{#1}}%
    \ifrtdebug\typeout{\string\rt@newListIn: \the\rt@newListIn}\fi
  \fi
}
\def\rt@modarith#1#2{\count\z@=#1\relax\count\tw@=#1\relax
  \advance\count\z@\m@ne\divide\count\z@ #2\relax
  \multiply\count\z@ #2\relax
  \advance\count\tw@-\count\z@
  \edef\rt@mod{\the\count\tw@}}
\def\rt@badIndex#1#2{\PackageWarningNoLine{ran_toks}
    {The argument of \string\useRanTok{#1} on line
      \the\inputlineno\space is\MessageBreak
        greater than \string\nToksFor{#2} (\nToksFor{#2}),
        instead will use\MessageBreak
        \string\useRanTok{\rt@mod}, obtained from modular
        arithmetic.\MessageBreak
        You might want to fix this}
}
\def\rt@badTokName#1{%
  \PackageWarningNoLine{ran_toks}
    {The token list `#1' on line \the\inputlineno\space
      is undefined,\MessageBreak
      possibly simply mispelled; check spelling.\MessageBreak
      If undefined, use \string\ranToks\space or \string\bRTVToks/%
      \string\eRTVToks\space\MessageBreak
      to define a list with the name `#1'}%
}
\def\rt@warnTokName#1{%
  \PackageWarningNoLine{ran_toks}
    {The token list `#1' on line \the\inputlineno\space
      is already defined,\MessageBreak
      will overwrite this list}%
}
\def\ranToks#1{\begingroup
  \useRTName{#1}%
  \r@nToks
}
\long\def\r@nToks#1{\rt@nMax\z@\r@ndToks#1\rt@NIL}
\def\rt@NIL{@nil}
\newcommand{\useRTName}[1]{\gdef\rt@BaseName{#1}}%
\let\rt@BaseName\@empty
\newcommand{\bRTVToks}[1]{\rt@nCnt\z@\useRTName{#1}}
\newcommand{\eRTVToks}{\global
  \rt@nameedef{\rt@BaseName Cnt}{\the\rt@nCnt}%
  \expandafter\r@nVToks\expandafter{\rt@BaseName}}
\def\reVerbEnd{\ifhmode\unskip\fi}
\def\rtVWHook#1{\def\@rgi{#1}\ifx\@rgi\@empty
  \let\RTVWHook\relax\else\def\RTVWHook{#1}\fi}
\rtVWHook{}
\newenvironment{rtVW}{\global\advance\rt@nCnt\@ne
  \immediate\openout\rt@Verb@write
    \jobname_\rt@BaseName\the\rt@nCnt.cut
  \let\verbatim@out\rt@Verb@write
  \rt@IWVO{\string\RTVWHook}%
  \verbatimwrite
}{%
  \endverbatimwrite
  \immediate\write\rt@Verb@write{\string\reVerbEnd}%
  \immediate\closeout\rt@Verb@write
}
\def\r@nVToks#1{\begingroup
  \gdef\rt@BaseName{#1}%
  \expandafter\rt@nMax\@nameuse{#1Cnt}%
  \rt@listIn={}\rt@nCnt=0\relax\let\rt@listInHold\@empty
  \@whilenum\rt@nCnt<\rt@nMax\do{\advance\rt@nCnt\@ne
    \edef\rt@listInHold{%
      \the\rt@listIn{\noexpand\rt@inputVerb{#1\the\rt@nCnt}}}%
    \rt@listIn=\expandafter{\rt@listInHold}}\ifrtdebug
  \typeout{\string\r@nVToks: \the\rt@listIn}\fi
  \expandafter\r@nToks\expandafter{\the\rt@listIn}}
\def\rt@inputVerb#1{\input{\jobname_#1.cut}}
\def\rt@PAR{\par}
\long\def\r@ndToks#1{\def\rt@rgi{#1}%
  \ifx\rt@rgi\rt@PAR\def\rt@next{\r@ndToks}\else
    \advance\rt@nMax\@ne
    \global\@namedef{rtTok\the\rt@nMax\rt@BaseName}{#1}%
    \def\rt@next{\@ifnextchar\rt@NIL
      {\rt@endToks\@gobble}{\r@ndToks}}\fi\rt@next}
\def\rt@performRanDefns#1{%
  \rt@RandomizeList{#1}\rt@nCnt\z@
  \let\\\rt@ssign\the\rt@listOut}
\def\rt@endToks{\global
  \rt@nameedef{nMax4\rt@BaseName}{\the\rt@nMax}%
  \rt@performRanDefns{\the\rt@nMax}\endgroup}
\def\reorderRanToks#1{\begingroup\useRTName{#1}\expandafter
  \ifx\csname nMax4#1\endcsname\relax
    \rt@badTokName{#1}\else
    \rt@performRanDefns{\@nameuse{nMax4#1}}\fi
\endgroup}
\newcommand\copyRanToks[2]{\begingroup\expandafter
  \ifx\csname nMax4#1\endcsname\relax
        \rt@badTokName{#1}%
  \else\expandafter
    \ifx\csname nMax4#2\endcsname\relax
      \useRTName{#2}\global
      \rt@nameedef{nMax4#2}{\@nameuse{nMax4#1}}%
      \rt@nCnt=\csname nMax4#2\endcsname\relax
      \@whilenum\rt@nCnt>\z@\do{\global
        \rt@nameedef{rtTok\the\rt@nCnt#2}%
          {\noexpand\@nameuse{rtTok\the\rt@nCnt#1}}%
        \advance\rt@nCnt\m@ne}%
      \rt@performRanDefns{\@nameuse{nMax4#2}}\else
      \rt@warnTokName{#2}\fi
  \fi
\endgroup}
\def\rt@ssign#1{\advance\rt@nCnt\@ne\global
  \rt@nameedef{rtRanTok\the\rt@nCnt\rt@BaseName}{\noexpand
  \@nameuse{rtTok#1\rt@BaseName}}}
\newcommand{\nToksFor}[1]{\expandafter
  \ifx\csname nMax4#1\endcsname\relax
    \textbf{??}\rt@badTokName{#1}\else
    \@nameuse{nMax4#1}\fi}
\newcommand{\rtTokByNum}[2][\rt@BaseName]{\expandafter
  \ifx\csname nMax4#1\endcsname\relax
    \textbf{??}\rt@badTokName{#1}\else
    \@nameuse{rtTok#2#1}\expandafter\ignorespaces\fi}
\newcommand{\useRanTok}[2][\rt@BaseName]{\bgroup
  \expandafter\ifx\csname nMax4#1\endcsname\relax
    \rt@badTokName{#1}\else
    \ifnum#2>\nToksFor{#1}\rt@modarith{#2}{\nToksFor{#1}}%
      \rt@badIndex{#2}{#1}\@nameuse{rtRanTok\rt@mod#1}\else
      \@nameuse{rtRanTok#2#1}\fi\fi\egroup}
\newcommand{\displayListRandomly}[1][]{\bgroup\def\rt@prior{#1}%
  \displ@yListRandomly}
\newcommand{\displ@yListRandomly}[2][]{\rt@nCnt\z@
  \expandafter\ifx\csname nMax4#2\endcsname\relax
    \rt@rgi\space\textbf{??}\rt@badTokName{#2}#1%
  \else
    \def\rt@post{#1}\useRTName{#2}\let\i\rt@nCnt
    \def\first{1}\edef\last{\@nameuse{nMax4#2}}%
    \@tempcnta\last \advance\@tempcnta\m@ne
    \edef\lessone{\the\@tempcnta}%
    \@whilenum\rt@nCnt<\last\advance\rt@nCnt\@ne
    \do{\rt@prior\useRanTok{\the\rt@nCnt}\rt@post}%
  \fi
\egroup}
\def\rt@gettonil#1\@nil{\def\to@nilarg{#1}}
\def\rt@ifspc{\ifx\@let@token\@sptoken
  \let\rt@next\rt@xifspc\else
  \let\rt@next\rt@gettonil\fi\rt@next}
\begingroup
\def\:{\rt@xifspc}
\expandafter\gdef\: {\futurelet\@let@token\rt@ifspc}
\endgroup
\def\rt@strpspcs{\futurelet\@let@token\rt@ifspc}
\def\ProbDBWarningMsg#1{\filename@parse{#1}
  \PackageWarning{ran_toks}
  {The file \filename@area\filename@base.\ifx\filename@ext\relax
      tex\else\filename@ext\fi\space cannot be found}}
\def\useTheseDBs#1{\def\rt@dblist{#1}\ifx\rt@dblist\@empty\else
  \let\rt@DB@List\@empty
  \edef\temp@expand{\noexpand\@for\noexpand\@@tmp:=\rt@dblist}%
  \temp@expand\do{\ifx\@@tmp\@empty\else
    \expandafter\rt@strpspcs\@@tmp\@nil\edef\@@tmp{\to@nilarg}%
    \edef\rt@nextDB{\noexpand
      \InputIfFileExists{\@@tmp}{}{\noexpand
      \ProbDBWarningMsg{\@@tmp}}}%
    \toks\tw@=\expandafter{\rt@DB@List}%
    \toks@=\expandafter{\rt@nextDB}%
    \edef\rt@DB@List{\the\toks\tw@\space\the\toks@}\fi
  }\expandafter\rt@DB@List\fi}
\let\useProbDBs\useTheseDBs
\endinput
%%
%% End of file `ran_toks.sty'.
