LIBRCSC Docs
Documentation for HELIOS's BASE LIBRCSC library for RoboCup 2D Simulation League.
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
random.h
Go to the documentation of this file.
1// -*-c++-*-
2
8/*
9 *Copyright:
10
11 Copyright (C) Hidehisa AKIYAMA
12
13 This code is free software; you can redistribute it and/or
14 modify it under the terms of the GNU Lesser General Public
15 License as published by the Free Software Foundation; either
16 version 3 of the License, or (at your option) any later version.
17
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
22
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
27 *EndCopyright:
28 */
29
31
32#ifndef RCSC_UTIL_RANDOM_H
33#define RCSC_UTIL_RANDOM_H
34
35#include <random>
36#include <algorithm> // min, max
37#include <iostream>
38#include <ctime>
39
40namespace rcsc {
41
42/*-------------------------------------------------------------------*/
48public:
50 typedef std::mt19937 base_type;
51private:
53 base_type M_engine;
54
62 : M_engine( std::random_device()() )
63 { }
64
66 RandomEngine( const RandomEngine & ) = delete;
68 RandomEngine & operator=( const RandomEngine & ) = delete;
69
70public:
71
76 static
78 {
79 static RandomEngine s_instance;
80 return s_instance;
81 }
82
87 void seed( base_type::result_type value )
88 {
89 M_engine.seed( value );
90 }
91
97 {
98 return M_engine;
99 }
100};
101
102/*-------------------------------------------------------------------*/
108template < typename DstType >
110public:
112 typedef typename DstType::result_type result_type;
113
114private:
116 DstType M_dst;
117
119 UniformRNG();
120public:
127 result_type max )
128 : M_dst( min, max )
129 { }
130
136 {
137 return M_dst( RandomEngine::instance().get() );
138 }
139};
140
145
146}
147
148#endif
random engine holder for boost.
Definition: random.h:47
base_type & get()
get engine object
Definition: random.h:96
void seed(base_type::result_type value)
apply new seed to random engine.
Definition: random.h:87
static RandomEngine & instance()
singleton interface.
Definition: random.h:77
std::mt19937 base_type
alias of the randome engine object type.
Definition: random.h:50
template uniform random number generator class. DstType must be uniform type.
Definition: random.h:109
result_type operator()()
functional operator
Definition: random.h:135
DstType::result_type result_type
alias of the result value type
Definition: random.h:112
UniformRNG(result_type min, result_type max)
construct with value range
Definition: random.h:126