NewGenerator - Maple Help

 NewGenerator
 Quadratic Congruence Pseudo Random Number Generator

 Calling Sequence NewGenerator( opt1, opt2, ... )

Parameters

 opt1, opt2, ... - (optional) argument of the form option=value where option is one of primes, range, or seed

Description

 • The NewGenerator command outputs a Maple procedure, a pseudo-random number generator, which when called outputs one pseudo-random integer. The output of the generator depends on the options described below. The default is to output integers on the range $0..999999999999$, i.e., a random 12 digit integer.
 • The generator is a Quadratic Congruence (QC) generator. A QC generator uses 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$ which generates a sequence of integers ${x}_{1},...$ where n is a product of two primes p and q and ${x}_{0}$ is determined from the seed of the generator. The pseudo-random integers are extracted from the sequence ${x}_{1},...$ by using the least significant half of the digits of the ${x}_{k}$'s.
 • The quality of the pseudo-random numbers generated is expected to be good because the least significant bits of the ${x}_{k+1}$ are cryptographically secure.  See RandomTools[BlumBlumShub].
 • The primes p and q are chosen to be of the form $p=\mathrm{2s}+1$ and $q=\mathrm{2t}+1$ where s and t are prime and 2 is a primitive element in the Z mod s and in Z mod t.  The initial value ${x}_{0}$ is chosen as a function of the seed so that the period of the generator is maximal where the maximal period is lcm(s-1,t-1) which about n/8. We have precomputed random primes p and q satisfying these requirements of lengths 10, 12, 15 and 16 decimal digits in length. They are

 p q (9999948359) (9999854759) (999999911447) (999999811607) (999999999847799) (999999999771959) (9999999999716999) (9999999999691319)

 Thus there are four choices of n available which have lengths 20, 24, 30, and 32 digits respectively with periods > 10^19, 10^23, 10^29 and 10^31, respectively. The larger primes will give better'' pseudo-random numbers and provide a longer the period. For most applications the smallest choice, the default, will be fine and it will be slightly faster than the larger choices.
 • The following optional arguments are supported. They are input as equations in any order.
 seed=integer
 The given integer is the seed of the generator. The value used for ${x}_{0}$ is computed from the value of the seed argument It will be a quadratic residue in Z mod n of maximal period and ${x}_{0}$ will be larger than the sqrt(n).  The default value for seed is $3$.
 • range=integer..integer or integer
 If the value of the range argument is a range, then the integer will be chosen from that range.  If the value of the range argument is an integer, then the integer will be take from the range [0..value).  The default range is $1000000000000$.
 • primes=$10$, $12$, $15$ or $16$
 The integer l, which must be one of 10, 12, 15 and 16 specifies the choice of the length of the primes p and q in decimal digits.  The default value for primes in $10$.

Examples

 > $\mathrm{with}\left(\mathrm{RandomTools}\left[\mathrm{QuadraticCongruence}\right]\right)$
 $\left[{\mathrm{NewGenerator}}\right]$ (1)
 > $Q≔\mathrm{NewGenerator}\left(\mathrm{range}=1..6\right)$
 ${Q}{≔}{\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)
 > $Q\left(\right)$
 ${6}$ (3)
 > $\mathrm{seq}\left(Q\left(\right),i=1..10\right)$
 ${2}{,}{2}{,}{5}{,}{5}{,}{1}{,}{3}{,}{2}{,}{5}{,}{4}{,}{4}$ (4)
 > $Q≔\mathrm{NewGenerator}\left(\mathrm{range}={10}^{10}\right)$
 ${Q}{≔}{\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}{,}{10000000000}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (5)
 > $Q\left(\right)$
 ${949577917}$ (6)
 > $\mathrm{seq}\left(Q\left(\right),i=1..5\right)$
 ${1692203819}{,}{8074260747}{,}{7379622648}{,}{939761758}{,}{1745728396}$ (7)
 > $\mathrm{Float}\left(Q\left(\right),-10\right)$
 ${0.7635452190}$ (8)
 > $\mathrm{seq}\left(\mathrm{Float}\left(Q\left(\right),-10\right),i=1..5\right)$
 ${0.1932583925}{,}{0.2079613478}{,}{0.8029354267}{,}{0.6006911435}{,}{0.6024141496}$ (9)
 > $Q≔\mathrm{NewGenerator}\left(\mathrm{primes}=16,\mathrm{range}={10}^{32}\right)$
 ${Q}{≔}{\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}{,}{10000000000000000}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{while}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{y}{<}{100000000000000000000000000000000}\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}{≔}{10000000000000000}{*}{y}{+}{\mathrm{irem}}{}\left({x}{,}{10000000000000000}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end do}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{irem}}{}\left({y}{,}{100000000000000000000000000000000}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (10)
 > $Q\left(\right)$
 ${18259096917880657442169378214465}$ (11)