A random generator might come in handy at some point. The lcg package provides exactly that.
All you have to do is load the package with options if needed.
1 | \usepackage [option1, option2, ...]{lcg} |
Available options:
first
: lower bound (),
last
: upper bound (),
counter
: name of the random number (overwritten if existing),
seed
: starting value for reproducibility, and
quiet
: suppress log and console output.
Without specifying boundaries, a random number will be generated in the interval .
The \rand
command produces a new random number and \arabic{rand}
writes the number to the document, assuming you are using the default counter name “rand”.
Example code for a random number between -100 and 100. The code also defines the macro random
for simplification.
1 2 3 4 | \usepackage [first=-100, last=100]{lcg} \newcommand { \random }{ \rand \arabic {rand}} ... \random |
Similarly, roman
random numbers can be generated using \roman{rand}
instead of \arabic{rand}
.
You can find the package as well as the documentation here.
Cool stuff, as always, thanks! There’s a typo, though, in “\usepcakge[]{lcg}”
Thanks, appreciate it! Tom.
Realy wear, but i think that is nice.
Cool. It’s very useful — i can easily generate different quiz for each student.
Thanks a lot!