summaryrefslogtreecommitdiff
path: root/texmf-dist/doc/latex/rangen/rangen_man.tex
blob: cfecd31ecd68ff40d060e60a109b675b863a6122 (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
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
% makeindex < aebpro_man.idx > aebpro_man.ind
\documentclass[12pt]{article}
\usepackage[fleqn]{amsmath}
\usepackage[
    web={centertitlepage,designv,tight*,forcolorpaper,
%         usesf,
         latextoc,pro},
         aebxmp,exerquiz,
        dljslib={equations,ImplMulti,indefIntegral,limitArith,nodec}
]{aeb_pro}
\usepackage{multicol}
\usepackage{array}
%\usepackage{myriadpro} %[usecmtt]
\usepackage[altbullet]{lucidbry}
\usepackage[quiet,testmode]{rangen} % testmode
%\usepackage[quiet,seed=98]{rangen} % 128
%\usepackage[quiet,seed=135]{rangen} %

\DeclareInitView
{%
    layoutmag={mag=100},
%    windowoptions={fit}
}


%\usepackage{makeidx}\makeindex

\usepackage{acroman}

\usepackage[active]{srcltx}

\def\expath{../examples}

\urlstyle{tt}

%\def\tutpath{doc/tutorial}
%\def\tutpathi{tutorial}

\DeclareDocInfo
{
    university={\AcroTeX.Net},
    title={The \texorpdfstring{\pkg{rangen} Package\\[1em]}{: }
        Random Generation of Integer, Rational, and Real Numbers with
    Applications to the \texttt{exercise}, \texttt{quiz}, and \texttt{shortquiz} Environments of \textsf{Exerquiz}},
    author={D. P. Story},
    email={dpstory@acrotex.net},
    subject={Documentation for annot\textunderscore pro from AcroTeX},
    talksite={\url{www.acrotex.net}},
    version={1.4},
    copyrightStatus=True,
    copyrightNotice={Copyright (C) \the\year, D. P. Story},
    copyrightInfoURL={http://www.acrotex.net}
}

\def\anglemeta#1{\ensuremath{\langle\textit{\texttt{#1}}\rangle}}
\def\meta#1{\textit{\texttt{#1}}}
\let\meta\anglemeta
\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}
\let\pkg\textsf
\let\env\texttt
\let\opt\texttt
\let\app\textsf

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

\newdimen\aebdimen \aebdimen 0pt %\advance\aebdimen\partopsep
\newcommand\bVerb[1][]{\begingroup#1\vskip\aebdimen\parindent0pt}%
\def\eVerb{\vskip\aebdimen\endgroup\noindent}

\makeatletter
\renewcommand{\paragraph}
    {\@startsection{paragraph}{4}{0pt}{6pt}{-3pt}{\bfseries}}
\renewcommand*\l@subsection{\@dottedtocline{2}{1.5em}{2.5em}}
\renewcommand*\descriptionlabel[1]{\hspace\labelsep
    \normalfont #1}
\newcommand{\aebDescriptionlabel}[1]{%
    \setlength\dimen@{\amtIndent+\labelsep}%
    {\hspace*{\dimen@}#1}}
\makeatother
\newenvironment{aebDescript}
    {\begin{list}{}{\setlength{\labelwidth}{0pt}%
        \setlength{\leftmargin}{\leftmargin}%
        \setlength{\leftmargin}{\leftmargin+\amtIndent}%
        \setlength\itemindent{-\leftmargin}%
        \let\makelabel\aebDescriptionlabel
    }}{\end{list}}


\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}}

\newenvironment{eqComments}[1][\strut]{\smallskip\leftskip-\labelwidth
\item[]\textbf{\textcolor{blue}{#1}}}{\par\smallskip}

\renewcommand\nodecAlertMsg{%
    "A decimal answer is not acceptable here.
     Please express your answer using a fraction."}

%\previewtrue

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

\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}\label{s:intro}

This is a package that I began back in the year 2000 AD; at that
time, I managed to obtain a working version up and running with many
bugs, then forgot about it. Now, in my retirement, I stumbled across
the work and decided to give it another go.

The \pkg{rangen} package, as the title implies, can (pseudo-)randomly generate
integers, rationals, and real numbers. Generate said numbers using the
\cs{RandomZ}, \cs{RandomQ}, and \cs{RandomR} commands, respectively; in addition
to these, there is \cs{RandomL} for creating a list of numbers, from which one number
is selected at random, and \cs{RandomI} for generating a random index value that can
be used in conjunction with \cs{RandomL}.

The \AcroTeX{} eDucation Bundle (AeB) contains a package called \textsf{exerquiz}
that is used to create exercises and quizzes.  My goal in writing the
\pkg{rangen} package was to integrate it with the quiz system of \textsf{exerquiz}
so that quiz questions could be composed using the ``natural'' syntax of \pkg{rangen},
each time the source file is {\LaTeX}ed, new random numbers populate the question. To get your
interest, here is an example,



\begingroup\parskip0pt  %\previewtrue

\def\aftershortquizskip{}
\setlength{\multicolsep}{0pt}

\begin{shortquiz}*[answer] \textbf{\textcolor{blue}{Arithmetic.}}
A simple arithmetic problem, I've created one problem, then copied it to make
two problems.

\vskip6pt

\begin{multicols}{2}
\begin{questions}

% subtraction
\RandomQ{\a}[16]{1/8}{15/16}\RandomQ[ne=\a]{\b}[16]{1/8}{15/16}

\item  $\displaystyle \ds\a - \ds\b =
       \RespBoxMath[\rectW{.5in}]{ (\nOf\a * \dOf\b - \nOf\b * \dOf\a )/( \dOf\a * \dOf\b ) }{2}{.0001}{[0,2]}[{priorParse: \Array(nodec,NoAddOrSub)}]$\hfill
       \CorrAnsButton{rFrac( rEval( \nOf\a * \dOf\b - \nOf\b * \dOf\a )/rEval( \dOf\a * \dOf\b ) )}*{rngCorrAnsButton}\kern1bp\sqTallyBox

% subtraction
\RandomQ{\a}[16]{1/8}{15/16}\RandomQ[ne=\a]{\b}[16]{1/8}{15/16}

\item  $\displaystyle \ds\a - \ds\b =
       \RespBoxMath[\rectW{.5in}]{ (\nOf\a * \dOf\b - \nOf\b * \dOf\a )/( \dOf\a * \dOf\b ) }{2}{.0001}{[0,2]}[{priorParse: \Array(nodec,NoAddOrSub)}]$\hfill
       \CorrAnsButton{rFrac( rEval( \nOf\a * \dOf\b - \nOf\b * \dOf\a )/rEval( \dOf\a * \dOf\b ) )}*{rngCorrAnsButton}\kern1bp\sqTallyBox
\pushquestions
\end{multicols}
\popquestions

\vskip-6pt

\begin{eqComments}[Indefinite Integration.]
There are two integration problems, again, the second question is a copy and paste of the first.
The parameters of the problem were, of course, populated by different random numbers.
\end{eqComments}

\RandomQ{\a}{1/6}{3/2}
\RandomQ{\b}{1/6}{3/2}
\RandomZ{\c}{1}{3}

\item   $\displaystyle\int \cds\a x^2 + \cds\b x + \ds\c\,dx =
        \RespBoxMath{(\a/3)x^3+(\b/2) x^2 + \c x}{3}{.0001}{[0,2]}$\hfill
        \CorrAnsButton{(rFrac(rEval(\nOf\a)/rEval(3*\dOf\a))) x^3
            + (rFrac(rEval(\nOf\b)/rEval(2*\dOf\b))) x^2
            + \c x + C}*{rngCorrAnsButton}\kern1bp\sqTallyBox

\RandomQ{\a}{1/6}{3/2}
\RandomQ{\b}{1/6}{3/2}
\RandomZ{\c}{1}{3}

\item   $\displaystyle\int \cds\a x^2 + \cds\b x + \ds\c\,dx =
        \RespBoxMath{(\a/3)x^3+(\b/2) x^2 + \c x}{3}{.0001}{[0,2]}$\hfill
        \CorrAnsButton{(rFrac(rEval(\nOf\a)/rEval(3*\dOf\a))) x^3
            + (rFrac(rEval(\nOf\b)/rEval(2*\dOf\b))) x^2
            + \c x + C}*{rngCorrAnsButton}\kern1bp\sqTallyBox

%\vskip-6pt
\vskip-6pt

\begin{eqComments}
Definite integration can also be posed, but is not illustrated here.
\end{eqComments}

\vskip-6pt

\begin{eqComments}[Analytic Geometry.]
Find the equation of the line that passes through $P$ and $Q$.
\end{eqComments}

\RandomZ{\a}{-10}{9}
\RandomZ{\b}{-10}{9}
\RandomZ{\c}{\a*}{10}
\RandomZ{\d}{\b*}{10}
\defineDepQJS{\m}{\d - \b}{\c - \a}{rFrac(rEval(\nOf\m)/rEval(\dOf\m))}

\item   $P(\,\a, \b\,)$, $Q(\,\c, \d\,)$:
        \RespBoxMath{y = \m*x + (\b - \a*\m) }(xy){3}{.0001}{[0,2]x[0,2]}*{ProcRespEq}\hfill
        \CorrAnsButton{y = \js\m\space x + rFrac((rEval( \b * \dOf\m - \a*\nOf\m ))/(rEval(\dOf\m)))}*{rngCorrAnsButton}%
        \kern1bp\sqTallyBox

\RandomZ{\a}{-10}{9}
\RandomZ{\b}{-10}{9}
\RandomZ{\c}{\a*}{10}
\RandomZ{\d}{\b*}{10}
\defineDepQJS{\m} {\d - \b} {\c - \a} {rFrac(rEval(\nOf\m)/rEval(\dOf\m))}

\item   $P(\,\a, \b\,)$, $Q(\,\c, \d\,)$:
        \RespBoxMath{y = \m*x + (\b - \a*\m) }(xy){3}{.0001}{[0,2]x[0,2]}*{ProcRespEq}\hfill
        \CorrAnsButton{y = \js\m\space x + rFrac((rEval( \b * \dOf\m - \a*\nOf\m ))/(rEval(\dOf\m)))}*{rngCorrAnsButton}%
        \kern1bp\sqTallyBox\par\kern2pt
\end{questions}
\end{shortquiz}\hfill\sqClearButton\kern1bp\sqTallyTotal
\par\endgroup
\newtopic\noindent
Each time the manual is compiled, a new set of problems of the same type is generated.
This package is pretty impressive, I'm sure you'll agree. \dps

These examples were taken from the demo file \texttt{rangen\_tst.tex}.

\section{Requirements}

The requirements for your {\LaTeX} system, and well as any other
software, is highlighted in this section.

\subsection{{\LaTeX} Package Requirements}

The following packages, in addition to the standard {\LaTeX}
distribution, are required:
\begin{enumerate}
  \item The \textsf{lcg} package (2008/09/10 v1.2) by Erich Janka.
  \item The \textsf{hyperref} package, a recent version.
  \item If you want to use \pkg{rangen} to create quizzes, then
  \textsf{exerquiz} of \textcolor{blue}{AeB} is required.\footnote{AeB: \url{http://www.math.uakron.edu/~dpstory/webeq.html}}
\end{enumerate}

\subsection{PDF Creator Requirements}

The package works for all PDF creators: Acrobat Distiller, pdftex, and dvipdfm.

\section{Installation}

Unzip \texttt{rangen.zip} into your {\LaTeX} tree, the folder \texttt{rangen} is constructed
with to contain the installation.

\section{Package Options}

Currently, there is only one option, \opt{testmode}. Then this option is used,
each time the file is run, the random number generator of \pkg{lcd} is re-seeded
Normally, the seed is based on the time, the date and other factors; the clock
of the {\TeX} compiler gives the time to the nearest minute, so one must wait at least
a minute before getting a new seed, this is not acceptable when testing a package.
When \opt{testmode} is used, the initial seed is \texttt{seed=1}, and increments
by one thereafter; after the increment, this value is saved to the file
\cs{jobname.seed} and input back in on the next compile.

Any other options that are passed to \pkg{rangen}, are passed on to the \textsf{lcg} package.
Useful options for \pkg{lcg} are \texttt{quiet} and \texttt{seed=\meta{number}}.


\section{Basic Commands}

This package defines the commands \cs{RandomZ},
\cs{RandomQ}, and \cs{RandomR}, \cs{RandomL}, and \cs{RandomI}. We describe
these commands in this section.

For convenience of terminology, a number created by one of the above commands
will be referred to as a RV (random variable).

\cs{RandomZ} and \cs{RandomQ} use the count registers, so there is a restriction
on the size of any RV generated by these two commands, we must have
\begin{equation*}
    -2^{31}+1 \leq \text{RV} \leq  2^{31}-1\implies
    -2147483647 \leq \text{RV} \leq 2147483647
\end{equation*}
For simple applications envisioned for \pkg{rangen}, this range should be plenty
enough.

The \cs{RandomR} command uses the dimension registers, so a RV generated by
\cs{RandomR} is restricted to
\begin{equation*}
    -2^{14} < \text{RV} <  2^{14}\implies
    -16384 < \text{RV} < 16384
\end{equation*}
Again, this is not a package for making floating point calculations, it is a package
for generating integers, rationals, and decimal numbers with an eye towards application
to academic problem generation. Floating point arithmetic can be accomplished using
the \textsf{fp} package; \pkg{rangen} and \textsf{fp} seem to be compatible.

\subsection{\texorpdfstring{\protect\cs{RandomZ}}{\CMD{RandomZ}}}

The command \Com{RandomZ} defines a random integer, the syntax is

\takeMeasure{\string\RandomZ[\meta{key-values}]\darg{\cs{\meta{name}}}\darg{\meta{zLEP}}\darg{\meta{zUEP}}}
\begin{dCmd*}[commandchars=!()]{\bxSize}
\RandomZ[!meta(key-values)]{!cs(!meta(name))}{!meta(zLEP)}{!meta(zUEP)}
\end{dCmd*}
\PD
\begin{description}
\item [\texttt{\meta{key-values}}] The key-value pairs that modify the choice of
the variable. The key-value pairs recognize are
\begin{description}
  \item [\texttt{ne=\meta{value}}] Restrict the choice of the random integer by requiring
  it \emph{not be equal} to another number, for example, \texttt{ne=0} or \texttt{ne=\cs{b}}.
  In the latter case, \cs{b} is a number defined already by either an earlier
  \cs{RandomZ} call, or by \Com{defineZ}, discussed later. Multiple restrictions can
  be placed as well, for example, if \verb!ne={0,-1}!, \pkg{rangen} selects an integer
  different from 0 or -1.
%  \item \texttt{formatOne}: A Boolean formatting key for formatting the number 1;
%  for example, instead of typesetting \texttt{1x} the correct syntax is to typeset \texttt{x}.
%  To obtain this special formatting, you must use
%  \cs{fmt} or \cs{ds}, for example \verb!\fmt\a!. Details are described below.
%  \item \texttt{formatPMOne}: A Boolean formatting key for formatting the numbers 1 and -1;
%  in addition to formatting of the number 1, if the random integer is -1 we want to
%  typeset \texttt{-x} not \texttt{-1x}. To obtain this special formatting, you must use
%  \cs{fmt} or \cs{ds}, for example \verb!\fmt\a!. Details are described below.
\end{description}
\item[\cs{\meta{name}}] The name of the random integer. For example,
    \cs{a}, \cs{b}, etc.
\item [\meta{zLEP}] An integer that is the lower endpoint of the interval
    from which the number is randomly selected. The lower endpoint may be
    an integer previously calculated by an earlier \cs{RandomZ} call, for
    example, \verb!\RandomZ{\b}{\a}{5}!, this will generate an integer
    \cs{b} such that $\cs{a}\le\cs{b}\le5$. To get strict inequality,
    append an asterisk (\texttt{*}), for example, if the syntax
    \verb!\RandomZ{\b}{\a*}{5}! is used, then \pkg{rangen} attempts to
    satisfy $\cs{a}<\cs{b}\le5$. The range of \cs{a} should be such that
    the upper limit for \cs{a} is less than the upper limit of \cs{b}. When
    the endpoint is a number, the \texttt{*} is ignored.\smallskip

    When the lower endpoint is a command created by the commands
    \cs{Random\meta{\upshape{Z|Q|R|L}}} or by
    \cs{define\meta{\upshape{Z|Q|R}}}, the endpoint is converted to a real
    number.

\item [\meta{zUEP}] An integer that is the upper endpoint of the interval
    from which the number is randomly selected. The upper endpoint may be
    an integer previously calculated by an earlier \cs{RandomZ} call, for
    example, \verb!\RandomZ{\b}{-5}{\a}!, this will generate an integer
    \cs{b} such that $-5\le\cs{b}\le\cs{a}$. To get strict inequality, use
    the syntax $-5\le\cs{b}\le\cs{a}*$, then \pkg{rangen} attempts to
    satisfy $-5\le\cs{b}<\cs{a}$. The range of \cs{a} should be such that
    the lower limit for \cs{a} is greater than the lower limit of \cs{b}.
    When the endpoint is a number, the \texttt{*} is ignored.\smallskip

    When the upper endpoint is a command created by the commands
    \cs{Random\meta{\upshape{Z|Q|R|L}}} or by
    \cs{define\meta{\upshape{Z|Q|R}}}, the endpoint is converted to a real
    number.

\end{description}

\noindent
\textbf{Examples:}
\begin{enumerate}
    \item \verb!\RandomZ{\a}{-5}{5}!: \RandomZ{\a}{-5}{5}\cs{a}=\a. To get another
    random integer, we repeatedly execute \verb!\RandomZ{\a}{-5}{5}! followed by
    \cs{a}, for example, we copy and paste \verb!\RandomZ{\a}{-5}{5}\a! three times to get
    \RandomZ{\a}{-5}{5}\a, \RandomZ{\a}{-5}{5}\a, \RandomZ{\a}{-5}{5}\a.

    \item Illustrate \texttt{ne}: Consider
        \verb!\RandomZ[ne={0,-1}]{\a}{-5}{5}\a!, copy and paste
        repeatedly: \RandomZ[ne={0,-1}]{\a}{-5}{5}\a,
        \RandomZ[ne={0,-1}]{\a}{-5}{5}\a, \RandomZ[ne={0,-1}]{\a}{-5}{5}\a,
        \RandomZ[ne={0,-1}]{\a}{-5}{5}\a, and
        \RandomZ[ne={0,-1}]{\a}{-5}{5}\a. If \pkg{rangen} worked as it
        should, the list of five number should not contain a 0 or a -1,
        does it?
    \item Illustrate $\cs{a}\le\cs{b}$: We use the code
\begin{Verbatim}
\RandomZ{\a}{-5}{5}\RandomZ{\b}{\a}{10}$\a \le \b$
\end{Verbatim}
    We now copy and paste this code: \RandomZ{\a}{-5}{5}\RandomZ{\b}{\a}{10}$\a \le \b$,
    \RandomZ{\a}{-5}{5}\RandomZ{\b}{\a}{10}$\a \le \b$. To get strict inequality we execute
\begin{Verbatim}
\RandomZ{\a}{-5}{5}\RandomZ{\b}{\a*}{10}$\a < \b$
\end{Verbatim}
    We now copy and paste this code: \RandomZ{\a}{-5}{5}\RandomZ{\b}{\a*}{10}$\a < \b$,
    \RandomZ{\a}{-5}{5}\RandomZ{\b}{\a*}{10}$\a < \b$
%\item\texttt{formatOne}: We execute the code
%\begin{Verbatim}
%\RandomZ[formatOne]{\a}{1}{3}$\fmt\a x$
%\end{Verbatim}
%    to get \RandomZ[formatOne]{\a}{1}{3}$\fmt\a x$, \RandomZ[formatOne]{\a}{1}{3}$\fmt\a x$,
%    \RandomZ[formatOne]{\a}{1}{3}$\fmt\a x$, \RandomZ[formatOne]{\a}{1}{3}$\fmt\a x$.
%    Notice the use of the command \cs{fmt}. When \cs{fmt} is present, the special formatting
%    is used; there are times when you want the formatting, and other times when you don't it. For example,
%    suppose we want \cs{a} to be a constant term, we want $ 1 + x $ not $\phantom{1}+x$, to get this
%    we use create \cs{a} as before \verb!\RandomZ[formatOne]{\a}{1}{3}$\a+\fmt\a x$!, but do not use
%    the \cs{fmt} on the first term. This gets us \RandomZ[formatOne]{\a}{1}{3}$\a+\fmt\a x$,
%    \RandomZ[formatOne]{\a}{1}{3}$\a+\fmt\a x$, \RandomZ[formatOne]{\a}{1}{3}$\a+\fmt\a x$.
%
%\item\texttt{formatPMOne}: We execute the code
%\begin{Verbatim}
%\RandomZ[ne=0,formatPMOne]{\a}{-2}{2}$\fmt\a x$
%\end{Verbatim}
%to obtain \RandomZ[ne=0,formatPMOne]{\a}{-2}{2}$\fmt\a x$, \RandomZ[ne=0,formatPMOne]{\a}{-2}{2}$\fmt\a x$,
%\RandomZ[ne=0,formatPMOne]{\a}{-2}{2}$\fmt\a x$, \RandomZ[ne=0,formatPMOne]{\a}{-2}{2}$\fmt\a x$. Let us hope
%we get a -1 in one of those generations.
\end{enumerate}

\paragraph*{Data Type Properties.}\label{dtProperties}When a random number is created, there are several auxiliary commands that are defined.

\takeMeasure{\string\nOf\darg{\cs{\meta{name}}}\quad\string\dOf\darg{\cs{\meta{name}}}}
\begin{dCmd*}[commandchars=!()]{\bxSize}
\nOf{!cs(!meta(name))}!quad\dOf{!cs(!meta(name))}
\fmt{!cs(!meta(name))}!quad\ds{!cs(!meta(name))}
\end{dCmd*}
\CmdDescription
\begin{description}\def\1{\hspace{-\labelsep}}
  \item\1 \cs{nOf\darg{\cs{\meta{name}}}} is the numerator for the number
      \cs{\meta{name}}. For an integer this is just \cs{\meta{name}}. This
      function becomes important for rational numbers. If \cs{a} is the
      rational number 2/3, then \verb!\nOf{\a}=2!.

  \item\1 \cs{dOf\darg{\cs{\meta{name}}}} is the denominator for the number
      \cs{\meta{name}}. For an integer this is just \texttt{1}. This
      function becomes important for rational numbers. If \cs{a} is the
      rational number 2/3, then \verb!\dOf{\a}=3!.

  \item\1 \cs{fmt\darg{\cs{\meta{name}}}} allows for special formatting for
      in-line numbers. Without one of the special formatting options,
      \cs{fmt}\cs{a} is the same as \cs{a}.

  \item\1 \cs{ds\darg{\cs{\meta{name}}}} allows for special formatting for
      display style number. \cs{ds} is relevant for rational numbers. If
      \cs{a} represents the rational 1/2, the \cs{a} expanded is 1/2, while
      \cs{ds}\cs{a} expanded is $\frac{1}{2}$. The \cs{ds} command also
      obeys the formatting options.
\end{description}


\subsection{\texorpdfstring{\protect\cs{RandomQ}}{\CMD{RandomQ}}}

The command \Com{RandomQ} defines a random rational, the syntax is

\takeMeasure{\small\string\RandomQ[\meta{key-values}]\darg{\cs{\meta{name}}}%
[\meta{max\_denom}]\darg{\meta{qLEP}}\darg{\meta{qUEP}}}
\begin{dCmd*}[commandchars=!(),fontsize=\small]{\bxSize}
\RandomQ[!meta(key-values)]{!cs(!meta(name))}[!meta(max_denom)]{!meta(qLEP)}{!meta(qUEP)}
\end{dCmd*}
\PD
\begin{description}\def\1{\hspace{-\labelsep}}
\item [\meta{key-values}] The key-value pairs that modify the choice of
the variable. The key-value pairs recognize are
\begin{description}
  \item [\texttt{ne=\meta{value}}] Restrict the choice of the random rational by requiring
  it \emph{not be equal} to another number, for example, \texttt{ne=0} or \texttt{ne=\cs{b}}.
  In the latter case, \cs{b} is a number defined already by either an earlier
  \cs{RandomQ} call, or by \Com{defineQ}, discussed later. Multiple restrictions can
  be placed as well, for example, if \verb!ne={0,-1}!, \pkg{rangen} selects an integer
  different from 0 or -1.
%  \item \texttt{formatOne}: A Boolean formatting key for formatting the number 1;
%  for example, instead of typesetting \texttt{1x} the correct syntax is to typeset \texttt{x}.
%  To obtain this special formatting, you must use
%  \cs{fmt} or \cs{ds}, for example \verb!\fmt\a!. Details are described below.
%  \item \texttt{formatPMOne}: A Boolean formatting key for formatting the numbers 1 and -1;
%  in addition to formatting of the number 1, if the random integer is -1 we want to
%  typeset \texttt{-x} not \texttt{-1x}. To obtain this special formatting, you must use
%  \cs{fmt} or \cs{ds}, for example \verb!\fmt\a!. Details are described below.
\end{description}
\item\1\cs{\meta{name}} is the name of the random rational. For example,
\cs{a}, \cs{b}, etc.

\item\1\meta{max\_denom} is the largest denominator you want your random
    rational to have. For example, \verb!\RandomQ{\a}[9]{1/2}{7/2}!: The
    value of \cs{a} is a rational number between 1/2 and 7/2 having a
    maximum denominator of 9. If this parameter is not specified, the least
    common denominator is used; for the example, that would be 2. To
    contrast the two, consider the following examples:
\begin{enumerate}
  \item \verb!\RandomQ{\a}[9]{1/2}{7/2}\a!: \RandomQ{\a}[9]{1/2}{7/2}\a, \RandomQ{\a}[9]{1/2}{7/2}\a,
  \RandomQ{\a}[9]{1/2}{7/2}\a, and \RandomQ{\a}[9]{1/2}{7/2}\a.
  \item \verb!\RandomQ{\a}{1/2}{7/2}\a!: \RandomQ{\a}{1/2}{7/2}\a, \RandomQ{\a}{1/2}{7/2}\a,
  \RandomQ{\a}{1/2}{7/2}\a, \RandomQ{\a}{1/2}{7/2}\a.
\end{enumerate}
The fractions are reduced to lowest terms, and represented as an integer if needed.

Here is more detail on the algorithm used to generate a rational: We illustrate
using the example, \verb!\RandomQ{\a}[9]{1/2}{7/2}!, the details are simplified slightly.
\begin{enumerate}
    \item Convert the range so that the endpoints have a denominator of~9.
\begin{alignat*}{2}
    &\texttt{LEP}: \frac{1}{2}= \frac{9/2}{9}=\frac{4.5}{9}< \frac{5}{9}&&\quad\text{round up} \\[1em]
    &\texttt{UEP}: \frac{7}{2}= \frac{63/2}{9}=\frac{31.5}{9}>\frac{31}{9}&&\quad\text{round down}
\end{alignat*}
\item We randomly choose an integer between 5 and 31, call it \cs{z}; our random
rational is then \texttt{\cs{z}/9}, unless there is an \texttt{*} affixed to one of
both endpoints.
\item If one or both endpoints is itself a random rational (or integer) and the \texttt{*}
character is used, then the lower end of the range is incremented (from 5 to 6) and/or
the upper end is decremented (from 31 to 30).
\item Reduce the fraction obtained in the previous step.
\end{enumerate}

You can see from this example, there are a lot of choices for the random
integer, there are 27 possibilities between 5 and 32.

\item\1 \meta{qLEP} is a rational (of the form a/b) that is the lower
    endpoint of the interval from which the number is randomly selected.
    The lower endpoint may be a rational (or integer) previously calculated
    by an earlier \cs{RandomQ} call, for example,
    \verb!\RandomQ{\b}{\a}{4/3}!, this will generate an integer \cs{b} such
    that $\cs{a}\le\cs{b}\le4/3$. To get strict inequality, use the syntax
    \verb!\RandomZ{\b}{\a*}{4/3}!, then \pkg{rangen} attempts to satisfy
    $\cs{a}<\cs{b}\le4/3$. The range of \cs{a} should be such that the
    upper limit for \cs{a} is less than the upper limit of \cs{b}. When the
    endpoint is a number, the \texttt{*} is ignored.\smallskip

    When the lower endpoint is a command created by any of the commands
    \cs{Random\meta{\upshape{Z|Q|R|L}}} or \cs{define\meta{\upshape{Z|Q|R}}},
    the endpoint is converted to a real number.

\item\1\meta{qUEP} is a rational that is the upper endpoint of the interval
    from which the number is randomly selected. The upper endpoint may be a
    rational  (or integer) previously calculated by an earlier \cs{RandomQ}
    call, for example, \verb!\RandomQ{\b}{-4/3}{\a}!, this will generate an
    integer \cs{b} such that $-4/3\le\cs{b}\le\cs{a}$. To get strict
    inequality, use the syntax $-4/3\le\cs{b}\le\cs{a}*$, then \pkg{rangen}
    attempts to satisfy $-4/3\le\cs{b}<\cs{a}$. The range of \cs{a} should
    be such that the lower limit for \cs{a} is greater than the lower limit
    of \cs{b}. When the endpoint is a number, the \texttt{*} is
    ignored.\smallskip

    When the upper endpoint is a command created by any of the commands
    \cs{Random\meta{\upshape{Z|Q|R|L}}} or \cs{define\meta{\upshape{Z|Q|R}}},
    the endpoint is converted to a real number.
\end{description}

\paragraph*{Examples}
\begin{enumerate}
    \item \verb!\RandomZ{\a}{-5}{5}!: \RandomZ{\a}{-5}{5}\cs{a}=\a. To get
        another random integer, we repeatedly execute
        \verb!\RandomZ{\a}{-5}{5}! followed by \cs{a}, for example, we copy
        and paste \verb!\RandomZ{\a}{-5}{5}\a! three times to get
        \RandomZ{\a}{-5}{5}\a, \RandomZ{\a}{-5}{5}\a,
        \RandomZ{\a}{-5}{5}\a.

    \item Illustrate \texttt{ne}: Copy and paste
\begin{Verbatim}
\RandomZ[ne={0,-1}]{\a}{-5}{5}\a
\end{Verbatim}
        repeatedly to obtain:
        \RandomZ[ne={0,-1}]{\a}{-5}{5}\a, \RandomZ[ne={0,-1}]{\a}{-5}{5}\a,
        \RandomZ[ne={0,-1}]{\a}{-5}{5}\a, \RandomZ[ne={0,-1}]{\a}{-5}{5}\a,
        and \RandomZ[ne={0,-1}]{\a}{-5}{5}\a. If \pkg{rangen} worked as it
        should, the list of five number should not contain a 0 or a -1,
        does it?
    \item Illustrate $\cs{a}\le\cs{b}$: We use the code
\begin{Verbatim}
\RandomZ{\a}{-5}{5}\RandomZ{\b}{\a}{10}$\a \le \b$
\end{Verbatim}
    We now copy and paste this code: \RandomZ{\a}{-5}{5}\RandomZ{\b}{\a}{10}$\a \le \b$,
    \RandomZ{\a}{-5}{5}\RandomZ{\b}{\a}{10}$\a \le \b$. To get strict inequality we execute
\begin{Verbatim}
\RandomZ{\a}{-5}{5}\RandomZ{\b}{\a*}{10}$\a < \b$
\end{Verbatim}
    We now copy and paste this code:
    \RandomZ{\a}{-5}{5}\RandomZ{\b}{\a*}{10}$\a < \b$,
    \RandomZ{\a}{-5}{5}\RandomZ{\b}{\a*}{10}$\a < \b$
%\item\texttt{formatOne}: We execute the code
%\begin{Verbatim}
%\RandomZ[formatOne]{\a}{1}{3}$\fmt\a x$
%\end{Verbatim}
%    to get \RandomZ[formatOne]{\a}{1}{3}$\fmt\a x$, \RandomZ[formatOne]{\a}{1}{3}$\fmt\a x$,
%    \RandomZ[formatOne]{\a}{1}{3}$\fmt\a x$, \RandomZ[formatOne]{\a}{1}{3}$\fmt\a x$.
%    Notice the use of the command \cs{fmt}. When \cs{fmt} is present, the special formatting
%    is used; there are times when you want the formatting, and other times when you don't it. For example,
%    suppose we want \cs{a} to be a constant term, we want $ 1 + x $ not $\phantom{1}+x$, to get this
%    we use create \cs{a} as before \verb!\RandomZ[formatOne]{\a}{1}{3}$\a+\fmt\a x$!, but do not use
%    the \cs{fmt} on the first term. This gets us \RandomZ[formatOne]{\a}{1}{3}$\a+\fmt\a x$,
%    \RandomZ[formatOne]{\a}{1}{3}$\a+\fmt\a x$, \RandomZ[formatOne]{\a}{1}{3}$\a+\fmt\a x$.
%
%\item\texttt{formatPMOne}: We execute the code
%\begin{Verbatim}
%\RandomZ[ne=0,formatPMOne]{\a}{-2}{2}$\fmt\a x$
%\end{Verbatim}
%to obtain \RandomZ[ne=0,formatPMOne]{\a}{-2}{2}$\fmt\a x$, \RandomZ[ne=0,formatPMOne]{\a}{-2}{2}$\fmt\a x$,
%\RandomZ[ne=0,formatPMOne]{\a}{-2}{2}$\fmt\a x$, \RandomZ[ne=0,formatPMOne]{\a}{-2}{2}$\fmt\a x$. Let us hope
%we get a -1 in one of those generations.

    \item \verb!\RandomQ{\a}{-5/2}{5/2}!: \RandomQ{\a}{-5/2}{5/2}\cs{a}=\a.
        We repeatedly copy and paste \verb!\RandomQ{\a}{-5/2}{5/2}\a! three
        times to get \RandomQ{\a}{-5/2}{5/2}\a, \RandomQ{\a}{-5/2}{5/2}\a,
        \RandomQ{\a}{-5/2}{5/2}\a.

    \item Illustrate \texttt{ne}:
        \verb!\RandomQ[ne={0,-1}]{\a}{-5/2}{5/2}\a!, copy and paste this
        code repeatedly: \RandomQ[ne={0,-1}]{\a}{-5/2}{5/2}\a,
        \RandomQ[ne={0,-1}]{\a}{-5/2}{5/2}\a,
        \RandomQ[ne={0,-1}]{\a}{-5/2}{5/2}\a,
        \RandomQ[ne={0,-1}]{\a}{-5/2}{5/2}\a, and
        \RandomQ[ne={0,-1}]{\a}{-5/2}{5/2}\a. If \pkg{rangen} worked as it
        should, the list of five number should not contain a 0 or a -1,
        does it?

    \item Illustrate $\cs{a}\le\cs{b}$: We use the code
\begin{Verbatim}[fontsize=\small]
\RandomQ{\a}{-5/2}{5/2}\RandomQ{\b}[4]{\a}{10}$\a \le \b$
\end{Verbatim}
    and copy and paste: \RandomQ{\a}{-5/2}{5/2}\RandomQ{\b}[4]{\a}{10}$\a \le \b$,
    \RandomQ{\a}{-5/2}{5/2}\RandomQ{\b}[4]{\a}{10}$\a \le \b$. To get strict inequality we execute
\begin{Verbatim}[fontsize=\small]
\RandomQ{\a}{-5/2}{5/2}\RandomQ{\b}[4]{\a*}{10}$\a < \b$
\end{Verbatim}
    to get \RandomQ{\a}{-5/2}{5/2}\RandomQ{\b}[4]{\a*}{10}$\a < \b$,
    \RandomQ{\a}{-5/2}{5/2}\RandomQ{\b}[4]{\a*}{10}$\a < \b$
%\item\texttt{formatOne}: We execute the code
%\begin{Verbatim}
%\RandomQ[formatOne]{\a}{2/3}{4/3}$\ds\a x$
%\end{Verbatim}
%    to get \RandomQ[formatOne]{\a}{2/3}{4/3}$\ds\a x$, \RandomQ[formatOne]{\a}{2/3}{4/3}$\ds\a x$,
%    \RandomQ[formatOne]{\a}{2/3}{4/3}$\ds\a x$, \RandomQ[formatOne]{\a}{2/3}{4/3}$\ds\a x$.
%    Notice the use of the command \cs{ds}. When \cs{ds} is present, the special formatting
%    is used; there are times when you want the formatting, and other times when you don't it. For example,
%    suppose we want \cs{a} to be a constant term, we want $ 1 + x $ not $\phantom{1}+x$, to get this
%    we use create \cs{a} as before\\[3pt]
%        \verb!\RandomQ[formatOne]{\a}{2/3}{4/3}$\a+\ds\a x$!,\\[3pt]
%    but do not use
%    the \cs{ds} on the first term. This gets us \RandomQ[formatOne]{\a}{2/3}{4/3}$\a+\ds\a x$,
%    \RandomQ[formatOne]{\a}{2/3}{4/3}$\a+\ds\a x$, \RandomQ[formatOne]{\a}{2/3}{4/3}$\a+\ds\a x$.
%
%\item\texttt{formatPMOne}: We execute the code
%\begin{Verbatim}
%\RandomQ[formatPMOne]{\a}{-6/5}{-4/5}$\ds\a x$
%\end{Verbatim}
%to obtain \RandomQ[formatPMOne]{\a}{-6/5}{-4/5}$\ds\a x$, \RandomQ[formatPMOne]{\a}{-6/5}{-4/5}$\ds\a x$,
%\RandomQ[formatPMOne]{\a}{-6/5}{-4/5}$\ds\a x$, \RandomQ[formatPMOne]{\a}{-6/5}{-4/5}$\ds\a x$. Let us hope
%we get a -1 in one of those generations.
\end{enumerate}
For a rational number, the commands \cs{nOf}, \cs{dOf}, \cs{fmt}, and \cs{ds} are
also defined, see \Nameref{dtProperties}.

\subsection{\texorpdfstring{\protect\cs{RandomR}}{\CMD{RandomR}}}

The command \Com{RandomR} defines a random real number, the syntax is

\takeMeasure{\string\RandomR[\meta{key-values}]\darg{\cs{\meta{name}}}%
\darg{\meta{rLEP}}\darg{\meta{rUEP}}}
\begin{dCmd*}[commandchars=!()]{\bxSize}
\RandomR[!meta(key-values)]{!cs(!meta(name))}{!meta(rLEP)}{!meta(rUEP)}
\end{dCmd*}
\PD
\begin{description}\def\1{\hspace{-\labelsep}}
\item [\meta{key-values}] The key-value pairs that modify the choice of
the variable. The key-value pairs recognize are
\begin{description}
  \item [\texttt{round=\meta{value}}] Round the generated real number so
      that number of decimal places equals the \meta{value}, the value of
      the \texttt{round} key; for example, \texttt{round=2} rounds the
      result to 2 decimal places.

  \item [\texttt{showzeros=\meta{\upshape{true|false}}}] Show trailing
      zeros, only valid when the \texttt{round} key is used. For example,
      \texttt{round=4,showzeros} might yield a result of 3.2300, whereas
      without the \texttt{showzeros} key (or with
      \texttt{showzeros=false}), the same result would be 3.23.

  \item [\texttt{ne=\meta{value}}] Restrict the choice of the random real
      by requiring it \emph{not be equal} to another number real, for
      example, \texttt{ne=-1} or \texttt{ne=\cs{b}}. In the latter case,
      \cs{b} is a number defined already by either an earlier
      \cs{RandomR} call, or by \Com{defineR}, discussed later. Multiple
      restrictions can be placed as well, for example, if
      \verb!ne={0,-1}!, \pkg{rangen} selects an integer different from 0
      or -1.\smallskip

  Note, comparisons are made \emph{after} rounding.

\end{description}

\item\1\cs{\meta{name}} is the name of the random rational. For example,
\cs{a}, \cs{b}, etc.

\item\1 \meta{rLEP} is a real number (or integer) that is the lower
    endpoint of the interval from which the number is randomly selected.
    The lower endpoint may be a number previously calculated by an earlier
    \cs{RandomR} call, for example, \verb!\RandomR{\b}{\a}{1.3}!, this will
    generate an integer \cs{b} such that $\cs{a}\le\cs{b}\le1.3$. To get
    strict inequality, use the syntax \verb!\RandomZ{\b}{\a*}{1.3}!, then
    \pkg{rangen} attempts to satisfy $\cs{a}<\cs{b}\le4/3$. The range of
    \cs{a} should be such that the upper limit for \cs{a} is less than the
    upper limit of \cs{b}. When the endpoint is a number, the \texttt{*} is
    ignored.\smallskip

    When the lower endpoint is a command created by ant if the command
    \cs{Random\meta{\upshape{Z|Q|R|L}}}, or by
    \cs{define\meta{\upshape{Z|Q|R}}}, the endpoint is converted to a real
    number.

\item\1 \meta{rUEP} is a real number that is the upper endpoint of the
    interval from which the number is randomly selected. The upper endpoint
    may be a number previously calculated by an earlier \cs{RandomR} call,
    for example, \verb!\RandomR{\b}{-1.3}{\a}!, this will generate an
    integer \cs{b} such that $-1.3\le\cs{b}\le\cs{a}$. To get strict
    inequality, use the syntax $-1.3\le\cs{b}\le\cs{a}*$, then \pkg{rangen}
    attempts to satisfy $-1.3\le\cs{b}<\cs{a}$. The range of \cs{a} should
    be such that the lower limit for \cs{a} is greater than the lower limit
    of \cs{b}. When the endpoint is a number, the \texttt{*} is
    ignored.\smallskip

    When the upper endpoint is a command created by ant if the command
    \cs{Random\meta{\upshape{Z|Q|R|L}}}, or by
    \cs{define\meta{\upshape{Z|Q|R}}}, the endpoint is converted to a real
    number.
\end{description}
The \cs{RandomR} command divides range ($\meta{rUEP}-\meta{rLEP}$) into equal
sub-intervals, and randomly chooses node (an endpoint of one of the
sub-intervals). The number of subdivisions is determined by
\cs{RNGpowerOfTen}, and can be set by \cs{nDivisionsPowerOfTen}. This latter
command takes an integer argument, $n$, $1\le n\le 4$, the number of
subdivisions is then $10^n$.  Strictly speaking \cs{RNGpowerOfTen} does not
have to be a power of 10, you can make the definition
\verb!\def\RNGpowerOfTen{16}!, and that should work as well. The default is
\verb!\nDivisionsPowerOfTen{2}!, that is, divide the range into 100 equal
subdivisions.

\paragraph*{Examples:}

\begin{enumerate}
    \item \verb!\RandomR{\a}{-2.3}{2.3}!: \RandomR{\a}{-2.3}{2.3}\cs{a}=\a.
        To obtain more random real numbers, repeatedly execute
        \verb!\RandomR{\a}{-2.3}{2.3}! followed by \cs{a}; for example,
        \verb!\RandomR{\a}{-2.3}{2.3}\a! repeated three times yields the following:
\begin{equation*}
    \RandomR{\a}{-2.3}{2.3}\a,\ \RandomR{\a}{-2.3}{2.3}\a,\ \RandomR{\a}{-2.3}{2.3}\a
\end{equation*}

    \item \texttt{round}: We use \verb!\RandomR[round=4]{\a}{-2}{2}\a! to get
\begin{equation*}
    \RandomR[round=4]{\a}{-2}{2}\a,\ \RandomR[round=4]{\a}{-2}{2}\a,\
    \RandomR[round=4]{\a}{-2}{2}\a
\end{equation*}

    \item \texttt{showzeros}: \verb!\RandomR[round=4,showzeros]{\a}{-2}{2}\a!:
\begin{equation*}
    \RandomR[round=4,showzeros]{\a}{-2}{2}\a,\ \RandomR[round=4,showzeros]{\a}{-2}{2}\a,\
    \RandomR[round=4,showzeros]{\a}{-2}{2}\a,\ \RandomR[round=4,showzeros]{\a}{-2}{2}\a,\
    \RandomR[round=4,showzeros]{\a}{-2}{2}\a
\end{equation*}

    \item Illustrate $\cs{a}\le\cs{b}$: We use the code
\begin{Verbatim}
\RandomR{\a}{-5}{5}\RandomR{\b}{\a}{10}$\a \le \b$
\end{Verbatim}
    We now copy and paste this code twice:
\begin{equation*}
    \RandomR{\a}{-5}{5}\RandomR{\b}{\a}{10}\a \le \b,\
    \RandomR{\a}{-5}{5}\RandomR{\b}{\a}{10}\a \le \b
\end{equation*}
To get strict inequality we execute
\begin{Verbatim}
\RandomR{\a}{-5}{5}\RandomR{\b}{\a*}{10}$\a < \b$
\end{Verbatim}
    We now copy and paste this code a couple of times:
\begin{equation*}
    \RandomR{\a}{-5}{5}\RandomR{\b}{\a*}{10} \a < \b,\
    \RandomR{\a}{-5}{5}\RandomR{\b}{\a*}{10} \a < \b
\end{equation*}
For real numbers, there is little chance the two values are equal, but just in case, strict
inequality may be specified in this way.
\end{enumerate}

\subsection{\texorpdfstring{\protect\cs{RandomL}}{\CMD{RandomL}}}

The command \Com{RandomL} defines a list of numbers (integer, rational, decimal),
and randomly selects a number from the list.

\takeMeasure{\string\RandomR[\meta{key-values}]\darg{\cs{\meta{name}}}%
\darg{\meta{n\SUB{1},n\SUB{2},n\SUB{3},...}}}%
\begin{dCmd*}[commandchars=!()]{\bxSize}
\RandomL[!meta(key-values)]{!cs(!meta(name))}{!meta(n!SUB(1),n!SUB(2),n!SUB(3),...)}
\end{dCmd*}

\PD
\begin{description}\def\1{\hspace{-\labelsep}}
\item [\texttt{\meta{key-values}}] The only key-value pairs recognized is
    \texttt{index=\meta{posZ}}. The index is a base-1 index, thus \texttt{index=1}
    references the first number in the list.

    The \texttt{index} key can be used to retrieve a particular number from
    this list; for example, declaring
    \verb!\RandomL[index=2]{\a}{17,1/2,1.3}!, the value of \cs{a} is 1/2.

    The value of \texttt{index} can be any positive integer, even one generated
    using \cs{RandomI}.  If the value of \texttt{index} is greater than the
    number of items in the list, modular arithmetic is performed to put the
    index back into the proper range.

    When the \texttt{index} key is not present, a number is randomly selected
    from the list.

\item\1\cs{\meta{name}} is the name of the number generated. The number
    generated will be defined as integer, rational, or real; consequently
    \cs{nOf}, \cs{dOf}, \cs{fmt}, and \cs{ds} are defined.

\item \meta{n\SUB{1},n\SUB{2},n\SUB{3},...} A (possibly mixed) list of
    numbers. The numbers can be literal (12, 1.2, 3/4), or control
    sequences of numbers (commands) defined earlier by \cs{Random\meta{\upshape{Z|Q|R|L}}}
    or by \cs{define\meta{\upshape{Z|Q|R}}}.
\end{description}

\paragraph*{Examples}

\begin{enumerate}
    \item After declaring \verb!\RandomL{\a}{17,3.14,88,3/4,1/2}!, the value
        of \cs{a} is \RandomL{\a}{17,3.14,88,3/4,1/2}\texttt{\cs{a} = \a},
        Select a number from this list at random
        \RandomL{\a}{17,3.14,88,3/4,1/2}\texttt{\string\a=\a}, again
        \RandomL{\a}{17,3.14,88,3/4,1/2}\texttt{\string\a=\a}, and again
        \RandomL{\a}{17,3.14,88,3/4,1/2}\texttt{\string\a=\a}.
    \item \verb!\RandomL[index=3]{\a}{17,3.14,88,3/4,1/2}\a!,
    \RandomL[index=3]{\a}{17,3.14,88,3/4,1/2}\texttt{\string\a=\a}.
\end{enumerate}

\subsection{\texorpdfstring{\protect\cs{RandomI}}{\CMD{RandomI}}}

The command \Com{RandomI} defines a list of integers, \verb!{1,2,3...n}!
and randomly selects an integer, thought of as an index value, from the list.

\takeMeasure{\string\RandomI\darg{\cs{\meta{name}}}\darg{\meta{n}}}%
\begin{dCmd*}[commandchars=!()]{\bxSize}
\RandomI{!cs(!meta(name))}{!meta(n)}
\end{dCmd*}
\PD
\begin{description}\def\1{\hspace{-\labelsep}}

\item\1\cs{\meta{name}} is the name of the number generated, the number
will be defined as an integer number.

\item\1 \meta{n} is a positive number greater than 1. The list
    \verb!{1,2,3...n}! is implicitly created.
\end{description}

\paragraph*{Example:} \verb!\RandomI{\indx}{20}\indx! yields \RandomI{\indx}{20}\indx,
\RandomI{\indx}{20}\indx, \RandomI{\indx}{20}\indx, \RandomI{\indx}{20}\indx, when copied
and pasted four times.

\newtopic\noindent
My thought in creating \cs{RandomI} is to use it in conjunction with
\cs{RandomL} (using the \texttt{index} key). For example,
\begin{Verbatim}
    \RandomI{\indx}{4}
    \RandomL[index=\indx]{\a}{1/2,1/3,1/4,1/5}
    \RandomL[index=\indx]{\b}{5/3,6/5,7/2,5/6}
\begin{equation*}
    (\a)+(\b) =
\end{equation*}
\end{Verbatim}

    \RandomI{\indx}{4}
    \RandomL[index=\indx]{\a}{1/2,1/3,1/4,1/5}
    \RandomL[index=\indx]{\b}{5/3,6/5,7/2,5/6}

\noindent
This code results in the following arithmetic problem:
\begin{equation*}
    (\a)+(\b) =
\end{equation*}
This is probably not a good example of the usage of \cs{RandomI}. See the next section
on \cs{RandomP}.

\subsection{\texorpdfstring{\protect\cs{RandomP}}{\CMD{RandomP}}}

The command \Com{RandomP} defines a list of strings (literal expressions),
and randomly selects one from the list. (The ``P'' in \cs{RandomP} stands
for ``Problem.'')

\takeMeasure{\string\RandomP[\meta{key-values}]\darg{\cs{\meta{name}}}\darg{\meta{list of literals}}}%
\begin{dCmd*}[commandchars=!()]{\bxSize}
\RandomP[!meta(key-values)]{!cs(!meta(name))}{!meta(list of literals)}
\end{dCmd*}

\PD
\begin{description}\def\1{\hspace{-\labelsep}}

\item [\texttt{\meta{key-values}}] The only key-value pairs recognized is
    \texttt{index=\meta{posZ}}. The index is a base-1 index, thus index=1
    references the first number in the list.

    The \texttt{index} key can be used to retrieve a particular literal from
    this list; for example, by executing \verb!\RandomP[index=2]{\a}{d,p,s}!,
    the value of \cs{a} is \texttt{p}.

    The value of \texttt{index} can be any positive integer, even one generated
    using \cs{RandomI}, or by another list.  If the value of \texttt{index} is
    greater than the number of items in the list, modular arithmetic is
    performed to put the index back into the proper range.

    When the \texttt{index} key is not present, a number is randomly selected
    from the list.

\item\1\cs{\meta{name}} is the name of the literal generated.

\item\1\meta{list of literals} is a comma-delimited list of literal
    strings, selected literal is not interpreted as a number, but is passed
    into the definition of \cs{\meta{name}}.
\end{description}

\paragraph*{Examples}

\begin{enumerate}
    \item Executing \verb!\RandomP{\a}{1+16,\cos(\pi),%!\\
    \verb!  \frac{d}{dx}\frac{1}{2}x^2,{\int \cos(x)\,dx}}!\\
    \verb!$\texttt{\string\a} = \a$!, we get
    \RandomP[index=5]{\a}{1+16,\cos(\pi),\frac{d}{dx}\frac{1}{2}x^2}%
    $\texttt{\string\a} = \a $, and then again,
    \RandomP{\a}{1+16,\cos(\pi),\frac{d}{dx}\frac{1}{2}x^2}%
    $ \texttt{\string\a} = \a $.
    \item Use \cs{RandomI} with \cs{RandomP}. You can create a series
    of questions and answers using these two:
\begin{Verbatim}[fontsize=\small]
\RandomI{\indx}{5}
\RandomP[index=\indx]{\q}{1+16,\cos(\pi),\pi\sin(\pi),%
    \frac{d}{dx}\frac{1}{2}x^2,{\int \cos(x)\,dx}}
\RandomP[index=\indx]{\a}{17,-1,0,x,\sin(x)+C}
\begin{equation*}
  \q = \a
\end{equation*}
\end{Verbatim}

\RandomI{\indx}{5}
%\typeout{index=\iOf{\indx}}%
\RandomP[index=\indx]{\q}{1+16,\cos(\pi),\pi\sin(\pi),\frac{d}{dx}\frac{1}{2}x^2,{\int \cos(x)\,dx}}
\RandomP[index=\indx]{\a}{17,-1,0,x,\sin(x)+C}

The execution of these lines becomes
\begin{equation*}
  \q = \a
\end{equation*}
You can create a switch to include the answer or not.

\item There is an alternate approach to this previous example.
Random lists (\cs{RandomL} and \cs{RandomP}) define a macro \cs{iOf},
the value of which is the index of the item selected (at random).
We can use \cs{iOf} in the above problem as follows:
\begin{Verbatim}[fontsize=\small]
\RandomP{\q}{1+16,\cos(\pi),\pi\sin(\pi),%
    \displaystyle\frac{d}{dx}\frac{1}{2}x^2,%
    {\int \cos(x)\,dx}}
\RandomP[index=\iOf{\q}]{\a}{17,-1,0,x,\sin(x)+C}
\begin{equation*}
  \q = \a
\end{equation*}
\end{Verbatim}
The execution of these lines gives the output\dots
\RandomP{\q}{1+16,\cos(\pi),\pi\sin(\pi),%
    \displaystyle\frac{d}{dx}\frac{1}{2}x^2,{\int \cos(x)\,dx}}
\RandomP[index=\iOf{\q}]{\a}{17,-1,0,x,\sin(x)+C}
\begin{equation*}
  \q = \a
\end{equation*}
Here, we select the answer to the randomly chosen question.
\end{enumerate}

\subsection{\texorpdfstring{\protect\cs{RandomS}}{\CMD{RandomS}}}

The command \cs{RandomS} generates a random sign, either \texttt{+}
or \texttt{-}. This may be useful for creating addition/subtraction
problems.

\takeMeasure{\string\RandomS[\meta{dec}]\darg{\cs{\meta{name}}}}%
\begin{dCmd*}[commandchars=!()]{\bxSize}
\RandomS[!meta(dec)]{!cs(!meta(name))}
\end{dCmd*}

\PD
\begin{description}\def\1{\hspace{-\labelsep}}

\item\1\meta{dec} is a number between 0 and 1. This command generates a
    \texttt{+} sign with probability \meta{dec}. The default value is
    0.5.

\item\1\cs{\meta{name}} is the name that references the generated random sign.

\end{description}

\paragraph*{Examples}

\begin{enumerate}
  \item Random addition problem:
\begin{Verbatim}
\RandomZ{\a}{1}{20}\RandomZ{\b}{1}{20}\RandomS{\s}
\begin{equation*}
    \a \s \b
\end{equation*}
\end{Verbatim}

\RandomZ{\a}{1}{20}\RandomZ{\b}{1}{20}\RandomS{\s}

This code expands to
\begin{equation*}
    \a \s \b
\end{equation*}
Whether we add or subtract the summands is determined by the command \cs{s}.

\item Random Differentiation problem:
\begin{Verbatim}
\RandomQ{\a}[8]{1}{2}\RandomQ{\b}[8]{2}{3}
\RandomZ{\n}{1}{6}\RandomS{\si}\RandomS{\sii}

Differentiate
\begin{equation*}
    \frac{d}{dx}(\bigl (\a) \si (\b) x^{\sii\n}\bigr)
\end{equation*}
\end{Verbatim}

\RandomQ{\a}[8]{1}{2}\RandomQ{\b}[8]{2}{3}
\RandomZ{\n}{1}{6}\RandomS{\si}\RandomS{\sii}

Differentiate
\begin{equation*}
    \frac{d}{dx}\bigl( (\a) \si (\b) x^{\sii\n}\bigr)
\end{equation*}
\end{enumerate}

\subsection{Commands that Operate on Numbers}

Associated with each data type (integer, rational, and real) are several
useful commands \cs{nOf}, \cs{dOf}, \cs{iOf}, \cs{fmt}, and \cs{ds}.

\subsubsection{\texorpdfstring{\protect\cs{nOf} and \protect\cs{dOf}}{\CMD{nOf} and \CMD{dOf}}}

For integer, rational, and real numbers \cs{nOf} and \cs{dOf} are
the numerator and denominator, respectively.
\begin{itemize}
  \item Integer: \cs{nOf} is the integer, and \cs{dOf} is 1; for example,
  define an integer by \verb!\RandomZ{\a}{-5}{5}!,\RandomZ{\a}{-5}{5} \cs{a}=\a,
  \verb!\nOf{\a}!=\nOf{\a}, \verb!\dOf{\a}!=\dOf{\a}, as advertised.

  \item Rational: \cs{nOf} is the numerator (an integer), and \cs{dOf} is the
  denominator (an integer) of the reduced fraction. For example, define \cs{a} by
  \verb!\RandomQ[ne=0]{\a}[9]{-3/2}{3/2}!,\RandomQ[ne=0]{\a}[9]{-3/2}{3/2} then
  \begin{equation*}
  \cs{a}=\a,\ \verb!\nOf{\a}!=\nOf{\a},\ \text{and}\ \verb!\dOf{\a}!=\dOf{\a}.
  \end{equation*}
  \item Real: \cs{nOf} is the numerator (an integer), and \cs{dOf} is the
  denominator (an integer) of the reduced fraction, after the real is converted
  into a rational number. For example, \verb!\RandomR{\a}{.25}{.75}!,\RandomR{\a}{.25}{.75}
  then
  \begin{equation*}
  \cs{a}=\a,\ \verb!\nOf{\a}!=\nOf{\a},\ \text{and}\ \verb!\dOf{\a}!=\dOf{\a}
  \end{equation*}
  If we round using with \verb!\RandomR[round=2]{\a}{.25}{.75}!, we get
  \begin{equation*}
  \RandomR[round=2]{\a}{.25}{.75}\cs{a}=\a,\ \verb!\nOf{\a}!=\nOf{\a},\ \text{and}\ \verb!\dOf{\a}!=\dOf{\a}
  \end{equation*}
%  \cs{a}=\a, \verb!\nOf{\a}!=\nOf{\a}, and \verb!\dOf{\a}!=\dOf{\a}
\end{itemize}


\subsubsection{Special Formatting Commands: The \texorpdfstring{\protect\cs{ds}}{\CMD{ds}}
and \texorpdfstring{\protect\cs{fmt}}{\CMD{fmt}} families}

When a RV, such as \cs{a}, is a rational number type, say \cs{a}=1/3, the command \cs{a} expands
to 1/3. To get a display style formatting of the rational use the \Com{ds} command.
The expansion of \texttt{\$\cs{ds}\cs{a}\$} is $\frac13$.

We have seen in several examples in which the formatting was not always what we'd like.
Expressions like $x^{1}$ should be $x$, $1x$ should be $x$, $-1x$ should be $-x$.
The formatting commands \cs{cfmt} and \cs{efmt} (and their display style counterparts
\cs{cds} and \cs{eds}) attempt to format the special cases of 1 and -1, as they appear
in an exponent (the `e' variations) and as they appear as a coefficient (the `c' variations).

All the formatting commands \cs{cfmt}, \cs{efmt}, \cs{ds}, \cs{cds}, and
\cs{eds} take a RV as its argument.
\cs{\meta{\upshape{c|e}}fmt}|\cs{\meta{\upshape{c|e}}ds}\cs{a} expands to
\cs{a} when \cs{a} is not 1 or -1. These cases are covered below.

\begin{itemize}
    \item For \cs{a}=1,
        \cs{cfmt}\cs{a}=\cs{efmt}\cs{a}=\cs{cds}\cs{a}=\cs{eds}\cs{a}=\darg{},
        the empty string. Thus, \defineZ{\a}{1}if \cs{a}=\a, and we typeset
        \verb!$\a x^{\a}$!, we get $\a x^{\a}$, which is not the standard
        way of writing this expression, but if we typeset \verb!$\cfmt\a x^{\efmt\a}$! we get $\cfmt\a x^{\efmt\a}$, which is correct.
        Notice that we used \cs{cfmt} on the baseline, and \cs{efmt} in the
        exponent. It does not make any difference here, but it does if
        \cs{a}=-1, see the next bullet point.

    \item \cs{a}=-1, then
    \begin{align*}
        &\cs{cfmt}\cs{a}=\cs{cds}\cs{a}=\texttt{-}\quad\text{(minus sign)}\\
        &\cs{efmt}\cs{a}=\cs{eds}\cs{a}=\texttt{-1}\quad\text{(minus one)}
    \end{align*}
    Returning to the same expression in the previous bullet, if
    \defineZ{\a}{-1}\cs{a}=\a, and we typeset
    \verb!$\a x^{\a}$!, we get $\a x^{\a}$, which is not the standard way
    of writing this expression, but, on the other hand, if we typeset
    \verb!$\cfmt\ax^{\efmt\a}$! we get $\cfmt\a x^{\efmt\a}$, which is correct. Notice
    the difference cases if I had typeset \verb!$\cfmt\a x^{\cfmt\a}$!, I
    would have gotten $\cfmt\a x^{\cfmt\a}$, not good.

    The `c'-variation is used for unitary signs, not binary signs. For example,
    \defineZ{\a}{-1}, if \cs{a}=\a, and we typeset \verb!$2 + \cfmt\a x$!, we get
    $2 + \cfmt\a x$, which may be fine is some situations, but most of the time
    it is not. As a work around, make coefficients positive, and generate a random sign
    using \cs{RandomS}; for example, after declaring
\begin{Verbatim}
\RandomS{\s}\RandomZ{\a}{1}{3}
\end{Verbatim}
    and typeseting \verb!$2 \s \cfmt\a x$!, we get an addition half the
    time and subtraction the other half: \RandomS{\s}\RandomZ{\a}{1}{3}$2
    \s \cfmt\a x$, \RandomS{\s}\RandomZ{\a}{1}{3}$2 \s \cfmt\a x$,
    \RandomS{\s}\RandomZ{\a}{1}{3}$2 \s \cfmt\a x$,
    \RandomS{\s}\RandomZ{\a}{1}{3}$2 \s \cfmt\a x$,
    \RandomS{\s}\RandomZ{\a}{1}{3}$2 \s \cfmt\a x$,
    \RandomS{\s}\RandomZ{\a}{1}{3}$2 \s \cfmt\a x$.

    Similarly, the `e'-variation is for unitary sign in the exponent, and
    should be used when there is a need for these special format rules.

  \item Random Sign: The formatting commands are defined for a random sign
      created by \cs{RandomS} and following the same definitions outline
      above. These are of marginal value in this context.
%  \item[] \verb!\RandomL{\a}{-1,1}\RandomS{\s}$\a \s x^{\efmt\s x}$! yields the
%  expression \RandomL{\a}{-1,1}\RandomS{\s}$\a \s e^{\efmt\a x}$
\end{itemize}

\subsubsection{Getting the Data type with \texorpdfstring{\protect\cs{typeOf}}{\CMD{typeOf}}}

There may be occasions where you want to know the data type of a RV. The \pkg{rangen}
does change the data type in special cases. For example, if \cs{a} is created by
\verb~\cs{RandomQ}{\a}[2]{1}{3}~, and its value happens to be an integer, \pkg{rangen}
changes its type of integer. You can determine the type of a RV with the \cs{typeOf}
command, which takes a RV as its argument,  the value of \cs{typeOf} is a nonnegative integer. The following table gives
the values of \cs{typeOf}, and associated data types.
\begin{flushleft}
\hspace{\amtIndent}\begin{tabular}{lc}
Data type & \cs{typeOf}\\\hline
Integer & 0 \\
Rational & 1 \\
Real & 2 \\
Literal & 3
\end{tabular}
\end{flushleft}

\paragraph*{A suggested application to \cs{typeOf}.} Suppose, \cs{a} is a rational RV
(for example, \verb!\RandomQ{\a}[2]{1}{3}!), and we want to typeset the
expression \verb!$\cfmt\a x$!. One instance might be
\defineQ{\a}{3}{2}$\cfmt\a x$, this is not good syntax; so we typeset
\verb!$(\cfmt\a) x$! to get $(\cfmt\a) x$, that's good. But if \cs{a} is an
integer, such as 1, 2, or 3, we get \defineQ{\a}{2}{1}$(\cfmt\a) x$, which
contains redundant parentheses. Now we come to the use of \cs{typeof}. We now
typeset the expression
\begin{Verbatim}
$ \ifnum\typeOf\a=0\relax\cfmt\a\else(\cfmt\a)\fi x $
\end{Verbatim}
If \cs{a} is \emph{not an integer} we get, \defineQ{\a}{3}{2}for \cs{a}=\a, we obtain
$\ifnum\typeOf\a=0\relax\cfmt\a\else(\cfmt\a)\fi x$, but for
\defineQ{\a}{2}{1}for \cs{a}=\a, we get
$\ifnum\typeOf\a=0\relax\cfmt\a\else(\cfmt\a)\fi x$.

\subsection{\texorpdfstring{\protect\cs{defineZ}}{\CMD{defineZ}},
\texorpdfstring{\protect\cs{defineQ}}{\CMD{defineQ}}, and
\texorpdfstring{\protect\cs{defineR}}{\CMD{defineR}}}

The \pkg{rangen} package internally uses \cs{defineZ}, \cs{defineQ},
and \cs{defineR} to define an integer, a rational number, and a real (decimal) number.
These command may be used by the document author as well to create non-random variables.

\takeMeasure{\string\defineQ\darg{\cs{\meta{name}}}\darg{\meta{zNumer}}\darg{\meta{zDenom}}}%
\begin{dCmd*}[commandchars=!()]{\bxSize}
\defineZ{!cs(!meta(name))}{!meta(zValue)}
\defineQ{!cs(!meta(name))}{!meta(zNumer)}{!meta(zDenom)}
\defineR{!cs(!meta(name))}{!meta(rValue)}
\end{dCmd*}
Thus, \verb!\defineZ{\a}{17}!\defineZ{\a}{17} defines \cs{a}=\a, \verb!\defineQ{\a}{-3}{2}!
\defineQ{\a}{-3}{2} defines \cs{a}=\a, and \verb!\defineR{\a}{17.88}!\defineR{\a}{17.88} defines
\cs{a}=\a.

The various properties data types are created by \cs{defineZ}, \cs{defineQ},
and \cs{defineR}; these are \cs{nOf}, \cs{dOf}, \cs{typeOf}, \cs{ds}, \cs{eds},
\cs{cds}, \cs{efmt}, and \cs{cfmt}.

\newtopic\noindent
The following are other important points to remember.
\begin{itemize}
\item \textbf{Positive Denominators.} Notice that if \verb!\defineQ{\a}{3}{-2}!,\defineQ{\a}{3}{-2} then \cs{a}=\a, and
\cs{nOf}\cs{a}=\nOf\a, and \cs{dOf}\cs{a}=\dOf\a. Thus, \pkg{rangen} does not allow a
negative denominator.

\item \textbf{Automatic Reduction.} If we declare
    \verb!\defineQ{\a}{6}{4}!,\defineQ{\a}{6}{4} then \cs{a}=\a, a rational
    number is automatically reduced to lowest terms.

\item \textbf{Re-classification.} If we make the definition \verb!\defineQ{\a}{6}{2}!,\defineQ{\a}{6}{2} then \cs{a}={\a} is reduced
to lowest terms and re-classified as an integer \cs{typeOf}\cs{a}=\typeOf\a~(an integer).
\end{itemize}

\section{\textsf{rangen} and \textsf{fp}}

After a little bit of testing, it appears that \textsf{fp} can work with the \texttt{rangen} package.
The \texttt{rangen} package does not provide any command for combining RVs using such operations
as addition, subtraction, multiplication, division, etc.

The \texttt{rangen} package package does provide several useful commands that \textsf{fp} does not,
these are \cs{reduceFrac}, \cs{gcd}, and \cs{lcm}.

\Com{reduceFrac} takes two arguments (numerator and denominator), both integers, and attempts to reduce the implied fraction
to lowest terms, and returns the result in two macros \cs{rfNumer} and \cs{rfDenom}. For example,
to reduce the fraction $4/12$, we execute \verb!\reduceFrac{4}{12}!, which returns\reduceFrac{4}{12} \cs{rfNumer}=\rfNumer, and
\cs{rfDenom}=\rfDenom, forming the reduced fraction $\rfNumer/\rfDenom$; thus,
$4/12 = \rfNumer/\rfDenom$.

The \emph{greatest common divisor} command \cs{gcd} takes two integers as its arguments
and returns its result in the macro \cs{thegcd}. For example, the \verb!\gcd{4,8}! is
\gcd{4}{8}\thegcd, while the \verb!\gcd{4}{6}! is \gcd{4}{6}\thegcd.

The \emph{least common multiple} command \cs{lcd} takes two integers as its arguments,
and returns its result in the macro \cs{thelcd}. For example, \verb!\lcm{4}{5}! is
\lcm{4}{5}\cs{thelcm}=\thelcm, while, \verb!\lcm{4}{6}! is  \lcm{4}{6}\cs{thelcm}=\thelcm.

The following example illustrates the use of the \texttt{rangen} and \texttt{fp} packages to pose a random
arithmetic problem, and present a detailed solution.
\begin{Verbatim}[fontsize=\footnotesize]
\RandomQ{\a}[6]{2}{4}\RandomQ{\b}[6]{2}{4}
\gcd{\dOf\a}{\dOf\b}
\FPeval\lcd{clip((\dOf\a)*(\dOf\b)/\thegcd)}
\FPeval\si{clip(\lcd/(\dOf\a))}
\FPeval\sii{clip(\lcd/(\dOf\b))}
\FPeval\finalnum{clip((\si)*(\nOf\a)+(\sii)*(\nOf\b))}
\defineQ{\ans}{\finalnum}{\lcd}
$$
    \ds\a \thisop \ds\b = \frac{(\si)(\nOf\a)+(\sii)(\nOf\b)}{\lcd}
        = \frac{\finalnum}{\lcd}\ifnum\lcd=\dOf\ans\else =\ds\ans\fi
$$
\end{Verbatim}
An instance of this code might look like this:
$$
    \frac{8}{3}+\frac{17}{6}=\frac{(2)(8)+(1)(17)}{6}=\frac{33}{6}=\frac{11}{2}
$$
If there is any reduction of the fraction (brought on by the \cs{defineQ} command),
this additional expression is included.

\paragraph*{Demo file.}
See the demo file \texttt{rangen\_fp.tex} for a complete example.

\section{\textsf{rangen} and \textsf{exerquiz}}

Developing a package for randomly generating numbers that could be
used as a basis for creating random quizzes (see the example back in
\hyperref[s:intro]{Section~\ref*{s:intro}}, page~\pageref*{s:intro})
was my original motivation for writing the original package back in
the year 2000 AD. In this section, we introduce the techniques that
I've developed for creating random quizzes, and, more importantly,
how to grade them and to exhibit to the user the correct answer.
This system is not a computer algebra system, so, it is difficult,
but not impossible to also supply a solution (a opposed to just the
answer) to the problem as well.

\paragraph*{Demo file.}  Now, let's see how its done! Examples of this section were taken from the
demo file \texttt{rangen\_tst.tex}.

\subsection{Creating Quizzes using \textsf{rangen}}


The \pkg{rangen} package provides three JavaScript functions that are used with \textsf{exerquiz}
quizzes, these are
\begin{itemize}
    \item \texttt{rEval(str)}: The function \texttt{rEval} evaluates its
        argument. The \texttt{rEval} function searches its argument for
        \texttt{rEval} and \texttt{rFrac}, and executes any inner nested
        functions first.
    \item \texttt{rFrac(str)}: Evaluates a rational number by evaluating
        the value of the numerator and denominator separately. The function
        \texttt{rFrac} searches its argument for \texttt{rEval} and
        \texttt{rFrac}, and executes any inner nested functions first.
    \item \texttt{rngCorrAnsButton}: A function that is used to represent
        the correct answer to the user.
\end{itemize}
The best way of illustrating these function is by discussing an example or two.

\renewcommand\titleQuizfmt{\bfseries\color{red}}
\titleQuiz*{Example~1. }
\begin{shortquiz}*[sq1] We create two RVs, \cs{a} and \cs{b} that are rational numbers. We want to
add them, and present the answer as a rational number.
\begin{Verbatim}[fontsize=\small]
\RandomQ{\a}[16]{1/8}{15/16}\RandomQ[ne=\a]{\b}[16]{1/8}{15/16}
\end{Verbatim}
\begin{questions}
\RandomQ{\a}[16]{1/8}{15/16}\RandomQ[ne=\a]{\b}[16]{1/8}{15/16}

\item  $\displaystyle\ds\a - \ds\b =
       \RespBoxMath[\rectW{.5in}]{ (\nOf\a * \dOf\b - \nOf\b * \dOf\a )/( \dOf\a * \dOf\b ) }{2}{.0001}{[0,2]}[{priorParse: \Array(nodec,NoAddOrSub)}]$\hfill
       \CorrAnsButton{rFrac( rEval( \nOf\a * \dOf\b - \nOf\b * \dOf\a )/rEval( \dOf\a * \dOf\b ) )}*{rngCorrAnsButton}\kern1bp\sqClearButton
\end{questions}
\end{shortquiz}
\vskip-.5\baselineskip
The question is posed using \cs{RespBoxMath}.
\begin{Verbatim}[xleftmargin=20pt,numbers=left,fontsize=\small]
$\displaystyle\ds\a - \ds\b =
\RespBoxMath[\rectW{.5in}]{
    (\nOf\a*\dOf\b-\nOf\b*\dOf\a)/(\dOf\a*\dOf\b)}
    {2}{.0001}{[0,2]}
    [{priorParse: \Array(nodec,NoAddOrSub)}]$
\end{Verbatim}
\textsf{Exerquiz} determines whether the user's answer is correct, it by evaluating
the author's answer at randomly selected points. Exerquiz uses the floating point arithmetic
of JavaScript to evaluate the user's answer. The author's correct answer is given
in line (1), and it is just the formula for combining two fractions \cs{a} and \cs{b};
note the use of \cs{nOf} and \cs{dOf}. Line~(2) is standard parameters for \cs{RespBoxMath},
the number of random points to use, the precision, and the interval from which to select the
points. Line~(3) specifies a couple of routines from the \textsf{dljslib} package, these
prevent the user from using decimals and rational arithmetic to answer the question. (The latter
function would, for example, prevent the user from copying the question and pasting it into the
answer.)

Now comes the most interesting part, at least to me: The presentation of the correct
answer to the user. These is where the JavaScript functions \texttt{rEval} and \texttt{rFrac} are used.
The code for the answer button is shown below.
\begin{Verbatim}[xleftmargin=20pt,numbers=left,fontsize=\small]
\CorrAnsButton{rFrac(
   rEval(\nOf\a*\dOf\b-\nOf\b*\dOf\a)/rEval(\dOf\a*\dOf\b)
)}*{rngCorrAnsButton}
\end{Verbatim}
Here, this code is broken across several lines to fit on the page. We direct the \cs{CorrAnsButton}
to use the function \texttt{rngCorrAnsButton}, as seen in line~(3). This is a special function
define by \pkg{rangen} to help in the presentation of the answer to the user.

Keep in mind, the inner-most \texttt{rEval} and \texttt{rFrac}
functions are evaluated first; consequently, the two \texttt{rEval}
functions in line~(2) are evaluated first. These two evaluations
calculate the numerator and denominator separately, this results in
a numerical numerator and denominator. The function \texttt{rFrac}
is then executed on the resulting rational number, this function
reduces the fraction to lowers terms. This final calculation is what
the user sees when the correct answer button is pressed.

The next example will illustrate a decimal presentation of the answer, and introduces
a new command, \Com{RNGprintf}.

\titleQuiz*{Example~2. }
\begin{shortquiz}*[sq2] We create four RVs, \cs{a}, \cs{b}, \cs{c}, and \cs{n}, three rational and one integer.
The exponent of the power is rational, hence, we represent a decimal answer to the user.
\begin{Verbatim}[fontsize=\small]
\RandomQ{\a}[8]{1/4}{7/6}\RandomZ{\b}{1}{3}
\RandomQ{\n}[8]{1/2}{3/2}\RandomZ[ne=\zZero]{\c}{-3}{3}
\end{Verbatim}
\begin{questions}\setcounter{eqquestionnoi}{1}
\RandomQ{\a}[8]{1/4}{7/6}
\RandomZ{\b}{1}{3}
\RandomQ{\n}[8]{1/2}{3/2}
\RandomZ[ne=\zZero]{\c}{-3}{3}

\item   $\displaystyle\int_{\a}^{\b} \cfmt\c x^{\efmt\n}\,dx =
        \RespBoxMath{\c((\b)^(\n+1)-(\a)^(\n+1))/(\n+1)}{3}{.0001}{[0,2]}$\hfill
        \CorrAnsButton{rEval(\c((\b)^(\n+1)-(\a)^(\n+1))/(\n+1))}*{rngCorrAnsButton\RNGprintf{\%.4f}}\kern1bp\sqClearButton
\end{questions}
\end{shortquiz}
\vskip-.5\baselineskip
The question is posed using \cs{RespBoxMath}.
\begin{Verbatim}[xleftmargin=20pt,numbers=left,fontsize=\small]
$\displaystyle\int_{\a}^{\b} \cfmt\c x^{\efmt\n}\,dx =
    \RespBoxMath{\c((\b)^(\n+1)-(\a)^(\n+1))/(\n+1)}
        {3}{.0001}{[0,2]}$
\end{Verbatim}
The correct answer is given on line~(2), and is based on the known form of the integrand; here,
we use standard integration formulas.

The code for the correct answer button has a new element in it
\begin{Verbatim}[xleftmargin=20pt,numbers=left,fontsize=\small]
\CorrAnsButton{rEval(
    \c((\b)^(\n+1)-(\a)^(\n+1))/(\n+1)
)}*{rngCorrAnsButton\RNGprintf{\%.4f}}}\kern1bp\sqTallyBox
\end{Verbatim}
The \texttt{rEval} function evaluates the expression on line~(2), the result
is a decimal number. As before, we use the \texttt{rngCorrAnsButton}, but we've
added the \Com{RNGprintf} command to the end of the function name. This is a kludge
that I've developed to be able to format a numerical answer. The \cs{RNGprintf} command
uses the Acrobat JavaScript function \texttt{util.printf}. The argument of \cs{RNGprintf}
is passed to \texttt{util.printf} as its formatting string. Here, we use
\verb!\%.4f!, so the number is presented as a floating point number with four decimal places.
See the documentation of \texttt{util.printf} in the \textsl{JavaScript for Acrobat API Reference.}\footnote
{\url{{http://livedocs.adobe.com/acrobat_sdk/9/Acrobat9_HTMLHelp}}}


The final example it the one seen in \Nameref{s:intro}, it uses another new command,
\Com{defineDepQJS}. This command is used to define a new RV as a rational function of other RVs,
and to define special JavaScript formatting, \cs{js}. The results of this command are used
exclusively for JavaScript, and are not meant to be typeset.

\takeMeasure{\string\defineDepQJS\darg{\cs{\meta{name}}}%
\darg{\meta{numer}}\darg{\meta{denom}}\darg{\meta{script}}}%
\begin{dCmd*}[commandchars=!()]{\bxSize}
\defineDepQJS{!cs(!meta(name))}{!meta(numer)}{!meta(denom)}{!meta(script)}
\end{dCmd*}
\noindent This function defines \cs{\meta{name}} to be
\texttt{(\meta{numer})/(\meta{denom})}.  The expression \meta{numer} and
\meta{denom} can be functions of RV defined earlier. The $4^{\text{th}}$
argument is JavaScript for evaluating \cs{\meta{name}}; \meta{script} is
accessed by \cs{js\cs{\meta{name}}} and is used from within a
\cs{CorrAnsButton}. The $4^{\text{th}}$ argument can include such
commands as \cs{\meta{name}}, \cs{nOf}\cs{\meta{name}}, and
\cs{dOf}\cs{\meta{name}}. An example will perhaps illustrate.

\titleQuiz*{Example~3. }
\begin{shortquiz}*[sq3] Find the equation of the line that passes through $P$ and $Q$.

We begin by defining our variables:
\begin{Verbatim}[xleftmargin=20pt,numbers=left,fontsize=\small]
\RandomZ{\a}{-10}{9}\RandomZ{\b}{-10}{9}
\RandomZ{\c}{\a*}{10}\RandomZ{\d}{\b*}{10}
\defineDepQJS{\m}{\d - \b}{\c - \a}
    {rFrac(rEval(\nOf\m)/rEval(\dOf\m))}
\defineDepQJS{\yIntercept}{\b - \a*\m}{1}
    {rFrac((rEval(\b*\dOf\m-\a*\nOf\m))/(rEval(\dOf\m)))}
\end{Verbatim}
Our big problem is to compute the slope of the line, \cs{m}. I define \cs{m}
as using \cs{defineDepQJS}. The numerator and denominator are those in the
slope calculation, given two points. The expansion of \cs{m} is
\verb!(\d-\b)/(\c-\a)!, and the JavaScript will perform the arithmetic
operations. The expression that is accessed with the \cs{js} is the fourth
argument, line~(4); here, we calculate slope as a rational number. We make a
similar definition for the \cs{yIntercept} of the line.

Below are the two points \verb!$P(\a, \b)$! and \verb!$Q(\c, \d)$!.
\begin{questions}\setcounter{eqquestionnoi}{2}
\RandomZ{\a}{-10}{9}\RandomZ{\b}{-10}{9}
\RandomZ{\c}{\a*}{10}\RandomZ{\d}{\b*}{10}
\defineDepQJS{\m}{\d - \b}{\c - \a}{rFrac(rEval(\nOf\m)/rEval(\dOf\m))}
\defineDepQJS{\yIntercept}{\b - \a*\m}{1}{rFrac((rEval( \b * \dOf\m - \a*\nOf\m ))/(rEval(\dOf\m)))}

\item   $P(\,\a, \b\,)$, $Q(\,\c, \d\,)$:
        \RespBoxMath{y = \m*x + \yIntercept}(xy){3}{.0001}{[0,2]x[0,2]}*{ProcRespEq}\hfill
        \CorrAnsButton{y = \js\m\space x + \js\yIntercept}*{rngCorrAnsButton}%
        \kern1bp\sqClearButton
\end{questions}
\end{shortquiz}
\vskip-.5\baselineskip
The question is posed using \cs{RespBoxMath}.
\begin{Verbatim}[xleftmargin=20pt,numbers=left,fontsize=\small]
$P(\,\a, \b\,)$, $Q(\,\c, \d\,)$:
    \RespBoxMath{y=\m*x + \yIntercept}(xy)
    {3}{.0001}{[0,2]x[0,2]}*{ProcRespEq}
\end{Verbatim}
The answer is given in line~(2), and will be evaluated numerically, and compared numerically
with the user's response.

The code for the correct answer button has a new element in it
\begin{Verbatim}[xleftmargin=20pt,numbers=left,fontsize=\small]
\CorrAnsButton{y = \js\m\space x + \js\yIntercept}
    *{rngCorrAnsButton}
\end{Verbatim}
The display of the answer is done using \cs{js}\cs{m} and
\cs{js}\cs{yIntercept} to represent the slope and intercept as a rational
number.

Think of \cs{defineDepQJS} a convenient way of defining (JavaScript) expressions
that will appear in \cs{RespBoxMath} and for \cs{CorrAnsButton}.

\subsection{Creating Solutions to Random Quizzes}

Writing a solution to a question that is based on a formula or template can be difficult.
{\LaTeX} is not a computer algebra system, so the possibilities are limited. Still,
\pkg{rangen} supplies the \texttt{writeRVsTo} environment to support a solution.

\titleQuiz*{Example~4. }
\begin{shortquiz}*[sq1] We create two RVs, \cs{a} and \cs{b} that are rational numbers. We want to
add them, and present the answer as a rational number.
\begin{Verbatim}[fontsize=\small]
\begin{writeRVsTo}{quizzes}
\RandomQ{\a}[16]{1/8}{15/16}\RandomQ[ne=\a]{\b}[16]{1/8}{15/16}
\end{writeRVsTo}
\end{Verbatim}
We make that same definitions as in \textbf{\textcolor{red}{Example~1}}, but we enclose
these definitions within the \texttt{writeRVsTo}. This environment writes its contents
to the quiz solutions file, and also executes its contents. This way, the definitions are
make both here, and just before the solution to this problem in the solutions file.
\begin{questions}\setcounter{eqquestionnoi}{3}
\begin{writeRVsTo}{quizzes}
\RandomQ{\a}[16]{1/8}{15/16}\RandomQ[ne=\a]{\b}[16]{1/8}{15/16}
\end{writeRVsTo}

\item  $\displaystyle\ds\a + \ds\b =
       \RespBoxMath[\rectW{.5in}]{ (\nOf\a * \dOf\b + \nOf\b * \dOf\a )/( \dOf\a * \dOf\b ) }*{2}{.0001}{[0,2]}[{priorParse: \Array(nodec,NoAddOrSub)}]$\hfill
       \CorrAnsButton{rFrac( rEval( \nOf\a * \dOf\b + \nOf\b * \dOf\a )/rEval( \dOf\a * \dOf\b ) )}*{rngCorrAnsButton}\kern1bp\sqClearButton
\begin{solution}\relax\RNGadd\a\b\defineQ{\ans}{\rfNumer}{\rfDenom}%
The solution to this problem is
\begin{equation*}
        \boxed{\ds\a +  \ds\b = \ds\ans}
\end{equation*}
Did I forget to tell you that a simple command \cs{RNGadd} for adding two rational numbers
is defined by \pkg{rangen}. Sorry about that! \dps
\end{solution}
\end{questions}
\end{shortquiz}
\vskip-.5\baselineskip
The verbatim listing of this quiz is
\begin{Verbatim}[fontsize=\footnotesize]
\item  $\displaystyle\ds\a + \ds\b =
\RespBoxMath[\rectW{.5in}]{
    (\nOf\a*\dOf\b+\nOf\b*\dOf\a)/(\dOf\a*\dOf\b)}*{2}
    {.0001}{[0,2]}[{priorParse: \Array(nodec,NoAddOrSub)}]$\hfill
\CorrAnsButton{rFrac(rEval(
    \nOf\a * \dOf\b + \nOf\b * \dOf\a)/rEval(\dOf\a * \dOf\b))
}*{rngCorrAnsButton}\kern1bp\sqClearButton
\begin{solution}\relax\RNGadd\a\b\defineQ{\ans}{\rfNumer}{\rfDenom}%
The solution to this problem is
\begin{equation*}
    \boxed{\ds\a - \ds\b = \ds\ans}
\end{equation*}
Did I forget to tell you that a simple command \cs{RNGadd}
for adding two rational numbers is defined by
\pkg{rangen}. Sorry about that! \dps
\end{solution}
\end{Verbatim}

\newtopic\noindent
The \texttt{writeRVsTo} has the following syntax

\takeMeasure{\string\begin\darg{writeRVsTo}\darg{quizzes|exercises}}%
\begin{dCmd*}[commandchars=!()]{\bxSize}
\begin{writeRVsTo}{quizzes|exercises}
    !meta(rangen commands creating RVs)
\end{writeRVsTo}
\end{dCmd*}
The argument can be either the string \texttt{quizzes} or \texttt{exercises}. In the first case,
the content of the environment is written to the solutions file for quizzes, and in the latter case,
to the solutions file for the exercises.

\bigskip

That's all for now, I simply must get back to my retirement. \dps

\end{document}