00001 /* 00002 ------------------------------------------------------------------- 00003 00004 Copyright (C) 2006, 2007, 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 */ 00050 class rnga { 00051 public: 00052 00053 rnga() {}; 00054 00055 /** \brief Initialize the seed with a value taken from the computer 00056 clock 00057 00058 This is a naive seed generator which uses \c seed=time(NULL) 00059 to generate a seed. 00060 00061 \todo Ensure this function is ANSI compatible 00062 */ 00063 void clock_seed(); 00064 00065 /// Get the seed 00066 unsigned long int get_seed() { return seed; } 00067 00068 /// Set the seed 00069 void set_seed(unsigned long int s) { seed=s; } 00070 00071 protected: 00072 00073 #ifndef DOXYGEN_INTERNAL 00074 00075 /// The seed 00076 unsigned long int seed; 00077 00078 rnga(const rnga &); 00079 rnga& operator=(const rnga&); 00080 00081 #endif 00082 00083 }; 00084 00085 #ifndef DOXYGENP 00086 } 00087 #endif 00088 00089 #endif