1 /* 2 * Copyright (C) 2015, 2016 Christoph L. Spiel 3 * 4 * This file is part of Enblend. 5 * 6 * Enblend is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * Enblend is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with Enblend; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 */ 20 21 #ifndef MERSENNE_H_INCLUDED_ 22 #define MERSENNE_H_INCLUDED_ 23 24 #ifdef HAVE_CONFIG_H 25 #include <config.h> 26 #endif 27 28 #include <gsl/gsl_rng.h> 29 30 31 class MersenneTwister 32 { 33 public: 34 typedef unsigned long result_type; 35 36 MersenneTwister(); 37 MersenneTwister(const MersenneTwister& another_generator); 38 virtual ~MersenneTwister(); 39 40 MersenneTwister& operator=(const MersenneTwister& another_generator); 41 min()42 result_type min() const {return gsl_rng_min(generator_);} max()43 result_type max() const {return gsl_rng_max(generator_);} 44 45 void seed(); 46 void seed(result_type a_seed); 47 operator()48 result_type operator()() {return gsl_rng_get(generator_);} 49 50 private: 51 gsl_rng* generator_; 52 }; // class MersenneTwister 53 54 55 class UniformMersenneTwister : public MersenneTwister 56 { 57 public: 58 void non_deterministic_seed(); 59 get()60 result_type get() {return this->operator()();} get_uniform()61 double get_uniform() {return static_cast<double>(get()) / static_cast<double>(max());} 62 }; // class UniformMersenneTwister 63 64 65 #endif // MERSENNE_H_INCLUDED_ 66 67 // Local Variables: 68 // mode: c++ 69 // End: 70