RavEngine
Loading...
Searching...
No Matches
random.hpp
1/*
2______ ___ _ _______ ________ __
3| ___ \/ _ \ | \ | | _ \ _ | \/ | Random for modern C++
4| |_/ / /_\ \| \| | | | | | | | . . |
5| /| _ || . ` | | | | | | | |\/| | version 1.4.0
6| |\ \| | | || |\ | |/ /\ \_/ / | | |
7\_| \_\_| |_/\_| \_/___/ \___/\_| |_/ https://github.com/effolkronium/random
8
9Licensed under the MIT License <http://opensource.org/licenses/MIT>.
10Copyright (c) 2017-2021 effolkronium
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files( the "Software" ), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions :
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29*/
30
31#ifndef EFFOLKRONIUM_RANDOM_HPP
32#define EFFOLKRONIUM_RANDOM_HPP
33
34#include <random>
35#include <chrono> // timed seed
36#include <type_traits>
37#include <cassert>
38#include <initializer_list>
39#include <utility> // std::forward, std::declval
40#include <algorithm> // std::shuffle, std::next, std::distance
41#include <iterator> // std::begin, std::end, std::iterator_traits
42#include <limits> // std::numeric_limits
43#include <ostream>
44#include <istream>
45
46namespace effolkronium {
47
48 namespace details {
50 struct common{ };
51
53 template<typename T>
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;
64 };
65
67 template<typename T>
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;
73 };
74
76 template<typename T>
77 struct is_byte {
78 static constexpr bool value =
79 std::is_same<T, signed char>::value
80 || std::is_same<T, unsigned char>::value;
81 };
82
84 template<typename T>
86 static constexpr bool value =
87 is_byte <T>::value
89 || is_uniform_int <T>::value;
90 };
91
93 template<typename T>
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;
100 };
101
103 template<typename T>
104 struct is_iterator {
105 private:
106 static char test( ... );
107
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&& );
115 public:
116 static constexpr bool value = std::is_same<
117 decltype( test( std::declval<T>( ) ) ), long>::value;
118 };
119
120 template <typename T>
122 {
123 private:
124 template <typename C>
125 static char test(...);
126
127 template <typename C>
128 static long test(decltype(&C::reserve));
129 public:
130 static constexpr bool value = std::is_same<
131 decltype(test<T>(0)), long>::value;
132 };
133
134 template <typename T>
136 {
137 private:
138 template <typename C>
139 static char test(...);
140
141 template <typename C>
142 static long test(decltype(&C::insert));
143 public:
144 static constexpr bool value = std::is_same<
145 decltype(test<T>(0)), long>::value;
146 };
147
148 } // namespace details
149
153 std::seed_seq& operator() ( ) {
154 // MinGW issue, std::random_device returns constant value
155 // Use std::seed_seq with additional seed from C++ chrono
156 return seed_seq;
157 }
158 private:
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( ) ),
163 } };
164 };
165
175 template<
176 typename Engine,
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
181 >
183 public:
184 basic_random_static( ) = delete;
185
187 using engine_type = Engine;
188
190 using seeder_type = Seeder;
191
193 template<typename T>
194 using integer_dist_t = IntegerDist<T>;
195
197 template<typename T>
198 using real_dist_t = RealDist<T>;
199
201 using bool_dist_t = BoolDist;
202
205
210 static constexpr typename Engine::result_type min( ) {
211 return Engine::min( );
212 }
213
218 static constexpr typename Engine::result_type max( ) {
219 return Engine::max( );
220 }
221
223 static void discard( const unsigned long long z ) {
224 engine_instance( ).discard( z );
225 }
226
228 static void reseed( ) {
229 Seeder seeder;
230 seed( seeder( ) );
231 }
232
239 static void seed( const typename Engine::result_type value =
240 Engine::default_seed ) {
241 engine_instance( ).seed( value );
242 }
243
250 template<typename Sseq>
251 static void seed( Sseq& seq ) {
252 engine_instance( ).seed( seq );
253 }
254
256 static typename Engine::result_type get( ) {
257 return engine_instance( )( );
258 }
259
269 static bool is_equal( const Engine& other ) {
270 return engine_instance( ) == other;
271 }
272
282 template<typename CharT, typename Traits>
283 static void serialize( std::basic_ostream<CharT, Traits>& ost ) {
284 ost << engine_instance( );
285 }
286
298 template<typename CharT, typename Traits>
299 static void deserialize( std::basic_istream<CharT, Traits>& ist ) {
300 ist >> engine_instance( );
301 }
302
312 template<typename T>
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( ) ) {
316 if( from < to ) // Allow range from higher to lower
317 return IntegerDist<T>{ from, to }( engine_instance( ) );
318 return IntegerDist<T>{ to, from }( engine_instance( ) );
319 }
320
330 template<typename T>
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( ) ) {
334 if( from < to ) // Allow range from higher to lower
335 return RealDist<T>{ from, to }( engine_instance( ) );
336 return RealDist<T>{ to, from }( engine_instance( ) );
337 }
338
347 template<typename T>
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( ) ) {
351 // Choose between short and unsigned short for byte conversion
352 using short_t = typename std::conditional<std::is_signed<T>::value,
353 short, unsigned short>::type;
354
355 return static_cast<T>( get<short_t>( from, to ) );
356 }
357
373 template<
374 typename Key,
375 typename A,
376 typename B,
377 typename C = typename std::common_type<A, B>::type
378 >
379 static typename std::enable_if<
380 std::is_same<Key, common>::value
383 // Prevent implicit type conversion from singed to unsigned types
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 ) );
388 }
389
399 template<typename T>
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()) {
403 if (from < to) // Allow range from higher to lower
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()));
406 }
407
415 template<typename T>
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 ); // out of [0; 1] range
419 return BoolDist{ probability }( engine_instance( ) );
420 }
421
430 template<typename T>
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( ) );
434 }
435
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 ) );
449 }
450
457 template<typename Container>
458 static auto get( Container& container ) ->
459 typename std::enable_if<details::is_iterator<
460 decltype(std::begin(container))>::value
461 , decltype(std::begin(container))
462 >::type {
463 return get( std::begin( container ), std::end( container ) );
464 }
465
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;
479
480 container.reserve(size);
481 for (std::size_t i = 0; i < size; ++i)
482 container.insert(std::end(container), get(from, to));
483
484 return container;
485 }
486
497 template<
498 template<typename...> class Container,
499 typename Key,
500 typename A,
501 typename B,
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;
508
509 container.reserve(size);
510 for (std::size_t i = 0; i < size; ++i)
511 container.insert(std::end(container), get<common>(start, end));
512
513 return container;
514 }
515
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;
528
529 for (std::size_t i = 0; i < size; ++i)
530 container.insert(std::end(container), get(start, end));
531
532 return container;
533 }
534
544 template<
545 template<typename...> class Container,
546 typename Key,
547 typename A,
548 typename B,
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;
555
556 for (std::size_t i = 0; i < size; ++i)
557 container.insert(std::end(container), get<common>(start, end));
558
559 return container;
560 }
561
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 }};
574
575 for (std::size_t i = 0; i < N; ++i)
576 container[i] = get(start, end);
577
578 return container;
579 }
580
590 template<
591 template<typename AA, std::size_t NN, typename...> class Container,
592 std::size_t N,
593 typename Key,
594 typename A,
595 typename B,
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 }};
602
603 for (std::size_t i = 0; i < N; ++i)
604 container[i] = get<common>(start, end);
605
606 return container;
607 }
608
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 ) ] );
617 }
618
627 template<typename Dist, typename... Args>
628 static typename Dist::result_type get( Args&&... args ) {
629 return Dist{ std::forward<Args>( args )... }( engine_instance( ) );
630 }
631
640 template<typename Dist>
641 static typename Dist::result_type get( Dist& dist ) {
642 return dist( engine_instance( ) );
643 }
644
651 template<typename RandomIt>
652 static void shuffle( RandomIt first, RandomIt last ) {
653 std::shuffle( first, last, engine_instance( ) );
654 }
655
662 template<typename Container>
663 static void shuffle( Container& container ) {
664 shuffle( std::begin( container ), std::end( container ) );
665 }
666
668 static Engine get_engine( ) {
669 return engine_instance( );
670 }
671
673 static Engine& engine() {
674 return engine_instance();
675 }
676 protected:
678 static Engine& engine_instance( ) {
679 static Engine engine{ Seeder{ }( ) };
680 return engine;
681 }
682 };
683
693 template<
694 typename Engine,
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
699 >
701 public:
702 basic_random_thread_local( ) = delete;
703
705 using engine_type = Engine;
706
708 using seeder_type = Seeder;
709
711 template<typename T>
712 using integer_dist_t = IntegerDist<T>;
713
715 template<typename T>
716 using real_dist_t = RealDist<T>;
717
719 using bool_dist_t = BoolDist;
720
723
728 static constexpr typename Engine::result_type min( ) {
729 return Engine::min( );
730 }
731
736 static constexpr typename Engine::result_type max( ) {
737 return Engine::max( );
738 }
739
741 static void discard( const unsigned long long z ) {
742 engine_instance( ).discard( z );
743 }
744
746 static void reseed( ) {
747 Seeder seeder;
748 seed( seeder( ) );
749 }
750
757 static void seed( const typename Engine::result_type value =
758 Engine::default_seed ) {
759 engine_instance( ).seed( value );
760 }
761
768 template<typename Sseq>
769 static void seed( Sseq& seq ) {
770 engine_instance( ).seed( seq );
771 }
772
774 static typename Engine::result_type get( ) {
775 return engine_instance( )( );
776 }
777
787 static bool is_equal( const Engine& other ) {
788 return engine_instance( ) == other;
789 }
790
800 template<typename CharT, typename Traits>
801 static void serialize( std::basic_ostream<CharT, Traits>& ost ) {
802 ost << engine_instance( );
803 }
804
816 template<typename CharT, typename Traits>
817 static void deserialize( std::basic_istream<CharT, Traits>& ist ) {
818 ist >> engine_instance( );
819 }
820
830 template<typename T>
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( ) ) {
834 if( from < to ) // Allow range from higher to lower
835 return IntegerDist<T>{ from, to }( engine_instance( ) );
836 return IntegerDist<T>{ to, from }( engine_instance( ) );
837 }
838
848 template<typename T>
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( ) ) {
852 if( from < to ) // Allow range from higher to lower
853 return RealDist<T>{ from, to }( engine_instance( ) );
854 return RealDist<T>{ to, from }( engine_instance( ) );
855 }
856
865 template<typename T>
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( ) ) {
869 // Choose between short and unsigned short for byte conversion
870 using short_t = typename std::conditional<std::is_signed<T>::value,
871 short, unsigned short>::type;
872
873 return static_cast<T>( get<short_t>( from, to ) );
874 }
875
891 template<
892 typename Key,
893 typename A,
894 typename B,
895 typename C = typename std::common_type<A, B>::type
896 >
897 static typename std::enable_if<
898 std::is_same<Key, common>::value
901 // Prevent implicit type conversion from singed to unsigned types
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 ) );
906 }
907
917 template<typename T>
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()) {
921 if (from < to) // Allow range from higher to lower
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()));
924 }
925
933 template<typename T>
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 ); // out of [0; 1] range
937 return BoolDist{ probability }( engine_instance( ) );
938 }
939
948 template<typename T>
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( ) );
952 }
953
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 ) );
967 }
968
975 template<typename Container>
976 static auto get( Container& container ) ->
977 typename std::enable_if<details::is_iterator<
978 decltype(std::begin(container))>::value
979 , decltype(std::begin(container))
980 >::type {
981 return get( std::begin( container ), std::end( container ) );
982 }
983
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;
997
998 container.reserve(size);
999 for (std::size_t i = 0; i < size; ++i)
1000 container.insert(std::end(container), get(from, to));
1001
1002 return container;
1003 }
1004
1015 template<
1016 template<typename...> class Container,
1017 typename Key,
1018 typename A,
1019 typename B,
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;
1026
1027 container.reserve(size);
1028 for (std::size_t i = 0; i < size; ++i)
1029 container.insert(std::end(container), get<common>(start, end));
1030
1031 return container;
1032 }
1033
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;
1046
1047 for (std::size_t i = 0; i < size; ++i)
1048 container.insert(std::end(container), get(start, end));
1049
1050 return container;
1051 }
1052
1062 template<
1063 template<typename...> class Container,
1064 typename Key,
1065 typename A,
1066 typename B,
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;
1073
1074 for (std::size_t i = 0; i < size; ++i)
1075 container.insert(std::end(container), get<common>(start, end));
1076
1077 return container;
1078 }
1079
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 }};
1092
1093 for (std::size_t i = 0; i < N; ++i)
1094 container[i] = get(start, end);
1095
1096 return container;
1097 }
1098
1108 template<
1109 template<typename AA, std::size_t NN, typename...> class Container,
1110 std::size_t N,
1111 typename Key,
1112 typename A,
1113 typename B,
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 }};
1120
1121 for (std::size_t i = 0; i < N; ++i)
1122 container[i] = get<common>(start, end);
1123
1124 return container;
1125 }
1126
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 ) ] );
1135 }
1136
1145 template<typename Dist, typename... Args>
1146 static typename Dist::result_type get( Args&&... args ) {
1147 return Dist{ std::forward<Args>( args )... }( engine_instance( ) );
1148 }
1149
1158 template<typename Dist>
1159 static typename Dist::result_type get( Dist& dist ) {
1160 return dist( engine_instance( ) );
1161 }
1162
1169 template<typename RandomIt>
1170 static void shuffle( RandomIt first, RandomIt last ) {
1171 std::shuffle( first, last, engine_instance( ) );
1172 }
1173
1180 template<typename Container>
1181 static void shuffle( Container& container ) {
1182 shuffle( std::begin( container ), std::end( container ) );
1183 }
1184
1186 static Engine get_engine( ) {
1187 return engine_instance( );
1188 }
1189
1191 static Engine& engine() {
1192 return engine_instance();
1193 }
1194 protected:
1196 static Engine& engine_instance( ) {
1197 thread_local Engine engine{ Seeder{ }( ) };
1198 return engine;
1199 }
1200 };
1201
1211 template<
1212 typename Engine,
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
1217 >
1219 public:
1221 using engine_type = Engine;
1222
1224 using seeder_type = Seeder;
1225
1227 template<typename T>
1228 using integer_dist_t = IntegerDist<T>;
1229
1231 template<typename T>
1232 using real_dist_t = RealDist<T>;
1233
1235 using bool_dist_t = BoolDist;
1236
1239
1244 static constexpr typename Engine::result_type min( ) {
1245 return Engine::min( );
1246 }
1247
1252 static constexpr typename Engine::result_type max( ) {
1253 return Engine::max( );
1254 }
1255
1257 void discard( const unsigned long long z ) {
1258 m_engine.discard( z );
1259 }
1260
1262 void reseed( ) {
1263 Seeder seeder;
1264 seed( seeder( ) );
1265 }
1266
1273 void seed( const typename Engine::result_type value =
1274 Engine::default_seed ) {
1275 m_engine.seed( value );
1276 }
1277
1284 template<typename Sseq>
1285 void seed( Sseq& seq ) {
1286 m_engine.seed( seq );
1287 }
1288
1290 typename Engine::result_type get( ) {
1291 return m_engine( );
1292 }
1293
1303 bool is_equal( const Engine& other ) {
1304 return m_engine == other;
1305 }
1306
1316 template<typename CharT, typename Traits>
1317 void serialize( std::basic_ostream<CharT, Traits>& ost ) {
1318 ost << m_engine;
1319 }
1320
1332 template<typename CharT, typename Traits>
1333 void deserialize( std::basic_istream<CharT, Traits>& ist ) {
1334 ist >> m_engine;
1335 }
1336
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( ) ) {
1350 if( from < to ) // Allow range from higher to lower
1351 return IntegerDist<T>{ from, to }( m_engine );
1352 return IntegerDist<T>{ to, from }( m_engine );
1353 }
1354
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( ) ) {
1368 if( from < to ) // Allow range from higher to lower
1369 return RealDist<T>{ from, to }( m_engine );
1370 return RealDist<T>{ to, from }( m_engine );
1371 }
1372
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( ) ) {
1385 // Choose between short and unsigned short for byte conversion
1386 using short_t = typename std::conditional<std::is_signed<T>::value,
1387 short, unsigned short>::type;
1388
1389 return static_cast<T>( get<short_t>( from, to ) );
1390 }
1391
1407 template<
1408 typename Key,
1409 typename A,
1410 typename B,
1411 typename C = typename std::common_type<A, B>::type
1412 >
1413 typename std::enable_if<
1414 std::is_same<Key, common>::value
1417 // Prevent implicit type conversion from singed to unsigned types
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 ) );
1422 }
1423
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()) {
1437 if (from < to) // Allow range from higher to lower
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));
1440 }
1441
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 ); // out of [0; 1] range
1453 return BoolDist{ probability }( m_engine );
1454 }
1455
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( ) );
1468 }
1469
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 ) );
1483 }
1484
1491 template<typename Container>
1492 auto get( Container& container ) ->
1493 typename std::enable_if<details::is_iterator<
1494 decltype(std::begin(container))>::value
1495 , decltype(std::begin(container))
1496 >::type {
1497 return get( std::begin( container ), std::end( container ) );
1498 }
1499
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;
1513
1514 container.reserve(size);
1515 for (std::size_t i = 0; i < size; ++i)
1516 container.insert(std::end(container), get(from, to));
1517
1518 return container;
1519 }
1520
1531 template<
1532 template<typename...> class Container,
1533 typename Key,
1534 typename A,
1535 typename B,
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;
1542
1543 container.reserve(size);
1544 for (std::size_t i = 0; i < size; ++i)
1545 container.insert(std::end(container), get<common>(start, end));
1546
1547 return container;
1548 }
1549
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;
1562
1563 for (std::size_t i = 0; i < size; ++i)
1564 container.insert(std::end(container), get(start, end));
1565
1566 return container;
1567 }
1568
1578 template<
1579 template<typename...> class Container,
1580 typename Key,
1581 typename A,
1582 typename B,
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;
1589
1590 for (std::size_t i = 0; i < size; ++i)
1591 container.insert(std::end(container), get<common>(start, end));
1592
1593 return container;
1594 }
1595
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 }};
1608
1609 for (std::size_t i = 0; i < N; ++i)
1610 container[i] = get(start, end);
1611
1612 return container;
1613 }
1614
1624 template<
1625 template<typename AA, std::size_t NN, typename...> class Container,
1626 std::size_t N,
1627 typename Key,
1628 typename A,
1629 typename B,
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 }};
1636
1637 for (std::size_t i = 0; i < N; ++i)
1638 container[i] = get<common>(start, end);
1639
1640 return container;
1641 }
1642
1648 template<typename T, std::size_t N>
1649 T* get( T( &array )[ N ] ) {
1650 return std::addressof( array[ get<std::size_t>( 0, N - 1 ) ] );
1651 }
1652
1661 template<typename Dist, typename... Args>
1662 typename Dist::result_type get( Args&&... args ) {
1663 return Dist{ std::forward<Args>( args )... }( m_engine );
1664 }
1665
1674 template<typename Dist>
1675 typename Dist::result_type get( Dist& dist ) {
1676 return dist( m_engine );
1677 }
1678
1685 template<typename RandomIt>
1686 void shuffle( RandomIt first, RandomIt last ) {
1687 std::shuffle( first, last, m_engine );
1688 }
1689
1696 template<typename Container>
1697 void shuffle( Container& container ) {
1698 shuffle( std::begin( container ), std::end( container ) );
1699 }
1700
1702 Engine get_engine( ) const {
1703 return m_engine;
1704 }
1705
1707 Engine& engine() {
1708 return m_engine;
1709 }
1710 protected:
1712 static Engine make_seeded_engine( ) {
1713 // Make seeder instance for seed return by reference like std::seed_seq
1714 return Engine{ Seeder{ }( ) };
1715 }
1716 protected:
1719 };
1720
1726 using random_static = basic_random_static<std::mt19937>;
1727
1733 using random_thread_local = basic_random_thread_local<std::mt19937>;
1734
1740 using random_local = basic_random_local<std::mt19937>;
1741
1742} // namespace effolkronium
1743
1744#endif // #ifndef EFFOLKRONIUM_RANDOM_HPP
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
True if type T is applicable by a std::uniform_int_distribution.
Definition random.hpp:54
True if type T is applicable by a std::uniform_real_distribution.
Definition random.hpp:68
Default seeder for 'random' classes.
Definition random.hpp:151
std::seed_seq & operator()()
return seed sequence
Definition random.hpp:153