%%
%% This is file `aebrandom.def',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% exerquiz.dtx  (with options: `copyright,randomize')
%% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Exerquiz.sty package,             2014-01-16         %%
%% Copyright (C) 1999-2014  D. P. Story                 %%
%%   dpstory@uakron.edu                                 %%
%%                                                      %%
%% 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.      %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ProvidesFile{aebrandom.def}
 [2014/11/05 v7.0 %
 Exerquiz support for randomization (dps)]
\@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
}
\def\@ansChoices[#1]%
{%
    \global\let\@tempholdSaveAns\@empty % 5/24
    \global\let\@tempholdSaveChoice\@empty % 5/24
    \global\let\bChoiceLabel\@empty % 5/24
    \ifeq@randomizeallChoices
        \setkeys{bchoice}{#1,random=true}\else
        \setkeys{bchoice}{#1}\fi
    \global\eq@tabColCnt=0
    \ifeq@randomizeChoices\expandafter\@@bChoices
    \else\expandafter\@@ansChoices\fi
}
\def\@@ansChoices{%
    \ifnum\aeb@numCols=1 % list mode
        \def\eq@next{\@layoutListAns}%
    \else % tabular mode
        \edef\eq@next{\noexpand\@layoutTabularAns{\bChoiceNumCols}}%
    \fi
    \eq@next
}
\newcount\aeb@numChoices
\newcount\aeb@ranChoice
\newtoks\aeb@hold\aeb@hold={}
\def\@@bChoices{\gdef\@temphold{}\gdef\@tempholdrandom{}%
    \gdef\@tempholdfreeze{}\aeb@searchfortoken{\@getAns}%
}
\def\aeb@searchfortoken#1{%
    \@ifnextchar\Ans{\advance\aeb@numChoices1\relax#1}
        {\@ifnextchar\eFreeze{\expandafter\@getFreezeAns\@gobble}
        {\@ifnextchar\par{\def\@@temp{\aeb@searchfortoken{#1}}%
        \expandafter\@@temp\@gobble}{\@eChoices}}}%
}
\long\def\@getAns\Ans#1\eAns{%
    \g@addto@macro\@temphold{{\Ans#1\eAns}}%
    \aeb@searchfortoken{\@getAns}%
}
\def\@getFreezeAns{\aeb@searchfortoken{\@@getFreezeAns}}
\long\def\@@getFreezeAns\Ans#1\eAns{%
    \g@addto@macro\@tempholdfreeze{\Ans#1\eAns}%
    \aeb@searchfortoken{\@@getFreezeAns}%
}
\long\def\@eChoices#1\eChoices{%
    \aeb@randomizeChoices{\the\aeb@numChoices}%
}
\def\aeb@randomizeChoices#1{%
    \setrannum{\aeb@ranChoice}{1}{#1}
    \count0=0 \aeb@hold=\expandafter{\@temphold}\def\@temphold{}%
    \expandafter\@tfor\expandafter
        \@temp\expandafter:\expandafter=\the\aeb@hold \do {%
        \advance\count0by1
        \ifnum\count0=\aeb@ranChoice
            \aeb@hold=\expandafter\expandafter\expandafter
                {\expandafter\@tempholdrandom\@temp}%
            \edef\@tempholdrandom{\the\aeb@hold}%
        \else
            \aeb@hold=\expandafter\expandafter\expandafter
                {\expandafter\@temphold\expandafter{\@temp}}%
            \edef\@temphold{\the\aeb@hold}%
        \fi
    }%
    \aeb@numChoices=#1
    \advance\aeb@numChoices-1
    \ifnum\aeb@numChoices=0\relax
        \def\aeb@next{\aeb@finishedRandomizing}\else
        \def\aeb@next{\aeb@randomizeChoices{\the\aeb@numChoices}}\fi
    \aeb@next
}
\def\aeb@finishedRandomizing{%
    \aeb@hold=\expandafter\expandafter\expandafter
        {\expandafter\@tempholdrandom\@tempholdfreeze}%
    \gdef\@temphold{}\gdef\@tempholdrandom{}\gdef\@tempholdfreeze{}%
    \edef\finished@Randomizing{%
    \noexpand\@@ansChoices
    \the\aeb@hold
    \noexpand\eChoices}%
    \finished@Randomizing
}
\def\saveRandomSeed{\PackageInfo{exerquiz}
    {The command \string\saveRandomSeed\space
    is deprecated.\MessageBreak Seed automatically saved}}
\@ifpackageloaded{ran_toks}{%
    \let\inputRandomSeed\useLastAsSeed
    \let\useRandomSeed\useThisSeed
}{%
    \def\inputRandomSeed{\eq@readRandomData}%
    \def\useRandomSeed#1{\saveseedfalse\randomi=#1}%
}
\def\InitSeedValue{\the\randomi} % dps
\@ifundefined{ifsaveseed}{\newif\ifsaveseed\saveseedtrue}{} % dps
\def\eq@writeRandomData
{%
    \ifsaveseed
        \@ifundefined{saveseedinfo}{\newwrite\saveseedinfo}{}
        \immediate\openout \saveseedinfo \jobname_rt.sav
        \let\verbatim@out\saveseedinfo
        \def\eqrt@msgi{initializing seed value}%
        \def\eqrt@msgii{last random number used}%
        \uccode`c=`\%\uppercase{%
            \immediate\write\verbatim@out
                {\InitSeedValue\space c \eqrt@msgi}%
            \immediate\write\verbatim@out
                {\the\randomi\space c \eqrt@msgii}%
        }\immediate\closeout\saveseedinfo
    \fi
}
\AtEndDocument{\eq@writeRandomData}
\def\eq@readRandomData{\IfFileExists{\jobname_rt.sav}{%
    \PackageInfo{exerquiz}{Inputting \jobname_rt.sav}%
   \@ifundefined{readsavfile}{\newread\readsavfile}{}%
    \openin\readsavfile=\jobname_rt.sav
    \read\readsavfile to \InitSeedValue
    \read\readsavfile to \eqlastRandomNum
    \closein\readsavfile
    \randomi=\eqlastRandomNum
    \xdef\InitSeedValue{\the\randomi}%
    \immediate\closeout\readsavfile
}{%
    \PackageInfo{exerquiz}{\jobname_rt.sav cannot
    be found, \MessageBreak
    using the random initializer}%
}}
\endinput
%%
%% End of file `aebrandom.def'.
