cppcore
A small, portable C++ core library
Loading...
Searching...
No Matches
RandomGenerator.h
Go to the documentation of this file.
1/*-----------------------------------------------------------------------------------------------
2The MIT License (MIT)
3
4Copyright (c) 2014-2026 Kim Kulling
5
6Permission is hereby granted, free of charge, to any person obtaining a copy of
7this software and associated documentation files (the "Software"), to deal in
8the Software without restriction, including without limitation the rights to
9use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10the Software, and to permit persons to whom the Software is furnished to do so,
11subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22-----------------------------------------------------------------------------------------------*/
23#pragma once
24
26
27#include <memory>
28
29namespace cppcore {
30
31//-------------------------------------------------------------------------------------------------
36//-------------------------------------------------------------------------------------------------
38public:
40 enum class GeneratorType {
41 Standard,
42 MersenneTwister
43 };
44
47 RandomGenerator( GeneratorType type = GeneratorType::Standard ) noexcept;
48
50 ~RandomGenerator() = default;
51
56 int get( int lower, int upper );
57
58 // Copying is not allowed
60 RandomGenerator &operator = (const RandomGenerator &) = delete;
61
62private:
63 GeneratorType mType;
64};
65
66} // Namespace cppcore
#define DLL_CPPCORE_EXPORT
This class is used to wrap different random number generators.
RandomGenerator(GeneratorType type=GeneratorType::Standard) noexcept
The class constructor.
int get(int lower, int upper)
Gets a new random number.
RandomGenerator(const RandomGenerator &)=delete
~RandomGenerator()=default
The class destructor.
GeneratorType
This enum describes the requested random generator.