Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

random_generator.h

Go to the documentation of this file.
00001 //  This random generator is a C++ wrapper for the GNU Scientific Library
00002 //  Copyright (C) 2001 Torbjorn Vik
00003 
00004 //  This program is free software; you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation; either version 2 of the License, or
00007 //  (at your option) any later version.
00008 
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program; if not, write to the Free Software
00016 //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 #ifndef __random_generator_h
00018 #define __random_generator_h
00019 
00020 #include "gsl/gsl_rng.h"
00021 #include <string>
00022 
00023 namespace gsl
00024 {
00025 
00026 //class RandomNumberGenerator 
00027 class random_generator 
00028 {
00029 public:
00030 // Construction and Initializing:
00032         random_generator (const random_generator& other) : generator(NULL) {generator = gsl_rng_clone(other.generator);}
00033         random_generator (const gsl_rng_type* type=NULL, unsigned long int seed=0) : generator(NULL)
00034         {
00035                 gsl_rng_env_setup();
00036                 if (!type)
00037                 {
00038                         generator = gsl_rng_alloc (gsl_rng_default);
00039                 }
00040                 else 
00041                 {
00042                         generator = gsl_rng_alloc (type) ; 
00043                         if (seed)
00044                                 gsl_rng_set(generator, seed);
00045                 }
00046         }
00047         ~random_generator () {gsl_rng_free(generator);}
00048         random_generator& operator=(const random_generator& other){if (generator) gsl_rng_free(generator); generator = gsl_rng_clone(other.generator);return *this;}
00049         void set(unsigned long int seed){gsl_rng_set(generator, seed);}
00050         
00051 // Sampling:
00052         unsigned long int get(unsigned long int n=0) {if (n) return gsl_rng_uniform_int(generator, n); else return gsl_rng_get(generator);}
00053         double uniform() { return gsl_rng_uniform(generator);}
00054         double uniform_positive() { return gsl_rng_uniform_pos(generator);}
00055 
00056 // Information:
00057         string name(){return gsl_rng_name(generator);}
00058         unsigned long int max(){return gsl_rng_max(generator);}
00059         unsigned long int min(){return gsl_rng_min(generator);}
00060 
00061 // For calling gsl functions directly
00062         gsl_rng*       gslobj()       { return generator;}
00063         const gsl_rng* gslobj() const { return generator;}
00064 //      static void Test();
00065 private:
00066         gsl_rng* generator;
00067 };
00068 
00069 }
00070 
00071 #endif //__random_generator_h

Generated at Sun Dec 16 23:44:43 2001 for gslwrap by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001