Object-oriented Scientific Computing Library: Version 0.910
rnga.h
00001 /*
00002   -------------------------------------------------------------------
00003   
00004   Copyright (C) 2006-2012, Andrew W. Steiner
00005   
00006   This file is part of O2scl.
00007   
00008   O2scl is free software; you can redistribute it and/or modify
00009   it under the terms of the GNU General Public License as published by
00010   the Free Software Foundation; either version 3 of the License, or
00011   (at your option) any later version.
00012   
00013   O2scl is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016   GNU General Public License for more details.
00017   
00018   You should have received a copy of the GNU General Public License
00019   along with O2scl. If not, see <http://www.gnu.org/licenses/>.
00020 
00021   -------------------------------------------------------------------
00022 */
00023 #ifndef O2SCL_RNGA_H
00024 #define O2SCL_RNGA_H
00025 
00026 #include <iostream>
00027 #include <ctime>
00028 
00029 #ifndef DOXYGENP
00030 namespace o2scl {
00031 #endif
00032 
00033   /** \brief Random number generator base
00034 
00035       Using virtual functions is not recommended for random
00036       number generators, as speed is often an important issue. In
00037       order to facilitate the use of templates for routines which
00038       require random number generators, all descendants ought to
00039       provides the following functions:
00040       - double random() - Provide a random number in [0.0,1.0)
00041       - unsigned long int random_int(unsigned long int n) - 
00042       Provide a random integer in [0,n-1]
00043       - unsigned long int get_max() - Return the maximum integer
00044       for the random number generator. The argument to random_int()
00045       should be less than the value returned by get_max().
00046 
00047       \future Consider some analog of the GSL function
00048       <tt>gsl_rng_uniform_pos()</tt>, i.e. as used in the GSL Monte
00049       Carlo classes.
00050       
00051   */
00052   class rnga {
00053   public:
00054 
00055     rnga() {};
00056 
00057     /** \brief Initialize the seed with a value taken from the computer 
00058         clock
00059         
00060         This is a naive seed generator which uses <tt>seed=time(0)</tt>
00061         to generate a seed.
00062 
00063         \future Figure out a better way of computing a random
00064         seed in a platform-independent way.
00065     */
00066     void clock_seed();
00067 
00068     /// Get the seed
00069     unsigned long int get_seed() { return seed; }
00070 
00071     /// Set the seed
00072     void set_seed(unsigned long int s) { seed=s; }
00073 
00074   protected:
00075 
00076 #ifndef DOXYGEN_INTERNAL
00077 
00078     /// The seed
00079     unsigned long int seed;  
00080 
00081     rnga(const rnga &);
00082     rnga& operator=(const rnga&);
00083 
00084 #endif
00085   
00086   };
00087 
00088 #ifndef DOXYGENP
00089 }
00090 #endif
00091 
00092 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).

Get Object-oriented Scientific Computing
Lib at SourceForge.net. Fast, secure and Free Open Source software
downloads.