31#ifndef EFFOLKRONIUM_RANDOM_HPP
32#define EFFOLKRONIUM_RANDOM_HPP
38#include <initializer_list>
46namespace effolkronium {
55 static constexpr bool value =
56 std::is_same<T, short>::value
57 || std::is_same<T, int>::value
58 || std::is_same<T, long>::value
59 || std::is_same<T, long long>::value
60 || std::is_same<T, unsigned short>::value
61 || std::is_same<T, unsigned int>::value
62 || std::is_same<T, unsigned long>::value
63 || std::is_same<T, unsigned long long>::value;
69 static constexpr bool value =
70 std::is_same<T, float>::value
71 || std::is_same<T, double>::value
72 || std::is_same<T, long double>::value;
78 static constexpr bool value =
79 std::is_same<T, signed char>::value
80 || std::is_same<T, unsigned char>::value;
86 static constexpr bool value =
89 || is_uniform_int <T>::value;
95 static constexpr bool value =
96 std::is_same<T, char>::value
97 || std::is_same<T, wchar_t>::value
98 || std::is_same<T, char16_t>::value
99 || std::is_same<T, char32_t>::value;
106 static char test( ... );
108 template <
typename U,
109 typename =
typename std::iterator_traits<U>::difference_type,
110 typename =
typename std::iterator_traits<U>::pointer,
111 typename =
typename std::iterator_traits<U>::reference,
112 typename =
typename std::iterator_traits<U>::value_type,
113 typename =
typename std::iterator_traits<U>::iterator_category
114 >
static long test( U&& );
116 static constexpr bool value = std::is_same<
117 decltype( test( std::declval<T>( ) ) ),
long>::value;
120 template <
typename T>
124 template <
typename C>
125 static char test(...);
127 template <
typename C>
128 static long test(
decltype(&C::reserve));
130 static constexpr bool value = std::is_same<
131 decltype(test<T>(0)),
long>::value;
134 template <
typename T>
138 template <
typename C>
139 static char test(...);
141 template <
typename C>
142 static long test(
decltype(&C::insert));
144 static constexpr bool value = std::is_same<
145 decltype(test<T>(0)),
long>::value;
159 std::seed_seq seed_seq{ {
160 static_cast<std::uintmax_t
>( std::random_device{ }( ) ),
161 static_cast<std::uintmax_t
>( std::chrono::steady_clock::now( )
162 .time_since_epoch( ).count( ) ),
177 typename Seeder = seeder_default,
178 template<
typename>
class IntegerDist = std::uniform_int_distribution,
179 template<
typename>
class RealDist = std::uniform_real_distribution,
180 typename BoolDist = std::bernoulli_distribution
210 static constexpr typename Engine::result_type
min( ) {
211 return Engine::min( );
218 static constexpr typename Engine::result_type
max( ) {
219 return Engine::max( );
223 static void discard(
const unsigned long long z ) {
239 static void seed(
const typename Engine::result_type value =
240 Engine::default_seed ) {
250 template<
typename Sseq>
251 static void seed( Sseq& seq ) {
256 static typename Engine::result_type
get( ) {
282 template<
typename CharT,
typename Traits>
283 static void serialize( std::basic_ostream<CharT, Traits>& ost ) {
298 template<
typename CharT,
typename Traits>
299 static void deserialize( std::basic_istream<CharT, Traits>& ist ) {
313 static typename std::enable_if<details::is_uniform_int<T>::value
314 , T>::type
get( T from = std::numeric_limits<T>::min( ),
315 T to = std::numeric_limits<T>::max( ) ) {
331 static typename std::enable_if<details::is_uniform_real<T>::value
332 , T>::type
get( T from = std::numeric_limits<T>::min( ),
333 T to = std::numeric_limits<T>::max( ) ) {
348 static typename std::enable_if<details::is_byte<T>::value
349 , T>::type
get( T from = std::numeric_limits<T>::min( ),
350 T to = std::numeric_limits<T>::max( ) ) {
352 using short_t =
typename std::conditional<std::is_signed<T>::value,
353 short,
unsigned short>::type;
355 return static_cast<T
>( get<short_t>( from, to ) );
377 typename C =
typename std::common_type<A, B>::type
379 static typename std::enable_if<
380 std::is_same<Key, common>::value
384 && std::is_signed<A>::value != std::is_unsigned<B>::value
385 , C>::type
get( A from = std::numeric_limits<A>::min( ),
386 B to = std::numeric_limits<B>::max( ) ) {
387 return get(
static_cast<C
>( from ),
static_cast<C
>( to ) );
400 static typename std::enable_if<details::is_supported_character<T>::value
401 , T>::type
get(T from = std::numeric_limits<T>::min(),
402 T to = std::numeric_limits<T>::max()) {
404 return static_cast<T
>(IntegerDist<std::int64_t>{
static_cast<std::int64_t
>(from),
static_cast<std::int64_t
>(to) }(
engine_instance()));
405 return static_cast<T
>(IntegerDist<std::int64_t>{
static_cast<std::int64_t
>(to),
static_cast<std::int64_t
>(from) }(
engine_instance()));
416 static typename std::enable_if<std::is_same<T, bool>::value
417 ,
bool>::type
get(
const double probability = 0.5 ) {
418 assert( 0 <= probability && 1 >= probability );
431 static T
get( std::initializer_list<T> init_list ) {
432 assert( 0u != init_list.size( ) );
433 return *
get( init_list.begin( ), init_list.end( ) );
442 template<
typename InputIt>
443 static typename std::enable_if<details::is_iterator<InputIt>::value
444 , InputIt>::type
get( InputIt first, InputIt last ) {
445 const auto size = std::distance( first, last );
446 if( 0 == size )
return last;
447 using diff_t =
typename std::iterator_traits<InputIt>::difference_type;
448 return std::next( first, get<diff_t>( 0, size - 1 ) );
457 template<
typename Container>
458 static auto get( Container& container ) ->
460 decltype(std::begin(container))>::value
461 ,
decltype(std::begin(container))
463 return get( std::begin( container ), std::end( container ) );
474 template<
template<
typename...>
class Container,
typename A>
475 static typename std::enable_if<
477 , Container<A>>::type
get(A from, A to, std::size_t size) {
478 Container<A> container;
480 container.reserve(size);
481 for (std::size_t i = 0; i < size; ++i)
482 container.insert(std::end(container),
get(from, to));
498 template<
typename...>
class Container,
502 typename C =
typename std::common_type<A, B>::type>
503 static typename std::enable_if<
504 std::is_same<Key, common>::value
506 , Container<C>>::type
get(A start, B end, std::size_t size) {
507 Container<C> container;
509 container.reserve(size);
510 for (std::size_t i = 0; i < size; ++i)
511 container.insert(std::end(container), get<common>(start, end));
523 template<
template<
typename...>
class Container,
typename A>
524 static typename std::enable_if<
526 , Container<A>>::type
get(A start, A end, std::size_t size) {
527 Container<A> container;
529 for (std::size_t i = 0; i < size; ++i)
530 container.insert(std::end(container),
get(start, end));
545 template<
typename...>
class Container,
549 typename C =
typename std::common_type<A, B>::type>
550 static typename std::enable_if<
551 std::is_same<Key, common>::value
553 , Container<C>>::type
get(A start, B end, std::size_t size) {
554 Container<C> container;
556 for (std::size_t i = 0; i < size; ++i)
557 container.insert(std::end(container), get<common>(start, end));
569 template<
template<
typename AA, std::size_t NN,
typename...>
class Container, std::size_t N,
typename A>
570 static typename std::enable_if<
572 , Container<A, N>>::type
get(A start, A end) {
573 Container<A, N> container = {{ 0 }};
575 for (std::size_t i = 0; i < N; ++i)
576 container[i] =
get(start, end);
591 template<
typename AA, std::size_t NN,
typename...>
class Container,
596 typename C =
typename std::common_type<A, B>::type>
597 static typename std::enable_if<
598 std::is_same<Key, common>::value
600 , Container<C, N>>::type
get(A start, B end) {
601 Container<C, N> container = {{ 0 }};
603 for (std::size_t i = 0; i < N; ++i)
604 container[i] = get<common>(start, end);
614 template<
typename T, std::
size_t N>
615 static T*
get( T( &array )[ N ] ) {
616 return std::addressof( array[ get<std::size_t>( 0, N - 1 ) ] );
627 template<
typename Dist,
typename... Args>
628 static typename Dist::result_type
get( Args&&... args ) {
640 template<
typename Dist>
641 static typename Dist::result_type
get( Dist& dist ) {
651 template<
typename RandomIt>
652 static void shuffle( RandomIt first, RandomIt last ) {
662 template<
typename Container>
664 shuffle( std::begin( container ), std::end( container ) );
679 static Engine
engine{ Seeder{ }( ) };
695 typename Seeder = seeder_default,
696 template<
typename>
class IntegerDist = std::uniform_int_distribution,
697 template<
typename>
class RealDist = std::uniform_real_distribution,
698 typename BoolDist = std::bernoulli_distribution
728 static constexpr typename Engine::result_type
min( ) {
729 return Engine::min( );
736 static constexpr typename Engine::result_type
max( ) {
737 return Engine::max( );
741 static void discard(
const unsigned long long z ) {
757 static void seed(
const typename Engine::result_type value =
758 Engine::default_seed ) {
768 template<
typename Sseq>
769 static void seed( Sseq& seq ) {
774 static typename Engine::result_type
get( ) {
800 template<
typename CharT,
typename Traits>
801 static void serialize( std::basic_ostream<CharT, Traits>& ost ) {
816 template<
typename CharT,
typename Traits>
817 static void deserialize( std::basic_istream<CharT, Traits>& ist ) {
831 static typename std::enable_if<details::is_uniform_int<T>::value
832 , T>::type
get( T from = std::numeric_limits<T>::min( ),
833 T to = std::numeric_limits<T>::max( ) ) {
849 static typename std::enable_if<details::is_uniform_real<T>::value
850 , T>::type
get( T from = std::numeric_limits<T>::min( ),
851 T to = std::numeric_limits<T>::max( ) ) {
866 static typename std::enable_if<details::is_byte<T>::value
867 , T>::type
get( T from = std::numeric_limits<T>::min( ),
868 T to = std::numeric_limits<T>::max( ) ) {
870 using short_t =
typename std::conditional<std::is_signed<T>::value,
871 short,
unsigned short>::type;
873 return static_cast<T
>( get<short_t>( from, to ) );
895 typename C =
typename std::common_type<A, B>::type
897 static typename std::enable_if<
898 std::is_same<Key, common>::value
902 && std::is_signed<A>::value != std::is_unsigned<B>::value
903 , C>::type
get( A from = std::numeric_limits<A>::min( ),
904 B to = std::numeric_limits<B>::max( ) ) {
905 return get(
static_cast<C
>( from ),
static_cast<C
>( to ) );
918 static typename std::enable_if<details::is_supported_character<T>::value
919 , T>::type
get(T from = std::numeric_limits<T>::min(),
920 T to = std::numeric_limits<T>::max()) {
922 return static_cast<T
>(IntegerDist<std::int64_t>{
static_cast<std::int64_t
>(from),
static_cast<std::int64_t
>(to) }(
engine_instance()));
923 return static_cast<T
>(IntegerDist<std::int64_t>{
static_cast<std::int64_t
>(to),
static_cast<std::int64_t
>(from) }(
engine_instance()));
934 static typename std::enable_if<std::is_same<T, bool>::value
935 ,
bool>::type
get(
const double probability = 0.5 ) {
936 assert( 0 <= probability && 1 >= probability );
949 static T
get( std::initializer_list<T> init_list ) {
950 assert( 0u != init_list.size( ) );
951 return *
get( init_list.begin( ), init_list.end( ) );
960 template<
typename InputIt>
961 static typename std::enable_if<details::is_iterator<InputIt>::value
962 , InputIt>::type
get( InputIt first, InputIt last ) {
963 const auto size = std::distance( first, last );
964 if( 0 == size )
return last;
965 using diff_t =
typename std::iterator_traits<InputIt>::difference_type;
966 return std::next( first, get<diff_t>( 0, size - 1 ) );
975 template<
typename Container>
976 static auto get( Container& container ) ->
978 decltype(std::begin(container))>::value
979 ,
decltype(std::begin(container))
981 return get( std::begin( container ), std::end( container ) );
992 template<
template<
typename...>
class Container,
typename A>
993 static typename std::enable_if<
995 , Container<A>>::type
get(A from, A to, std::size_t size) {
996 Container<A> container;
998 container.reserve(size);
999 for (std::size_t i = 0; i < size; ++i)
1000 container.insert(std::end(container),
get(from, to));
1016 template<
typename...>
class Container,
1020 typename C =
typename std::common_type<A, B>::type>
1021 static typename std::enable_if<
1022 std::is_same<Key, common>::value
1024 , Container<C>>::type
get(A start, B end, std::size_t size) {
1025 Container<C> container;
1027 container.reserve(size);
1028 for (std::size_t i = 0; i < size; ++i)
1029 container.insert(std::end(container), get<common>(start, end));
1041 template<
template<
typename...>
class Container,
typename A>
1042 static typename std::enable_if<
1044 , Container<A>>::type
get(A start, A end, std::size_t size) {
1045 Container<A> container;
1047 for (std::size_t i = 0; i < size; ++i)
1048 container.insert(std::end(container),
get(start, end));
1063 template<
typename...>
class Container,
1067 typename C =
typename std::common_type<A, B>::type>
1068 static typename std::enable_if<
1069 std::is_same<Key, common>::value
1071 , Container<C>>::type
get(A start, B end, std::size_t size) {
1072 Container<C> container;
1074 for (std::size_t i = 0; i < size; ++i)
1075 container.insert(std::end(container), get<common>(start, end));
1087 template<
template<
typename AA, std::size_t NN,
typename...>
class Container, std::size_t N,
typename A>
1088 static typename std::enable_if<
1090 , Container<A, N>>::type
get(A start, A end) {
1091 Container<A, N> container = {{ 0 }};
1093 for (std::size_t i = 0; i < N; ++i)
1094 container[i] =
get(start, end);
1109 template<
typename AA, std::size_t NN,
typename...>
class Container,
1114 typename C =
typename std::common_type<A, B>::type>
1115 static typename std::enable_if<
1116 std::is_same<Key, common>::value
1118 , Container<C, N>>::type
get(A start, B end) {
1119 Container<C, N> container = {{ 0 }};
1121 for (std::size_t i = 0; i < N; ++i)
1122 container[i] = get<common>(start, end);
1132 template<
typename T, std::
size_t N>
1133 static T*
get( T( &array )[ N ] ) {
1134 return std::addressof( array[ get<std::size_t>( 0, N - 1 ) ] );
1145 template<
typename Dist,
typename... Args>
1146 static typename Dist::result_type
get( Args&&... args ) {
1158 template<
typename Dist>
1159 static typename Dist::result_type
get( Dist& dist ) {
1169 template<
typename RandomIt>
1170 static void shuffle( RandomIt first, RandomIt last ) {
1180 template<
typename Container>
1182 shuffle( std::begin( container ), std::end( container ) );
1197 thread_local Engine
engine{ Seeder{ }( ) };
1213 typename Seeder = seeder_default,
1214 template<
typename>
class IntegerDist = std::uniform_int_distribution,
1215 template<
typename>
class RealDist = std::uniform_real_distribution,
1216 typename BoolDist = std::bernoulli_distribution
1227 template<
typename T>
1231 template<
typename T>
1244 static constexpr typename Engine::result_type
min( ) {
1245 return Engine::min( );
1252 static constexpr typename Engine::result_type
max( ) {
1253 return Engine::max( );
1273 void seed(
const typename Engine::result_type value =
1274 Engine::default_seed ) {
1284 template<
typename Sseq>
1290 typename Engine::result_type
get( ) {
1316 template<
typename CharT,
typename Traits>
1332 template<
typename CharT,
typename Traits>
1346 template<
typename T>
1347 typename std::enable_if<details::is_uniform_int<T>::value
1348 , T>::type
get( T from = std::numeric_limits<T>::min( ),
1349 T to = std::numeric_limits<T>::max( ) ) {
1351 return IntegerDist<T>{ from, to }(
m_engine );
1352 return IntegerDist<T>{ to, from }(
m_engine );
1364 template<
typename T>
1365 typename std::enable_if<details::is_uniform_real<T>::value
1366 , T>::type
get( T from = std::numeric_limits<T>::min( ),
1367 T to = std::numeric_limits<T>::max( ) ) {
1369 return RealDist<T>{ from, to }(
m_engine );
1370 return RealDist<T>{ to, from }(
m_engine );
1381 template<
typename T>
1382 typename std::enable_if<details::is_byte<T>::value
1383 , T>::type
get( T from = std::numeric_limits<T>::min( ),
1384 T to = std::numeric_limits<T>::max( ) ) {
1386 using short_t =
typename std::conditional<std::is_signed<T>::value,
1387 short,
unsigned short>::type;
1389 return static_cast<T
>( get<short_t>( from, to ) );
1411 typename C =
typename std::common_type<A, B>::type
1413 typename std::enable_if<
1414 std::is_same<Key, common>::value
1418 && std::is_signed<A>::value != std::is_unsigned<B>::value
1419 , C>::type
get( A from = std::numeric_limits<A>::min( ),
1420 B to = std::numeric_limits<B>::max( ) ) {
1421 return get(
static_cast<C
>( from ),
static_cast<C
>( to ) );
1433 template<
typename T>
1434 typename std::enable_if<details::is_supported_character<T>::value
1435 , T>::type
get(T from = std::numeric_limits<T>::min(),
1436 T to = std::numeric_limits<T>::max()) {
1438 return static_cast<T
>(IntegerDist<std::int64_t>{
static_cast<std::int64_t
>(from),
static_cast<std::int64_t
>(to) }(
m_engine));
1439 return static_cast<T
>(IntegerDist<std::int64_t>{
static_cast<std::int64_t
>(to),
static_cast<std::int64_t
>(from) }(
m_engine));
1449 template<
typename T>
1450 typename std::enable_if<std::is_same<T, bool>::value
1451 ,
bool>::type
get(
const double probability = 0.5 ) {
1452 assert( 0 <= probability && 1 >= probability );
1453 return BoolDist{ probability }(
m_engine );
1464 template<
typename T>
1465 T
get( std::initializer_list<T> init_list ) {
1466 assert( 0u != init_list.size( ) );
1467 return *
get( init_list.begin( ), init_list.end( ) );
1476 template<
typename InputIt>
1477 typename std::enable_if<details::is_iterator<InputIt>::value
1478 , InputIt>::type
get( InputIt first, InputIt last ) {
1479 const auto size = std::distance( first, last );
1480 if( 0 == size )
return last;
1481 using diff_t =
typename std::iterator_traits<InputIt>::difference_type;
1482 return std::next( first, get<diff_t>( 0, size - 1 ) );
1491 template<
typename Container>
1492 auto get( Container& container ) ->
1494 decltype(std::begin(container))>::value
1495 ,
decltype(std::begin(container))
1497 return get( std::begin( container ), std::end( container ) );
1508 template<
template<
typename...>
class Container,
typename A>
1509 typename std::enable_if<
1511 , Container<A>>::type
get(A from, A to, std::size_t size) {
1512 Container<A> container;
1514 container.reserve(size);
1515 for (std::size_t i = 0; i < size; ++i)
1516 container.insert(std::end(container),
get(from, to));
1532 template<
typename...>
class Container,
1536 typename C =
typename std::common_type<A, B>::type>
1537 typename std::enable_if<
1538 std::is_same<Key, common>::value
1540 , Container<C>>::type
get(A start, B end, std::size_t size) {
1541 Container<C> container;
1543 container.reserve(size);
1544 for (std::size_t i = 0; i < size; ++i)
1545 container.insert(std::end(container), get<common>(start, end));
1557 template<
template<
typename...>
class Container,
typename A>
1558 typename std::enable_if<
1560 , Container<A>>::type
get(A start, A end, std::size_t size) {
1561 Container<A> container;
1563 for (std::size_t i = 0; i < size; ++i)
1564 container.insert(std::end(container),
get(start, end));
1579 template<
typename...>
class Container,
1583 typename C =
typename std::common_type<A, B>::type>
1584 typename std::enable_if<
1585 std::is_same<Key, common>::value
1587 , Container<C>>::type
get(A start, B end, std::size_t size) {
1588 Container<C> container;
1590 for (std::size_t i = 0; i < size; ++i)
1591 container.insert(std::end(container), get<common>(start, end));
1603 template<
template<
typename AA, std::size_t NN,
typename...>
class Container, std::size_t N,
typename A>
1604 typename std::enable_if<
1606 , Container<A, N>>::type
get(A start, A end) {
1607 Container<A, N> container = {{ 0 }};
1609 for (std::size_t i = 0; i < N; ++i)
1610 container[i] =
get(start, end);
1625 template<
typename AA, std::size_t NN,
typename...>
class Container,
1630 typename C =
typename std::common_type<A, B>::type>
1631 typename std::enable_if<
1632 std::is_same<Key, common>::value
1634 , Container<C, N>>::type
get(A start, B end) {
1635 Container<C, N> container = {{ 0 }};
1637 for (std::size_t i = 0; i < N; ++i)
1638 container[i] = get<common>(start, end);
1648 template<
typename T, std::
size_t N>
1650 return std::addressof( array[ get<std::size_t>( 0, N - 1 ) ] );
1661 template<
typename Dist,
typename... Args>
1662 typename Dist::result_type
get( Args&&... args ) {
1663 return Dist{ std::forward<Args>( args )... }(
m_engine );
1674 template<
typename Dist>
1675 typename Dist::result_type
get( Dist& dist ) {
1685 template<
typename RandomIt>
1687 std::shuffle( first, last,
m_engine );
1696 template<
typename Container>
1698 shuffle( std::begin( container ), std::end( container ) );
1714 return Engine{ Seeder{ }( ) };
1726 using random_static = basic_random_static<std::mt19937>;
1733 using random_thread_local = basic_random_thread_local<std::mt19937>;
1740 using random_local = basic_random_local<std::mt19937>;
Base template class for random with local API and local internal member storage.
Definition random.hpp:1218
std::enable_if< details::is_uniform_real< T >::value, T >::type get(T from=std::numeric_limits< T >::min(), T to=std::numeric_limits< T >::max())
Generate a random real number in a [from; to] range by std::uniform_real_distribution.
Definition random.hpp:1366
Dist::result_type get(Args &&... args)
Return value from custom Dist distribution seeded by internal random engine.
Definition random.hpp:1662
void shuffle(RandomIt first, RandomIt last)
Reorders the elements in the given range [first, last) such that each possible permutation of those e...
Definition random.hpp:1686
void discard(const unsigned long long z)
Advances the internal state by z times.
Definition random.hpp:1257
void reseed()
Reseed by Seeder.
Definition random.hpp:1262
bool is_equal(const Engine &other)
Compares internal pseudo-random number engine with 'other' pseudo-random number engine....
Definition random.hpp:1303
Dist::result_type get(Dist &dist)
Return value from custom 'dist' distribution seeded by internal random engine.
Definition random.hpp:1675
BoolDist bool_dist_t
Type of used bool distribution.
Definition random.hpp:1235
std::enable_if< std::is_same< Key, common >::value &&!details::has_insert< Container< C, N > >::value, Container< C, N > >::type get(A start, B end)
Return array-like container filled with random common_type values.
Definition random.hpp:1634
Engine & engine()
return internal engine by ref
Definition random.hpp:1707
Engine m_engine
The random number engine.
Definition random.hpp:1718
auto get(Container &container) -> typename std::enable_if< details::is_iterator< decltype(std::begin(container))>::value, decltype(std::begin(container)) >::type
Return random iterator from Container.
Definition random.hpp:1492
std::enable_if< details::is_byte< T >::value, T >::type get(T from=std::numeric_limits< T >::min(), T to=std::numeric_limits< T >::max())
Generate a random byte number in a [from; to] range.
Definition random.hpp:1383
std::enable_if< details::is_supported_character< T >::value, T >::type get(T from=std::numeric_limits< T >::min(), T to=std::numeric_limits< T >::max())
Generate a random character in a [from; to] range by std::uniform_int_distribution.
Definition random.hpp:1435
Engine engine_type
Type of used random number engine.
Definition random.hpp:1221
void seed(Sseq &seq)
Reinitializes the internal state of the random-number engine using new seed value.
Definition random.hpp:1285
T * get(T(&array)[N])
Return random pointer from built-in array.
Definition random.hpp:1649
IntegerDist< T > integer_dist_t
Type of used integer distribution.
Definition random.hpp:1228
static Engine make_seeded_engine()
return engine seeded by Seeder
Definition random.hpp:1712
std::enable_if< std::is_same< Key, common >::value &&details::is_supported_number< A >::value &&details::is_supported_number< B >::value &&std::is_signed< A >::value!=std::is_unsigned< B >::value, C >::type get(A from=std::numeric_limits< A >::min(), B to=std::numeric_limits< B >::max())
Generate a random common_type number in a [from; to] range.
Definition random.hpp:1419
std::enable_if<!details::has_reserve< Container< A > >::value, Container< A > >::type get(A start, A end, std::size_t size)
Return container filled with random values.
Definition random.hpp:1560
std::enable_if< details::is_iterator< InputIt >::value, InputIt >::type get(InputIt first, InputIt last)
Return random iterator from iterator range.
Definition random.hpp:1478
void deserialize(std::basic_istream< CharT, Traits > &ist)
Restores the internal state of the internal pseudo-random number engine from the serialized represent...
Definition random.hpp:1333
std::enable_if<!details::has_insert< Container< A, N > >::value, Container< A, N > >::type get(A start, A end)
Return array-like container filled with random values.
Definition random.hpp:1606
Seeder seeder_type
Type of used random number seeder.
Definition random.hpp:1224
void shuffle(Container &container)
Reorders the elements in the given container such that each possible permutation of those elements ha...
Definition random.hpp:1697
std::enable_if< std::is_same< T, bool >::value, bool >::type get(const double probability=0.5)
Generate a bool value with specific probability by std::bernoulli_distribution.
Definition random.hpp:1451
T get(std::initializer_list< T > init_list)
Return random value from initilizer_list.
Definition random.hpp:1465
void seed(const typename Engine::result_type value=Engine::default_seed)
Reinitializes the internal state of the random-number engine using new seed value.
Definition random.hpp:1273
std::enable_if< details::has_reserve< Container< A > >::value, Container< A > >::type get(A from, A to, std::size_t size)
Return container filled with random values.
Definition random.hpp:1511
Engine::result_type get()
return random number from engine in [min(), max()] range
Definition random.hpp:1290
std::enable_if< details::is_uniform_int< T >::value, T >::type get(T from=std::numeric_limits< T >::min(), T to=std::numeric_limits< T >::max())
Generate a random integer number in a [from; to] range by std::uniform_int_distribution.
Definition random.hpp:1348
void serialize(std::basic_ostream< CharT, Traits > &ost)
Serializes the internal state of the internal pseudo-random number engine as a sequence of decimal nu...
Definition random.hpp:1317
std::enable_if< std::is_same< Key, common >::value &&!details::has_reserve< Container< C > >::value, Container< C > >::type get(A start, B end, std::size_t size)
Return container filled with random common_type values.
Definition random.hpp:1587
static constexpr Engine::result_type max()
Definition random.hpp:1252
Engine get_engine() const
return internal engine by copy
Definition random.hpp:1702
static constexpr Engine::result_type min()
Definition random.hpp:1244
RealDist< T > real_dist_t
Type of used real distribution.
Definition random.hpp:1232
std::enable_if< std::is_same< Key, common >::value &&details::has_reserve< Container< A > >::value, Container< C > >::type get(A start, B end, std::size_t size)
Return container filled with random common_type values.
Definition random.hpp:1540
Base template class for random with static API and static internal member storage.
Definition random.hpp:182
static Dist::result_type get(Args &&... args)
Return value from custom Dist distribution seeded by internal random engine.
Definition random.hpp:628
static constexpr Engine::result_type min()
Definition random.hpp:210
static std::enable_if< details::is_iterator< InputIt >::value, InputIt >::type get(InputIt first, InputIt last)
Return random iterator from iterator range.
Definition random.hpp:444
static void discard(const unsigned long long z)
Advances the internal state by z times.
Definition random.hpp:223
static std::enable_if< details::is_supported_character< T >::value, T >::type get(T from=std::numeric_limits< T >::min(), T to=std::numeric_limits< T >::max())
Generate a random character in a [from; to] range by std::uniform_int_distribution.
Definition random.hpp:401
static void seed(const typename Engine::result_type value=Engine::default_seed)
Reinitializes the internal state of the random-number engine using new seed value.
Definition random.hpp:239
static void seed(Sseq &seq)
Reinitializes the internal state of the random-number engine using new seed value.
Definition random.hpp:251
static std::enable_if< details::is_uniform_int< T >::value, T >::type get(T from=std::numeric_limits< T >::min(), T to=std::numeric_limits< T >::max())
Generate a random integer number in a [from; to] range by std::uniform_int_distribution.
Definition random.hpp:314
static bool is_equal(const Engine &other)
Compares internal pseudo-random number engine with 'other' pseudo-random number engine....
Definition random.hpp:269
static T get(std::initializer_list< T > init_list)
Return random value from initilizer_list.
Definition random.hpp:431
static Dist::result_type get(Dist &dist)
Return value from custom 'dist' distribution seeded by internal random engine.
Definition random.hpp:641
static auto get(Container &container) -> typename std::enable_if< details::is_iterator< decltype(std::begin(container))>::value, decltype(std::begin(container)) >::type
Return random iterator from Container.
Definition random.hpp:458
static std::enable_if< details::is_byte< T >::value, T >::type get(T from=std::numeric_limits< T >::min(), T to=std::numeric_limits< T >::max())
Generate a random byte number in a [from; to] range.
Definition random.hpp:349
static Engine::result_type get()
return random number from engine in [min(), max()] range
Definition random.hpp:256
static std::enable_if< details::has_reserve< Container< A > >::value, Container< A > >::type get(A from, A to, std::size_t size)
Return container filled with random values.
Definition random.hpp:477
static void shuffle(Container &container)
Reorders the elements in the given container such that each possible permutation of those elements ha...
Definition random.hpp:663
static void serialize(std::basic_ostream< CharT, Traits > &ost)
Serializes the internal state of the internal pseudo-random number engine as a sequence of decimal nu...
Definition random.hpp:283
static std::enable_if< details::is_uniform_real< T >::value, T >::type get(T from=std::numeric_limits< T >::min(), T to=std::numeric_limits< T >::max())
Generate a random real number in a [from; to] range by std::uniform_real_distribution.
Definition random.hpp:332
static void reseed()
Reseed by Seeder.
Definition random.hpp:228
static void shuffle(RandomIt first, RandomIt last)
Reorders the elements in the given range [first, last) such that each possible permutation of those e...
Definition random.hpp:652
Engine engine_type
Type of used random number engine.
Definition random.hpp:187
Seeder seeder_type
Type of used random number seeder.
Definition random.hpp:190
static void deserialize(std::basic_istream< CharT, Traits > &ist)
Restores the internal state of the internal pseudo-random number engine from the serialized represent...
Definition random.hpp:299
static Engine & engine()
return internal engine by ref
Definition random.hpp:673
static std::enable_if< std::is_same< Key, common >::value &&!details::has_insert< Container< C, N > >::value, Container< C, N > >::type get(A start, B end)
Return array-like container filled with random common_type values.
Definition random.hpp:600
static std::enable_if< std::is_same< Key, common >::value &&details::has_reserve< Container< A > >::value, Container< C > >::type get(A start, B end, std::size_t size)
Return container filled with random common_type values.
Definition random.hpp:506
static std::enable_if< std::is_same< Key, common >::value &&details::is_supported_number< A >::value &&details::is_supported_number< B >::value &&std::is_signed< A >::value!=std::is_unsigned< B >::value, C >::type get(A from=std::numeric_limits< A >::min(), B to=std::numeric_limits< B >::max())
Generate a random common_type number in a [from; to] range.
Definition random.hpp:385
static T * get(T(&array)[N])
Return random pointer from built-in array.
Definition random.hpp:615
static Engine get_engine()
return internal engine by copy
Definition random.hpp:668
static std::enable_if< std::is_same< Key, common >::value &&!details::has_reserve< Container< C > >::value, Container< C > >::type get(A start, B end, std::size_t size)
Return container filled with random common_type values.
Definition random.hpp:553
IntegerDist< T > integer_dist_t
Type of used integer distribution.
Definition random.hpp:194
RealDist< T > real_dist_t
Type of used real distribution.
Definition random.hpp:198
static std::enable_if< std::is_same< T, bool >::value, bool >::type get(const double probability=0.5)
Generate a bool value with specific probability by std::bernoulli_distribution.
Definition random.hpp:417
BoolDist bool_dist_t
Type of used bool distribution.
Definition random.hpp:201
static constexpr Engine::result_type max()
Definition random.hpp:218
static std::enable_if<!details::has_reserve< Container< A > >::value, Container< A > >::type get(A start, A end, std::size_t size)
Return container filled with random values.
Definition random.hpp:526
static Engine & engine_instance()
get reference to the static engine instance
Definition random.hpp:678
static std::enable_if<!details::has_insert< Container< A, N > >::value, Container< A, N > >::type get(A start, A end)
Return array-like container filled with random values.
Definition random.hpp:572
Base template class for random with thread_local API and thread_local internal member storage.
Definition random.hpp:700
Seeder seeder_type
Type of used random number seeder.
Definition random.hpp:708
static Engine::result_type get()
return random number from engine in [min(), max()] range
Definition random.hpp:774
RealDist< T > real_dist_t
Type of used real distribution.
Definition random.hpp:716
static std::enable_if< details::is_uniform_real< T >::value, T >::type get(T from=std::numeric_limits< T >::min(), T to=std::numeric_limits< T >::max())
Generate a random real number in a [from; to] range by std::uniform_real_distribution.
Definition random.hpp:850
IntegerDist< T > integer_dist_t
Type of used integer distribution.
Definition random.hpp:712
static std::enable_if< details::is_uniform_int< T >::value, T >::type get(T from=std::numeric_limits< T >::min(), T to=std::numeric_limits< T >::max())
Generate a random integer number in a [from; to] range by std::uniform_int_distribution.
Definition random.hpp:832
static void shuffle(RandomIt first, RandomIt last)
Reorders the elements in the given range [first, last) such that each possible permutation of those e...
Definition random.hpp:1170
Engine engine_type
Type of used random number engine.
Definition random.hpp:705
static std::enable_if< std::is_same< Key, common >::value &&!details::has_reserve< Container< C > >::value, Container< C > >::type get(A start, B end, std::size_t size)
Return container filled with random common_type values.
Definition random.hpp:1071
static bool is_equal(const Engine &other)
Compares internal pseudo-random number engine with 'other' pseudo-random number engine....
Definition random.hpp:787
static Engine & engine()
return internal engine by ref
Definition random.hpp:1191
static std::enable_if<!details::has_insert< Container< A, N > >::value, Container< A, N > >::type get(A start, A end)
Return array-like container filled with random values.
Definition random.hpp:1090
static std::enable_if< std::is_same< T, bool >::value, bool >::type get(const double probability=0.5)
Generate a bool value with specific probability by std::bernoulli_distribution.
Definition random.hpp:935
static void serialize(std::basic_ostream< CharT, Traits > &ost)
Serializes the internal state of the internal pseudo-random number engine as a sequence of decimal nu...
Definition random.hpp:801
static Engine & engine_instance()
get reference to the thread local engine instance
Definition random.hpp:1196
static auto get(Container &container) -> typename std::enable_if< details::is_iterator< decltype(std::begin(container))>::value, decltype(std::begin(container)) >::type
Return random iterator from Container.
Definition random.hpp:976
static std::enable_if<!details::has_reserve< Container< A > >::value, Container< A > >::type get(A start, A end, std::size_t size)
Return container filled with random values.
Definition random.hpp:1044
static constexpr Engine::result_type min()
Definition random.hpp:728
static Dist::result_type get(Args &&... args)
Return value from custom Dist distribution seeded by internal random engine.
Definition random.hpp:1146
static void shuffle(Container &container)
Reorders the elements in the given container such that each possible permutation of those elements ha...
Definition random.hpp:1181
static std::enable_if< std::is_same< Key, common >::value &&details::has_reserve< Container< A > >::value, Container< C > >::type get(A start, B end, std::size_t size)
Return container filled with random common_type values.
Definition random.hpp:1024
static constexpr Engine::result_type max()
Definition random.hpp:736
static std::enable_if< std::is_same< Key, common >::value &&!details::has_insert< Container< C, N > >::value, Container< C, N > >::type get(A start, B end)
Return array-like container filled with random common_type values.
Definition random.hpp:1118
static void seed(const typename Engine::result_type value=Engine::default_seed)
Reinitializes the internal state of the random-number engine using new seed value.
Definition random.hpp:757
static void deserialize(std::basic_istream< CharT, Traits > &ist)
Restores the internal state of the internal pseudo-random number engine from the serialized represent...
Definition random.hpp:817
static std::enable_if< details::is_byte< T >::value, T >::type get(T from=std::numeric_limits< T >::min(), T to=std::numeric_limits< T >::max())
Generate a random byte number in a [from; to] range.
Definition random.hpp:867
static void seed(Sseq &seq)
Reinitializes the internal state of the random-number engine using new seed value.
Definition random.hpp:769
static std::enable_if< details::is_iterator< InputIt >::value, InputIt >::type get(InputIt first, InputIt last)
Return random iterator from iterator range.
Definition random.hpp:962
static Dist::result_type get(Dist &dist)
Return value from custom 'dist' distribution seeded by internal random engine.
Definition random.hpp:1159
static T get(std::initializer_list< T > init_list)
Return random value from initilizer_list.
Definition random.hpp:949
static std::enable_if< details::has_reserve< Container< A > >::value, Container< A > >::type get(A from, A to, std::size_t size)
Return container filled with random values.
Definition random.hpp:995
static void discard(const unsigned long long z)
Advances the internal state by z times.
Definition random.hpp:741
static T * get(T(&array)[N])
Return random pointer from built-in array.
Definition random.hpp:1133
static Engine get_engine()
return internal engine by copy
Definition random.hpp:1186
static void reseed()
Reseed by Seeder.
Definition random.hpp:746
static std::enable_if< details::is_supported_character< T >::value, T >::type get(T from=std::numeric_limits< T >::min(), T to=std::numeric_limits< T >::max())
Generate a random character in a [from; to] range by std::uniform_int_distribution.
Definition random.hpp:919
BoolDist bool_dist_t
Type of used bool distribution.
Definition random.hpp:719
static std::enable_if< std::is_same< Key, common >::value &&details::is_supported_number< A >::value &&details::is_supported_number< B >::value &&std::is_signed< A >::value!=std::is_unsigned< B >::value, C >::type get(A from=std::numeric_limits< A >::min(), B to=std::numeric_limits< B >::max())
Generate a random common_type number in a [from; to] range.
Definition random.hpp:903
Definition random.hpp:136
Definition random.hpp:122
Key type for getting common type numbers or objects.
Definition random.hpp:50
True if type T is plain byte.
Definition random.hpp:77
True if type T is iterator.
Definition random.hpp:104
True if type T is character type.
Definition random.hpp:94
True if type T is plain number type.
Definition random.hpp:85
Default seeder for 'random' classes.
Definition random.hpp:151
std::seed_seq & operator()()
return seed sequence
Definition random.hpp:153