Created
November 16, 2019 18:04
-
-
Save bwedding/c384112a155c0d19f93681e6079504d3 to your computer and use it in GitHub Desktop.
Class to Generate Random Numbers in a Range
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> | |
class RandomRange | |
{ | |
private: | |
int low; | |
int high; | |
std::uniform_int_distribution<> distr; // define the range | |
std::mt19937 eng{ std::random_device{}() }; | |
public: | |
RandomRange() = delete; | |
RandomRange(int Low, int High) | |
{ | |
std::random_device rd; // obtain a random number from hardware | |
low = Low; | |
high = High; | |
} | |
int Get() | |
{ | |
return std::uniform_int_distribution<uint32_t>{low,high}(eng); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment