GNU Radio Manual and C++ API Reference  3.7.9.2
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
random.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2002, 2015 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef INCLUDED_GR_RANDOM_H
24 #define INCLUDED_GR_RANDOM_H
25 
26 #include <gnuradio/api.h>
27 #include <gnuradio/gr_complex.h>
28 
29 #include <stdlib.h>
30 #include <boost/random.hpp>
31 #include <ctime>
32 
33 namespace gr {
34 
35  /*!
36  * \brief pseudo random number generator
37  * \ingroup math_blk
38  */
40  {
41  protected:
42  long d_seed;
45 
46  boost::mt19937 *d_rng; // mersenne twister as random number generator
47  boost::uniform_real<float> *d_uniform; // choose uniform distribution, default is [0,1)
48  boost::random::uniform_int_distribution<> *d_integer_dis;
49  boost::variate_generator<boost::mt19937&, boost::uniform_real<float> > *d_generator;
50  boost::variate_generator<boost::mt19937&, boost::random::uniform_int_distribution<> > *d_integer_generator;
51 
52  public:
53  random(unsigned int seed=0, int min_integer = 0, int max_integer = 2);
54  ~random();
55 
56  /*!
57  * \brief Change the seed for the initialized number generator. seed = 0 initializes the random number generator with the system time. Note that a fast initialization of various instances can result in the same seed.
58  */
59  void reseed(unsigned int seed);
60 
61  /*!
62  * set minimum and maximum for integer random number generator.
63  * Limits are [minimum, maximum)
64  * Default: [0, std::numeric_limits< IntType >::max)]
65  */
66  void set_integer_limits(const int minimum, const int maximum);
67 
68  /*!
69  * Uniform random integers in the range set by 'set_integer_limits' [min, max).
70  */
71  int ran_int();
72 
73  /*!
74  * \brief Uniform random numbers in the range [0.0, 1.0)
75  */
76  float ran1();
77 
78  /*!
79  * \brief Normally distributed random numbers (Gaussian distribution with zero mean and variance 1)
80  */
81  float gasdev();
82 
83  /*!
84  * \brief Laplacian distributed random numbers with zero mean and variance 1
85  */
86  float laplacian();
87 
88  /*!
89  * \brief Rayleigh distributed random numbers (zero mean and variance 1 for the underlying Gaussian distributions)
90  */
91  float rayleigh();
92 
93  /*!
94  * \brief FIXME: add description
95  */
96  float impulse(float factor);
97 
98  /*!
99  * \brief Normally distributed random numbers with zero mean and variance 1 on real and imaginary part. This results in a Rayleigh distribution for the amplitude and an uniform distribution for the phase.
100  */
101  gr_complex rayleigh_complex();
102  };
103 
104 } /* namespace gr */
105 
106 #endif /* INCLUDED_GR_RANDOM_H */
107 
float d_gauss_value
Definition: random.h:44
boost::variate_generator< boost::mt19937 &, boost::random::uniform_int_distribution<> > * d_integer_generator
Definition: random.h:50
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:30
boost::uniform_real< float > * d_uniform
Definition: random.h:47
std::complex< float > gr_complex
Definition: gr_complex.h:27
Include this header to use the message passing features.
Definition: logger.h:131
boost::random::uniform_int_distribution * d_integer_dis
Definition: random.h:48
long d_seed
Definition: random.h:42
boost::variate_generator< boost::mt19937 &, boost::uniform_real< float > > * d_generator
Definition: random.h:49
bool d_gauss_stored
Definition: random.h:43
boost::mt19937 * d_rng
Definition: random.h:46
pseudo random number generator
Definition: random.h:39