Version 0 of random

Updated 2003-04-14 21:13:53

This is a package that provides alternative pseudo-random number generators.

mt_rand() is based upon the Mersenne Twister PRNG algorithm ([L1 ], [L2 ]). This PRNG has an enormous period (in fact it is 2**19937-1 which is a Mersenne Prime, hence the name). It is also suposedly faster than the standard C library rand() function. Furthermore, while the stock Tcl rand function generates numbers in the range (0,1) - randmt produces numbers in the range [0,1]. If required, it can also produce values within (0,1) as well as integer values (any 32bit value) - we would just need some names for these functions.

isaac_rand() uses the ISAAC algorithm [L3 ] by Bob Jenkins. ISAAC (Indirection, Shift, Accumulate, Add, and Count) generates 32-bit random numbers. The period is guaranteed to be at least 2**40 and is 2**8295 on average. The results are uniformly distributed, unbiased, and unpredictable unless you know the seed. This PRNG is suitable for cryptographic use provided a suitably random seed can be provided.

Currently the code is available at

 cvs -d:pserver:[email protected]:/cvsroot/tclsoap co Random

and the distributable files are at in the downloads section.


  # Seed and use the Mersenne Twister PRNG
  % expr {mt_srand(0)}
  % expr {mt_rand()}

  # Seed and use the ISAAC PRNG
  % expr {isaac_srand(0)}
  % expr {isaac_rand()}

  # Extended ISAAC commands
  # Provide extra seed data (up to 256 values can be used)
  % ::isaac::isaac seed "\x01\x02\x03\x04\x05"

  # Get integers from the PRNG (must have been seeded already)
  % ::isaac::isaac integer

  # Get doubles (equivalent to the expr function)
  % ::isaac::isaac double

[ Category Mathematics | Category Package ]