Created
May 7, 2018 07:28
-
-
Save artivis/4f04cbfb7c99b4d4901c833cbf8cb674 to your computer and use it in GitHub Desktop.
Simple Gaussian Noise Generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <typename _Scalar = double> | |
class GaussianNoiseGenerator | |
{ | |
using Clock = std::chrono::system_clock; | |
using Scalar = _Scalar; | |
public: | |
GaussianNoiseGenerator(const Scalar mean, | |
const Scalar std) | |
: re_(Clock::now().time_since_epoch().count()) | |
, distr_(mean, std) | |
{ | |
// | |
} | |
Scalar noise() | |
{ | |
return distr_(re_); | |
} | |
Scalar operator()() | |
{ | |
return noise(); | |
} | |
protected: | |
std::default_random_engine re_; | |
std::normal_distribution<Scalar> distr_; | |
}; | |
/* | |
usage: | |
GaussianNoiseGenerator<> noise(0, 0.1); | |
double my_noisy_value = 5 + noise(); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment