Gobelijn API documentation  - generated for commit a0cbea7
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
RandInt.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This file is part of the gobelijn software.
4  * Gobelijn is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation, either version 3 of the License, or any later
7  * version. Gobelijn is distributed in the hope that it will be useful, but
8  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9  * or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for details. You should have received
11  * a copy of the GNU General Public License along with the software. If not,
12  * see <http://www.gnu.org/licenses/>.
13  *
14  * Copyright 2012, Jan Broeckhove, CoMP/UA.
15  */
21 #include <cstdlib>
22 #include <random>
23 
27 class RandInt
28 {
29 public:
31  RandInt(unsigned int a, unsigned int b)
32  : m_mt(std::mt19937(std::random_device()())), m_dist(std::uniform_int_distribution<int>(a, b)) {}
33 
35  int operator()() { return m_dist(m_mt); }
36 
37 private:
38  std::mt19937 m_mt;
39  std::uniform_int_distribution<int> m_dist;
40 };
RandInt(unsigned int a, unsigned int b)
Initialize seed and ranfe of generator.
Definition: RandInt.h:31
std::uniform_int_distribution< int > m_dist
Definition: RandInt.h:39
Produce random integer (int) values.
Definition: RandInt.h:27
int operator()()
return random int within range.
Definition: RandInt.h:35
std::mt19937 m_mt
Definition: RandInt.h:38