Add exponential random distribution
This commit is contained in:
parent
9b304ead00
commit
d90317576c
1 changed files with 28 additions and 0 deletions
28
libs/random/include/psemek/random/exponential.hpp
Normal file
28
libs/random/include/psemek/random/exponential.hpp
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <psemek/random/uniform.hpp>
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
namespace psemek::random
|
||||||
|
{
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct exponential_distribution
|
||||||
|
{
|
||||||
|
exponential_distribution(T lambda)
|
||||||
|
: lambda_(lambda)
|
||||||
|
{}
|
||||||
|
|
||||||
|
template <typename RNG>
|
||||||
|
T operator()(RNG & rng)
|
||||||
|
{
|
||||||
|
T const y = uniform<T>(rng);
|
||||||
|
return - std::log(1 - y) / lambda_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
T lambda_;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue