00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00027 class random_generator
00028 {
00029 public:
00030
00032
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
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
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
00062 gsl_rng* gslobj() { return generator;}
00063 const gsl_rng* gslobj() const { return generator;}
00064
00065 private:
00066 gsl_rng* generator;
00067 };
00068
00069 }
00070
00071 #endif //__random_generator_h