IT++ Logo Newcom Logo

itpp::Random_Generator Class Reference
[Random Number Generation]

Base class for random (stochastic) sources. More...

#include <itpp/base/random.h>

List of all members.

Public Member Functions

 Random_Generator ()
 Construct a new Random_Generator.
void randomize ()
 Set the seed to a semi-random value (based on hashed time and clock).
void reset ()
 Reset the source. The same sequance will be generated as the last time.
void reset (unsigned int seed)
 Reset the source after setting the seed to seed.
unsigned int random_int ()
 Return a uniformly distributed [0,2^32-1] integer.
double random_01 ()
 Return a uniformly distributed (0,1) value.
double random_01_closed ()
 Return a uniformly distributed [0,1] value.
void get_state (ivec &out_state)
 Save current full state of generator in memory.
void set_state (ivec &new_state)
 Resume the state saved in memory. Clears memory.


Detailed Description

Base class for random (stochastic) sources.

The Random_Generator class is based on the MersenneTwister MTRand class code in version 1.0 (15 May 2003) by Richard J. Wagner. See http://www-personal.engin.umich.edu/~wagnerr/MersenneTwister.html for details.

Here are the original release notes copied from the MersenneTwister.h file:

   * Mersenne Twister random number generator -- a C++ class MTRand Based on
   * code by Makoto Matsumoto, Takuji Nishimura, and Shawn Cokus Richard J.
   * Wagner v1.0 15 May 2003 rjwagner@writeme.com
   *
   * The Mersenne Twister is an algorithm for generating random numbers. It
   * was designed with consideration of the flaws in various other generators.
   * The period, 2^19937-1, and the order of equidistribution, 623 dimensions,
   * are far greater. The generator is also fast; it avoids multiplication and
   * division, and it benefits from caches and pipelines. For more information
   * see the inventors' web page at
   * http://www.math.keio.ac.jp/~matumoto/emt.html

   * Reference:
   * M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-Dimensionally
   * Equidistributed Uniform Pseudo-Random Number Generator", ACM Transactions
   * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp. 
   * 3-30.
   *
   * Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
   * Copyright (C) 2000 - 2003, Richard J. Wagner
   * All rights reserved.                          
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   *   1. Redistributions of source code must retain the above copyright
   *      notice, this list of conditions and the following disclaimer.
   *
   *   2. 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.
   *
   *   3. 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.
   *
   * The original code included the following notice:
   *
   *     When you use this, send an email to: matumoto@math.keio.ac.jp with an
   *     appropriate reference to your work.
   *
   * It would be nice to CC: rjwagner@writeme.com and
   * Cokus@math.washington.edu when you write.
   * 

Definition at line 115 of file random.h.


Constructor & Destructor Documentation

itpp::Random_Generator::Random_Generator (  ) 

Construct a new Random_Generator.

Definition at line 50 of file random.cpp.

References itpp::__Random_Generator_seed_is_initialized, and reset().


Member Function Documentation

void itpp::Random_Generator::randomize (  ) 

Set the seed to a semi-random value (based on hashed time and clock).

Definition at line 82 of file random.cpp.

References reset().

Referenced by itpp::RNG_randomize().

void itpp::Random_Generator::reset (  )  [inline]

Reset the source. The same sequance will be generated as the last time.

Definition at line 122 of file random.h.

Referenced by Random_Generator(), randomize(), and itpp::RNG_reset().

void itpp::Random_Generator::reset ( unsigned int  seed  )  [inline]

Reset the source after setting the seed to seed.

Definition at line 124 of file random.h.

unsigned int itpp::Random_Generator::random_int (  )  [inline]

Return a uniformly distributed [0,2^32-1] integer.

Definition at line 126 of file random.h.

Referenced by random_01(), and random_01_closed().

double itpp::Random_Generator::random_01 (  )  [inline]

Return a uniformly distributed (0,1) value.

Definition at line 140 of file random.h.

References random_int().

Referenced by itpp::Complex_Normal_RNG::sample(), itpp::Laplace_RNG::sample(), itpp::Normal_RNG::sample(), itpp::Uniform_RNG::sample(), itpp::I_Uniform_RNG::sample(), and itpp::Bernoulli_RNG::sample().

double itpp::Random_Generator::random_01_closed (  )  [inline]

Return a uniformly distributed [0,1] value.

Definition at line 142 of file random.h.

References random_int().

void itpp::Random_Generator::get_state ( ivec &  out_state  ) 

Save current full state of generator in memory.

Definition at line 88 of file random.cpp.

Referenced by itpp::RNG_get_state().

void itpp::Random_Generator::set_state ( ivec &  new_state  ) 

Resume the state saved in memory. Clears memory.

Definition at line 97 of file random.cpp.

References it_assert.

Referenced by itpp::RNG_set_state().


The documentation for this class was generated from the following files:
SourceForge Logo

Generated on Fri Jun 8 00:37:37 2007 for IT++ by Doxygen 1.5.2