Overview of the RandomTools[QuadraticCongruence] Subpackage - Maple Programming Help

Description

 • The RandomTools[QuadraticCongruence] subpackage contains functions for creating pseudo-random number generators using the Quadratic Congruence algorithm.  The integers ${x}_{1},{x}_{2}$, ... are generated using the quadratic recurrence

${x}_{k+1}={x}_{k}^{2}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{mod}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}n$

 where $n$ is a product of two primes and ${x}_{0}$, the seed, may be specified by the user.  They use the least significant bits of the x's to form the random numbers.
 • The Quadratic Congruential Generator creates generators using primes of length either 10, 12, 15 or 16 digits. These generators can be used for every day scientific applications.
 • Each command in the RandomTools[QuadraticCongruence] subpackage can be accessed by using either the long form or the short form of the command name in the command calling sequence.
 As the underlying implementation of the RandomTools[QuadraticCongruence] subpackage is a module, it is also possible to use the form RandomTools:-QuadraticCongruence:-command to access a command from the package. For more information, see Module Members.

 To display the help page for a particular QuadraticCongruence command, see Getting Help with a Command in a Package.

Examples

 > $\mathrm{with}\left({\mathrm{RandomTools}}_{\mathrm{QuadraticCongruence}}\right)$
 $\left[{\mathrm{NewGenerator}}\right]$ (1)

We first create a random number generator for generating random numbers on the range 1..6 and generate two random numbers.

 > $\mathrm{die}≔\mathrm{NewGenerator}\left(\mathrm{range}=1..6\right)$
 ${\mathrm{die}}{:=}{\mathbf{proc}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{x}{:=}{\mathrm{irem}}{}\left({x}{^}{2}{,}{n}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{irem}}{}\left({x}{,}{6}\right){+}{1}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (2)
 > $\mathrm{die}\left(\right)$
 ${6}$ (3)
 > $\mathrm{die}\left(\right)$
 ${2}$ (4)

Now we roll the die 10 times.

 > $\mathrm{seq}\left(\mathrm{die}\left(\right),i=1..10\right)$
 ${2}{,}{5}{,}{5}{,}{1}{,}{3}{,}{2}{,}{5}{,}{4}{,}{4}{,}{5}$ (5)

Now we create a 10 decimal digit random number generator. To form uniformly distributed floating point random numbers with 10 digits of precision on [0,1) we use the command $\mathrm{Float}\left(m,e\right)$ which forms the floating point number $m{10}^{e}$.

 > $R≔\mathrm{NewGenerator}\left(\mathrm{range}=0..{10}^{10}\right)$
 ${R}{:=}{\mathbf{proc}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{y}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{x}{:=}{\mathrm{irem}}{}\left({x}{^}{2}{,}{n}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{y}{:=}{\mathrm{irem}}{}\left({x}{,}{10000000000}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{while}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{y}{<}{10000000001}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{do}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{x}{:=}{\mathrm{irem}}{}\left({x}{^}{2}{,}{n}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{y}{:=}{10000000000}{*}{y}{+}{\mathrm{irem}}{}\left({x}{,}{10000000000}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end do}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{irem}}{}\left({y}{,}{10000000001}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (6)
 > $m≔R\left(\right)$
 ${m}{≔}{742625902}$ (7)
 > $e≔-10$
 ${e}{≔}{-10}$ (8)
 > $\mathrm{Float}\left(m,e\right)$
 ${0.0742625902}$ (9)
 > $\mathrm{seq}\left(\mathrm{Float}\left(R\left(\right),e\right),i=1..5\right)$
 ${0.9305361902}{,}{0.0805966638}{,}{0.4297131736}{,}{0.5949740789}{,}{0.0017230061}$ (10)

For further options see help page for the NewGenerator command.