NEST  2.6.0,not_revisioned_source_dir@0
gslrandomgen.h
Go to the documentation of this file.
1 /*
2  * gslrandomgen.h
3  *
4  * This file is part of NEST.
5  *
6  * Copyright (C) 2004 The NEST Initiative
7  *
8  * NEST is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * NEST is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with NEST. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 /*
24  * Interface to GSL Random Number Generators
25  *
26  */
27 
28 #ifndef GSLRANDOMGEN_H
29 #define GSLRANDOMGEN_H
30 
31 #include <cassert>
32 #include <list>
33 #include <string>
34 #include "config.h"
35 #include "dictdatum.h"
36 #include "randomgen.h"
37 #include "random_datums.h"
38 
39 // essential GSL includes or replacements
40 // GSL Versions < 1.2 have weak MT seeding
41 #ifdef HAVE_GSL_1_2
42 
43 // "Real" version in presence of GSL
44 
45 #include <gsl/gsl_rng.h>
46 
47 namespace librandom {
48 
58  class GslRandomGen : public RandomGen
59  {
60  friend class GSL_BinomialRandomDev;
61 
62  public:
63  explicit GslRandomGen(const gsl_rng_type *,
64  unsigned long);
65 
66  ~GslRandomGen();
67 
69  static void add_gsl_rngs(Dictionary&);
70 
71  RngPtr clone(unsigned long s)
72  {
73  return RngPtr(new GslRandomGen(rng_type_, s));
74  }
75 
76 
77  private:
78  void seed_(unsigned long);
79  double drand_(void);
80 
81  private:
82  gsl_rng_type const *rng_type_;
83  gsl_rng *rng_;
84 
85  };
86 
87  inline
88  void GslRandomGen::seed_(unsigned long s)
89  {
90  gsl_rng_set(rng_, s);
91  }
92 
93  inline
94  double GslRandomGen::drand_(void)
95  {
96  return gsl_rng_uniform(rng_);
97  }
98 
101  {
102  public:
103  GslRNGFactory(gsl_rng_type const * const);
104  RngPtr create(unsigned long) const;
105  private:
107  gsl_rng_type const * const gsl_rng_;
108  };
109 
110 }
111 
112 #else
113 
114 // NO GSL Available---Implement class as empty shell
115 namespace librandom {
116 
117  class GslRandomGen : public RandomGen
118  {
119  public:
122  static void add_gsl_rngs(Dictionary&) {}
123 
124  private:
125  GslRandomGen() { assert(false); }
126  ~GslRandomGen() { assert(false); }
127  };
128 
129 }
130 
131 #endif
132 
133 
134 #endif
gsl_rng * rng_
Definition: gslrandomgen.h:83
Factory class for GSL-based random generators.
Definition: gslrandomgen.h:100
RngPtr clone(unsigned long s)
clone a random number generator of same type initialized with given seed
Definition: gslrandomgen.h:71
~GslRandomGen()
Definition: gslrandomgen.cpp:38
Class GSL_BinomialRandomDev.
Definition: gsl_binomial_randomdev.h:81
assert(pNet!=0)
A class that associates names and tokens.
Definition: dict.h:45
lockPTR< RandomGen > RngPtr
Common lock-pointer type for RNG.
Definition: randomgen.h:208
Factory class for random generators.
Definition: randomgen.h:314
double drand_(void)
drawing interface
Definition: gslrandomgen.h:94
GslRNGFactory(gsl_rng_type const *const)
Definition: gslrandomgen.cpp:65
class GslRandomGen C++ wrapper for GSL/GSL-style generators.
Definition: gslrandomgen.h:58
GslRandomGen()
Definition: gslrandomgen.h:125
Abstract base class for all random generator objects.
Definition: randomgen.h:238
RngPtr create(unsigned long) const
Create generator with given seed.
Definition: gslrandomgen.cpp:71
static void add_gsl_rngs(Dictionary &)
Add all GSL RNGs to rngdict Do nothing if GSL not available.
Definition: gslrandomgen.h:122
gsl_rng_type const * rng_type_
Definition: gslrandomgen.h:82
void seed_(unsigned long)
The following functions provide the interface to the actual random generator.
Definition: gslrandomgen.h:88
static void add_gsl_rngs(Dictionary &)
Add all GSL RNGs to rngdict.
Definition: gslrandomgen.cpp:45
gsl_rng_type const *const gsl_rng_
GSL generator type information.
Definition: gslrandomgen.h:107