summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/ran_toks/doc/rantoks_man.tex
blob: 2776e3863dbfb40944090032b606c11fe2f9607f (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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
\documentclass{article}
\usepackage[fleqn]{amsmath}
\usepackage[
    web={centertitlepage,designv,forcolorpaper,
         latextoc,pro}, %tight,
    eforms,aebxmp
]{aeb_pro}
\usepackage{ran_toks}

\useThisSeed{1441984427}
%\useLastAsSeed
%\useThisSeed{2001383846}

%2001383846 % initializing seed value
%1629639958 % last random number used

\let\pkg\textsf
\let\env\texttt

%\rtdebugtrue
%\ranToksOn
%\ranToksOff


%\usepackage{myriadpro}
\usepackage[altbullet]{lucidbry}

%\usepackage{makeidx}
%\makeindex
\usepackage{acroman}

\makeatletter
\def\eq@fititin#1{\noindent\unskip\nobreak\hfill\penalty50
    \hskip2em\hbox{}\nobreak\hfill#1}
\def\fitit{\eq@fititin{\exrtnlabelformat}}
\@mparswitchfalse\reversemarginpar
\renewcommand{\paragraph}
    {\@startsection{paragraph}{4}{0pt}{6pt}{-3pt}
    {\normalfont\normalsize\bfseries}}
\renewcommand{\subparagraph}
    {\@startsection{subparagraph}{5}{\parindent}{6pt}{-3pt}%
    {\normalfont\normalsize\bfseries}}
\makeatother

\def\anglemeta#1{$\langle\textit{\texttt{#1}}\rangle$}
\let\ameta\anglemeta
\def\meta#1{\textit{\texttt{#1}}}
\def\darg#1{\texttt{\{#1\}}}
\def\takeMeasure{\bgroup\obeyspaces\takeMeasurei}
\def\takeMeasurei#1{\global\setbox\webtempboxi\hbox{\ttfamily#1}\egroup}
\def\bxSize{\wd\webtempboxi+2\fboxsep+2\fboxrule}

\usepackage[active]{srcltx}

\let\amtIndent\leftmargini
\def\SUB#1{${}_{\text{#1}}$}

\newdimen\aebdimen \aebdimen\topsep
\newcommand\bVerb[1][]{\begingroup#1\vskip\aebdimen\parindent0pt}%
\def\eVerb{\vskip\aebdimen\endgroup\noindent}


\urlstyle{rm}

\DeclareDocInfo
{
    university={\AcroTeX.Net},
    title={\texorpdfstring{The \textsf{ran\_toks}}{The manual for the ran\_toks}
        Package\texorpdfstring{\\[6pt]\large}{: }
        Randomizing the order of tokens},
    author={D. P. Story},
    email={dpstory@acrotex.net},
    subject=Documentation for the ran\_toks package,
    talksite={\url{www.acrotex.net}},
    version={1.1},
    Keywords={LaTeX,PDF,random, tokens, JavaScript,Adobe Acrobat},
    copyrightStatus=True,
    copyrightNotice={Copyright (C) \the\year, D. P. Story},
    copyrightInfoURL={http://www.acrotex.net}
}
\DeclareInitView{windowoptions={showtitle}}


\def\dps{$\hbox{$\mathfrak D$\kern-.3em\hbox{$\mathfrak P$}%
       \kern-.6em \hbox{$\mathcal S$}}$}

\universityLayout{fontsize=Large}
\titleLayout{fontsize=LARGE}
\authorLayout{fontsize=Large}
\tocLayout{fontsize=Large,color=aeb}
\sectionLayout{indent=-62.5pt,fontsize=large,color=aeb}
\subsectionLayout{indent=-31.25pt,color=aeb}
\subsubsectionLayout{indent=0pt,color=aeb}
\subsubDefaultDing{\texorpdfstring{$\bullet$}{\textrm\textbullet}}

\def\exSrc{\makebox[0pt][r]{\large{\Pisymbol{webd}{157}}\enspace}}

%\pagestyle{empty}
%\parindent0pt\parskip\medskipamount

\chngDocObjectTo{\newDO}{doc}
\begin{docassembly}
var titleOfManual="The ran_toks Package";
var manualfilename="Manual_BG_Print_rt.pdf";
var manualtemplate="Manual_BG_Brown.pdf"; // Blue, Green, Brown
var _pathToBlank="C:/Users/Public/Documents/ManualBGs/"+manualtemplate;
var doc;
var buildIt=false;
if ( buildIt ) {
    console.println("Creating new " + manualfilename + " file.");
    doc = \appopenDoc({cPath: _pathToBlank, bHidden: true});
    var _path=this.path;
    var pos=_path.lastIndexOf("/");
    _path=_path.substring(0,pos)+"/"+manualfilename;
    \docSaveAs\newDO ({ cPath: _path });
    doc.closeDoc();
    doc = \appopenDoc({cPath: manualfilename, oDoc:this, bHidden: true});
    f=doc.getField("ManualTitle");
    f.value=titleOfManual;
    doc.flattenPages();
    \docSaveAs\newDO({ cPath: manualfilename });
    doc.closeDoc();
} else {
    console.println("Using the current "+manualfilename+" file.");
}
var _path=this.path;
var pos=_path.lastIndexOf("/");
_path=_path.substring(0,pos)+"/"+manualfilename;
\addWatermarkFromFile({
    bOnTop:false,
    bOnPrint:false,
    cDIPath:_path
});
\executeSave();
\end{docassembly}

%\definePath\bgPath{"C:/Users/Public/Documents/%
%    ManualBGs/Manual_BG_Print_AeB.pdf"}
%\begin{docassembly}
%\addWatermarkFromFile({%
%    bOnTop: false,
%    cDIPath: \bgPath
%})
%\executeSave()
%\end{docassembly}

\begin{document}

\maketitle

\selectColors{linkColor=black}
\tableofcontents
\selectColors{linkColor=webgreen}

\section{Introduction}

This is a short package for randomizing the order of tokens. The package
is long overdue; users of \textbf{AeB} and of \textsf{eqexam} have long asked for a way to
randomize the order of the problems in a test or quiz, or anything for
that matter.

\newtopic\noindent\exSrc The \texttt{examples} folder contains three demonstration files:
\begin{enumerate}
    \item \texttt{ran\_toks.tex} reproduces the sample code of this manual.
    \item \texttt{random\_tst.tex} shows how to use \pkg{ran\_toks} to
        randomize the \emph{questions} of an exam document created by the
        \pkg{eqexam} package.
    \item \texttt{random\_tst\_qz.tex} shows how to randomize choices of a
        multiple choice field in a \env{quiz} environment of the
        \pkg{exerquiz} package, when the choices contain verbatim text.
    \item \texttt{mc-db.tex} is an \pkg{eqexam} file that draws from the
        database files \texttt{db1.tex}, \texttt{db2.tex},
        \texttt{db3.tex}, and \texttt{db4.tex}, to construct the questions
        of the exam. The questions are drawn at random from the DB files. Refer
        to \hyperref[s:DBConcept]{Section~\ref*{s:DBConcept}} for a few more details.

\end{enumerate}

\section{The Preamble and Package Options}

The preamble for this package is
\bVerb\takeMeasure{\string\usepackage\darg{ran\_toks}}%
\begin{minipage}{\bxSize}\kern0pt
\begin{Verbatim}[frame=single]
\usepackage{ran_toks}
\end{Verbatim}
\end{minipage}\eVerb
The package itself has no options.

The requirements for \textsf{ran\_toks} are the \textsf{verbatim} package
(part of the standard {\LaTeX} distribution, and the macro file
\texttt{random.tex} by Donald Arseneau.


\section{The main commands and environments}\label{rtmain}

There are two styles for defining a series of tokens to be randomized,
using either the \cs{ranToks} command or the \cs{bRTVToks}/\cs{eRTVToks}
pair. Each of these is discussed in the next two subsections.

\subsection{The \texorpdfstring{\protect\cs{ranToks}}{\CMD{ranToks}} command}

The \cs{ranToks} command was the original concept; declare a series of
tokens to be randomized.
\bVerb\takeMeasure{\string\ranToks\darg{\meta{name}}\{\%\enspace}%
\begin{minipage}{\bxSize}\kern0pt
\begin{Verbatim}[frame=single,commandchars=!()]
\ranToks{!meta(name)}{%
    {!meta(token!SUB(1))}
    {!meta(token!SUB(2))}
    ...
    {!meta(token!SUB(n))}
}
\end{Verbatim}
\end{minipage}\eVerb
were \meta{token\SUB{k}} is any non-verbatim content;\footnote{Any token that
can be in the argument of a command.} each token is enclosed in braces
(\darg{}), this is required. The \meta{name} parameter is required, and
must be unique for the document; it is used to build the names of internal
macros. Of course several such \cs{ranToks} can be used in the document,
either in the preamble or in the body of the document. Multiple
\cs{ranToks} commands must have a different \meta{name} parameter.

\emph{After} a \cs{ranToks} command has been executed, the number of tokens
counted is accessible through the \cs{nToksFor} command,
\bVerb\takeMeasure{\string\nToksFor\darg{\meta{name}}}%
\begin{minipage}{\bxSize}\kern0pt
\begin{Verbatim}[frame=single,commandchars=!()]
\nToksFor{!meta(name)}
\end{Verbatim}
\end{minipage}\eVerb
The one argument is \meta{name}, and will expand to the total number
of tokens listing as argument in the \cs{ranToks} command by the same
name.

The \cs{ranToks} command does not display the randomized tokens, for that
the command \cs{useRanTok} is used.
\bVerb\takeMeasure{\string\useRTName\darg{\meta{name}}}%
\begin{minipage}{\bxSize}
\begin{Verbatim}[frame=single,commandchars=!()]
\useRanTok{!meta(num)}
\useRTName{!meta(name)}
\end{Verbatim}
\end{minipage}\eVerb
The argument of \cs{useRanTok} is a positive integer between 1 and
\cs{nToksFor\darg{\meta{name}}}, the number of tokens declared by
\cs{ranToks}, inclusive. There is no space created following the
\cs{useRanTok} command, so if these are to be used ``inline'', enclose them
in braces (\darg{}), for example, \darg{\cs{useRanTok\darg{1}}}. The use of
\cs{useRTName} is optional unless the listing of the \cs{useRanTok} commands
is separated from the \cs{ranToks} command that defined them by another
\cs{ranToks} command of a different name. That should be clear!

Consider this example.

\begin{Verbatim}[xleftmargin=\amtIndent]
\ranToks{myPals}{%
    {Jim}{Richard}{Don}
    {Alex}{Tom}{J\"{u}rgen}
}
\end{Verbatim}
\ranToks{myPals}{%
    {Jim}{Richard}{Don}
    {Alex}{Tom}{J\"{u}rgen}
}
I have {\nToksFor{myPals}} pals, they are \useRanTok{1}, \useRanTok{2},
\useRanTok{3}, \useRanTok{4}, {\useRanTok{5}} and \useRanTok{6}. (Listed
in the order of best friend to least best friend.)
The verbatim listing is,
\begin{Verbatim}[xleftmargin=\amtIndent]
I have {\nToksFor{myPals}} pals, they are \useRanTok{1},
\useRanTok{2}, \useRanTok{3}, \useRanTok{4}, {\useRanTok{5}}
and \useRanTok{6}.
\end{Verbatim}
Notice that \cs{useRanToks} are not enclosed in braces for 1--4 because
they are each followed by a comma; the fifth token, \texttt{\darg{\cs{useRanTok\darg{5}}}}, is
enclosed in braces to generate a space following the insertion of the text.

Repeating the sentence yields, ``I have {\nToksFor{myPals}} pals, they are
\useRanTok{1}, \useRanTok{2}, \useRanTok{3}, \useRanTok{4},
{\useRanTok{5}} and \useRanTok{6}'', which is the exact same random order. To
obtain a different order, re-execute the \cs{ranToks} command with the same
arguments.\footnote{{\ttfamily\string\ranToks\darg{myPals}\darg{\darg{Jim}\darg{Richard}\darg{Don}\darg{Alex}\darg{Tom}\darg{J\string\"\darg{u}rgen}}} in this example.} Doing just that, \ranToks{myPals}{{Jim}{Richard}{Don}
{Alex}{Tom}{J\"{u}rgen}}we obtain, ``I have {\nToksFor{myPals}} pals, they
are \useRanTok{1}, \useRanTok{2}, \useRanTok{3}, \useRanTok{4},
{\useRanTok{5}} and \useRanTok{6}.'' A new order?
An alternative to re-executing \cs{ranToks} is to use the \cs{reorderRanToks} command:
\bVerb\takeMeasure{\string\reorderRanToks\darg{\meta{name}}}%
\begin{minipage}{\bxSize}\kern0pt
\begin{Verbatim}[frame=single,commandchars=!()]
\reorderRanToks{!meta(name)}
\end{Verbatim}
\end{minipage}\eVerb Now, executing \verb~\reorderRanToks{myPals}~ and compiling the sentence again yields,
``I have {\nToksFor{myPals}} pals, they are
\useRanTok{1}, \useRanTok{2}, \useRanTok{3}, \useRanTok{4},
{\useRanTok{5}} and \useRanTok{6}.'' For most applications, re-randomizing
the same token list in the same document is not very likely something you
need to do.

The \cs{reorderRanToks\darg{\meta{name}}} rearranges the list of tokens
associated with \ameta{name}, which may not be what you want; the
\cs{copyRanToks} command, on the other hand, makes a (randomized) copy of its
first required argument \ameta{name\SUB1} and saves it as \ameta{name\SUB2}, without
effecting the order of \ameta{name\SUB1}.
\bVerb\takeMeasure{\string\copyRanToks\darg{\ameta{name\SUB1}}\darg{\ameta{name\SUB2}}}%
\begin{minipage}{\bxSize}\kern0pt
\begin{Verbatim}[frame=single,commandchars=!()]
\copyRanToks{!ameta(name!SUB1)}{!ameta(name!SUB2)}
\end{Verbatim}
\end{minipage}\eVerb Thus, if \verb!\copyRanToks{myPals}{myPals1}! is executed, the token list name
\texttt{myPals1} contains the names of my pals in another randomized order,
while maintaining the same order of \texttt{myPals}.


\newtopic
My original application for this, the one that motivated writing this
package at long last, was the need to arrange several form buttons
randomly on the page. My point is that the listing given in the argument
of \cs{ranToks} can pretty much be anything that is allowed to be an
argument of a macro; this would exclude verbatim text created by \cs{verb}
and verbatim environments.

\subsection{The
\texorpdfstring{\protect\cs{bRTVToks}/\protect\cs{eRTVToks}}
    {\CMD{bRTVToks}/\CMD{eRTVToks}} pair of commands}\label{ss:RTVToks}

Sometimes the content to be randomized is quite large or contains verbatim
text. For this, it may be more convenient to use the
\cs{bRTVToks}/\penalty0\cs{eRTVToks} command pair. The syntax is
\bVerb\takeMeasure{\string\bRTVToks\darg{\meta{name}}\quad}%
\edef\WIDTH{\the\wd\webtempboxi}%
\def\1{\rlap{\hspace*{\WIDTH}\texttt{\% <-{\sffamily{ End token listing}}}}}%
\takeMeasure{\string\bRTVToks\darg{\meta{name}}\quad\% <-{\sffamily{ Begin token listing}}}%
\begin{minipage}{\bxSize}\kern0pt
\begin{Verbatim}[frame=single,commandchars=!()]
\bRTVToks{!meta(name)}!quad% <-!sffamily( Begin token listing)
\begin{rtVW}
!qquad!ameta(content!SUB(1))
\end{rtVW}
...
...
\begin{rtVW}
!qquad!ameta(content!SUB(n))
\end{rtVW}
!1\eRTVToks
\end{Verbatim}
\end{minipage}\eVerb
The \cs{bRTVToks}\texttt{\{\meta{name}\}} command begins the (pseudo)
environment and is ended by \cs{eRTVToks}. Between these two are a series of
\texttt{rtVW} (random toks verbatim write) environments. When the document is
compiled, the contents (\ameta{content\SUB{i}}) of each of these environments
are written to the computer hard drive and saved under a different name
(based on the parameter \meta{name}). Later, using the \cs{useRanTok}
commands, they are input back into the document in a random order.

The use of \cs{useRTName} and \cs{useRanTok} were explained and illustrated
in the previous section. Let's go to the examples,
\begin{Verbatim}[xleftmargin=\amtIndent]
\bRTVToks{myThoughts}
\begin{rtVW}
\begin{minipage}[t]{.67\linewidth}
Roses are red and violets are blue,
I've forgotten the rest, have you too?
\end{minipage}
\end{rtVW}
\begin{rtVW}
\begin{minipage}[t]{.67\linewidth}
I gave up saying bad things like
\verb!$#%%%^*%^&#$@#! when I was just a teenager.
\end{minipage}
\end{rtVW}
\begin{rtVW}
\begin{minipage}[t]{.67\linewidth}
I am a good guy, pass it on! The code for this last sentence is,
\begin{verbatim}
%#$% I am a good guy, pass it on! ^&*&^*
\end{verbatim}
How did that other stuff get in there?
\end{minipage}
\end{rtVW}
\eRTVToks
\end{Verbatim}
OK, now, let's display these three in random order. Here we place them in
an \texttt{enumerate} environment.

\bRTVToks{myThoughts}%
\begin{rtVW}
\begin{minipage}[t]{.67\linewidth}
Roses are red and violets are blue,
I've forgotten the rest, have you too?
\end{minipage}
\end{rtVW}
\begin{rtVW}
\begin{minipage}[t]{.67\linewidth}
I gave up saying bad things like
\verb!$#%%%^*%^&#$@#! when I was just a teenager.
\end{minipage}
\end{rtVW}
\begin{rtVW}
\begin{minipage}[t]{.67\linewidth}
I am a good guy, pass it on! The code for this last sentence is,
\begin{verbatim}
%#$% I am a good guy, pass it on! ^&*&^*
\end{verbatim}
How did that other stuff get in there?
\end{minipage}
\end{rtVW}
\eRTVToks
\begin{enumerate}
    \item \useRanTok{1}
    \item \useRanTok{2}
    \item \useRanTok{3}
\end{enumerate}
The verbatim listing of the example above is
\begin{Verbatim}[xleftmargin=\amtIndent]
\begin{enumerate}
    \item \useRanTok{1}
    \item \useRanTok{2}
    \item \useRanTok{3}
\end{enumerate}
\end{Verbatim}
The \cs{reorderRanToks} works for lists created by the \cs{bRTVToks}/\penalty0\cs{bRTVToks} construct.
If we say \cs{reorderRanToks\darg{myThoughts}} and reissue the above list, we obtain,
\begin{enumerate}\ranToksOn\reorderRanToks{myThoughts}
    \displayListRandomly[\item]{myThoughts}
\end{enumerate}
The command \cs{copyRanToks} works for list created by
\cs{bRTVToks}/\penalty0\cs{bRTVToks} as well.


\paragraph*{On the \cs{displayListRandomly} command.}\label{para:DLR}
In the enumerate example immediately above, the items in the list are
explicitly listed as \cs{item \cs{useRanTok\darg{1}}} and so one; an
alternate approach is to use the command \cs{displayListRandomly}, like so,
\begin{Verbatim}[xleftmargin=\amtIndent]
\begin{enumerate}
    \displayListRandomly[\item]{myThoughts}
\end{enumerate}
\end{Verbatim}
The full syntax for \cs{displayListRandomly} is displayed next.
\bVerb\takeMeasure{\string\displayListRandomly[\ameta{prior}][\ameta{post}]\darg{\meta{name}}}%
\begin{minipage}{\bxSize}\kern0pt
\begin{Verbatim}[frame=single,commandchars=!()]
\displayListRandomly[!ameta(prior)][!ameta(post)]{!meta(name)}
\end{Verbatim}
\end{minipage}
\eVerb The action of \cs{displayListRandomly} is to expand all tokens that
are listed in the \meta{name} token list, each entry is displayed as
\ameta{prior}\cs{useRanTok\darg{i}}\ameta{post}, where \texttt{i}
goes from~1 to \cs{nToksFor\darg{\meta{name}}}. In the example above,
\meta{prior} is \cs{item}, but normally, its default is empty. The defaults
for \ameta{prior} and \ameta{post} are both empty.

\subparagraph*{The optional arguments.} When only one optional argument is present,
if is interpreted as \ameta{prior}. To obtain a \ameta{post} with no \ameta{prior}
use the syntax,
\begin{quote}
\cs{displayListRandomly[][\ameta{post}]\darg{\ameta{name}}}
\end{quote}
Within \emph{each optional argument}, the four commands \cs{i},
\cs{first}, \cs{last}, and \cs{lessone} are (locally) defined. The \cs{i} command is the index
counter of the token currently being typeset; \cs{first} is the index of the
first item; \cs{last} is the index of the last item; and \cs{lessone} is one
less than \cs{last}. The two optional arguments and the four commands may use
to perform logic on the token as it is being typeset. For example:
\begin{Verbatim}[xleftmargin=\amtIndent,fontsize=\small]
List of pals: \displayListRandomly
    [\ifnum\i=\last and \fi]
    [\ifnum\i=\last.\else, \fi]{myPals}
\end{Verbatim}
yields,
\begin{quote}
List of pals: \displayListRandomly
    [\ifnum\i=\last and \fi]
    [\ifnum\i=\last.\else, \fi]{myPals}
\end{quote}
The optional arguments are wrapped to the next line to keep them within the margins, cool.

The example above shows the list of my pals with an Oxford comma. How would
you modify the optional argument to get the same listing without the Oxford
comma? (\displayListRandomly[\ifnum\i=\last and \fi][\ifnum\i=\last.\else\ifnum\i=\lessone\relax\space\else, \fi\fi]{myPals})
Hint: a solution involves the other command \cs{lessone}.



\section{Additional arguments and commands}\label{AddCmds}

The syntax given earlier for \cs{useRanTok} was not completely specified.
It is
\bVerb\takeMeasure{\string\useRanTok[\meta{name}]\darg{\meta{num}}}%
\begin{minipage}{\bxSize}\kern0pt
\begin{Verbatim}[frame=single,commandchars=!()]
\useRanTok[!meta(name)]{!meta(num)}
\end{Verbatim}
\end{minipage}\eVerb
The optional first parameter specifies the \meta{name} of the list from
which to draw a random token; \meta{num} is the number of the
token in the range of 1 and \cs{nToksFor\darg{\meta{name}}},
inclusive. The optional argument is useful in special circumstances when
you want to mix two random lists together.

\newtopic\noindent To illustrate: \useRanTok[myPals]{1}, \useRanTok[myThoughts]{2}

\newtopic\noindent The verbatim listing is
\begin{Verbatim}[xleftmargin=\amtIndent]
To illustrate: \useRanTok[myPals]{1}, \useRanTok[myThoughts]{2}
\end{Verbatim}
The typeset version looks a little strange, but recall, the text of
\texttt{myThoughts} were each put in a \texttt{minipage} of width \texttt{.67\cs{linewidth}}.
Without the \texttt{minipage}, the text would wrap around normally.

\paragraph*{Accessing the original order.} The original order of the list of tokens is not lost, you can retrieve
them using the command \cs{rtTokByNum},
\bVerb\takeMeasure{\string\rtTokByNum[\meta{name}]\darg{\meta{num}}}%
\begin{minipage}{\bxSize}\kern0pt
\begin{Verbatim}[frame=single,commandchars=!()]
\rtTokByNum[!meta(name)]{!meta(num)}
\end{Verbatim}
\end{minipage}\eVerb
This command expands to the token declared in the list named \meta{name}
that appears at the \meta{num} place in the list. (Rather awkwardly written.)
For example, my really best pals are {\rtTokByNum[myPals]{3}} and
\rtTokByNum[myPals]{4}, but don't tell them. The listing is,
\begin{Verbatim}[xleftmargin=\amtIndent]
For example, my really best pals are {\rtTokByNum[myPals]{3}}
and \rtTokByNum[myPals]{4}, but don't tell them.
\end{Verbatim}
In some sense, \cs{rtTokByNum[\meta{name}]} acts like a simple array, the
length of which is \cs{nToksFor\{\meta{name}\}}, and whose $k^{\text{th}}$
element is \cs{rtTokByNum[\meta{name}]\{\meta{k}\}}.

\paragraph*{Turning off randomization.} The randomization may be turned off
using \cs{ranToksOff} or turned back on with \cs{ranToksOn}.
\bVerb\takeMeasure{\string\ranToksOff\quad\string\ranToksOn}%
\begin{minipage}{\bxSize}\kern0pt
\begin{Verbatim}[frame=single,commandchars=!()]
\ranToksOff!quad\ranToksOn
\end{Verbatim}
\end{minipage}\eVerb
This can be done globally in the preamble for the whole of the document,
or in the body of the document just prior to either \cs{ranToks} or
\cs{bRTVToks}. For example,
\begin{Verbatim}[xleftmargin=\amtIndent]
\ranToksOff
\ranToks{integers}{ {1}{2}{3}{4} }
\ranToksOn
\end{Verbatim}
As a check, executing `$\cs{useRanTok\darg{3}} =  \cs{rtTokByNum\darg{3}} = 3 $' yields
`\ranToksOff\ranToks{integers}{ {1}{2}{3}{4}}\ranToksOn
$\useRanTok{3} = \rtTokByNum{3} = 3 $'? As anticipated.

To create a non-randomized list of tokens that already have been created (and randomized), use
\cs{copyRanToks}:
\begin{Verbatim}[xleftmargin=\amtIndent]
\ranToksOff\copyRanToks{myPals}{myOriginalPals}\ranToksOn
\end{Verbatim}
Then, using \cs{displayListRandomly} in a clever way,
\begin{Verbatim}[xleftmargin=\amtIndent]
\displayListRandomly[\ifnum\i=\last\space and \fi(\the\i)~]
    [\ifnum\i=\last.\else,\fi\space]{myOriginalPals}
\end{Verbatim}
we obtain: \ranToksOff\copyRanToks{myPals}{myOriginalPals}\ranToksOn
\displayListRandomly[\ifnum\i=\last\space and \fi(\the\i)~][\ifnum\i=\last.\else,\fi\space]{myOriginalPals}
The original list for \texttt{myPals} remains unchanged:
\displayListRandomly[\ifnum\i=\last\space and \fi(\the\i)~][\ifnum\i=\last.\else,\fi\space]{myPals}

The \cs{useRanTok} command---whether it operates on a randomized token list
or not---behaves similarly to an array. Thus, if we wanted the extract
the third entry of the non-randomized token list (array)
\texttt{myOriginalPals}, we do so by expanding the command
\verb!\useRanTok[myOriginalPals]{3}! to produce
\useRanTok[myOriginalPals]{3}.

\subparagraph*{Document preparation.}
The command \cs{ranToksOff} is probably best in the preamble to turn off
all randomization while the rest of the document is being composed.

\paragraph*{The \textsf{ran\_toks} auxiliary file.} The package writes to a file named
\cs{jobname\_rt.sav}, below represents two typical lines in this file.
\begin{Verbatim}[xleftmargin=\amtIndent]
1604051353 % initializing seed value
5747283528 % last random number used
\end{Verbatim}
The first line is the initializing seed value used for the last
compilation of the document; the second line is the last value of the
pseudo-random number generator used in the document.

Normally, the pseudo-random number generator provided by
\texttt{random.tex} produces a new initial seed value every minute. So if
you recompile again before another minute, you'll get the same initial
seed value.

\paragraph*{Controlling the initial seed value.} To obtain a new initial seed
value each time you compile, place \cs{useLastAsSeed} in the preamble.
\bVerb\takeMeasure{\string\useLastAsSeed}%
\begin{minipage}{\bxSize}\kern0pt
\begin{Verbatim}[frame=single]
\useLastAsSeed
\end{Verbatim}
\end{minipage}\eVerb
When the document is compiled, the initial seed value taken as the second
line in the \cs{jobname\_rt.sav} file, as seen in the above example.
With this command in the preamble, a new set of random numbers is
generated on each compile. If the file \cs{jobname\_rt.sav} does not
exist, the generator will be initialized by its usual method, using the time and date.

The command \cs{useThisSeed} allows you to reproduce a previous
pseudo-random sequence.
\bVerb\takeMeasure{\string\useThisSeed\darg{\meta{init\_seed\_value}}}%
\begin{minipage}{\bxSize}\kern0pt
\begin{Verbatim}[frame=single,commandchars=!()]
\useThisSeed{!meta(init_seed_value)}
\end{Verbatim}
\end{minipage}\eVerb
This command needs to be placed in the preamble. The value of
\meta{init\_seed\_value} is an integer, normally taken from the
first line of the \cs{jobname\_rt.sav} file.

When creating tests (possibly using \textsf{eqexam}), the problems, or
contiguous collections of problems, can be randomly ordered using the
\cs{bRTVToks}/\penalty0\cs{eRTVToks} command pair paradigm. For example,
suppose there are two classes and you want a random order (some of) the
problems for each of the two classes. Proceed as follows:
\begin{enumerate}
\item Compile the document, open \cs{jobname\_rt.sav}, and copy the
    first line (in the above example, that would be
    \texttt{1604051353}).
\item Place \cs{useThisSeed\darg{1604051353}} in the preamble. Compiling
    will bring back the same pseudo-random sequence very time.
\item Comment this line out, and repeat the process (use
    \cs{useLastAsSeed} to generate new random sequences at each
    compile) until you get another distinct randomization, open
    \cs{jobname\_rt.sav}, and copy the first line again, say its \texttt{735794511}.
\item Place \cs{useThisSeed\darg{735794511}} in the preamble.
\item Label each
\begin{Verbatim}
%\useThisSeed{1604051353} % 11:00 class
%\useThisSeed{735794511}  % 12:30 class
\end{Verbatim}
To reproduce the random sequence for the class, just uncomment the random
seed used for that class.
\end{enumerate}
If you are using \textsf{eqexam}, the process can be automated as follows:
\begin{Verbatim}[xleftmargin=\amtIndent,commandchars=!()]
\vA{\useThisSeed{1604051353}} % 11:00 class
\vB{\useThisSeed{735794511}}  % 12:30 class
\end{Verbatim}
Again, this goes in the preamble.

\section{Commands to support a DB application}\label{s:DBConcept}

One user wanted to create exams using \pkg{eqexam}, but wanted to randomly
select questions from a series of `database' files. My thought was that
\pkg{ran\_toks} would do the job for him. After setting up a demo for him, I
added the new command \cs{useTheseDBs} to \pkg{ran\_toks}:
\bVerb\takeMeasure{\string\useTheseDBs\darg{\ameta{db\SUB{1}},\ameta{db\SUB{2}},...,\ameta{db\SUB{n}}}}%
\begin{minipage}{\bxSize}\kern0pt
\begin{Verbatim}[frame=single,commandchars=!()]
\useTheseDBs{!ameta(db!SUB(1)),!ameta(db!SUB(2)),...,!ameta(db!SUB(n))}
\useProbDBs{!ameta(db!SUB(1)),!ameta(db!SUB(2)),...,!ameta(db!SUB(n))}
\end{Verbatim}
\end{minipage}\eVerb The argument of \cs{useTheseDBs} is a comma-delimited
list of file names. Each file name contains a
\cs{bRTVToks}/\penalty0\cs{eRTVToks} construct. Within this pair are
\env{rtVW} environments, as described in
\hyperref[ss:RTVToks]{Section~\ref*{ss:RTVToks}}. The \cs{useTheseDBs}
command inputs the files listed in its comma-delimited argument; a warning is
emitted if one or more of the files are not found. The default extension is
\texttt{.tex}, \cs{useTheseDBs\darg{db1,db2}} inputs the files
\texttt{db1.tex} and \texttt{db2.tex}, if they exist, while
\cs{useTheseDBs\darg{db1.def,db2.db}} inputs the files \texttt{db1.def} and
\texttt{db2.db}, if they exist. The command \cs{useProbDBs} is an alias for
\cs{useTheseDBs}.

The placement of \cs{useTheseDBs} is anywhere prior to the insertion of the
problems into the document, usually in the preamble.

Refer to the demonstration file \texttt{mc-db.tex} for an example.

\newtopic\noindent
Now, I simply must get back to my retirement. \dps

\end{document}