Add a New Pseudo-Random Number GeneratorArjen Markus$Revision: 1.3 $expr
This TIP proposes to add a new expr function: a random number generator with a longer sequence than the one currently in the core.
The expr command has used a straightforward implementation of a pseudo-random number generator via the rand() function for many years. This has a number of desirable properties, but better ones (e.g. with a longer sequence) have been known for a long time. This TIP proposes a new function as an alternative PRNG.
PRNGs with different properties can be important for Monte Carlo simulations and other algorithms that require large amounts of random numbers without having to worry about the sequence length.
Introduce a new function, randM(), as an alternative PRNG to the expr command. This function is based on work by George Marsaglia and implementations in many different languages are available on the Internet. There will be a corresponding seed function srandM(x).
The new function is not a replacement of the original rand() function.
With the new tcl::mathfunc mechanism () it should be simple to add this function to the core.
An example implementation in Tcl is given below:
ICMgbWFyc2FnbGlhLnRjbCAtLQ==ICMgICAgIEltcGxlbWVudGF0aW9uIG9mIGEgUFJORyBhY2NvcmRpbmcgdG8gR2VvcmdlIE1hcnNhZ2xpYQ==ICM=IG5hbWVzcGFjZSBldmFsIDo6UFJORyB7ICAgICB2YXJpYWJsZSBtb2QgW2V4cHIge3dpZGUoMjU2KSp3aWRlKDI1Nikqd2lkZSgyNTYpKndpZGUoMjU2KS01fV0=ICAgICB2YXJpYWJsZSBmYWMgW2V4cHIge3dpZGUoMjU2KSp3aWRlKDMyKX1dICAgICB2YXJpYWJsZSB4MSBbZXhwciB7d2lkZSgkbW9kKnJhbmQoKSl9XQ==ICAgICB2YXJpYWJsZSB4MiBbZXhwciB7d2lkZSgkbW9kKnJhbmQoKSl9XQ==ICAgICB2YXJpYWJsZSB4MyBbZXhwciB7d2lkZSgkbW9kKnJhbmQoKSl9XQ==ICAgICBwdXRzICRtb2Q=IH0=IHByb2MgOjpQUk5HOjptYXJzYWdsaWEge30gew==ICAgICB2YXJpYWJsZSBtb2Q=ICAgICB2YXJpYWJsZSBmYWM=ICAgICB2YXJpYWJsZSB4MQ==ICAgICB2YXJpYWJsZSB4Mg==ICAgICB2YXJpYWJsZSB4Mw==ICAgICBzZXQgeG4gW2V4cHIgeygkZmFjKigkeDMrJHgyKyR4MSkpJSRtb2R9XQ==ICAgICBzZXQgeDEgJHgyICAgICBzZXQgeDIgJHgzICAgICBzZXQgeDMgJHhuICAgICByZXR1cm4gW2V4cHIgeyR4bi9kb3VibGUoJG1vZCl9XQ==IH0=
This document is placed in the public domain