NEST  2.6.0,not_revisioned_source_dir@0
uniformint_randomdev.h
Go to the documentation of this file.
1 /*
2  * uniformint_randomdev.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 #ifndef UNIFORMINT_RANDOMDEV_H
24 #define UNIFORMINT_RANDOMDEV_H
25 
26 #include <cmath>
27 #include "randomgen.h"
28 #include "randomdev.h"
29 #include "lockptr.h"
30 
31 /************************************************************/
32 /* Class UniformIntRNG */
33 /* */
34 /* Generates an RNG which returns integer random numbers */
35 /* uniformly distributed between two limits. */
36 /* */
37 /* Arguments: */
38 /* - pointer to an RNG */
39 /* */
40 /* Author: */
41 /* Hans Ekkehard Plesser */
42 /* */
43 /* History: */
44 /* HEP, 2004-08-05 */
45 /* */
46 /************************************************************/
47 
48 namespace librandom {
49 
50 /*BeginDocumentation
51 Name: rdevdict::uniform_int - uniform integer random deviate generator
52 Description: Generates uniformly distributed integers between two given limits
53 
54  p(n) = 1 / (high - low + 1), n = low, low+1, ..., high
55 
56 Parameters:
57  low - smallest allowed random number
58  high - largest allowed random number
59 
60 SeeAlso: CreateRDV, RandomArray, rdevdict
61 Author: Hans Ekkehard Plesser
62 */
63 
72  {
73 
74  public:
75 
76  // accept only lockPTRs for initialization,
77  // otherwise creation of a lock ptr would
78  // occur as side effect---might be unhealthy
80  UniformIntRandomDev(); // threaded
81 
90  using RandomDev::operator();
91  using RandomDev::ldev;
92 
93  long ldev(RngPtr) const;
94  bool has_ldev() const { return true; }
95 
96  double operator()(RngPtr rthrd) const; // threaded
97 
99  void set_status(const DictionaryDatum&);
100 
102  void get_status(DictionaryDatum&) const;
103 
104  private:
105  long nmin_;
106  long nmax_;
107  long range_;
108  };
109 
110  inline
112  {
113  return static_cast<double>(ldev(rthrd));
114  }
115 
116  inline
118  {
119  assert(range_ > 0);
120  return nmin_ + r_s->ulrand(range_);
121  }
122 }
123 
124 # endif
125 
126 
127 
128 
129 
130 
131 
132 
133 
134 
135 
136 
137 
138 
139 
140 
141 
142 
virtual double operator()(void)
Operator delivering doubles.
Definition: randomdev.h:199
void set_status(const DictionaryDatum &)
set distribution parameters from SLI dict
Definition: uniformint_randomdev.cpp:48
Class UniformIntRandomDev Create uniformly distributed random integers from a given range...
Definition: uniformint_randomdev.h:71
long nmax_
largest permissible number
Definition: uniformint_randomdev.h:106
assert(pNet!=0)
long nmin_
smallest permissible number
Definition: uniformint_randomdev.h:105
bool has_ldev() const
true if RDG implements ldev function
Definition: uniformint_randomdev.h:94
long range_
nmax_ - nmin_ + 1
Definition: uniformint_randomdev.h:107
UniformIntRandomDev()
Definition: uniformint_randomdev.cpp:40
void get_status(DictionaryDatum &) const
get distribution parameters from SLI dict
Definition: uniformint_randomdev.cpp:68
Abstract base class for access to non-uniform random deviate generators.
Definition: randomdev.h:131
virtual long ldev(void)
integer valued functions for discrete distributions
Definition: randomdev.h:206