Skip to content

Instantly share code, notes, and snippets.

@artivis
Created May 7, 2018 07:28
Show Gist options
  • Save artivis/4f04cbfb7c99b4d4901c833cbf8cb674 to your computer and use it in GitHub Desktop.
Save artivis/4f04cbfb7c99b4d4901c833cbf8cb674 to your computer and use it in GitHub Desktop.
Simple Gaussian Noise Generator
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