GNU Radio Manual and C++ API Reference  3.8.1.0
The Free & Open Software Radio Ecosystem
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>*
48  d_uniform; // choose uniform distribution, default is [0,1)
49  boost::uniform_int<>* d_integer_dis;
50  boost::variate_generator<boost::mt19937&, boost::uniform_real<float>>* d_generator;
51  boost::variate_generator<boost::mt19937&, boost::uniform_int<>>* d_integer_generator;
52 
53 public:
54  random(unsigned int seed = 0, int min_integer = 0, int max_integer = 2);
55  ~random();
56 
57  /*!
58  * \brief Change the seed for the initialized number generator. seed = 0 initializes
59  * the random number generator with the system time. Note that a fast initialization
60  * of various instances can result in the same seed.
61  */
62  void reseed(unsigned int seed);
63 
64  /*!
65  * set minimum and maximum for integer random number generator.
66  * Limits are [minimum, maximum)
67  * Default: [0, std::numeric_limits< IntType >::max)]
68  */
69  void set_integer_limits(const int minimum, const int maximum);
70 
71  /*!
72  * Uniform random integers in the range set by 'set_integer_limits' [min, max).
73  */
74  int ran_int();
75 
76  /*!
77  * \brief Uniform random numbers in the range [0.0, 1.0)
78  */
79  float ran1();
80 
81  /*!
82  * \brief Normally distributed random numbers (Gaussian distribution with zero mean
83  * and variance 1)
84  */
85  float gasdev();
86 
87  /*!
88  * \brief Laplacian distributed random numbers with zero mean and variance 1
89  */
90  float laplacian();
91 
92  /*!
93  * \brief Rayleigh distributed random numbers (zero mean and variance 1 for the
94  * underlying Gaussian distributions)
95  */
96  float rayleigh();
97 
98  /*!
99  * \brief Exponentially distributed random numbers with values less than or equal
100  * to factor replaced with zero. The underlying exponential distribution has
101  * mean sqrt(2) and variance 2.
102  */
103  float impulse(float factor);
104 
105  /*!
106  * \brief Normally distributed random numbers with zero mean and variance 1 on real
107  * and imaginary part. This results in a Rayleigh distribution for the amplitude and
108  * an uniform distribution for the phase.
109  */
110  gr_complex rayleigh_complex();
111 };
112 
113 } /* namespace gr */
114 
115 #endif /* INCLUDED_GR_RANDOM_H */
float d_gauss_value
Definition: random.h:44
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:30
boost::uniform_real< float > * d_uniform
Definition: random.h:48
std::complex< float > gr_complex
Definition: gr_complex.h:27
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:43
long d_seed
Definition: random.h:42
boost::uniform_int * d_integer_dis
Definition: random.h:49
boost::variate_generator< boost::mt19937 &, boost::uniform_real< float > > * d_generator
Definition: random.h:50
boost::variate_generator< boost::mt19937 &, boost::uniform_int<> > * d_integer_generator
Definition: random.h:51
bool d_gauss_stored
Definition: random.h:43
boost::mt19937 * d_rng
Definition: random.h:46
pseudo random number generator
Definition: random.h:39