Main Page · Modules · All Classes · Class Hierarchy
MARandomness.hpp
1 /*
2  * This file is part of the AiBO+ project
3  *
4  * Copyright (C) 2005-2016 Csaba Kertész (csaba.kertesz@gmail.com)
5  *
6  * AiBO+ is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * AiBO+ is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
19  *
20  */
21 
22 #pragma once
23 
24 #include "MACoreTypes.hpp"
25 
26 #include <stdint.h>
27 #include <string>
28 
34 #define MA_RANDOM_POINT_1(_variable_name, _min, _max) \
36  int _variable_name = MARandomness::IsAnyRegisteredPoint() ? \
37  MARandomness::QueryRandomPoint(__PRETTY_FUNCTION__, 1, _min)[0] : \
38  MARandomness::GenerateRandomPoint(__PRETTY_FUNCTION__, 1, _min, _max)[0];
39 
41 #define MA_RANDOM_POINT_N(_variable_name, _count, _min, _max) \
42  MC::IntList _variable_name = \
43  MARandomness::IsAnyRegisteredPoint() ? \
44  MARandomness::QueryRandomPoint(__PRETTY_FUNCTION__, _count, _min) : \
45  MARandomness::GenerateRandomPoint(__PRETTY_FUNCTION__, _count, _min, _max);
46 
51 {
52 public:
65  static MC::IntList GenerateRandomPoint(const std::string& id, unsigned int count,
66  int min, int max);
67 
77  static void RegisterRandomPoint(int64_t timestamp, const std::string& id,
78  const int number);
79 
89  static void RegisterRandomPoint(int64_t timestamp, const std::string& id,
90  const MC::IntList& numbers);
91 
103  static MC::IntList QueryRandomPoint(const std::string& id, unsigned int count, int min);
104 
112  static bool IsAnyRegisteredPoint();
113 
114 private:
123  static inline void LogRandomPoint(const std::string& id, const MC::IntList& numbers);
124 };
125 
static void LogRandomPoint(const std::string &id, const MC::IntList &numbers)
Log a random point.
Randomness class.
static void RegisterRandomPoint(int64_t timestamp, const std::string &id, const int number)
Register a random point with a single number.
static MC::IntList GenerateRandomPoint(const std::string &id, unsigned int count, int min, int max)
Generate a random point.
static bool IsAnyRegisteredPoint()
Check if there is any registered random point.
static MC::IntList QueryRandomPoint(const std::string &id, unsigned int count, int min)
Query a random point.