Skip to content

Instantly share code, notes, and snippets.

@barsbek
barsbek / random_in_range.cpp
Last active September 23, 2017 23:24
Generate random number in range
#include <iostream>
#include <random>
int randomInRange(int min, int max, std::mt19937 &eng) {
std::uniform_int_distribution<> distr(min, max); // define the range
return distr(eng);
}
int main() {
std::random_device rd; // obtain a random number from hardware