Skip to content

Instantly share code, notes, and snippets.

@bwedding
Created November 16, 2019 18:04
Show Gist options
  • Save bwedding/c384112a155c0d19f93681e6079504d3 to your computer and use it in GitHub Desktop.
Save bwedding/c384112a155c0d19f93681e6079504d3 to your computer and use it in GitHub Desktop.
Class to Generate Random Numbers in a Range
#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