00001 /* 00002 ------------------------------------------------------------------- 00003 00004 Copyright (C) 2006, 2007, 2008, 2009, 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 #include <o2scl/collection.h> 00029 00030 #ifndef DOXYGENP 00031 namespace o2scl { 00032 #endif 00033 00034 /** 00035 \brief Random number generator base 00036 00037 Using virtual functions is not recommended for random 00038 number generators, as speed is often an important issue. In 00039 order to facilitate the use of templates for routines which 00040 require random number generators, all descendants ought to 00041 provides the following functions: 00042 - double random() - Provide a random number in [0.0,1.0) 00043 - unsigned long int random_int(unsigned long int n) - 00044 Provide a random integer in [0,n-1] 00045 - unsigned long int get_max() - Return the maximum integer 00046 for the random number generator. The argument to random_int() 00047 should be less than the value returned by get_max(). 00048 00049 \future Consider some analog of the GSL function 00050 <tt>gsl_rng_uniform_pos()</tt>, i.e. as used in the GSL Monte 00051 Carlo classes. 00052 00053 */ 00054 class rnga { 00055 public: 00056 00057 rnga() {}; 00058 00059 /** \brief Initialize the seed with a value taken from the computer 00060 clock 00061 00062 This is a naive seed generator which uses <tt>seed=time(0)</tt> 00063 to generate a seed. 00064 00065 \future Figure out a better way of computing a random 00066 seed in a platform-independent way. 00067 */ 00068 void clock_seed(); 00069 00070 /// Get the seed 00071 unsigned long int get_seed() { return seed; } 00072 00073 /// Set the seed 00074 void set_seed(unsigned long int s) { seed=s; } 00075 00076 protected: 00077 00078 #ifndef DOXYGEN_INTERNAL 00079 00080 /// The seed 00081 unsigned long int seed; 00082 00083 rnga(const rnga &); 00084 rnga& operator=(const rnga&); 00085 00086 #endif 00087 00088 }; 00089 00090 #ifndef DOXYGENP 00091 } 00092 #endif 00093 00094 #endif
Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.
Project hosting provided by
,
O2scl Sourceforge Project Page