Created
May 29, 2018 06:53
-
-
Save hsnks100/9525e2fe9a4d77a9dcdaf0d7b417152b to your computer and use it in GitHub Desktop.
mt19937 utility
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
| #include "ks19937.h" | |
| std::mt19937 ks19937::rng; |
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
| #pragma once | |
| #include <random> | |
| struct ks19937 { | |
| private: | |
| static std::mt19937 rng; | |
| public: | |
| // This is equivalent to srand(). | |
| static void seed(std::mt19937::result_type new_seed = std::mt19937::default_seed) { | |
| rng.seed(new_seed); | |
| } | |
| // This is equivalent to rand(). | |
| static uint64_t get() { | |
| return rng(); | |
| } | |
| static int getIntValue(int minValue, int maxValue) | |
| { | |
| std::uniform_int_distribution<int> dist(minValue, maxValue); | |
| return dist(rng); | |
| } | |
| static float getFloatValue(float minValue, float maxValue) | |
| { | |
| std::uniform_real_distribution<float> dist(minValue, maxValue); | |
| return dist(rng); | |
| } | |
| static double getDoubleValue(double minValue, double maxValue) | |
| { | |
| std::uniform_real_distribution<double> dist(minValue, maxValue); | |
| return dist(rng); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment