summaryrefslogtreecommitdiff
path: root/texmf-dist/tex/latex/acrotex/aebrandom.def
blob: 66271ebd37a4653339317bf3513b55abf125ba65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
%%
%% This is file `aebrandom.def',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% exerquiz.dtx  (with options: `copyright,randomize')
%% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Exerquiz.sty package,                                %%
%% Copyright (C) 1999-2018  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}
 [2019/02/11 v8.2.9 %
 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\writeSeedToSolnFile{\writeT@ExSolns{\string\randomi=\the\randomi}}
\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'.