It is possible to generate random numbers in a TeX document. For a gimmick I wanted a random line from a text file in my slides. The first step was to find a random number.
A random number generator is provided by the package lcg
. The generator can be initialized with a given positive value. The same positive seed results in the same random numbers. A seed of -1
initializes the generator with a more or less random value, based on the current time.
|
|
In addition it needs a counter to store the random value (SavedRandom
in my example) and a command to export
the random number (NewRandom
in the example) into the text.
The function which initializes the random generator accepts two parameters: the highest possible random number (the min value is set to 1
in my example) and the command to store the generated random number (NewRandom
). The number is exported as arabian number, it’s also possible to use roman numerals:
|
|
or alphabetic characters:
|
|