GNU Radio Manual and C++ API Reference 3.9.4.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 * SPDX-License-Identifier: GPL-3.0-or-later
8 *
9 */
10
11#ifndef INCLUDED_GR_RANDOM_H
12#define INCLUDED_GR_RANDOM_H
13
14#include <gnuradio/api.h>
15#include <gnuradio/gr_complex.h>
16
17#include <cstdlib>
18#include <ctime>
19#include <random>
20
21namespace gr {
22
23/*!
24 * \brief pseudo random number generator
25 * \ingroup math_blk
26 */
28{
29protected:
30 long d_seed;
33
34 std::mt19937 d_rng; // mersenne twister as random number generator
35 std::uniform_real_distribution<float>
36 d_uniform; // choose uniform distribution, default is [0,1)
37 std::uniform_int_distribution<> d_integer_dis;
38
39public:
40 random(unsigned int seed = 0, int min_integer = 0, int max_integer = 2);
42
43 /*!
44 * \brief Change the seed for the initialized number generator. seed = 0 initializes
45 * the random number generator with the system time.
46 */
47 void reseed(unsigned int seed);
48
49 /*!
50 * set minimum and maximum for integer random number generator.
51 * Limits are [minimum, maximum)
52 * Default: [0, std::numeric_limits< IntType >::max)]
53 */
54 void set_integer_limits(const int minimum, const int maximum);
55
56 /*!
57 * Uniform random integers in the range set by 'set_integer_limits' [min, max).
58 */
59 int ran_int();
60
61 /*!
62 * \brief Uniform random numbers in the range [0.0, 1.0)
63 */
64 float ran1();
65
66 /*!
67 * \brief Normally distributed random numbers (Gaussian distribution with zero mean
68 * and variance 1)
69 */
70 float gasdev();
71
72 /*!
73 * \brief Laplacian distributed random numbers with zero mean and variance 1
74 */
75 float laplacian();
76
77 /*!
78 * \brief Rayleigh distributed random numbers (zero mean and variance 1 for the
79 * underlying Gaussian distributions)
80 */
81 float rayleigh();
82
83 /*!
84 * \brief Exponentially distributed random numbers with values less than or equal
85 * to factor replaced with zero. The underlying exponential distribution has
86 * mean sqrt(2) and variance 2.
87 */
88 float impulse(float factor);
89
90 /*!
91 * \brief Normally distributed random numbers with zero mean and variance 1 on real
92 * and imaginary part. This results in a Rayleigh distribution for the amplitude and
93 * an uniform distribution for the phase.
94 */
96};
97
98} /* namespace gr */
99
100#endif /* INCLUDED_GR_RANDOM_H */
pseudo random number generator
Definition: random.h:28
random(unsigned int seed=0, int min_integer=0, int max_integer=2)
float rayleigh()
Rayleigh distributed random numbers (zero mean and variance 1 for the underlying Gaussian distributio...
void reseed(unsigned int seed)
Change the seed for the initialized number generator. seed = 0 initializes the random number generato...
void set_integer_limits(const int minimum, const int maximum)
std::uniform_int_distribution d_integer_dis
Definition: random.h:37
float impulse(float factor)
Exponentially distributed random numbers with values less than or equal to factor replaced with zero....
float ran1()
Uniform random numbers in the range [0.0, 1.0)
gr_complex rayleigh_complex()
Normally distributed random numbers with zero mean and variance 1 on real and imaginary part....
float laplacian()
Laplacian distributed random numbers with zero mean and variance 1.
long d_seed
Definition: random.h:30
std::mt19937 d_rng
Definition: random.h:34
std::uniform_real_distribution< float > d_uniform
Definition: random.h:36
float d_gauss_value
Definition: random.h:32
bool d_gauss_stored
Definition: random.h:31
int ran_int()
float gasdev()
Normally distributed random numbers (Gaussian distribution with zero mean and variance 1)
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:18
std::complex< float > gr_complex
Definition: gr_complex.h:15
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:29