Last active
February 27, 2023 21:23
-
-
Save Xenakios/09fe35f995354a2ac194889ced77c1ea to your computer and use it in GitHub Desktop.
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 RNG=std::default_random_engine, typename ResultType=float> | |
| struct RandomDistributionGenerator | |
| { | |
| RNG rng; | |
| std::uniform_real_distribution<ResultType> distrib_uniform; | |
| std::normal_distribution<ResultType> distrib_normal; | |
| std::exponential_distribution<ResultType> distrib_expo; | |
| std::cauchy_distribution<ResultType> distrib_cauchy; | |
| RandomDistributionGenerator() {} | |
| RandomDistributionGenerator(unsigned int seed) : rng(seed) {} | |
| void setSeed(unsigned int seed) { rng.seed(seed); } | |
| void setUniformDistributionParameters(ResultType low, ResultType high) | |
| { | |
| distrib_uniform = std::uniform_real_distribution<ResultType>(low,high); | |
| } | |
| void setNormalDistributionParameters(ResultType mean, ResultType deviation) | |
| { | |
| distrib_normal = std::normal_distribution<ResultType>(mean,deviation); | |
| } | |
| void setExponentialDistributionParameter(ResultType lambda) | |
| { | |
| distrib_expo = std::exponential_distribution<ResultType>(lambda); | |
| } | |
| void setCauchyDistributionParameters(ResultType quasimean, ResultType deviation) | |
| { | |
| distrib_cauchy = std::cauchy_distribution<ResultType>(quasimean,deviaton); | |
| } | |
| ResultType nextUniform() { return distrib_uniform(rng); } | |
| ResultType nextNormal() { return distrib_normal(rng); } | |
| ResultType nextExponential() { return distrib_expo(rng); } | |
| ResultType nextCauchy() { return distrib_cauchy(rng); } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment