BioND — Dynamics of Biological Networks

MyRNG: A convenient random number generator

About the class

The myrng c++ class provides two very efficient random number generators and several methods for generating random variates. You can chose between the Marsenne Twister MT19937a algorithm in the implementation by Makoto Matsumoto and Takuji Nishimura [1] and the well equidistributed long-period linear generator WELL1024a [2] implemented by Marton Morvai. Both generators are essentially shuffled linear congruential random number generators; they should not be used for cryptography applications but should otherwise cover most scientific needs. While the WELL1024a is slightly faster in the current implementation, the MT19937a has an astronomical recurrence time of 2^19937. Furthermore, the class provides several random variates including uniform, gaussian, beta, and gamma distributions. Generation of most random variates is based on Law and Kelton, 2000 [3]. Generation of the gamma distribution is based on Marsagli and Tsang, 2000 [4].

Getting started

To use the class include EITHER myrngMT.h (MT19937a) OR myrangWELL.h (WELL1024a) in your code. Including the header Files creates an instance of the generator class called rng. You can then use the generator by calling a member function of the generator. For instance rng.Uniform01() returns a uniformly distributed random variable between 0 and 1. For further information see the detailed documentation.

License and Copyright

myrng class by Marton Morvai and Thilo Gross.
Marsenne Twister code and algorithm: Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • The names of its contributors may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

References

[1] M. Matsumoto and T. Nishimura. Personal web pages.
[2] F. Panneton et al.: Improved long-period generators based on linear recurrences modulo 2, ACM Transactions on Mathematical Software, 32(1), 1-16,2006.
[3] A.M. Law and W.D. Kelton: Simulation, modeling and analysis, Third Edition, McGraw Hill, 2006.
[4] G. Marsaglia and W.W. Tsang: A simple method for generating gamma variables, ACM TOMS 26, 2000.

Version Log

Version 1.0 by Thilo Gross (basic functionality)
Version 1.1 by Thilo Gross (cleanup and extended documentation)
Version 1.2 by Marton Morvai (now include WELL1024a, MT19937a and generation of gamma distribution)

Files