EMAN2
randnum.h
Go to the documentation of this file.
1/*
2 * Author: Grant Tang, 03/10/2008 (gtang@bcm.edu)
3 * Copyright (c) 2000-2006 Baylor College of Medicine
4 *
5 * This software is issued under a joint BSD/GNU license. You may use the
6 * source code in this file under either license. However, note that the
7 * complete EMAN2 and SPARX software packages have some GPL dependencies,
8 * so you are responsible for compliance with the licenses of these packages
9 * if you opt to use BSD licensing. The warranty disclaimer below holds
10 * in either instance.
11 *
12 * This complete copyright notice must be included in any revised version of the
13 * source code. Additional authorship citations may be added, but existing
14 * author citations must be preserved.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 *
30 * */
31
32#ifndef randnum_h__
33#define randnum_h__
34
35#include <gsl/gsl_rng.h>
36
37namespace EMAN
38{
86 class Randnum {
87 public:
88 static Randnum * Instance();
89 static Randnum * Instance(const gsl_rng_type * _t);
90
101 void set_seed(unsigned long long seed);
102
106 unsigned long long get_seed();
107
115 long long get_irand(long long lo, long long hi) const;
116
123 float get_frand(double lo=0.0, double hi=1.0) const;
124
131 float get_frand_pos(double lo=0.0, double hi=1.0) const;
132
139 float get_gauss_rand(float mean, float sigma) const;
140
142 void print_generator_type() const;
143
144 protected:
148 Randnum();
150
158 explicit Randnum(const gsl_rng_type * _t);
159
160 ~Randnum();
161
162
163
164 private:
165 const static gsl_rng_type * T;
166 static gsl_rng * r;
167 static unsigned long long _seed;
168
170 };
171
172}
173
174#endif //randnum_h__
The wrapper class for gsl's random number generater.
Definition: randnum.h:86
static unsigned long long _seed
Definition: randnum.h:167
void print_generator_type() const
print out all possible random number generator type in gsl
Definition: randnum.cpp:190
void set_seed(unsigned long long seed)
Set the seed for the random number generator.
Definition: randnum.cpp:142
static const gsl_rng_type * T
Definition: randnum.h:165
static Randnum * Instance()
Definition: randnum.cpp:104
static Randnum * _instance
Definition: randnum.h:169
Randnum()
The default constructor will use the gsl default random number generator gal_rng_mt19937.
Definition: randnum.cpp:125
long long get_irand(long long lo, long long hi) const
This function returns a random integer from lo to hi inclusive.
Definition: randnum.cpp:153
Randnum(const Randnum &)
unsigned long long get_seed()
Get the current random number seed.
Definition: randnum.cpp:148
float get_gauss_rand(float mean, float sigma) const
Return a Gaussian random number.
Definition: randnum.cpp:168
float get_frand(double lo=0.0, double hi=1.0) const
This function returns a random float from lo inclusive to hi.
Definition: randnum.cpp:158
float get_frand_pos(double lo=0.0, double hi=1.0) const
This function returns a random float from lo to hi.
Definition: randnum.cpp:163
static gsl_rng * r
Definition: randnum.h:166
E2Exception class.
Definition: aligner.h:40