Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
random.hpp
Go to the documentation of this file.
1
6/*
7 * This file is part of Algorithms library toolkit.
8 * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
9
10 * Algorithms library toolkit is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14
15 * Algorithms library toolkit is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19
20 * You should have received a copy of the GNU General Public License
21 * along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#pragma once
25
26#include <random>
27#include <limits>
28
29namespace ext {
30
36public:
43 static std::random_device & getRandom ( ) {
44 static std::random_device res;
45 return res;
46 }
47
52 static std::random_device & random;
53
54private:
59 class semirandom_device {
60 public:
65 typedef unsigned int result_type;
66
67 private:
72 std::mt19937 gen;
73
78 std::uniform_int_distribution<unsigned int> dis;
79
80 public:
87 semirandom_device() : gen ( 0 ) {
88 }
89
96 result_type operator()() {
97 return dis(gen);
98 }
99
106 static constexpr result_type min() {
107 return 0;
108 }
109
116 static constexpr result_type max() {
118 }
119
126 void seed ( unsigned int seed ) {
127 gen.seed ( seed );
128 }
129 };
130
131public:
138 static semirandom_device & getSemirandom ( ) {
139 static semirandom_device res;
140 return res;
141 }
142
147 static semirandom_device & semirandom;
148
149};
150
151} /* namespace ext */
152
Definition of randomness sources. Provided sources are c++ builtin random_device and own semirandom_d...
Definition: random.hpp:35
static std::random_device & random
The reference to singleton random device.
Definition: random.hpp:52
static semirandom_device & semirandom
The reference to singleton semirandom device.
Definition: random.hpp:147
static semirandom_device & getSemirandom()
Getter of the singleton semirandom device.
Definition: random.hpp:138
static std::random_device & getRandom()
Getter of the singleton random device.
Definition: random.hpp:43
return res
Definition: MinimizeByPartitioning.h:145
Definition: sigHandler.cpp:20
constexpr const T & max(const T &a)
Root case of maximum computation. The maximum from one value is the value itself.
Definition: algorithm.hpp:278
constexpr const T & min(const T &a)
Definition: algorithm.hpp:310