Reference¶
-
using
tinymt
::
tinymt32
= tinymt_engine<uint_fast32_t, 32, detail::tinymt32_default_param_mat1, detail::tinymt32_default_param_mat2, detail::tinymt32_default_param_tmat, false>¶ TinyMT32 generator engine with the parameter set specified in RFC 8682.
-
template<class
UIntType
, std::size_tWordSize
, UIntTypeMat1
, UIntTypeMat2
, UIntTypeTMat
, boolDoPeriodCertification
= true>
classtinymt
::
tinymt_engine
¶ Pseudo-random number generator engine based on the TinyMT algorithms.
- Note
Currently
WordSize
must be32
.- Note
When
Mat
,Mat2
andTMat
are all zero, the generator parameter set must be provided in initialization (“Dynamic Creation” (DC) mode).- Template Parameters
UIntType
: unsigned integral type generated by the engineWordSize
: word size for the generated numbersMat1
: parameter used in the linear state transition functionMat2
: parameter used in the linear state transition functionTMat
: parameter used in the non-linear output functionDoPeriodCertification
: whether or not period certification is performed in initialization
Public Types
-
using
param_type
= typename impl::param_type¶ Type of the generator parameter set.
Public Functions
-
template<TINYMT_CPP_ENABLE_WHEN(!status_type::is_dynamic::value)> tinymt_engine (result_type seed=default_seed)
Constructs the engine (non-DC mode).
- Parameters
seed
: random seed
-
template<TINYMT_CPP_ENABLE_WHEN(status_type::is_dynamic::value)>
tinymt_engine
(const param_type ¶m, result_type seed = default_seed)¶ Constructs the engine (DC mode).
- Parameters
param
: parameter setseed
: random seed
-
void
seed
(result_type value = default_seed)¶ Reinitializes the engine.
- Parameters
value
: random seed
-
void
discard
(unsigned long long z)¶ Advances the state of the engine by the given amount.
- Parameters
z
: number of advances
-
result_type
operator()
()¶ Returns the next pseudo-random number.
- Return
generated value
Public Static Functions
-
constexpr result_type
min
()¶ Returns the smallest possible value in the output range.
- Return
smallest value
-
constexpr result_type
max
()¶ Returns the largest possible value in the output range.
- Return
largest value
Public Static Attributes
-
constexpr std::size_t
word_size
= WordSize¶ Word size that determines the range of numbers generated by the engine.
-
constexpr std::size_t
state_size
= impl::state_size¶ Size of the state of the generator in words.
-
constexpr result_type
default_seed
= 1¶ Default seed.
Friends
-
friend bool
operator==
(const tinymt_engine &a, const tinymt_engine &b)¶ Compares two engines.
- Return
true
if the engines are equivalent including their internal states,false
otherwise- Parameters
a
: first engineb
: second engine
-
friend bool
operator!=
(const tinymt_engine &a, const tinymt_engine &b)¶ Compares two engines.
- Return
true
if the engines are not equivalent including their internal states,false
otherwise- Parameters
a
: first engineb
: second engine
tinymt-cpp¶
A C++11 header-only implementation of the TinyMT pseudo-random number generator.
tinymt-cpp is a one-header-file library written in C++11, which implements a pseudo-random number generator engine based on the TinyMT algorithms. It can be used in the same way as random number generators in the standard library and combined with random number distributions.
Example¶
#include <iostream>
#include <tinymt/tinymt.h>
int main() {
tinymt::tinymt32 rng;
std::cout << rng() << std::endl;
std::cout << rng() << std::endl;
return 0;
}
Development¶
# Prerequisites (including optional ones)
brew install cmake doxygen gcc lcov llvm pre-commit
# Pre-commit hooks.
pre-commit install
pre-commit install --hook-type commit-msg
# Linters.
pre-commit run --all-files
# Tests.
cmake -S . -B build/debug -DCMAKE_BUILD_TYPE=Debug
cmake --build build/debug --target check
# Documents.
cmake -S . -B build/docs -DBUILD_TESTING=OFF
cmake --build build/docs --target doc
# Code coverage.
cmake -S . -B build/coverage -DCMAKE_BUILD_TYPE=Debug -DUSE_CODE_COVERAGE=ON
lcov -z -d build/coverage
cmake --build build/coverage --target check
lcov -c -d build/coverage -o build/coverage/coverage.info
genhtml -o build/coverage/html build/coverage/coverage.info
# Compiler sanitizers.
cmake -S . -B build/sanitizer -DCMAKE_BUILD_TYPE=Debug -DUSE_SANITIZER=ON
cmake --build build/sanitizer --target check
# Clang-Tidy.
cmake -S . -B build/clang-tidy -DCMAKE_BUILD_TYPE=Debug -DUSE_CLANG_TIDY=ON
cmake --build build/clang-tidy --target check
# Benchmarking.
cmake -S . -B build/release -DCMAKE_BUILD_TYPE=Release -DBUILD_BENCHMARKING=ON
cmake --build build/release --target bench
License¶
References¶
Mutsuo Saito, Makoto Matsumoto, Vincent Roca and Emmanuel Baccelli,
TinyMT32 Pseudorandom Number Generator (PRNG),
RFC 8682 (2020) 1-12.斎藤睦夫, 松本眞,
高速並列計算用の状態空間の小さな高品質疑似乱数生成器,
研究報告ハイパフォーマンスコンピューティング(HPC) 2011-HPC-131(3) (2011) 1-6.Tiny Mersenne Twister (TinyMT): A small-sized variant of Mersenne Twister.