eDSP  0.0.1
A cross-platform DSP library written in C++.
binary_generator.hpp
Go to the documentation of this file.
1 /*
2  * eDSP, A cross-platform Digital Signal Processing library written in modern C++.
3  * Copyright (C) 2018 Mohammed Boujemaoui Boulaghmoudi, All rights reserved.
4  *
5  * This program is free software: you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the Free
7  * Software Foundation, either version 3 of the License, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along width
16  * this program. If not, see <http://www.gnu.org/licenses/>
17 
18  *
19  * File: binary_sequence_generator.hpp
20  * Author: Mohammed Boujemaoui
21  * Date: 31/7/2018
22  */
23 #ifndef EDSP_BINARY_SEQUENCE_GENERATOR_HPP
24 #define EDSP_BINARY_SEQUENCE_GENERATOR_HPP
25 
26 #include <random>
27 #include <chrono>
28 
29 namespace edsp { namespace random {
30 
39  template <typename T, typename Engine = std::mt19937>
41  using value_type = T;
42 
47  explicit binary_generator(value_type probability) :
48  generator_(Engine(static_cast<std::size_t>(std::chrono::system_clock::now().time_since_epoch().count()))),
49  distribution_(std::bernoulli_distribution(probability)) {}
50 
56  return static_cast<value_type>(distribution_(generator_));
57  }
58 
59  private:
60  Engine generator_;
61  std::bernoulli_distribution distribution_;
62  };
63 
64 }} // namespace edsp::random
65 
66 #endif // EDSP_BINARY_SEQUENCE_GENERATOR_HPP
value_type operator()()
Generates a boolean value according to the discrete probability function.
Definition: binary_generator.hpp:55
binary_generator(value_type probability)
Creates a binary sequence generator.
Definition: binary_generator.hpp:47
T value_type
Definition: binary_generator.hpp:41
This class implements a binary generator according to the discrete probability function.
Definition: binary_generator.hpp:40
Definition: amplifier.hpp:29