2 //===--------------------------- random -----------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_RANDOM
12 #define _LIBCPP_RANDOM
17 #include <initializer_list>
24 template <class UIntType, UIntType a, UIntType c, UIntType m>
25 class linear_congruential_engine
29 typedef UIntType result_type;
31 // engine characteristics
32 static constexpr result_type multiplier = a;
33 static constexpr result_type increment = c;
34 static constexpr result_type modulus = m;
35 static constexpr result_type min() { return c == 0u ? 1u: 0u;}
36 static constexpr result_type max() { return m - 1u;}
37 static constexpr result_type default_seed = 1u;
39 // constructors and seeding functions
40 explicit linear_congruential_engine(result_type s = default_seed);
41 template<class Sseq> explicit linear_congruential_engine(Sseq& q);
42 void seed(result_type s = default_seed);
43 template<class Sseq> void seed(Sseq& q);
45 // generating functions
46 result_type operator()();
47 void discard(unsigned long long z);
50 template <class UIntType, UIntType a, UIntType c, UIntType m>
52 operator==(const linear_congruential_engine<UIntType, a, c, m>& x,
53 const linear_congruential_engine<UIntType, a, c, m>& y);
55 template <class UIntType, UIntType a, UIntType c, UIntType m>
57 operator!=(const linear_congruential_engine<UIntType, a, c, m>& x,
58 const linear_congruential_engine<UIntType, a, c, m>& y);
60 template <class charT, class traits,
61 class UIntType, UIntType a, UIntType c, UIntType m>
62 basic_ostream<charT, traits>&
63 operator<<(basic_ostream<charT, traits>& os,
64 const linear_congruential_engine<UIntType, a, c, m>& x);
66 template <class charT, class traits,
67 class UIntType, UIntType a, UIntType c, UIntType m>
68 basic_istream<charT, traits>&
69 operator>>(basic_istream<charT, traits>& is,
70 linear_congruential_engine<UIntType, a, c, m>& x);
72 template <class UIntType, size_t w, size_t n, size_t m, size_t r,
73 UIntType a, size_t u, UIntType d, size_t s,
74 UIntType b, size_t t, UIntType c, size_t l, UIntType f>
75 class mersenne_twister_engine
79 typedef UIntType result_type;
81 // engine characteristics
82 static constexpr size_t word_size = w;
83 static constexpr size_t state_size = n;
84 static constexpr size_t shift_size = m;
85 static constexpr size_t mask_bits = r;
86 static constexpr result_type xor_mask = a;
87 static constexpr size_t tempering_u = u;
88 static constexpr result_type tempering_d = d;
89 static constexpr size_t tempering_s = s;
90 static constexpr result_type tempering_b = b;
91 static constexpr size_t tempering_t = t;
92 static constexpr result_type tempering_c = c;
93 static constexpr size_t tempering_l = l;
94 static constexpr result_type initialization_multiplier = f;
95 static constexpr result_type min () { return 0; }
96 static constexpr result_type max() { return 2^w - 1; }
97 static constexpr result_type default_seed = 5489u;
99 // constructors and seeding functions
100 explicit mersenne_twister_engine(result_type value = default_seed);
101 template<class Sseq> explicit mersenne_twister_engine(Sseq& q);
102 void seed(result_type value = default_seed);
103 template<class Sseq> void seed(Sseq& q);
105 // generating functions
106 result_type operator()();
107 void discard(unsigned long long z);
110 template <class UIntType, size_t w, size_t n, size_t m, size_t r,
111 UIntType a, size_t u, UIntType d, size_t s,
112 UIntType b, size_t t, UIntType c, size_t l, UIntType f>
115 const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x,
116 const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& y);
118 template <class UIntType, size_t w, size_t n, size_t m, size_t r,
119 UIntType a, size_t u, UIntType d, size_t s,
120 UIntType b, size_t t, UIntType c, size_t l, UIntType f>
123 const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x,
124 const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& y);
126 template <class charT, class traits,
127 class UIntType, size_t w, size_t n, size_t m, size_t r,
128 UIntType a, size_t u, UIntType d, size_t s,
129 UIntType b, size_t t, UIntType c, size_t l, UIntType f>
130 basic_ostream<charT, traits>&
131 operator<<(basic_ostream<charT, traits>& os,
132 const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x);
134 template <class charT, class traits,
135 class UIntType, size_t w, size_t n, size_t m, size_t r,
136 UIntType a, size_t u, UIntType d, size_t s,
137 UIntType b, size_t t, UIntType c, size_t l, UIntType f>
138 basic_istream<charT, traits>&
139 operator>>(basic_istream<charT, traits>& is,
140 mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x);
142 template<class UIntType, size_t w, size_t s, size_t r>
143 class subtract_with_carry_engine
147 typedef UIntType result_type;
149 // engine characteristics
150 static constexpr size_t word_size = w;
151 static constexpr size_t short_lag = s;
152 static constexpr size_t long_lag = r;
153 static constexpr result_type min() { return 0; }
154 static constexpr result_type max() { return m-1; }
155 static constexpr result_type default_seed = 19780503u;
157 // constructors and seeding functions
158 explicit subtract_with_carry_engine(result_type value = default_seed);
159 template<class Sseq> explicit subtract_with_carry_engine(Sseq& q);
160 void seed(result_type value = default_seed);
161 template<class Sseq> void seed(Sseq& q);
163 // generating functions
164 result_type operator()();
165 void discard(unsigned long long z);
168 template<class UIntType, size_t w, size_t s, size_t r>
171 const subtract_with_carry_engine<UIntType, w, s, r>& x,
172 const subtract_with_carry_engine<UIntType, w, s, r>& y);
174 template<class UIntType, size_t w, size_t s, size_t r>
177 const subtract_with_carry_engine<UIntType, w, s, r>& x,
178 const subtract_with_carry_engine<UIntType, w, s, r>& y);
180 template <class charT, class traits,
181 class UIntType, size_t w, size_t s, size_t r>
182 basic_ostream<charT, traits>&
183 operator<<(basic_ostream<charT, traits>& os,
184 const subtract_with_carry_engine<UIntType, w, s, r>& x);
186 template <class charT, class traits,
187 class UIntType, size_t w, size_t s, size_t r>
188 basic_istream<charT, traits>&
189 operator>>(basic_istream<charT, traits>& is,
190 subtract_with_carry_engine<UIntType, w, s, r>& x);
192 template<class Engine, size_t p, size_t r>
193 class discard_block_engine
197 typedef typename Engine::result_type result_type;
199 // engine characteristics
200 static constexpr size_t block_size = p;
201 static constexpr size_t used_block = r;
202 static constexpr result_type min() { return Engine::min(); }
203 static constexpr result_type max() { return Engine::max(); }
205 // constructors and seeding functions
206 discard_block_engine();
207 explicit discard_block_engine(const Engine& e);
208 explicit discard_block_engine(Engine&& e);
209 explicit discard_block_engine(result_type s);
210 template<class Sseq> explicit discard_block_engine(Sseq& q);
212 void seed(result_type s);
213 template<class Sseq> void seed(Sseq& q);
215 // generating functions
216 result_type operator()();
217 void discard(unsigned long long z);
219 // property functions
220 const Engine& base() const noexcept;
223 template<class Engine, size_t p, size_t r>
226 const discard_block_engine<Engine, p, r>& x,
227 const discard_block_engine<Engine, p, r>& y);
229 template<class Engine, size_t p, size_t r>
232 const discard_block_engine<Engine, p, r>& x,
233 const discard_block_engine<Engine, p, r>& y);
235 template <class charT, class traits,
236 class Engine, size_t p, size_t r>
237 basic_ostream<charT, traits>&
238 operator<<(basic_ostream<charT, traits>& os,
239 const discard_block_engine<Engine, p, r>& x);
241 template <class charT, class traits,
242 class Engine, size_t p, size_t r>
243 basic_istream<charT, traits>&
244 operator>>(basic_istream<charT, traits>& is,
245 discard_block_engine<Engine, p, r>& x);
247 template<class Engine, size_t w, class UIntType>
248 class independent_bits_engine
252 typedef UIntType result_type;
254 // engine characteristics
255 static constexpr result_type min() { return 0; }
256 static constexpr result_type max() { return 2^w - 1; }
258 // constructors and seeding functions
259 independent_bits_engine();
260 explicit independent_bits_engine(const Engine& e);
261 explicit independent_bits_engine(Engine&& e);
262 explicit independent_bits_engine(result_type s);
263 template<class Sseq> explicit independent_bits_engine(Sseq& q);
265 void seed(result_type s);
266 template<class Sseq> void seed(Sseq& q);
268 // generating functions
269 result_type operator()(); void discard(unsigned long long z);
271 // property functions
272 const Engine& base() const noexcept;
275 template<class Engine, size_t w, class UIntType>
278 const independent_bits_engine<Engine, w, UIntType>& x,
279 const independent_bits_engine<Engine, w, UIntType>& y);
281 template<class Engine, size_t w, class UIntType>
284 const independent_bits_engine<Engine, w, UIntType>& x,
285 const independent_bits_engine<Engine, w, UIntType>& y);
287 template <class charT, class traits,
288 class Engine, size_t w, class UIntType>
289 basic_ostream<charT, traits>&
290 operator<<(basic_ostream<charT, traits>& os,
291 const independent_bits_engine<Engine, w, UIntType>& x);
293 template <class charT, class traits,
294 class Engine, size_t w, class UIntType>
295 basic_istream<charT, traits>&
296 operator>>(basic_istream<charT, traits>& is,
297 independent_bits_engine<Engine, w, UIntType>& x);
299 template<class Engine, size_t k>
300 class shuffle_order_engine
304 typedef typename Engine::result_type result_type;
306 // engine characteristics
307 static constexpr size_t table_size = k;
308 static constexpr result_type min() { return Engine::min; }
309 static constexpr result_type max() { return Engine::max; }
311 // constructors and seeding functions
312 shuffle_order_engine();
313 explicit shuffle_order_engine(const Engine& e);
314 explicit shuffle_order_engine(Engine&& e);
315 explicit shuffle_order_engine(result_type s);
316 template<class Sseq> explicit shuffle_order_engine(Sseq& q);
318 void seed(result_type s);
319 template<class Sseq> void seed(Sseq& q);
321 // generating functions
322 result_type operator()();
323 void discard(unsigned long long z);
325 // property functions
326 const Engine& base() const noexcept;
329 template<class Engine, size_t k>
332 const shuffle_order_engine<Engine, k>& x,
333 const shuffle_order_engine<Engine, k>& y);
335 template<class Engine, size_t k>
338 const shuffle_order_engine<Engine, k>& x,
339 const shuffle_order_engine<Engine, k>& y);
341 template <class charT, class traits,
342 class Engine, size_t k>
343 basic_ostream<charT, traits>&
344 operator<<(basic_ostream<charT, traits>& os,
345 const shuffle_order_engine<Engine, k>& x);
347 template <class charT, class traits,
348 class Engine, size_t k>
349 basic_istream<charT, traits>&
350 operator>>(basic_istream<charT, traits>& is,
351 shuffle_order_engine<Engine, k>& x);
353 typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647>
355 typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647>
357 typedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31,
362 18, 1812433253> mt19937;
363 typedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31,
365 29, 0x5555555555555555,
366 17, 0x71d67fffeda60000,
367 37, 0xfff7eee000000000,
368 43, 6364136223846793005> mt19937_64;
369 typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> ranlux24_base;
370 typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> ranlux48_base;
371 typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24;
372 typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48;
373 typedef shuffle_order_engine<minstd_rand0, 256> knuth_b;
374 typedef minstd_rand default_random_engine;
382 typedef unsigned int result_type;
384 // generator characteristics
385 static constexpr result_type min() { return numeric_limits<result_type>::min(); }
386 static constexpr result_type max() { return numeric_limits<result_type>::max(); }
389 explicit random_device(const string& token = "/dev/urandom");
391 // generating functions
392 result_type operator()();
394 // property functions
395 double entropy() const noexcept;
398 random_device(const random_device& ) = delete;
399 void operator=(const random_device& ) = delete;
408 typedef uint_least32_t result_type;
413 seed_seq(initializer_list<T> il);
414 template<class InputIterator>
415 seed_seq(InputIterator begin, InputIterator end);
417 // generating functions
418 template<class RandomAccessIterator>
419 void generate(RandomAccessIterator begin, RandomAccessIterator end);
421 // property functions
423 template<class OutputIterator>
424 void param(OutputIterator dest) const;
427 seed_seq(const seed_seq&) = delete;
428 void operator=(const seed_seq& ) = delete;
431 template<class RealType, size_t bits, class URNG>
432 RealType generate_canonical(URNG& g);
436 template<class IntType = int>
437 class uniform_int_distribution
441 typedef IntType result_type;
446 typedef uniform_int_distribution distribution_type;
448 explicit param_type(IntType a = 0,
449 IntType b = numeric_limits<IntType>::max());
451 result_type a() const;
452 result_type b() const;
454 friend bool operator==(const param_type& x, const param_type& y);
455 friend bool operator!=(const param_type& x, const param_type& y);
458 // constructors and reset functions
459 explicit uniform_int_distribution(IntType a = 0,
460 IntType b = numeric_limits<IntType>::max());
461 explicit uniform_int_distribution(const param_type& parm);
464 // generating functions
465 template<class URNG> result_type operator()(URNG& g);
466 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
468 // property functions
469 result_type a() const;
470 result_type b() const;
472 param_type param() const;
473 void param(const param_type& parm);
475 result_type min() const;
476 result_type max() const;
478 friend bool operator==(const uniform_int_distribution& x,
479 const uniform_int_distribution& y);
480 friend bool operator!=(const uniform_int_distribution& x,
481 const uniform_int_distribution& y);
483 template <class charT, class traits>
485 basic_ostream<charT, traits>&
486 operator<<(basic_ostream<charT, traits>& os,
487 const uniform_int_distribution& x);
489 template <class charT, class traits>
491 basic_istream<charT, traits>&
492 operator>>(basic_istream<charT, traits>& is,
493 uniform_int_distribution& x);
496 template<class RealType = double>
497 class uniform_real_distribution
501 typedef RealType result_type;
506 typedef uniform_real_distribution distribution_type;
508 explicit param_type(RealType a = 0,
511 result_type a() const;
512 result_type b() const;
514 friend bool operator==(const param_type& x, const param_type& y);
515 friend bool operator!=(const param_type& x, const param_type& y);
518 // constructors and reset functions
519 explicit uniform_real_distribution(RealType a = 0.0, RealType b = 1.0);
520 explicit uniform_real_distribution(const param_type& parm);
523 // generating functions
524 template<class URNG> result_type operator()(URNG& g);
525 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
527 // property functions
528 result_type a() const;
529 result_type b() const;
531 param_type param() const;
532 void param(const param_type& parm);
534 result_type min() const;
535 result_type max() const;
537 friend bool operator==(const uniform_real_distribution& x,
538 const uniform_real_distribution& y);
539 friend bool operator!=(const uniform_real_distribution& x,
540 const uniform_real_distribution& y);
542 template <class charT, class traits>
544 basic_ostream<charT, traits>&
545 operator<<(basic_ostream<charT, traits>& os,
546 const uniform_real_distribution& x);
548 template <class charT, class traits>
550 basic_istream<charT, traits>&
551 operator>>(basic_istream<charT, traits>& is,
552 uniform_real_distribution& x);
555 class bernoulli_distribution
559 typedef bool result_type;
564 typedef bernoulli_distribution distribution_type;
566 explicit param_type(double p = 0.5);
570 friend bool operator==(const param_type& x, const param_type& y);
571 friend bool operator!=(const param_type& x, const param_type& y);
574 // constructors and reset functions
575 explicit bernoulli_distribution(double p = 0.5);
576 explicit bernoulli_distribution(const param_type& parm);
579 // generating functions
580 template<class URNG> result_type operator()(URNG& g);
581 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
583 // property functions
586 param_type param() const;
587 void param(const param_type& parm);
589 result_type min() const;
590 result_type max() const;
592 friend bool operator==(const bernoulli_distribution& x,
593 const bernoulli_distribution& y);
594 friend bool operator!=(const bernoulli_distribution& x,
595 const bernoulli_distribution& y);
597 template <class charT, class traits>
599 basic_ostream<charT, traits>&
600 operator<<(basic_ostream<charT, traits>& os,
601 const bernoulli_distribution& x);
603 template <class charT, class traits>
605 basic_istream<charT, traits>&
606 operator>>(basic_istream<charT, traits>& is,
607 bernoulli_distribution& x);
610 template<class IntType = int>
611 class binomial_distribution
615 typedef IntType result_type;
620 typedef binomial_distribution distribution_type;
622 explicit param_type(IntType t = 1, double p = 0.5);
627 friend bool operator==(const param_type& x, const param_type& y);
628 friend bool operator!=(const param_type& x, const param_type& y);
631 // constructors and reset functions
632 explicit binomial_distribution(IntType t = 1, double p = 0.5);
633 explicit binomial_distribution(const param_type& parm);
636 // generating functions
637 template<class URNG> result_type operator()(URNG& g);
638 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
640 // property functions
644 param_type param() const;
645 void param(const param_type& parm);
647 result_type min() const;
648 result_type max() const;
650 friend bool operator==(const binomial_distribution& x,
651 const binomial_distribution& y);
652 friend bool operator!=(const binomial_distribution& x,
653 const binomial_distribution& y);
655 template <class charT, class traits>
657 basic_ostream<charT, traits>&
658 operator<<(basic_ostream<charT, traits>& os,
659 const binomial_distribution& x);
661 template <class charT, class traits>
663 basic_istream<charT, traits>&
664 operator>>(basic_istream<charT, traits>& is,
665 binomial_distribution& x);
668 template<class IntType = int>
669 class geometric_distribution
673 typedef IntType result_type;
678 typedef geometric_distribution distribution_type;
680 explicit param_type(double p = 0.5);
684 friend bool operator==(const param_type& x, const param_type& y);
685 friend bool operator!=(const param_type& x, const param_type& y);
688 // constructors and reset functions
689 explicit geometric_distribution(double p = 0.5);
690 explicit geometric_distribution(const param_type& parm);
693 // generating functions
694 template<class URNG> result_type operator()(URNG& g);
695 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
697 // property functions
700 param_type param() const;
701 void param(const param_type& parm);
703 result_type min() const;
704 result_type max() const;
706 friend bool operator==(const geometric_distribution& x,
707 const geometric_distribution& y);
708 friend bool operator!=(const geometric_distribution& x,
709 const geometric_distribution& y);
711 template <class charT, class traits>
713 basic_ostream<charT, traits>&
714 operator<<(basic_ostream<charT, traits>& os,
715 const geometric_distribution& x);
717 template <class charT, class traits>
719 basic_istream<charT, traits>&
720 operator>>(basic_istream<charT, traits>& is,
721 geometric_distribution& x);
724 template<class IntType = int>
725 class negative_binomial_distribution
729 typedef IntType result_type;
734 typedef negative_binomial_distribution distribution_type;
736 explicit param_type(result_type k = 1, double p = 0.5);
738 result_type k() const;
741 friend bool operator==(const param_type& x, const param_type& y);
742 friend bool operator!=(const param_type& x, const param_type& y);
745 // constructor and reset functions
746 explicit negative_binomial_distribution(result_type k = 1, double p = 0.5);
747 explicit negative_binomial_distribution(const param_type& parm);
750 // generating functions
751 template<class URNG> result_type operator()(URNG& g);
752 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
754 // property functions
755 result_type k() const;
758 param_type param() const;
759 void param(const param_type& parm);
761 result_type min() const;
762 result_type max() const;
764 friend bool operator==(const negative_binomial_distribution& x,
765 const negative_binomial_distribution& y);
766 friend bool operator!=(const negative_binomial_distribution& x,
767 const negative_binomial_distribution& y);
769 template <class charT, class traits>
771 basic_ostream<charT, traits>&
772 operator<<(basic_ostream<charT, traits>& os,
773 const negative_binomial_distribution& x);
775 template <class charT, class traits>
777 basic_istream<charT, traits>&
778 operator>>(basic_istream<charT, traits>& is,
779 negative_binomial_distribution& x);
782 template<class IntType = int>
783 class poisson_distribution
787 typedef IntType result_type;
792 typedef poisson_distribution distribution_type;
794 explicit param_type(double mean = 1.0);
798 friend bool operator==(const param_type& x, const param_type& y);
799 friend bool operator!=(const param_type& x, const param_type& y);
802 // constructors and reset functions
803 explicit poisson_distribution(double mean = 1.0);
804 explicit poisson_distribution(const param_type& parm);
807 // generating functions
808 template<class URNG> result_type operator()(URNG& g);
809 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
811 // property functions
814 param_type param() const;
815 void param(const param_type& parm);
817 result_type min() const;
818 result_type max() const;
820 friend bool operator==(const poisson_distribution& x,
821 const poisson_distribution& y);
822 friend bool operator!=(const poisson_distribution& x,
823 const poisson_distribution& y);
825 template <class charT, class traits>
827 basic_ostream<charT, traits>&
828 operator<<(basic_ostream<charT, traits>& os,
829 const poisson_distribution& x);
831 template <class charT, class traits>
833 basic_istream<charT, traits>&
834 operator>>(basic_istream<charT, traits>& is,
835 poisson_distribution& x);
838 template<class RealType = double>
839 class exponential_distribution
843 typedef RealType result_type;
848 typedef exponential_distribution distribution_type;
850 explicit param_type(result_type lambda = 1.0);
852 result_type lambda() const;
854 friend bool operator==(const param_type& x, const param_type& y);
855 friend bool operator!=(const param_type& x, const param_type& y);
858 // constructors and reset functions
859 explicit exponential_distribution(result_type lambda = 1.0);
860 explicit exponential_distribution(const param_type& parm);
863 // generating functions
864 template<class URNG> result_type operator()(URNG& g);
865 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
867 // property functions
868 result_type lambda() const;
870 param_type param() const;
871 void param(const param_type& parm);
873 result_type min() const;
874 result_type max() const;
876 friend bool operator==(const exponential_distribution& x,
877 const exponential_distribution& y);
878 friend bool operator!=(const exponential_distribution& x,
879 const exponential_distribution& y);
881 template <class charT, class traits>
883 basic_ostream<charT, traits>&
884 operator<<(basic_ostream<charT, traits>& os,
885 const exponential_distribution& x);
887 template <class charT, class traits>
889 basic_istream<charT, traits>&
890 operator>>(basic_istream<charT, traits>& is,
891 exponential_distribution& x);
894 template<class RealType = double>
895 class gamma_distribution
899 typedef RealType result_type;
904 typedef gamma_distribution distribution_type;
906 explicit param_type(result_type alpha = 1, result_type beta = 1);
908 result_type alpha() const;
909 result_type beta() const;
911 friend bool operator==(const param_type& x, const param_type& y);
912 friend bool operator!=(const param_type& x, const param_type& y);
915 // constructors and reset functions
916 explicit gamma_distribution(result_type alpha = 1, result_type beta = 1);
917 explicit gamma_distribution(const param_type& parm);
920 // generating functions
921 template<class URNG> result_type operator()(URNG& g);
922 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
924 // property functions
925 result_type alpha() const;
926 result_type beta() const;
928 param_type param() const;
929 void param(const param_type& parm);
931 result_type min() const;
932 result_type max() const;
934 friend bool operator==(const gamma_distribution& x,
935 const gamma_distribution& y);
936 friend bool operator!=(const gamma_distribution& x,
937 const gamma_distribution& y);
939 template <class charT, class traits>
941 basic_ostream<charT, traits>&
942 operator<<(basic_ostream<charT, traits>& os,
943 const gamma_distribution& x);
945 template <class charT, class traits>
947 basic_istream<charT, traits>&
948 operator>>(basic_istream<charT, traits>& is,
949 gamma_distribution& x);
952 template<class RealType = double>
953 class weibull_distribution
957 typedef RealType result_type;
962 typedef weibull_distribution distribution_type;
964 explicit param_type(result_type alpha = 1, result_type beta = 1);
966 result_type a() const;
967 result_type b() const;
969 friend bool operator==(const param_type& x, const param_type& y);
970 friend bool operator!=(const param_type& x, const param_type& y);
973 // constructor and reset functions
974 explicit weibull_distribution(result_type a = 1, result_type b = 1);
975 explicit weibull_distribution(const param_type& parm);
978 // generating functions
979 template<class URNG> result_type operator()(URNG& g);
980 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
982 // property functions
983 result_type a() const;
984 result_type b() const;
986 param_type param() const;
987 void param(const param_type& parm);
989 result_type min() const;
990 result_type max() const;
992 friend bool operator==(const weibull_distribution& x,
993 const weibull_distribution& y);
994 friend bool operator!=(const weibull_distribution& x,
995 const weibull_distribution& y);
997 template <class charT, class traits>
999 basic_ostream<charT, traits>&
1000 operator<<(basic_ostream<charT, traits>& os,
1001 const weibull_distribution& x);
1003 template <class charT, class traits>
1005 basic_istream<charT, traits>&
1006 operator>>(basic_istream<charT, traits>& is,
1007 weibull_distribution& x);
1010 template<class RealType = double>
1011 class extreme_value_distribution
1015 typedef RealType result_type;
1020 typedef extreme_value_distribution distribution_type;
1022 explicit param_type(result_type a = 0, result_type b = 1);
1024 result_type a() const;
1025 result_type b() const;
1027 friend bool operator==(const param_type& x, const param_type& y);
1028 friend bool operator!=(const param_type& x, const param_type& y);
1031 // constructor and reset functions
1032 explicit extreme_value_distribution(result_type a = 0, result_type b = 1);
1033 explicit extreme_value_distribution(const param_type& parm);
1036 // generating functions
1037 template<class URNG> result_type operator()(URNG& g);
1038 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
1040 // property functions
1041 result_type a() const;
1042 result_type b() const;
1044 param_type param() const;
1045 void param(const param_type& parm);
1047 result_type min() const;
1048 result_type max() const;
1050 friend bool operator==(const extreme_value_distribution& x,
1051 const extreme_value_distribution& y);
1052 friend bool operator!=(const extreme_value_distribution& x,
1053 const extreme_value_distribution& y);
1055 template <class charT, class traits>
1057 basic_ostream<charT, traits>&
1058 operator<<(basic_ostream<charT, traits>& os,
1059 const extreme_value_distribution& x);
1061 template <class charT, class traits>
1063 basic_istream<charT, traits>&
1064 operator>>(basic_istream<charT, traits>& is,
1065 extreme_value_distribution& x);
1068 template<class RealType = double>
1069 class normal_distribution
1073 typedef RealType result_type;
1078 typedef normal_distribution distribution_type;
1080 explicit param_type(result_type mean = 0, result_type stddev = 1);
1082 result_type mean() const;
1083 result_type stddev() const;
1085 friend bool operator==(const param_type& x, const param_type& y);
1086 friend bool operator!=(const param_type& x, const param_type& y);
1089 // constructors and reset functions
1090 explicit normal_distribution(result_type mean = 0, result_type stddev = 1);
1091 explicit normal_distribution(const param_type& parm);
1094 // generating functions
1095 template<class URNG> result_type operator()(URNG& g);
1096 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
1098 // property functions
1099 result_type mean() const;
1100 result_type stddev() const;
1102 param_type param() const;
1103 void param(const param_type& parm);
1105 result_type min() const;
1106 result_type max() const;
1108 friend bool operator==(const normal_distribution& x,
1109 const normal_distribution& y);
1110 friend bool operator!=(const normal_distribution& x,
1111 const normal_distribution& y);
1113 template <class charT, class traits>
1115 basic_ostream<charT, traits>&
1116 operator<<(basic_ostream<charT, traits>& os,
1117 const normal_distribution& x);
1119 template <class charT, class traits>
1121 basic_istream<charT, traits>&
1122 operator>>(basic_istream<charT, traits>& is,
1123 normal_distribution& x);
1126 template<class RealType = double>
1127 class lognormal_distribution
1131 typedef RealType result_type;
1136 typedef lognormal_distribution distribution_type;
1138 explicit param_type(result_type m = 0, result_type s = 1);
1140 result_type m() const;
1141 result_type s() const;
1143 friend bool operator==(const param_type& x, const param_type& y);
1144 friend bool operator!=(const param_type& x, const param_type& y);
1147 // constructor and reset functions
1148 explicit lognormal_distribution(result_type m = 0, result_type s = 1);
1149 explicit lognormal_distribution(const param_type& parm);
1152 // generating functions
1153 template<class URNG> result_type operator()(URNG& g);
1154 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
1156 // property functions
1157 result_type m() const;
1158 result_type s() const;
1160 param_type param() const;
1161 void param(const param_type& parm);
1163 result_type min() const;
1164 result_type max() const;
1166 friend bool operator==(const lognormal_distribution& x,
1167 const lognormal_distribution& y);
1168 friend bool operator!=(const lognormal_distribution& x,
1169 const lognormal_distribution& y);
1171 template <class charT, class traits>
1173 basic_ostream<charT, traits>&
1174 operator<<(basic_ostream<charT, traits>& os,
1175 const lognormal_distribution& x);
1177 template <class charT, class traits>
1179 basic_istream<charT, traits>&
1180 operator>>(basic_istream<charT, traits>& is,
1181 lognormal_distribution& x);
1184 template<class RealType = double>
1185 class chi_squared_distribution
1189 typedef RealType result_type;
1194 typedef chi_squared_distribution distribution_type;
1196 explicit param_type(result_type n = 1);
1198 result_type n() const;
1200 friend bool operator==(const param_type& x, const param_type& y);
1201 friend bool operator!=(const param_type& x, const param_type& y);
1204 // constructor and reset functions
1205 explicit chi_squared_distribution(result_type n = 1);
1206 explicit chi_squared_distribution(const param_type& parm);
1209 // generating functions
1210 template<class URNG> result_type operator()(URNG& g);
1211 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
1213 // property functions
1214 result_type n() const;
1216 param_type param() const;
1217 void param(const param_type& parm);
1219 result_type min() const;
1220 result_type max() const;
1222 friend bool operator==(const chi_squared_distribution& x,
1223 const chi_squared_distribution& y);
1224 friend bool operator!=(const chi_squared_distribution& x,
1225 const chi_squared_distribution& y);
1227 template <class charT, class traits>
1229 basic_ostream<charT, traits>&
1230 operator<<(basic_ostream<charT, traits>& os,
1231 const chi_squared_distribution& x);
1233 template <class charT, class traits>
1235 basic_istream<charT, traits>&
1236 operator>>(basic_istream<charT, traits>& is,
1237 chi_squared_distribution& x);
1240 template<class RealType = double>
1241 class cauchy_distribution
1245 typedef RealType result_type;
1250 typedef cauchy_distribution distribution_type;
1252 explicit param_type(result_type a = 0, result_type b = 1);
1254 result_type a() const;
1255 result_type b() const;
1257 friend bool operator==(const param_type& x, const param_type& y);
1258 friend bool operator!=(const param_type& x, const param_type& y);
1261 // constructor and reset functions
1262 explicit cauchy_distribution(result_type a = 0, result_type b = 1);
1263 explicit cauchy_distribution(const param_type& parm);
1266 // generating functions
1267 template<class URNG> result_type operator()(URNG& g);
1268 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
1270 // property functions
1271 result_type a() const;
1272 result_type b() const;
1274 param_type param() const;
1275 void param(const param_type& parm);
1277 result_type min() const;
1278 result_type max() const;
1280 friend bool operator==(const cauchy_distribution& x,
1281 const cauchy_distribution& y);
1282 friend bool operator!=(const cauchy_distribution& x,
1283 const cauchy_distribution& y);
1285 template <class charT, class traits>
1287 basic_ostream<charT, traits>&
1288 operator<<(basic_ostream<charT, traits>& os,
1289 const cauchy_distribution& x);
1291 template <class charT, class traits>
1293 basic_istream<charT, traits>&
1294 operator>>(basic_istream<charT, traits>& is,
1295 cauchy_distribution& x);
1298 template<class RealType = double>
1299 class fisher_f_distribution
1303 typedef RealType result_type;
1308 typedef fisher_f_distribution distribution_type;
1310 explicit param_type(result_type m = 1, result_type n = 1);
1312 result_type m() const;
1313 result_type n() const;
1315 friend bool operator==(const param_type& x, const param_type& y);
1316 friend bool operator!=(const param_type& x, const param_type& y);
1319 // constructor and reset functions
1320 explicit fisher_f_distribution(result_type m = 1, result_type n = 1);
1321 explicit fisher_f_distribution(const param_type& parm);
1324 // generating functions
1325 template<class URNG> result_type operator()(URNG& g);
1326 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
1328 // property functions
1329 result_type m() const;
1330 result_type n() const;
1332 param_type param() const;
1333 void param(const param_type& parm);
1335 result_type min() const;
1336 result_type max() const;
1338 friend bool operator==(const fisher_f_distribution& x,
1339 const fisher_f_distribution& y);
1340 friend bool operator!=(const fisher_f_distribution& x,
1341 const fisher_f_distribution& y);
1343 template <class charT, class traits>
1345 basic_ostream<charT, traits>&
1346 operator<<(basic_ostream<charT, traits>& os,
1347 const fisher_f_distribution& x);
1349 template <class charT, class traits>
1351 basic_istream<charT, traits>&
1352 operator>>(basic_istream<charT, traits>& is,
1353 fisher_f_distribution& x);
1356 template<class RealType = double>
1357 class student_t_distribution
1361 typedef RealType result_type;
1366 typedef student_t_distribution distribution_type;
1368 explicit param_type(result_type n = 1);
1370 result_type n() const;
1372 friend bool operator==(const param_type& x, const param_type& y);
1373 friend bool operator!=(const param_type& x, const param_type& y);
1376 // constructor and reset functions
1377 explicit student_t_distribution(result_type n = 1);
1378 explicit student_t_distribution(const param_type& parm);
1381 // generating functions
1382 template<class URNG> result_type operator()(URNG& g);
1383 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
1385 // property functions
1386 result_type n() const;
1388 param_type param() const;
1389 void param(const param_type& parm);
1391 result_type min() const;
1392 result_type max() const;
1394 friend bool operator==(const student_t_distribution& x,
1395 const student_t_distribution& y);
1396 friend bool operator!=(const student_t_distribution& x,
1397 const student_t_distribution& y);
1399 template <class charT, class traits>
1401 basic_ostream<charT, traits>&
1402 operator<<(basic_ostream<charT, traits>& os,
1403 const student_t_distribution& x);
1405 template <class charT, class traits>
1407 basic_istream<charT, traits>&
1408 operator>>(basic_istream<charT, traits>& is,
1409 student_t_distribution& x);
1412 template<class IntType = int>
1413 class discrete_distribution
1417 typedef IntType result_type;
1422 typedef discrete_distribution distribution_type;
1425 template<class InputIterator>
1426 param_type(InputIterator firstW, InputIterator lastW);
1427 param_type(initializer_list<double> wl);
1428 template<class UnaryOperation>
1429 param_type(size_t nw, double xmin, double xmax, UnaryOperation fw);
1431 vector<double> probabilities() const;
1433 friend bool operator==(const param_type& x, const param_type& y);
1434 friend bool operator!=(const param_type& x, const param_type& y);
1437 // constructor and reset functions
1438 discrete_distribution();
1439 template<class InputIterator>
1440 discrete_distribution(InputIterator firstW, InputIterator lastW);
1441 discrete_distribution(initializer_list<double> wl);
1442 template<class UnaryOperation>
1443 discrete_distribution(size_t nw, double xmin, double xmax,
1445 explicit discrete_distribution(const param_type& parm);
1448 // generating functions
1449 template<class URNG> result_type operator()(URNG& g);
1450 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
1452 // property functions
1453 vector<double> probabilities() const;
1455 param_type param() const;
1456 void param(const param_type& parm);
1458 result_type min() const;
1459 result_type max() const;
1461 friend bool operator==(const discrete_distribution& x,
1462 const discrete_distribution& y);
1463 friend bool operator!=(const discrete_distribution& x,
1464 const discrete_distribution& y);
1466 template <class charT, class traits>
1468 basic_ostream<charT, traits>&
1469 operator<<(basic_ostream<charT, traits>& os,
1470 const discrete_distribution& x);
1472 template <class charT, class traits>
1474 basic_istream<charT, traits>&
1475 operator>>(basic_istream<charT, traits>& is,
1476 discrete_distribution& x);
1479 template<class RealType = double>
1480 class piecewise_constant_distribution
1483 typedef RealType result_type;
1488 typedef piecewise_constant_distribution distribution_type;
1491 template<class InputIteratorB, class InputIteratorW>
1492 param_type(InputIteratorB firstB, InputIteratorB lastB,
1493 InputIteratorW firstW);
1494 template<class UnaryOperation>
1495 param_type(initializer_list<result_type> bl, UnaryOperation fw);
1496 template<class UnaryOperation>
1497 param_type(size_t nw, result_type xmin, result_type xmax,
1500 vector<result_type> intervals() const;
1501 vector<result_type> densities() const;
1503 friend bool operator==(const param_type& x, const param_type& y);
1504 friend bool operator!=(const param_type& x, const param_type& y);
1507 // constructor and reset functions
1508 piecewise_constant_distribution();
1509 template<class InputIteratorB, class InputIteratorW>
1510 piecewise_constant_distribution(InputIteratorB firstB,
1511 InputIteratorB lastB,
1512 InputIteratorW firstW);
1513 template<class UnaryOperation>
1514 piecewise_constant_distribution(initializer_list<result_type> bl,
1516 template<class UnaryOperation>
1517 piecewise_constant_distribution(size_t nw, result_type xmin,
1518 result_type xmax, UnaryOperation fw);
1519 explicit piecewise_constant_distribution(const param_type& parm);
1522 // generating functions
1523 template<class URNG> result_type operator()(URNG& g);
1524 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
1526 // property functions
1527 vector<result_type> intervals() const;
1528 vector<result_type> densities() const;
1530 param_type param() const;
1531 void param(const param_type& parm);
1533 result_type min() const;
1534 result_type max() const;
1536 friend bool operator==(const piecewise_constant_distribution& x,
1537 const piecewise_constant_distribution& y);
1538 friend bool operator!=(const piecewise_constant_distribution& x,
1539 const piecewise_constant_distribution& y);
1541 template <class charT, class traits>
1543 basic_ostream<charT, traits>&
1544 operator<<(basic_ostream<charT, traits>& os,
1545 const piecewise_constant_distribution& x);
1547 template <class charT, class traits>
1549 basic_istream<charT, traits>&
1550 operator>>(basic_istream<charT, traits>& is,
1551 piecewise_constant_distribution& x);
1554 template<class RealType = double>
1555 class piecewise_linear_distribution
1558 typedef RealType result_type;
1563 typedef piecewise_linear_distribution distribution_type;
1566 template<class InputIteratorB, class InputIteratorW>
1567 param_type(InputIteratorB firstB, InputIteratorB lastB,
1568 InputIteratorW firstW);
1569 template<class UnaryOperation>
1570 param_type(initializer_list<result_type> bl, UnaryOperation fw);
1571 template<class UnaryOperation>
1572 param_type(size_t nw, result_type xmin, result_type xmax,
1575 vector<result_type> intervals() const;
1576 vector<result_type> densities() const;
1578 friend bool operator==(const param_type& x, const param_type& y);
1579 friend bool operator!=(const param_type& x, const param_type& y);
1582 // constructor and reset functions
1583 piecewise_linear_distribution();
1584 template<class InputIteratorB, class InputIteratorW>
1585 piecewise_linear_distribution(InputIteratorB firstB,
1586 InputIteratorB lastB,
1587 InputIteratorW firstW);
1589 template<class UnaryOperation>
1590 piecewise_linear_distribution(initializer_list<result_type> bl,
1593 template<class UnaryOperation>
1594 piecewise_linear_distribution(size_t nw, result_type xmin,
1595 result_type xmax, UnaryOperation fw);
1597 explicit piecewise_linear_distribution(const param_type& parm);
1600 // generating functions
1601 template<class URNG> result_type operator()(URNG& g);
1602 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
1604 // property functions
1605 vector<result_type> intervals() const;
1606 vector<result_type> densities() const;
1608 param_type param() const;
1609 void param(const param_type& parm);
1611 result_type min() const;
1612 result_type max() const;
1614 friend bool operator==(const piecewise_linear_distribution& x,
1615 const piecewise_linear_distribution& y);
1616 friend bool operator!=(const piecewise_linear_distribution& x,
1617 const piecewise_linear_distribution& y);
1619 template <class charT, class traits>
1621 basic_ostream<charT, traits>&
1622 operator<<(basic_ostream<charT, traits>& os,
1623 const piecewise_linear_distribution& x);
1625 template <class charT, class traits>
1627 basic_istream<charT, traits>&
1628 operator>>(basic_istream<charT, traits>& is,
1629 piecewise_linear_distribution& x);
1637 #include <type_traits>
1638 #include <initializer_list>
1641 #include <algorithm>
1649 #include <__undef_min_max>
1651 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1652 #pragma GCC system_header
1655 _LIBCPP_BEGIN_NAMESPACE_STD
1657 // __is_seed_sequence
1659 template <class _Sseq, class _Engine>
1660 struct __is_seed_sequence
1662 static _LIBCPP_CONSTEXPR const bool value =
1663 !is_convertible<_Sseq, typename _Engine::result_type>::value &&
1664 !is_same<typename remove_cv<_Sseq>::type, _Engine>::value;
1667 // linear_congruential_engine
1669 template <unsigned long long __a, unsigned long long __c,
1670 unsigned long long __m, unsigned long long _Mp,
1671 bool _MightOverflow = (__a != 0 && __m != 0 && __m-1 > (_Mp-__c)/__a)>
1676 template <unsigned long long __a, unsigned long long __c, unsigned long long __m>
1677 struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), true>
1679 typedef unsigned long long result_type;
1680 _LIBCPP_INLINE_VISIBILITY
1681 static result_type next(result_type __x)
1683 // Schrage's algorithm
1684 const result_type __q = __m / __a;
1685 const result_type __r = __m % __a;
1686 const result_type __t0 = __a * (__x % __q);
1687 const result_type __t1 = __r * (__x / __q);
1688 __x = __t0 + (__t0 < __t1) * __m - __t1;
1689 __x += __c - (__x >= __m - __c) * __m;
1694 template <unsigned long long __a, unsigned long long __m>
1695 struct __lce_ta<__a, 0, __m, (unsigned long long)(~0), true>
1697 typedef unsigned long long result_type;
1698 _LIBCPP_INLINE_VISIBILITY
1699 static result_type next(result_type __x)
1701 // Schrage's algorithm
1702 const result_type __q = __m / __a;
1703 const result_type __r = __m % __a;
1704 const result_type __t0 = __a * (__x % __q);
1705 const result_type __t1 = __r * (__x / __q);
1706 __x = __t0 + (__t0 < __t1) * __m - __t1;
1711 template <unsigned long long __a, unsigned long long __c, unsigned long long __m>
1712 struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), false>
1714 typedef unsigned long long result_type;
1715 _LIBCPP_INLINE_VISIBILITY
1716 static result_type next(result_type __x)
1718 return (__a * __x + __c) % __m;
1722 template <unsigned long long __a, unsigned long long __c>
1723 struct __lce_ta<__a, __c, 0, (unsigned long long)(~0), false>
1725 typedef unsigned long long result_type;
1726 _LIBCPP_INLINE_VISIBILITY
1727 static result_type next(result_type __x)
1729 return __a * __x + __c;
1735 template <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp>
1736 struct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), true>
1738 typedef unsigned result_type;
1739 _LIBCPP_INLINE_VISIBILITY
1740 static result_type next(result_type __x)
1742 const result_type __a = static_cast<result_type>(_Ap);
1743 const result_type __c = static_cast<result_type>(_Cp);
1744 const result_type __m = static_cast<result_type>(_Mp);
1745 // Schrage's algorithm
1746 const result_type __q = __m / __a;
1747 const result_type __r = __m % __a;
1748 const result_type __t0 = __a * (__x % __q);
1749 const result_type __t1 = __r * (__x / __q);
1750 __x = __t0 + (__t0 < __t1) * __m - __t1;
1751 __x += __c - (__x >= __m - __c) * __m;
1756 template <unsigned long long _Ap, unsigned long long _Mp>
1757 struct __lce_ta<_Ap, 0, _Mp, unsigned(~0), true>
1759 typedef unsigned result_type;
1760 _LIBCPP_INLINE_VISIBILITY
1761 static result_type next(result_type __x)
1763 const result_type __a = static_cast<result_type>(_Ap);
1764 const result_type __m = static_cast<result_type>(_Mp);
1765 // Schrage's algorithm
1766 const result_type __q = __m / __a;
1767 const result_type __r = __m % __a;
1768 const result_type __t0 = __a * (__x % __q);
1769 const result_type __t1 = __r * (__x / __q);
1770 __x = __t0 + (__t0 < __t1) * __m - __t1;
1775 template <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp>
1776 struct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), false>
1778 typedef unsigned result_type;
1779 _LIBCPP_INLINE_VISIBILITY
1780 static result_type next(result_type __x)
1782 const result_type __a = static_cast<result_type>(_Ap);
1783 const result_type __c = static_cast<result_type>(_Cp);
1784 const result_type __m = static_cast<result_type>(_Mp);
1785 return (__a * __x + __c) % __m;
1789 template <unsigned long long _Ap, unsigned long long _Cp>
1790 struct __lce_ta<_Ap, _Cp, 0, unsigned(~0), false>
1792 typedef unsigned result_type;
1793 _LIBCPP_INLINE_VISIBILITY
1794 static result_type next(result_type __x)
1796 const result_type __a = static_cast<result_type>(_Ap);
1797 const result_type __c = static_cast<result_type>(_Cp);
1798 return __a * __x + __c;
1804 template <unsigned long long __a, unsigned long long __c, unsigned long long __m, bool __b>
1805 struct __lce_ta<__a, __c, __m, (unsigned short)(~0), __b>
1807 typedef unsigned short result_type;
1808 _LIBCPP_INLINE_VISIBILITY
1809 static result_type next(result_type __x)
1811 return static_cast<result_type>(__lce_ta<__a, __c, __m, unsigned(~0)>::next(__x));
1815 template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
1816 class _LIBCPP_TYPE_VIS linear_congruential_engine;
1818 template <class _CharT, class _Traits,
1819 class _Up, _Up _Ap, _Up _Cp, _Up _Np>
1820 _LIBCPP_INLINE_VISIBILITY
1821 basic_ostream<_CharT, _Traits>&
1822 operator<<(basic_ostream<_CharT, _Traits>& __os,
1823 const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&);
1825 template <class _CharT, class _Traits,
1826 class _Up, _Up _Ap, _Up _Cp, _Up _Np>
1827 basic_istream<_CharT, _Traits>&
1828 operator>>(basic_istream<_CharT, _Traits>& __is,
1829 linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x);
1831 template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
1832 class _LIBCPP_TYPE_VIS linear_congruential_engine
1836 typedef _UIntType result_type;
1841 static _LIBCPP_CONSTEXPR const result_type _Mp = result_type(~0);
1843 static_assert(__m == 0 || __a < __m, "linear_congruential_engine invalid parameters");
1844 static_assert(__m == 0 || __c < __m, "linear_congruential_engine invalid parameters");
1846 static _LIBCPP_CONSTEXPR const result_type _Min = __c == 0u ? 1u: 0u;
1847 static _LIBCPP_CONSTEXPR const result_type _Max = __m - 1u;
1848 static_assert(_Min < _Max, "linear_congruential_engine invalid parameters");
1850 // engine characteristics
1851 static _LIBCPP_CONSTEXPR const result_type multiplier = __a;
1852 static _LIBCPP_CONSTEXPR const result_type increment = __c;
1853 static _LIBCPP_CONSTEXPR const result_type modulus = __m;
1854 _LIBCPP_INLINE_VISIBILITY
1855 static _LIBCPP_CONSTEXPR result_type min() {return _Min;}
1856 _LIBCPP_INLINE_VISIBILITY
1857 static _LIBCPP_CONSTEXPR result_type max() {return _Max;}
1858 static _LIBCPP_CONSTEXPR const result_type default_seed = 1u;
1860 // constructors and seeding functions
1861 _LIBCPP_INLINE_VISIBILITY
1862 explicit linear_congruential_engine(result_type __s = default_seed)
1864 template<class _Sseq>
1865 _LIBCPP_INLINE_VISIBILITY
1866 explicit linear_congruential_engine(_Sseq& __q,
1867 typename enable_if<__is_seed_sequence<_Sseq, linear_congruential_engine>::value>::type* = 0)
1869 _LIBCPP_INLINE_VISIBILITY
1870 void seed(result_type __s = default_seed)
1871 {seed(integral_constant<bool, __m == 0>(),
1872 integral_constant<bool, __c == 0>(), __s);}
1873 template<class _Sseq>
1874 _LIBCPP_INLINE_VISIBILITY
1877 __is_seed_sequence<_Sseq, linear_congruential_engine>::value,
1881 {__seed(__q, integral_constant<unsigned,
1882 1 + (__m == 0 ? (sizeof(result_type) * __CHAR_BIT__ - 1)/32
1883 : (__m > 0x100000000ull))>());}
1885 // generating functions
1886 _LIBCPP_INLINE_VISIBILITY
1887 result_type operator()()
1888 {return __x_ = static_cast<result_type>(__lce_ta<__a, __c, __m, _Mp>::next(__x_));}
1889 _LIBCPP_INLINE_VISIBILITY
1890 void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
1892 friend _LIBCPP_INLINE_VISIBILITY
1893 bool operator==(const linear_congruential_engine& __x,
1894 const linear_congruential_engine& __y)
1895 {return __x.__x_ == __y.__x_;}
1896 friend _LIBCPP_INLINE_VISIBILITY
1897 bool operator!=(const linear_congruential_engine& __x,
1898 const linear_congruential_engine& __y)
1899 {return !(__x == __y);}
1903 _LIBCPP_INLINE_VISIBILITY
1904 void seed(true_type, true_type, result_type __s) {__x_ = __s == 0 ? 1 : __s;}
1905 _LIBCPP_INLINE_VISIBILITY
1906 void seed(true_type, false_type, result_type __s) {__x_ = __s;}
1907 _LIBCPP_INLINE_VISIBILITY
1908 void seed(false_type, true_type, result_type __s) {__x_ = __s % __m == 0 ?
1910 _LIBCPP_INLINE_VISIBILITY
1911 void seed(false_type, false_type, result_type __s) {__x_ = __s % __m;}
1913 template<class _Sseq>
1914 void __seed(_Sseq& __q, integral_constant<unsigned, 1>);
1915 template<class _Sseq>
1916 void __seed(_Sseq& __q, integral_constant<unsigned, 2>);
1918 template <class _CharT, class _Traits,
1919 class _Up, _Up _Ap, _Up _Cp, _Up _Np>
1921 basic_ostream<_CharT, _Traits>&
1922 operator<<(basic_ostream<_CharT, _Traits>& __os,
1923 const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&);
1925 template <class _CharT, class _Traits,
1926 class _Up, _Up _Ap, _Up _Cp, _Up _Np>
1928 basic_istream<_CharT, _Traits>&
1929 operator>>(basic_istream<_CharT, _Traits>& __is,
1930 linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x);
1933 template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
1934 _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
1935 linear_congruential_engine<_UIntType, __a, __c, __m>::multiplier;
1937 template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
1938 _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
1939 linear_congruential_engine<_UIntType, __a, __c, __m>::increment;
1941 template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
1942 _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
1943 linear_congruential_engine<_UIntType, __a, __c, __m>::modulus;
1945 template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
1946 _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
1947 linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed;
1949 template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
1950 template<class _Sseq>
1952 linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q,
1953 integral_constant<unsigned, 1>)
1955 const unsigned __k = 1;
1956 uint32_t __ar[__k+3];
1957 __q.generate(__ar, __ar + __k + 3);
1958 result_type __s = static_cast<result_type>(__ar[3] % __m);
1959 __x_ = __c == 0 && __s == 0 ? result_type(1) : __s;
1962 template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
1963 template<class _Sseq>
1965 linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q,
1966 integral_constant<unsigned, 2>)
1968 const unsigned __k = 2;
1969 uint32_t __ar[__k+3];
1970 __q.generate(__ar, __ar + __k + 3);
1971 result_type __s = static_cast<result_type>((__ar[3] +
1972 ((uint64_t)__ar[4] << 32)) % __m);
1973 __x_ = __c == 0 && __s == 0 ? result_type(1) : __s;
1976 template <class _CharT, class _Traits>
1979 typedef basic_ios<_CharT, _Traits> __stream_type;
1980 typedef typename __stream_type::fmtflags fmtflags;
1982 __stream_type& __stream_;
1983 fmtflags __fmtflags_;
1986 __save_flags(const __save_flags&);
1987 __save_flags& operator=(const __save_flags&);
1989 _LIBCPP_INLINE_VISIBILITY
1990 explicit __save_flags(__stream_type& __stream)
1991 : __stream_(__stream),
1992 __fmtflags_(__stream.flags()),
1993 __fill_(__stream.fill())
1995 _LIBCPP_INLINE_VISIBILITY
1998 __stream_.flags(__fmtflags_);
1999 __stream_.fill(__fill_);
2003 template <class _CharT, class _Traits,
2004 class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
2005 inline _LIBCPP_INLINE_VISIBILITY
2006 basic_ostream<_CharT, _Traits>&
2007 operator<<(basic_ostream<_CharT, _Traits>& __os,
2008 const linear_congruential_engine<_UIntType, __a, __c, __m>& __x)
2010 __save_flags<_CharT, _Traits> __lx(__os);
2011 __os.flags(ios_base::dec | ios_base::left);
2012 __os.fill(__os.widen(' '));
2013 return __os << __x.__x_;
2016 template <class _CharT, class _Traits,
2017 class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
2018 basic_istream<_CharT, _Traits>&
2019 operator>>(basic_istream<_CharT, _Traits>& __is,
2020 linear_congruential_engine<_UIntType, __a, __c, __m>& __x)
2022 __save_flags<_CharT, _Traits> __lx(__is);
2023 __is.flags(ios_base::dec | ios_base::skipws);
2031 typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647>
2033 typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647>
2035 typedef minstd_rand default_random_engine;
2036 // mersenne_twister_engine
2038 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2039 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2040 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2041 class _LIBCPP_TYPE_VIS mersenne_twister_engine;
2043 template <class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2044 _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp,
2045 _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp>
2047 operator==(const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2048 _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
2049 const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2050 _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
2052 template <class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2053 _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp,
2054 _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp>
2055 _LIBCPP_INLINE_VISIBILITY
2057 operator!=(const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2058 _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
2059 const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2060 _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
2062 template <class _CharT, class _Traits,
2063 class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2064 _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp,
2065 _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp>
2066 basic_ostream<_CharT, _Traits>&
2067 operator<<(basic_ostream<_CharT, _Traits>& __os,
2068 const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2069 _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
2071 template <class _CharT, class _Traits,
2072 class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2073 _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp,
2074 _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp>
2075 basic_istream<_CharT, _Traits>&
2076 operator>>(basic_istream<_CharT, _Traits>& __is,
2077 mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2078 _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
2080 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2081 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2082 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2083 class _LIBCPP_TYPE_VIS mersenne_twister_engine
2087 typedef _UIntType result_type;
2090 result_type __x_[__n];
2093 static_assert( 0 < __m, "mersenne_twister_engine invalid parameters");
2094 static_assert(__m <= __n, "mersenne_twister_engine invalid parameters");
2095 static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits;
2096 static_assert(__w <= _Dt, "mersenne_twister_engine invalid parameters");
2097 static_assert( 2 <= __w, "mersenne_twister_engine invalid parameters");
2098 static_assert(__r <= __w, "mersenne_twister_engine invalid parameters");
2099 static_assert(__u <= __w, "mersenne_twister_engine invalid parameters");
2100 static_assert(__s <= __w, "mersenne_twister_engine invalid parameters");
2101 static_assert(__t <= __w, "mersenne_twister_engine invalid parameters");
2102 static_assert(__l <= __w, "mersenne_twister_engine invalid parameters");
2104 static _LIBCPP_CONSTEXPR const result_type _Min = 0;
2105 static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) :
2106 (result_type(1) << __w) - result_type(1);
2107 static_assert(_Min < _Max, "mersenne_twister_engine invalid parameters");
2108 static_assert(__a <= _Max, "mersenne_twister_engine invalid parameters");
2109 static_assert(__b <= _Max, "mersenne_twister_engine invalid parameters");
2110 static_assert(__c <= _Max, "mersenne_twister_engine invalid parameters");
2111 static_assert(__d <= _Max, "mersenne_twister_engine invalid parameters");
2112 static_assert(__f <= _Max, "mersenne_twister_engine invalid parameters");
2114 // engine characteristics
2115 static _LIBCPP_CONSTEXPR const size_t word_size = __w;
2116 static _LIBCPP_CONSTEXPR const size_t state_size = __n;
2117 static _LIBCPP_CONSTEXPR const size_t shift_size = __m;
2118 static _LIBCPP_CONSTEXPR const size_t mask_bits = __r;
2119 static _LIBCPP_CONSTEXPR const result_type xor_mask = __a;
2120 static _LIBCPP_CONSTEXPR const size_t tempering_u = __u;
2121 static _LIBCPP_CONSTEXPR const result_type tempering_d = __d;
2122 static _LIBCPP_CONSTEXPR const size_t tempering_s = __s;
2123 static _LIBCPP_CONSTEXPR const result_type tempering_b = __b;
2124 static _LIBCPP_CONSTEXPR const size_t tempering_t = __t;
2125 static _LIBCPP_CONSTEXPR const result_type tempering_c = __c;
2126 static _LIBCPP_CONSTEXPR const size_t tempering_l = __l;
2127 static _LIBCPP_CONSTEXPR const result_type initialization_multiplier = __f;
2128 _LIBCPP_INLINE_VISIBILITY
2129 static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
2130 _LIBCPP_INLINE_VISIBILITY
2131 static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
2132 static _LIBCPP_CONSTEXPR const result_type default_seed = 5489u;
2134 // constructors and seeding functions
2135 _LIBCPP_INLINE_VISIBILITY
2136 explicit mersenne_twister_engine(result_type __sd = default_seed)
2138 template<class _Sseq>
2139 _LIBCPP_INLINE_VISIBILITY
2140 explicit mersenne_twister_engine(_Sseq& __q,
2141 typename enable_if<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value>::type* = 0)
2143 void seed(result_type __sd = default_seed);
2144 template<class _Sseq>
2145 _LIBCPP_INLINE_VISIBILITY
2148 __is_seed_sequence<_Sseq, mersenne_twister_engine>::value,
2152 {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());}
2154 // generating functions
2155 result_type operator()();
2156 _LIBCPP_INLINE_VISIBILITY
2157 void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
2159 template <class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2160 _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp,
2161 _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp>
2164 operator==(const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2165 _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
2166 const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2167 _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
2169 template <class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2170 _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp,
2171 _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp>
2174 operator!=(const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2175 _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
2176 const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2177 _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
2179 template <class _CharT, class _Traits,
2180 class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2181 _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp,
2182 _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp>
2184 basic_ostream<_CharT, _Traits>&
2185 operator<<(basic_ostream<_CharT, _Traits>& __os,
2186 const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2187 _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
2189 template <class _CharT, class _Traits,
2190 class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2191 _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp,
2192 _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp>
2194 basic_istream<_CharT, _Traits>&
2195 operator>>(basic_istream<_CharT, _Traits>& __is,
2196 mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2197 _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
2200 template<class _Sseq>
2201 void __seed(_Sseq& __q, integral_constant<unsigned, 1>);
2202 template<class _Sseq>
2203 void __seed(_Sseq& __q, integral_constant<unsigned, 2>);
2205 template <size_t __count>
2206 _LIBCPP_INLINE_VISIBILITY
2213 __lshift(result_type __x) {return (__x << __count) & _Max;}
2215 template <size_t __count>
2216 _LIBCPP_INLINE_VISIBILITY
2223 __lshift(result_type) {return result_type(0);}
2225 template <size_t __count>
2226 _LIBCPP_INLINE_VISIBILITY
2233 __rshift(result_type __x) {return __x >> __count;}
2235 template <size_t __count>
2236 _LIBCPP_INLINE_VISIBILITY
2243 __rshift(result_type) {return result_type(0);}
2246 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2247 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2248 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2249 _LIBCPP_CONSTEXPR const size_t
2250 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::word_size;
2252 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2253 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2254 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2255 _LIBCPP_CONSTEXPR const size_t
2256 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::state_size;
2258 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2259 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2260 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2261 _LIBCPP_CONSTEXPR const size_t
2262 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::shift_size;
2264 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2265 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2266 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2267 _LIBCPP_CONSTEXPR const size_t
2268 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mask_bits;
2270 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2271 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2272 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2273 _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
2274 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::xor_mask;
2276 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2277 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2278 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2279 _LIBCPP_CONSTEXPR const size_t
2280 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_u;
2282 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2283 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2284 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2285 _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
2286 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_d;
2288 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2289 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2290 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2291 _LIBCPP_CONSTEXPR const size_t
2292 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_s;
2294 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2295 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2296 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2297 _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
2298 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_b;
2300 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2301 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2302 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2303 _LIBCPP_CONSTEXPR const size_t
2304 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_t;
2306 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2307 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2308 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2309 _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
2310 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_c;
2312 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2313 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2314 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2315 _LIBCPP_CONSTEXPR const size_t
2316 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_l;
2318 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2319 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2320 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2321 _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
2322 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::initialization_multiplier;
2324 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2325 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2326 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2327 _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
2328 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::default_seed;
2330 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2331 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2332 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2334 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
2335 __t, __c, __l, __f>::seed(result_type __sd)
2337 __x_[0] = __sd & _Max;
2338 for (size_t __i = 1; __i < __n; ++__i)
2339 __x_[__i] = (__f * (__x_[__i-1] ^ __rshift<__w - 2>(__x_[__i-1])) + __i) & _Max;
2343 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2344 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2345 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2346 template<class _Sseq>
2348 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
2349 __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 1>)
2351 const unsigned __k = 1;
2352 uint32_t __ar[__n * __k];
2353 __q.generate(__ar, __ar + __n * __k);
2354 for (size_t __i = 0; __i < __n; ++__i)
2355 __x_[__i] = static_cast<result_type>(__ar[__i] & _Max);
2356 const result_type __mask = __r == _Dt ? result_type(~0) :
2357 (result_type(1) << __r) - result_type(1);
2359 if ((__x_[0] & ~__mask) == 0)
2361 for (size_t __i = 1; __i < __n; ++__i)
2368 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2369 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2370 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2371 template<class _Sseq>
2373 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
2374 __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 2>)
2376 const unsigned __k = 2;
2377 uint32_t __ar[__n * __k];
2378 __q.generate(__ar, __ar + __n * __k);
2379 for (size_t __i = 0; __i < __n; ++__i)
2380 __x_[__i] = static_cast<result_type>(
2381 (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max);
2382 const result_type __mask = __r == _Dt ? result_type(~0) :
2383 (result_type(1) << __r) - result_type(1);
2385 if ((__x_[0] & ~__mask) == 0)
2387 for (size_t __i = 1; __i < __n; ++__i)
2394 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2395 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2396 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2398 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
2399 __t, __c, __l, __f>::operator()()
2401 const size_t __j = (__i_ + 1) % __n;
2402 const result_type __mask = __r == _Dt ? result_type(~0) :
2403 (result_type(1) << __r) - result_type(1);
2404 const result_type _Yp = (__x_[__i_] & ~__mask) | (__x_[__j] & __mask);
2405 const size_t __k = (__i_ + __m) % __n;
2406 __x_[__i_] = __x_[__k] ^ __rshift<1>(_Yp) ^ (__a * (_Yp & 1));
2407 result_type __z = __x_[__i_] ^ (__rshift<__u>(__x_[__i_]) & __d);
2409 __z ^= __lshift<__s>(__z) & __b;
2410 __z ^= __lshift<__t>(__z) & __c;
2411 return __z ^ __rshift<__l>(__z);
2414 template <class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2415 _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp,
2416 _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp>
2418 operator==(const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2419 _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
2420 const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2421 _Bp, _Tp, _Cp, _Lp, _Fp>& __y)
2423 if (__x.__i_ == __y.__i_)
2424 return _VSTD::equal(__x.__x_, __x.__x_ + _Np, __y.__x_);
2425 if (__x.__i_ == 0 || __y.__i_ == 0)
2427 size_t __j = _VSTD::min(_Np - __x.__i_, _Np - __y.__i_);
2428 if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j,
2429 __y.__x_ + __y.__i_))
2432 return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Np, __y.__x_);
2433 return _VSTD::equal(__x.__x_, __x.__x_ + (_Np - __j), __y.__x_ + __j);
2435 if (__x.__i_ < __y.__i_)
2437 size_t __j = _Np - __y.__i_;
2438 if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j),
2439 __y.__x_ + __y.__i_))
2441 if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Np,
2444 return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_,
2445 __y.__x_ + (_Np - (__x.__i_ + __j)));
2447 size_t __j = _Np - __x.__i_;
2448 if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j),
2449 __x.__x_ + __x.__i_))
2451 if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Np,
2454 return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_,
2455 __x.__x_ + (_Np - (__y.__i_ + __j)));
2458 template <class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2459 _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp,
2460 _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp>
2461 inline _LIBCPP_INLINE_VISIBILITY
2463 operator!=(const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2464 _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
2465 const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2466 _Bp, _Tp, _Cp, _Lp, _Fp>& __y)
2468 return !(__x == __y);
2471 template <class _CharT, class _Traits,
2472 class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2473 _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp,
2474 _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp>
2475 basic_ostream<_CharT, _Traits>&
2476 operator<<(basic_ostream<_CharT, _Traits>& __os,
2477 const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2478 _Bp, _Tp, _Cp, _Lp, _Fp>& __x)
2480 __save_flags<_CharT, _Traits> __lx(__os);
2481 __os.flags(ios_base::dec | ios_base::left);
2482 _CharT __sp = __os.widen(' ');
2484 __os << __x.__x_[__x.__i_];
2485 for (size_t __j = __x.__i_ + 1; __j < _Np; ++__j)
2486 __os << __sp << __x.__x_[__j];
2487 for (size_t __j = 0; __j < __x.__i_; ++__j)
2488 __os << __sp << __x.__x_[__j];
2492 template <class _CharT, class _Traits,
2493 class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2494 _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp,
2495 _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp>
2496 basic_istream<_CharT, _Traits>&
2497 operator>>(basic_istream<_CharT, _Traits>& __is,
2498 mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2499 _Bp, _Tp, _Cp, _Lp, _Fp>& __x)
2501 __save_flags<_CharT, _Traits> __lx(__is);
2502 __is.flags(ios_base::dec | ios_base::skipws);
2504 for (size_t __i = 0; __i < _Np; ++__i)
2508 for (size_t __i = 0; __i < _Np; ++__i)
2509 __x.__x_[__i] = __t[__i];
2515 typedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31,
2516 0x9908b0df, 11, 0xffffffff,
2519 18, 1812433253> mt19937;
2520 typedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31,
2521 0xb5026f5aa96619e9ULL, 29, 0x5555555555555555ULL,
2522 17, 0x71d67fffeda60000ULL,
2523 37, 0xfff7eee000000000ULL,
2524 43, 6364136223846793005ULL> mt19937_64;
2526 // subtract_with_carry_engine
2528 template<class _UIntType, size_t __w, size_t __s, size_t __r>
2529 class _LIBCPP_TYPE_VIS subtract_with_carry_engine;
2531 template<class _UI, size_t _Wp, size_t _Sp, size_t _Rp>
2534 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x,
2535 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __y);
2537 template<class _UI, size_t _Wp, size_t _Sp, size_t _Rp>
2538 _LIBCPP_INLINE_VISIBILITY
2541 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x,
2542 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __y);
2544 template <class _CharT, class _Traits,
2545 class _UI, size_t _Wp, size_t _Sp, size_t _Rp>
2546 basic_ostream<_CharT, _Traits>&
2547 operator<<(basic_ostream<_CharT, _Traits>& __os,
2548 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x);
2550 template <class _CharT, class _Traits,
2551 class _UI, size_t _Wp, size_t _Sp, size_t _Rp>
2552 basic_istream<_CharT, _Traits>&
2553 operator>>(basic_istream<_CharT, _Traits>& __is,
2554 subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x);
2556 template<class _UIntType, size_t __w, size_t __s, size_t __r>
2557 class _LIBCPP_TYPE_VIS subtract_with_carry_engine
2561 typedef _UIntType result_type;
2564 result_type __x_[__r];
2568 static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits;
2569 static_assert( 0 < __w, "subtract_with_carry_engine invalid parameters");
2570 static_assert(__w <= _Dt, "subtract_with_carry_engine invalid parameters");
2571 static_assert( 0 < __s, "subtract_with_carry_engine invalid parameters");
2572 static_assert(__s < __r, "subtract_with_carry_engine invalid parameters");
2574 static _LIBCPP_CONSTEXPR const result_type _Min = 0;
2575 static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) :
2576 (result_type(1) << __w) - result_type(1);
2577 static_assert(_Min < _Max, "subtract_with_carry_engine invalid parameters");
2579 // engine characteristics
2580 static _LIBCPP_CONSTEXPR const size_t word_size = __w;
2581 static _LIBCPP_CONSTEXPR const size_t short_lag = __s;
2582 static _LIBCPP_CONSTEXPR const size_t long_lag = __r;
2583 _LIBCPP_INLINE_VISIBILITY
2584 static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
2585 _LIBCPP_INLINE_VISIBILITY
2586 static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
2587 static _LIBCPP_CONSTEXPR const result_type default_seed = 19780503u;
2589 // constructors and seeding functions
2590 _LIBCPP_INLINE_VISIBILITY
2591 explicit subtract_with_carry_engine(result_type __sd = default_seed)
2593 template<class _Sseq>
2594 _LIBCPP_INLINE_VISIBILITY
2595 explicit subtract_with_carry_engine(_Sseq& __q,
2596 typename enable_if<__is_seed_sequence<_Sseq, subtract_with_carry_engine>::value>::type* = 0)
2598 _LIBCPP_INLINE_VISIBILITY
2599 void seed(result_type __sd = default_seed)
2600 {seed(__sd, integral_constant<unsigned, 1 + (__w - 1) / 32>());}
2601 template<class _Sseq>
2602 _LIBCPP_INLINE_VISIBILITY
2605 __is_seed_sequence<_Sseq, subtract_with_carry_engine>::value,
2609 {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());}
2611 // generating functions
2612 result_type operator()();
2613 _LIBCPP_INLINE_VISIBILITY
2614 void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
2616 template<class _UI, size_t _Wp, size_t _Sp, size_t _Rp>
2620 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x,
2621 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __y);
2623 template<class _UI, size_t _Wp, size_t _Sp, size_t _Rp>
2627 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x,
2628 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __y);
2630 template <class _CharT, class _Traits,
2631 class _UI, size_t _Wp, size_t _Sp, size_t _Rp>
2633 basic_ostream<_CharT, _Traits>&
2634 operator<<(basic_ostream<_CharT, _Traits>& __os,
2635 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x);
2637 template <class _CharT, class _Traits,
2638 class _UI, size_t _Wp, size_t _Sp, size_t _Rp>
2640 basic_istream<_CharT, _Traits>&
2641 operator>>(basic_istream<_CharT, _Traits>& __is,
2642 subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x);
2646 void seed(result_type __sd, integral_constant<unsigned, 1>);
2647 void seed(result_type __sd, integral_constant<unsigned, 2>);
2648 template<class _Sseq>
2649 void __seed(_Sseq& __q, integral_constant<unsigned, 1>);
2650 template<class _Sseq>
2651 void __seed(_Sseq& __q, integral_constant<unsigned, 2>);
2654 template<class _UIntType, size_t __w, size_t __s, size_t __r>
2655 _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size;
2657 template<class _UIntType, size_t __w, size_t __s, size_t __r>
2658 _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::short_lag;
2660 template<class _UIntType, size_t __w, size_t __s, size_t __r>
2661 _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag;
2663 template<class _UIntType, size_t __w, size_t __s, size_t __r>
2664 _LIBCPP_CONSTEXPR const typename subtract_with_carry_engine<_UIntType, __w, __s, __r>::result_type
2665 subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed;
2667 template<class _UIntType, size_t __w, size_t __s, size_t __r>
2669 subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd,
2670 integral_constant<unsigned, 1>)
2672 linear_congruential_engine<result_type, 40014u, 0u, 2147483563u>
2673 __e(__sd == 0u ? default_seed : __sd);
2674 for (size_t __i = 0; __i < __r; ++__i)
2675 __x_[__i] = static_cast<result_type>(__e() & _Max);
2676 __c_ = __x_[__r-1] == 0;
2680 template<class _UIntType, size_t __w, size_t __s, size_t __r>
2682 subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd,
2683 integral_constant<unsigned, 2>)
2685 linear_congruential_engine<result_type, 40014u, 0u, 2147483563u>
2686 __e(__sd == 0u ? default_seed : __sd);
2687 for (size_t __i = 0; __i < __r; ++__i)
2689 result_type __e0 = __e();
2690 __x_[__i] = static_cast<result_type>(
2691 (__e0 + ((uint64_t)__e() << 32)) & _Max);
2693 __c_ = __x_[__r-1] == 0;
2697 template<class _UIntType, size_t __w, size_t __s, size_t __r>
2698 template<class _Sseq>
2700 subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q,
2701 integral_constant<unsigned, 1>)
2703 const unsigned __k = 1;
2704 uint32_t __ar[__r * __k];
2705 __q.generate(__ar, __ar + __r * __k);
2706 for (size_t __i = 0; __i < __r; ++__i)
2707 __x_[__i] = static_cast<result_type>(__ar[__i] & _Max);
2708 __c_ = __x_[__r-1] == 0;
2712 template<class _UIntType, size_t __w, size_t __s, size_t __r>
2713 template<class _Sseq>
2715 subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q,
2716 integral_constant<unsigned, 2>)
2718 const unsigned __k = 2;
2719 uint32_t __ar[__r * __k];
2720 __q.generate(__ar, __ar + __r * __k);
2721 for (size_t __i = 0; __i < __r; ++__i)
2722 __x_[__i] = static_cast<result_type>(
2723 (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max);
2724 __c_ = __x_[__r-1] == 0;
2728 template<class _UIntType, size_t __w, size_t __s, size_t __r>
2730 subtract_with_carry_engine<_UIntType, __w, __s, __r>::operator()()
2732 const result_type& __xs = __x_[(__i_ + (__r - __s)) % __r];
2733 result_type& __xr = __x_[__i_];
2734 result_type __new_c = __c_ == 0 ? __xs < __xr : __xs != 0 ? __xs <= __xr : 1;
2735 __xr = (__xs - __xr - __c_) & _Max;
2737 __i_ = (__i_ + 1) % __r;
2741 template<class _UI, size_t _Wp, size_t _Sp, size_t _Rp>
2744 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x,
2745 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __y)
2747 if (__x.__c_ != __y.__c_)
2749 if (__x.__i_ == __y.__i_)
2750 return _VSTD::equal(__x.__x_, __x.__x_ + _Rp, __y.__x_);
2751 if (__x.__i_ == 0 || __y.__i_ == 0)
2753 size_t __j = _VSTD::min(_Rp - __x.__i_, _Rp - __y.__i_);
2754 if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j,
2755 __y.__x_ + __y.__i_))
2758 return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Rp, __y.__x_);
2759 return _VSTD::equal(__x.__x_, __x.__x_ + (_Rp - __j), __y.__x_ + __j);
2761 if (__x.__i_ < __y.__i_)
2763 size_t __j = _Rp - __y.__i_;
2764 if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j),
2765 __y.__x_ + __y.__i_))
2767 if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Rp,
2770 return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_,
2771 __y.__x_ + (_Rp - (__x.__i_ + __j)));
2773 size_t __j = _Rp - __x.__i_;
2774 if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j),
2775 __x.__x_ + __x.__i_))
2777 if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Rp,
2780 return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_,
2781 __x.__x_ + (_Rp - (__y.__i_ + __j)));
2784 template<class _UI, size_t _Wp, size_t _Sp, size_t _Rp>
2785 inline _LIBCPP_INLINE_VISIBILITY
2788 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x,
2789 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __y)
2791 return !(__x == __y);
2794 template <class _CharT, class _Traits,
2795 class _UI, size_t _Wp, size_t _Sp, size_t _Rp>
2796 basic_ostream<_CharT, _Traits>&
2797 operator<<(basic_ostream<_CharT, _Traits>& __os,
2798 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x)
2800 __save_flags<_CharT, _Traits> __lx(__os);
2801 __os.flags(ios_base::dec | ios_base::left);
2802 _CharT __sp = __os.widen(' ');
2804 __os << __x.__x_[__x.__i_];
2805 for (size_t __j = __x.__i_ + 1; __j < _Rp; ++__j)
2806 __os << __sp << __x.__x_[__j];
2807 for (size_t __j = 0; __j < __x.__i_; ++__j)
2808 __os << __sp << __x.__x_[__j];
2809 __os << __sp << __x.__c_;
2813 template <class _CharT, class _Traits,
2814 class _UI, size_t _Wp, size_t _Sp, size_t _Rp>
2815 basic_istream<_CharT, _Traits>&
2816 operator>>(basic_istream<_CharT, _Traits>& __is,
2817 subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x)
2819 __save_flags<_CharT, _Traits> __lx(__is);
2820 __is.flags(ios_base::dec | ios_base::skipws);
2822 for (size_t __i = 0; __i < _Rp+1; ++__i)
2826 for (size_t __i = 0; __i < _Rp; ++__i)
2827 __x.__x_[__i] = __t[__i];
2828 __x.__c_ = __t[_Rp];
2834 typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> ranlux24_base;
2835 typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> ranlux48_base;
2837 // discard_block_engine
2839 template<class _Engine, size_t __p, size_t __r>
2840 class _LIBCPP_TYPE_VIS discard_block_engine
2845 static_assert( 0 < __r, "discard_block_engine invalid parameters");
2846 static_assert(__r <= __p, "discard_block_engine invalid parameters");
2849 typedef typename _Engine::result_type result_type;
2851 // engine characteristics
2852 static _LIBCPP_CONSTEXPR const size_t block_size = __p;
2853 static _LIBCPP_CONSTEXPR const size_t used_block = __r;
2855 #ifdef _LIBCPP_HAS_NO_CONSTEXPR
2856 static const result_type _Min = _Engine::_Min;
2857 static const result_type _Max = _Engine::_Max;
2859 static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min();
2860 static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max();
2863 _LIBCPP_INLINE_VISIBILITY
2864 static _LIBCPP_CONSTEXPR result_type min() { return _Engine::min(); }
2865 _LIBCPP_INLINE_VISIBILITY
2866 static _LIBCPP_CONSTEXPR result_type max() { return _Engine::max(); }
2868 // constructors and seeding functions
2869 _LIBCPP_INLINE_VISIBILITY
2870 discard_block_engine() : __n_(0) {}
2871 _LIBCPP_INLINE_VISIBILITY
2872 explicit discard_block_engine(const _Engine& __e)
2873 : __e_(__e), __n_(0) {}
2874 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2875 _LIBCPP_INLINE_VISIBILITY
2876 explicit discard_block_engine(_Engine&& __e)
2877 : __e_(_VSTD::move(__e)), __n_(0) {}
2878 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2879 _LIBCPP_INLINE_VISIBILITY
2880 explicit discard_block_engine(result_type __sd) : __e_(__sd), __n_(0) {}
2881 template<class _Sseq>
2882 _LIBCPP_INLINE_VISIBILITY
2883 explicit discard_block_engine(_Sseq& __q,
2884 typename enable_if<__is_seed_sequence<_Sseq, discard_block_engine>::value &&
2885 !is_convertible<_Sseq, _Engine>::value>::type* = 0)
2886 : __e_(__q), __n_(0) {}
2887 _LIBCPP_INLINE_VISIBILITY
2888 void seed() {__e_.seed(); __n_ = 0;}
2889 _LIBCPP_INLINE_VISIBILITY
2890 void seed(result_type __sd) {__e_.seed(__sd); __n_ = 0;}
2891 template<class _Sseq>
2892 _LIBCPP_INLINE_VISIBILITY
2895 __is_seed_sequence<_Sseq, discard_block_engine>::value,
2898 seed(_Sseq& __q) {__e_.seed(__q); __n_ = 0;}
2900 // generating functions
2901 result_type operator()();
2902 _LIBCPP_INLINE_VISIBILITY
2903 void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
2905 // property functions
2906 _LIBCPP_INLINE_VISIBILITY
2907 const _Engine& base() const _NOEXCEPT {return __e_;}
2909 template<class _Eng, size_t _Pp, size_t _Rp>
2913 const discard_block_engine<_Eng, _Pp, _Rp>& __x,
2914 const discard_block_engine<_Eng, _Pp, _Rp>& __y);
2916 template<class _Eng, size_t _Pp, size_t _Rp>
2920 const discard_block_engine<_Eng, _Pp, _Rp>& __x,
2921 const discard_block_engine<_Eng, _Pp, _Rp>& __y);
2923 template <class _CharT, class _Traits,
2924 class _Eng, size_t _Pp, size_t _Rp>
2926 basic_ostream<_CharT, _Traits>&
2927 operator<<(basic_ostream<_CharT, _Traits>& __os,
2928 const discard_block_engine<_Eng, _Pp, _Rp>& __x);
2930 template <class _CharT, class _Traits,
2931 class _Eng, size_t _Pp, size_t _Rp>
2933 basic_istream<_CharT, _Traits>&
2934 operator>>(basic_istream<_CharT, _Traits>& __is,
2935 discard_block_engine<_Eng, _Pp, _Rp>& __x);
2938 template<class _Engine, size_t __p, size_t __r>
2939 _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::block_size;
2941 template<class _Engine, size_t __p, size_t __r>
2942 _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::used_block;
2944 template<class _Engine, size_t __p, size_t __r>
2945 typename discard_block_engine<_Engine, __p, __r>::result_type
2946 discard_block_engine<_Engine, __p, __r>::operator()()
2950 __e_.discard(__p - __r);
2957 template<class _Eng, size_t _Pp, size_t _Rp>
2958 inline _LIBCPP_INLINE_VISIBILITY
2960 operator==(const discard_block_engine<_Eng, _Pp, _Rp>& __x,
2961 const discard_block_engine<_Eng, _Pp, _Rp>& __y)
2963 return __x.__n_ == __y.__n_ && __x.__e_ == __y.__e_;
2966 template<class _Eng, size_t _Pp, size_t _Rp>
2967 inline _LIBCPP_INLINE_VISIBILITY
2969 operator!=(const discard_block_engine<_Eng, _Pp, _Rp>& __x,
2970 const discard_block_engine<_Eng, _Pp, _Rp>& __y)
2972 return !(__x == __y);
2975 template <class _CharT, class _Traits,
2976 class _Eng, size_t _Pp, size_t _Rp>
2977 basic_ostream<_CharT, _Traits>&
2978 operator<<(basic_ostream<_CharT, _Traits>& __os,
2979 const discard_block_engine<_Eng, _Pp, _Rp>& __x)
2981 __save_flags<_CharT, _Traits> __lx(__os);
2982 __os.flags(ios_base::dec | ios_base::left);
2983 _CharT __sp = __os.widen(' ');
2985 return __os << __x.__e_ << __sp << __x.__n_;
2988 template <class _CharT, class _Traits,
2989 class _Eng, size_t _Pp, size_t _Rp>
2990 basic_istream<_CharT, _Traits>&
2991 operator>>(basic_istream<_CharT, _Traits>& __is,
2992 discard_block_engine<_Eng, _Pp, _Rp>& __x)
2994 __save_flags<_CharT, _Traits> __lx(__is);
2995 __is.flags(ios_base::dec | ios_base::skipws);
3007 typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24;
3008 typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48;
3010 // independent_bits_engine
3012 template<class _Engine, size_t __w, class _UIntType>
3013 class _LIBCPP_TYPE_VIS independent_bits_engine
3015 template <class _UI, _UI _R0, size_t _Wp, size_t _Mp>
3018 static _LIBCPP_CONSTEXPR const size_t _Dt = numeric_limits<_UI>::digits;
3019 static _LIBCPP_CONSTEXPR const size_t _Np = _Wp / _Mp + (_Wp % _Mp != 0);
3020 static _LIBCPP_CONSTEXPR const size_t _W0 = _Wp / _Np;
3021 static _LIBCPP_CONSTEXPR const _UI _Y0 = _W0 >= _Dt ? 0 : (_R0 >> _W0) << _W0;
3023 static _LIBCPP_CONSTEXPR const size_t value = _R0 - _Y0 > _Y0 / _Np ? _Np + 1 : _Np;
3027 typedef _UIntType result_type;
3032 static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits;
3033 static_assert( 0 < __w, "independent_bits_engine invalid parameters");
3034 static_assert(__w <= _Dt, "independent_bits_engine invalid parameters");
3036 typedef typename _Engine::result_type _Engine_result_type;
3037 typedef typename conditional
3039 sizeof(_Engine_result_type) <= sizeof(result_type),
3042 >::type _Working_result_type;
3043 #ifdef _LIBCPP_HAS_NO_CONSTEXPR
3044 static const _Working_result_type _Rp = _Engine::_Max - _Engine::_Min
3045 + _Working_result_type(1);
3047 static _LIBCPP_CONSTEXPR const _Working_result_type _Rp = _Engine::max() - _Engine::min()
3048 + _Working_result_type(1);
3050 static _LIBCPP_CONSTEXPR const size_t __m = __log2<_Working_result_type, _Rp>::value;
3051 static _LIBCPP_CONSTEXPR const size_t __n = __get_n<_Working_result_type, _Rp, __w, __m>::value;
3052 static _LIBCPP_CONSTEXPR const size_t __w0 = __w / __n;
3053 static _LIBCPP_CONSTEXPR const size_t __n0 = __n - __w % __n;
3054 static _LIBCPP_CONSTEXPR const size_t _WDt = numeric_limits<_Working_result_type>::digits;
3055 static _LIBCPP_CONSTEXPR const size_t _EDt = numeric_limits<_Engine_result_type>::digits;
3056 static _LIBCPP_CONSTEXPR const _Working_result_type __y0 = __w0 >= _WDt ? 0 :
3057 (_Rp >> __w0) << __w0;
3058 static _LIBCPP_CONSTEXPR const _Working_result_type __y1 = __w0 >= _WDt - 1 ? 0 :
3059 (_Rp >> (__w0+1)) << (__w0+1);
3060 static _LIBCPP_CONSTEXPR const _Engine_result_type __mask0 = __w0 > 0 ?
3061 _Engine_result_type(~0) >> (_EDt - __w0) :
3062 _Engine_result_type(0);
3063 static _LIBCPP_CONSTEXPR const _Engine_result_type __mask1 = __w0 < _EDt - 1 ?
3064 _Engine_result_type(~0) >> (_EDt - (__w0 + 1)) :
3065 _Engine_result_type(~0);
3067 static _LIBCPP_CONSTEXPR const result_type _Min = 0;
3068 static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) :
3069 (result_type(1) << __w) - result_type(1);
3070 static_assert(_Min < _Max, "independent_bits_engine invalid parameters");
3072 // engine characteristics
3073 _LIBCPP_INLINE_VISIBILITY
3074 static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
3075 _LIBCPP_INLINE_VISIBILITY
3076 static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
3078 // constructors and seeding functions
3079 _LIBCPP_INLINE_VISIBILITY
3080 independent_bits_engine() {}
3081 _LIBCPP_INLINE_VISIBILITY
3082 explicit independent_bits_engine(const _Engine& __e)
3084 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3085 _LIBCPP_INLINE_VISIBILITY
3086 explicit independent_bits_engine(_Engine&& __e)
3087 : __e_(_VSTD::move(__e)) {}
3088 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3089 _LIBCPP_INLINE_VISIBILITY
3090 explicit independent_bits_engine(result_type __sd) : __e_(__sd) {}
3091 template<class _Sseq>
3092 _LIBCPP_INLINE_VISIBILITY
3093 explicit independent_bits_engine(_Sseq& __q,
3094 typename enable_if<__is_seed_sequence<_Sseq, independent_bits_engine>::value &&
3095 !is_convertible<_Sseq, _Engine>::value>::type* = 0)
3097 _LIBCPP_INLINE_VISIBILITY
3098 void seed() {__e_.seed();}
3099 _LIBCPP_INLINE_VISIBILITY
3100 void seed(result_type __sd) {__e_.seed(__sd);}
3101 template<class _Sseq>
3102 _LIBCPP_INLINE_VISIBILITY
3105 __is_seed_sequence<_Sseq, independent_bits_engine>::value,
3108 seed(_Sseq& __q) {__e_.seed(__q);}
3110 // generating functions
3111 _LIBCPP_INLINE_VISIBILITY
3112 result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());}
3113 _LIBCPP_INLINE_VISIBILITY
3114 void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
3116 // property functions
3117 _LIBCPP_INLINE_VISIBILITY
3118 const _Engine& base() const _NOEXCEPT {return __e_;}
3120 template<class _Eng, size_t _Wp, class _UI>
3124 const independent_bits_engine<_Eng, _Wp, _UI>& __x,
3125 const independent_bits_engine<_Eng, _Wp, _UI>& __y);
3127 template<class _Eng, size_t _Wp, class _UI>
3131 const independent_bits_engine<_Eng, _Wp, _UI>& __x,
3132 const independent_bits_engine<_Eng, _Wp, _UI>& __y);
3134 template <class _CharT, class _Traits,
3135 class _Eng, size_t _Wp, class _UI>
3137 basic_ostream<_CharT, _Traits>&
3138 operator<<(basic_ostream<_CharT, _Traits>& __os,
3139 const independent_bits_engine<_Eng, _Wp, _UI>& __x);
3141 template <class _CharT, class _Traits,
3142 class _Eng, size_t _Wp, class _UI>
3144 basic_istream<_CharT, _Traits>&
3145 operator>>(basic_istream<_CharT, _Traits>& __is,
3146 independent_bits_engine<_Eng, _Wp, _UI>& __x);
3149 result_type __eval(false_type);
3150 result_type __eval(true_type);
3152 template <size_t __count>
3153 _LIBCPP_INLINE_VISIBILITY
3160 __lshift(result_type __x) {return __x << __count;}
3162 template <size_t __count>
3163 _LIBCPP_INLINE_VISIBILITY
3170 __lshift(result_type) {return result_type(0);}
3173 template<class _Engine, size_t __w, class _UIntType>
3174 inline _LIBCPP_INLINE_VISIBILITY
3176 independent_bits_engine<_Engine, __w, _UIntType>::__eval(false_type)
3178 return static_cast<result_type>(__e_() & __mask0);
3181 template<class _Engine, size_t __w, class _UIntType>
3183 independent_bits_engine<_Engine, __w, _UIntType>::__eval(true_type)
3185 result_type _Sp = 0;
3186 for (size_t __k = 0; __k < __n0; ++__k)
3188 _Engine_result_type __u;
3191 __u = __e_() - _Engine::min();
3192 } while (__u >= __y0);
3193 _Sp = static_cast<result_type>(__lshift<__w0>(_Sp) + (__u & __mask0));
3195 for (size_t __k = __n0; __k < __n; ++__k)
3197 _Engine_result_type __u;
3200 __u = __e_() - _Engine::min();
3201 } while (__u >= __y1);
3202 _Sp = static_cast<result_type>(__lshift<__w0+1>(_Sp) + (__u & __mask1));
3207 template<class _Eng, size_t _Wp, class _UI>
3208 inline _LIBCPP_INLINE_VISIBILITY
3211 const independent_bits_engine<_Eng, _Wp, _UI>& __x,
3212 const independent_bits_engine<_Eng, _Wp, _UI>& __y)
3214 return __x.base() == __y.base();
3217 template<class _Eng, size_t _Wp, class _UI>
3218 inline _LIBCPP_INLINE_VISIBILITY
3221 const independent_bits_engine<_Eng, _Wp, _UI>& __x,
3222 const independent_bits_engine<_Eng, _Wp, _UI>& __y)
3224 return !(__x == __y);
3227 template <class _CharT, class _Traits,
3228 class _Eng, size_t _Wp, class _UI>
3229 basic_ostream<_CharT, _Traits>&
3230 operator<<(basic_ostream<_CharT, _Traits>& __os,
3231 const independent_bits_engine<_Eng, _Wp, _UI>& __x)
3233 return __os << __x.base();
3236 template <class _CharT, class _Traits,
3237 class _Eng, size_t _Wp, class _UI>
3238 basic_istream<_CharT, _Traits>&
3239 operator>>(basic_istream<_CharT, _Traits>& __is,
3240 independent_bits_engine<_Eng, _Wp, _UI>& __x)
3249 // shuffle_order_engine
3251 template <uint64_t _Xp, uint64_t _Yp>
3254 static _LIBCPP_CONSTEXPR const uint64_t value = __ugcd<_Yp, _Xp % _Yp>::value;
3257 template <uint64_t _Xp>
3258 struct __ugcd<_Xp, 0>
3260 static _LIBCPP_CONSTEXPR const uint64_t value = _Xp;
3263 template <uint64_t _Np, uint64_t _Dp>
3266 static_assert(_Dp != 0, "__uratio divide by 0");
3267 static _LIBCPP_CONSTEXPR const uint64_t __gcd = __ugcd<_Np, _Dp>::value;
3269 static _LIBCPP_CONSTEXPR const uint64_t num = _Np / __gcd;
3270 static _LIBCPP_CONSTEXPR const uint64_t den = _Dp / __gcd;
3272 typedef __uratio<num, den> type;
3275 template<class _Engine, size_t __k>
3276 class _LIBCPP_TYPE_VIS shuffle_order_engine
3278 static_assert(0 < __k, "shuffle_order_engine invalid parameters");
3281 typedef typename _Engine::result_type result_type;
3285 result_type _V_[__k];
3289 // engine characteristics
3290 static _LIBCPP_CONSTEXPR const size_t table_size = __k;
3292 #ifdef _LIBCPP_HAS_NO_CONSTEXPR
3293 static const result_type _Min = _Engine::_Min;
3294 static const result_type _Max = _Engine::_Max;
3296 static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min();
3297 static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max();
3299 static_assert(_Min < _Max, "shuffle_order_engine invalid parameters");
3300 _LIBCPP_INLINE_VISIBILITY
3301 static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
3302 _LIBCPP_INLINE_VISIBILITY
3303 static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
3305 static _LIBCPP_CONSTEXPR const unsigned long long _Rp = _Max - _Min + 1ull;
3307 // constructors and seeding functions
3308 _LIBCPP_INLINE_VISIBILITY
3309 shuffle_order_engine() {__init();}
3310 _LIBCPP_INLINE_VISIBILITY
3311 explicit shuffle_order_engine(const _Engine& __e)
3312 : __e_(__e) {__init();}
3313 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3314 _LIBCPP_INLINE_VISIBILITY
3315 explicit shuffle_order_engine(_Engine&& __e)
3316 : __e_(_VSTD::move(__e)) {__init();}
3317 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3318 _LIBCPP_INLINE_VISIBILITY
3319 explicit shuffle_order_engine(result_type __sd) : __e_(__sd) {__init();}
3320 template<class _Sseq>
3321 _LIBCPP_INLINE_VISIBILITY
3322 explicit shuffle_order_engine(_Sseq& __q,
3323 typename enable_if<__is_seed_sequence<_Sseq, shuffle_order_engine>::value &&
3324 !is_convertible<_Sseq, _Engine>::value>::type* = 0)
3325 : __e_(__q) {__init();}
3326 _LIBCPP_INLINE_VISIBILITY
3327 void seed() {__e_.seed(); __init();}
3328 _LIBCPP_INLINE_VISIBILITY
3329 void seed(result_type __sd) {__e_.seed(__sd); __init();}
3330 template<class _Sseq>
3331 _LIBCPP_INLINE_VISIBILITY
3334 __is_seed_sequence<_Sseq, shuffle_order_engine>::value,
3337 seed(_Sseq& __q) {__e_.seed(__q); __init();}
3339 // generating functions
3340 _LIBCPP_INLINE_VISIBILITY
3341 result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());}
3342 _LIBCPP_INLINE_VISIBILITY
3343 void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
3345 // property functions
3346 _LIBCPP_INLINE_VISIBILITY
3347 const _Engine& base() const _NOEXCEPT {return __e_;}
3350 template<class _Eng, size_t _Kp>
3354 const shuffle_order_engine<_Eng, _Kp>& __x,
3355 const shuffle_order_engine<_Eng, _Kp>& __y);
3357 template<class _Eng, size_t _Kp>
3361 const shuffle_order_engine<_Eng, _Kp>& __x,
3362 const shuffle_order_engine<_Eng, _Kp>& __y);
3364 template <class _CharT, class _Traits,
3365 class _Eng, size_t _Kp>
3367 basic_ostream<_CharT, _Traits>&
3368 operator<<(basic_ostream<_CharT, _Traits>& __os,
3369 const shuffle_order_engine<_Eng, _Kp>& __x);
3371 template <class _CharT, class _Traits,
3372 class _Eng, size_t _Kp>
3374 basic_istream<_CharT, _Traits>&
3375 operator>>(basic_istream<_CharT, _Traits>& __is,
3376 shuffle_order_engine<_Eng, _Kp>& __x);
3378 _LIBCPP_INLINE_VISIBILITY
3381 for (size_t __i = 0; __i < __k; ++__i)
3386 _LIBCPP_INLINE_VISIBILITY
3387 result_type __eval(false_type) {return __eval2(integral_constant<bool, __k & 1>());}
3388 _LIBCPP_INLINE_VISIBILITY
3389 result_type __eval(true_type) {return __eval(__uratio<__k, _Rp>());}
3391 _LIBCPP_INLINE_VISIBILITY
3392 result_type __eval2(false_type) {return __eval(__uratio<__k/2, 0x8000000000000000ull>());}
3393 _LIBCPP_INLINE_VISIBILITY
3394 result_type __eval2(true_type) {return __evalf<__k, 0>();}
3396 template <uint64_t _Np, uint64_t _Dp>
3397 _LIBCPP_INLINE_VISIBILITY
3400 (__uratio<_Np, _Dp>::num > 0xFFFFFFFFFFFFFFFFull / (_Max - _Min)),
3403 __eval(__uratio<_Np, _Dp>)
3404 {return __evalf<__uratio<_Np, _Dp>::num, __uratio<_Np, _Dp>::den>();}
3406 template <uint64_t _Np, uint64_t _Dp>
3407 _LIBCPP_INLINE_VISIBILITY
3410 __uratio<_Np, _Dp>::num <= 0xFFFFFFFFFFFFFFFFull / (_Max - _Min),
3413 __eval(__uratio<_Np, _Dp>)
3415 const size_t __j = static_cast<size_t>(__uratio<_Np, _Dp>::num * (_Y_ - _Min)
3416 / __uratio<_Np, _Dp>::den);
3422 template <uint64_t __n, uint64_t __d>
3423 _LIBCPP_INLINE_VISIBILITY
3424 result_type __evalf()
3426 const double _Fp = __d == 0 ?
3427 __n / (2. * 0x8000000000000000ull) :
3429 const size_t __j = static_cast<size_t>(_Fp * (_Y_ - _Min));
3436 template<class _Engine, size_t __k>
3437 _LIBCPP_CONSTEXPR const size_t shuffle_order_engine<_Engine, __k>::table_size;
3439 template<class _Eng, size_t _Kp>
3442 const shuffle_order_engine<_Eng, _Kp>& __x,
3443 const shuffle_order_engine<_Eng, _Kp>& __y)
3445 return __x._Y_ == __y._Y_ && _VSTD::equal(__x._V_, __x._V_ + _Kp, __y._V_) &&
3446 __x.__e_ == __y.__e_;
3449 template<class _Eng, size_t _Kp>
3450 inline _LIBCPP_INLINE_VISIBILITY
3453 const shuffle_order_engine<_Eng, _Kp>& __x,
3454 const shuffle_order_engine<_Eng, _Kp>& __y)
3456 return !(__x == __y);
3459 template <class _CharT, class _Traits,
3460 class _Eng, size_t _Kp>
3461 basic_ostream<_CharT, _Traits>&
3462 operator<<(basic_ostream<_CharT, _Traits>& __os,
3463 const shuffle_order_engine<_Eng, _Kp>& __x)
3465 __save_flags<_CharT, _Traits> __lx(__os);
3466 __os.flags(ios_base::dec | ios_base::left);
3467 _CharT __sp = __os.widen(' ');
3469 __os << __x.__e_ << __sp << __x._V_[0];
3470 for (size_t __i = 1; __i < _Kp; ++__i)
3471 __os << __sp << __x._V_[__i];
3472 return __os << __sp << __x._Y_;
3475 template <class _CharT, class _Traits,
3476 class _Eng, size_t _Kp>
3477 basic_istream<_CharT, _Traits>&
3478 operator>>(basic_istream<_CharT, _Traits>& __is,
3479 shuffle_order_engine<_Eng, _Kp>& __x)
3481 typedef typename shuffle_order_engine<_Eng, _Kp>::result_type result_type;
3482 __save_flags<_CharT, _Traits> __lx(__is);
3483 __is.flags(ios_base::dec | ios_base::skipws);
3485 result_type _Vp[_Kp+1];
3487 for (size_t __i = 0; __i < _Kp+1; ++__i)
3492 for (size_t __i = 0; __i < _Kp; ++__i)
3493 __x._V_[__i] = _Vp[__i];
3499 typedef shuffle_order_engine<minstd_rand0, 256> knuth_b;
3503 class _LIBCPP_TYPE_VIS random_device
3508 typedef unsigned result_type;
3510 // generator characteristics
3511 static _LIBCPP_CONSTEXPR const result_type _Min = 0;
3512 static _LIBCPP_CONSTEXPR const result_type _Max = 0xFFFFFFFFu;
3514 _LIBCPP_INLINE_VISIBILITY
3515 static _LIBCPP_CONSTEXPR result_type min() { return _Min;}
3516 _LIBCPP_INLINE_VISIBILITY
3517 static _LIBCPP_CONSTEXPR result_type max() { return _Max;}
3520 explicit random_device(const string& __token = "/dev/urandom");
3523 // generating functions
3524 result_type operator()();
3526 // property functions
3527 double entropy() const _NOEXCEPT;
3530 // no copy functions
3531 random_device(const random_device&); // = delete;
3532 random_device& operator=(const random_device&); // = delete;
3537 class _LIBCPP_TYPE_VIS seed_seq
3541 typedef uint32_t result_type;
3544 vector<result_type> __v_;
3546 template<class _InputIterator>
3547 void init(_InputIterator __first, _InputIterator __last);
3550 _LIBCPP_INLINE_VISIBILITY
3552 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
3554 _LIBCPP_INLINE_VISIBILITY
3555 seed_seq(initializer_list<_Tp> __il) {init(__il.begin(), __il.end());}
3556 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
3558 template<class _InputIterator>
3559 _LIBCPP_INLINE_VISIBILITY
3560 seed_seq(_InputIterator __first, _InputIterator __last)
3561 {init(__first, __last);}
3563 // generating functions
3564 template<class _RandomAccessIterator>
3565 void generate(_RandomAccessIterator __first, _RandomAccessIterator __last);
3567 // property functions
3568 _LIBCPP_INLINE_VISIBILITY
3569 size_t size() const {return __v_.size();}
3570 template<class _OutputIterator>
3571 _LIBCPP_INLINE_VISIBILITY
3572 void param(_OutputIterator __dest) const
3573 {_VSTD::copy(__v_.begin(), __v_.end(), __dest);}
3576 // no copy functions
3577 seed_seq(const seed_seq&); // = delete;
3578 void operator=(const seed_seq&); // = delete;
3580 _LIBCPP_INLINE_VISIBILITY
3581 static result_type _Tp(result_type __x) {return __x ^ (__x >> 27);}
3584 template<class _InputIterator>
3586 seed_seq::init(_InputIterator __first, _InputIterator __last)
3588 for (_InputIterator __s = __first; __s != __last; ++__s)
3589 __v_.push_back(*__s & 0xFFFFFFFF);
3592 template<class _RandomAccessIterator>
3594 seed_seq::generate(_RandomAccessIterator __first, _RandomAccessIterator __last)
3596 if (__first != __last)
3598 _VSTD::fill(__first, __last, 0x8b8b8b8b);
3599 const size_t __n = static_cast<size_t>(__last - __first);
3600 const size_t __s = __v_.size();
3601 const size_t __t = (__n >= 623) ? 11
3606 const size_t __p = (__n - __t) / 2;
3607 const size_t __q = __p + __t;
3608 const size_t __m = _VSTD::max(__s + 1, __n);
3611 result_type __r = 1664525 * _Tp(__first[0] ^ __first[__p]
3612 ^ __first[__n - 1]);
3613 __first[__p] += __r;
3615 __first[__q] += __r;
3618 for (size_t __k = 1; __k <= __s; ++__k)
3620 const size_t __kmodn = __k % __n;
3621 const size_t __kpmodn = (__k + __p) % __n;
3622 result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn]
3623 ^ __first[(__k - 1) % __n]);
3624 __first[__kpmodn] += __r;
3625 __r += __kmodn + __v_[__k-1];
3626 __first[(__k + __q) % __n] += __r;
3627 __first[__kmodn] = __r;
3629 for (size_t __k = __s + 1; __k < __m; ++__k)
3631 const size_t __kmodn = __k % __n;
3632 const size_t __kpmodn = (__k + __p) % __n;
3633 result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn]
3634 ^ __first[(__k - 1) % __n]);
3635 __first[__kpmodn] += __r;
3637 __first[(__k + __q) % __n] += __r;
3638 __first[__kmodn] = __r;
3640 for (size_t __k = __m; __k < __m + __n; ++__k)
3642 const size_t __kmodn = __k % __n;
3643 const size_t __kpmodn = (__k + __p) % __n;
3644 result_type __r = 1566083941 * _Tp(__first[__kmodn] +
3646 __first[(__k - 1) % __n]);
3647 __first[__kpmodn] ^= __r;
3649 __first[(__k + __q) % __n] ^= __r;
3650 __first[__kmodn] = __r;
3655 // generate_canonical
3657 template<class _RealType, size_t __bits, class _URNG>
3659 generate_canonical(_URNG& __g)
3661 const size_t _Dt = numeric_limits<_RealType>::digits;
3662 const size_t __b = _Dt < __bits ? _Dt : __bits;
3663 #ifdef _LIBCPP_HAS_NO_CONSTEXPR
3664 const size_t __logR = __log2<uint64_t, _URNG::_Max - _URNG::_Min + uint64_t(1)>::value;
3666 const size_t __logR = __log2<uint64_t, _URNG::max() - _URNG::min() + uint64_t(1)>::value;
3668 const size_t __k = __b / __logR + (__b % __logR != 0) + (__b == 0);
3669 const _RealType _Rp = _URNG::max() - _URNG::min() + _RealType(1);
3670 _RealType __base = _Rp;
3671 _RealType _Sp = __g() - _URNG::min();
3672 for (size_t __i = 1; __i < __k; ++__i, __base *= _Rp)
3673 _Sp += (__g() - _URNG::min()) * __base;
3674 return _Sp / __base;
3677 // uniform_int_distribution
3681 template <class _CharT, class _Traits, class _IT>
3682 basic_ostream<_CharT, _Traits>&
3683 operator<<(basic_ostream<_CharT, _Traits>& __os,
3684 const uniform_int_distribution<_IT>& __x)
3686 __save_flags<_CharT, _Traits> __lx(__os);
3687 __os.flags(ios_base::dec | ios_base::left);
3688 _CharT __sp = __os.widen(' ');
3690 return __os << __x.a() << __sp << __x.b();
3693 template <class _CharT, class _Traits, class _IT>
3694 basic_istream<_CharT, _Traits>&
3695 operator>>(basic_istream<_CharT, _Traits>& __is,
3696 uniform_int_distribution<_IT>& __x)
3698 typedef uniform_int_distribution<_IT> _Eng;
3699 typedef typename _Eng::result_type result_type;
3700 typedef typename _Eng::param_type param_type;
3701 __save_flags<_CharT, _Traits> __lx(__is);
3702 __is.flags(ios_base::dec | ios_base::skipws);
3707 __x.param(param_type(__a, __b));
3711 // uniform_real_distribution
3713 template<class _RealType = double>
3714 class _LIBCPP_TYPE_VIS uniform_real_distribution
3718 typedef _RealType result_type;
3720 class _LIBCPP_TYPE_VIS param_type
3725 typedef uniform_real_distribution distribution_type;
3727 _LIBCPP_INLINE_VISIBILITY
3728 explicit param_type(result_type __a = 0,
3729 result_type __b = 1)
3730 : __a_(__a), __b_(__b) {}
3732 _LIBCPP_INLINE_VISIBILITY
3733 result_type a() const {return __a_;}
3734 _LIBCPP_INLINE_VISIBILITY
3735 result_type b() const {return __b_;}
3737 friend _LIBCPP_INLINE_VISIBILITY
3738 bool operator==(const param_type& __x, const param_type& __y)
3739 {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
3740 friend _LIBCPP_INLINE_VISIBILITY
3741 bool operator!=(const param_type& __x, const param_type& __y)
3742 {return !(__x == __y);}
3749 // constructors and reset functions
3750 _LIBCPP_INLINE_VISIBILITY
3751 explicit uniform_real_distribution(result_type __a = 0, result_type __b = 1)
3752 : __p_(param_type(__a, __b)) {}
3753 _LIBCPP_INLINE_VISIBILITY
3754 explicit uniform_real_distribution(const param_type& __p) : __p_(__p) {}
3755 _LIBCPP_INLINE_VISIBILITY
3758 // generating functions
3759 template<class _URNG>
3760 _LIBCPP_INLINE_VISIBILITY
3761 result_type operator()(_URNG& __g)
3762 {return (*this)(__g, __p_);}
3763 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
3765 // property functions
3766 _LIBCPP_INLINE_VISIBILITY
3767 result_type a() const {return __p_.a();}
3768 _LIBCPP_INLINE_VISIBILITY
3769 result_type b() const {return __p_.b();}
3771 _LIBCPP_INLINE_VISIBILITY
3772 param_type param() const {return __p_;}
3773 _LIBCPP_INLINE_VISIBILITY
3774 void param(const param_type& __p) {__p_ = __p;}
3776 _LIBCPP_INLINE_VISIBILITY
3777 result_type min() const {return a();}
3778 _LIBCPP_INLINE_VISIBILITY
3779 result_type max() const {return b();}
3781 friend _LIBCPP_INLINE_VISIBILITY
3782 bool operator==(const uniform_real_distribution& __x,
3783 const uniform_real_distribution& __y)
3784 {return __x.__p_ == __y.__p_;}
3785 friend _LIBCPP_INLINE_VISIBILITY
3786 bool operator!=(const uniform_real_distribution& __x,
3787 const uniform_real_distribution& __y)
3788 {return !(__x == __y);}
3791 template<class _RealType>
3792 template<class _URNG>
3793 inline _LIBCPP_INLINE_VISIBILITY
3794 typename uniform_real_distribution<_RealType>::result_type
3795 uniform_real_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
3797 return (__p.b() - __p.a())
3798 * _VSTD::generate_canonical<_RealType, numeric_limits<_RealType>::digits>(__g)
3802 template <class _CharT, class _Traits, class _RT>
3803 basic_ostream<_CharT, _Traits>&
3804 operator<<(basic_ostream<_CharT, _Traits>& __os,
3805 const uniform_real_distribution<_RT>& __x)
3807 __save_flags<_CharT, _Traits> __lx(__os);
3808 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
3809 ios_base::scientific);
3810 _CharT __sp = __os.widen(' ');
3812 return __os << __x.a() << __sp << __x.b();
3815 template <class _CharT, class _Traits, class _RT>
3816 basic_istream<_CharT, _Traits>&
3817 operator>>(basic_istream<_CharT, _Traits>& __is,
3818 uniform_real_distribution<_RT>& __x)
3820 typedef uniform_real_distribution<_RT> _Eng;
3821 typedef typename _Eng::result_type result_type;
3822 typedef typename _Eng::param_type param_type;
3823 __save_flags<_CharT, _Traits> __lx(__is);
3824 __is.flags(ios_base::dec | ios_base::skipws);
3829 __x.param(param_type(__a, __b));
3833 // bernoulli_distribution
3835 class _LIBCPP_TYPE_VIS bernoulli_distribution
3839 typedef bool result_type;
3841 class _LIBCPP_TYPE_VIS param_type
3845 typedef bernoulli_distribution distribution_type;
3847 _LIBCPP_INLINE_VISIBILITY
3848 explicit param_type(double __p = 0.5) : __p_(__p) {}
3850 _LIBCPP_INLINE_VISIBILITY
3851 double p() const {return __p_;}
3853 friend _LIBCPP_INLINE_VISIBILITY
3854 bool operator==(const param_type& __x, const param_type& __y)
3855 {return __x.__p_ == __y.__p_;}
3856 friend _LIBCPP_INLINE_VISIBILITY
3857 bool operator!=(const param_type& __x, const param_type& __y)
3858 {return !(__x == __y);}
3865 // constructors and reset functions
3866 _LIBCPP_INLINE_VISIBILITY
3867 explicit bernoulli_distribution(double __p = 0.5)
3868 : __p_(param_type(__p)) {}
3869 _LIBCPP_INLINE_VISIBILITY
3870 explicit bernoulli_distribution(const param_type& __p) : __p_(__p) {}
3871 _LIBCPP_INLINE_VISIBILITY
3874 // generating functions
3875 template<class _URNG>
3876 _LIBCPP_INLINE_VISIBILITY
3877 result_type operator()(_URNG& __g)
3878 {return (*this)(__g, __p_);}
3879 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
3881 // property functions
3882 _LIBCPP_INLINE_VISIBILITY
3883 double p() const {return __p_.p();}
3885 _LIBCPP_INLINE_VISIBILITY
3886 param_type param() const {return __p_;}
3887 _LIBCPP_INLINE_VISIBILITY
3888 void param(const param_type& __p) {__p_ = __p;}
3890 _LIBCPP_INLINE_VISIBILITY
3891 result_type min() const {return false;}
3892 _LIBCPP_INLINE_VISIBILITY
3893 result_type max() const {return true;}
3895 friend _LIBCPP_INLINE_VISIBILITY
3896 bool operator==(const bernoulli_distribution& __x,
3897 const bernoulli_distribution& __y)
3898 {return __x.__p_ == __y.__p_;}
3899 friend _LIBCPP_INLINE_VISIBILITY
3900 bool operator!=(const bernoulli_distribution& __x,
3901 const bernoulli_distribution& __y)
3902 {return !(__x == __y);}
3905 template<class _URNG>
3906 inline _LIBCPP_INLINE_VISIBILITY
3907 bernoulli_distribution::result_type
3908 bernoulli_distribution::operator()(_URNG& __g, const param_type& __p)
3910 uniform_real_distribution<double> __gen;
3911 return __gen(__g) < __p.p();
3914 template <class _CharT, class _Traits>
3915 basic_ostream<_CharT, _Traits>&
3916 operator<<(basic_ostream<_CharT, _Traits>& __os, const bernoulli_distribution& __x)
3918 __save_flags<_CharT, _Traits> __lx(__os);
3919 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
3920 ios_base::scientific);
3921 _CharT __sp = __os.widen(' ');
3923 return __os << __x.p();
3926 template <class _CharT, class _Traits>
3927 basic_istream<_CharT, _Traits>&
3928 operator>>(basic_istream<_CharT, _Traits>& __is, bernoulli_distribution& __x)
3930 typedef bernoulli_distribution _Eng;
3931 typedef typename _Eng::param_type param_type;
3932 __save_flags<_CharT, _Traits> __lx(__is);
3933 __is.flags(ios_base::dec | ios_base::skipws);
3937 __x.param(param_type(__p));
3941 // binomial_distribution
3943 template<class _IntType = int>
3944 class _LIBCPP_TYPE_VIS binomial_distribution
3948 typedef _IntType result_type;
3950 class _LIBCPP_TYPE_VIS param_type
3955 double __odds_ratio_;
3958 typedef binomial_distribution distribution_type;
3960 explicit param_type(result_type __t = 1, double __p = 0.5);
3962 _LIBCPP_INLINE_VISIBILITY
3963 result_type t() const {return __t_;}
3964 _LIBCPP_INLINE_VISIBILITY
3965 double p() const {return __p_;}
3967 friend _LIBCPP_INLINE_VISIBILITY
3968 bool operator==(const param_type& __x, const param_type& __y)
3969 {return __x.__t_ == __y.__t_ && __x.__p_ == __y.__p_;}
3970 friend _LIBCPP_INLINE_VISIBILITY
3971 bool operator!=(const param_type& __x, const param_type& __y)
3972 {return !(__x == __y);}
3974 friend class binomial_distribution;
3981 // constructors and reset functions
3982 _LIBCPP_INLINE_VISIBILITY
3983 explicit binomial_distribution(result_type __t = 1, double __p = 0.5)
3984 : __p_(param_type(__t, __p)) {}
3985 _LIBCPP_INLINE_VISIBILITY
3986 explicit binomial_distribution(const param_type& __p) : __p_(__p) {}
3987 _LIBCPP_INLINE_VISIBILITY
3990 // generating functions
3991 template<class _URNG>
3992 _LIBCPP_INLINE_VISIBILITY
3993 result_type operator()(_URNG& __g)
3994 {return (*this)(__g, __p_);}
3995 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
3997 // property functions
3998 _LIBCPP_INLINE_VISIBILITY
3999 result_type t() const {return __p_.t();}
4000 _LIBCPP_INLINE_VISIBILITY
4001 double p() const {return __p_.p();}
4003 _LIBCPP_INLINE_VISIBILITY
4004 param_type param() const {return __p_;}
4005 _LIBCPP_INLINE_VISIBILITY
4006 void param(const param_type& __p) {__p_ = __p;}
4008 _LIBCPP_INLINE_VISIBILITY
4009 result_type min() const {return 0;}
4010 _LIBCPP_INLINE_VISIBILITY
4011 result_type max() const {return t();}
4013 friend _LIBCPP_INLINE_VISIBILITY
4014 bool operator==(const binomial_distribution& __x,
4015 const binomial_distribution& __y)
4016 {return __x.__p_ == __y.__p_;}
4017 friend _LIBCPP_INLINE_VISIBILITY
4018 bool operator!=(const binomial_distribution& __x,
4019 const binomial_distribution& __y)
4020 {return !(__x == __y);}
4023 template<class _IntType>
4024 binomial_distribution<_IntType>::param_type::param_type(result_type __t, double __p)
4025 : __t_(__t), __p_(__p)
4027 if (0 < __p_ && __p_ < 1)
4029 __r0_ = static_cast<result_type>((__t_ + 1) * __p_);
4030 __pr_ = _VSTD::exp(_VSTD::lgamma(__t_ + 1.) - _VSTD::lgamma(__r0_ + 1.) -
4031 _VSTD::lgamma(__t_ - __r0_ + 1.) + __r0_ * _VSTD::log(__p_) +
4032 (__t_ - __r0_) * _VSTD::log(1 - __p_));
4033 __odds_ratio_ = __p_ / (1 - __p_);
4037 template<class _IntType>
4038 template<class _URNG>
4040 binomial_distribution<_IntType>::operator()(_URNG& __g, const param_type& __pr)
4042 if (__pr.__t_ == 0 || __pr.__p_ == 0)
4046 uniform_real_distribution<double> __gen;
4047 double __u = __gen(__g) - __pr.__pr_;
4050 double __pu = __pr.__pr_;
4052 result_type __ru = __pr.__r0_;
4053 result_type __rd = __ru;
4058 __pd *= __rd / (__pr.__odds_ratio_ * (__pr.__t_ - __rd + 1));
4065 if (__ru <= __pr.__t_)
4067 __pu *= (__pr.__t_ - __ru + 1) * __pr.__odds_ratio_ / __ru;
4075 template <class _CharT, class _Traits, class _IntType>
4076 basic_ostream<_CharT, _Traits>&
4077 operator<<(basic_ostream<_CharT, _Traits>& __os,
4078 const binomial_distribution<_IntType>& __x)
4080 __save_flags<_CharT, _Traits> __lx(__os);
4081 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
4082 ios_base::scientific);
4083 _CharT __sp = __os.widen(' ');
4085 return __os << __x.t() << __sp << __x.p();
4088 template <class _CharT, class _Traits, class _IntType>
4089 basic_istream<_CharT, _Traits>&
4090 operator>>(basic_istream<_CharT, _Traits>& __is,
4091 binomial_distribution<_IntType>& __x)
4093 typedef binomial_distribution<_IntType> _Eng;
4094 typedef typename _Eng::result_type result_type;
4095 typedef typename _Eng::param_type param_type;
4096 __save_flags<_CharT, _Traits> __lx(__is);
4097 __is.flags(ios_base::dec | ios_base::skipws);
4102 __x.param(param_type(__t, __p));
4106 // exponential_distribution
4108 template<class _RealType = double>
4109 class _LIBCPP_TYPE_VIS exponential_distribution
4113 typedef _RealType result_type;
4115 class _LIBCPP_TYPE_VIS param_type
4117 result_type __lambda_;
4119 typedef exponential_distribution distribution_type;
4121 _LIBCPP_INLINE_VISIBILITY
4122 explicit param_type(result_type __lambda = 1) : __lambda_(__lambda) {}
4124 _LIBCPP_INLINE_VISIBILITY
4125 result_type lambda() const {return __lambda_;}
4127 friend _LIBCPP_INLINE_VISIBILITY
4128 bool operator==(const param_type& __x, const param_type& __y)
4129 {return __x.__lambda_ == __y.__lambda_;}
4130 friend _LIBCPP_INLINE_VISIBILITY
4131 bool operator!=(const param_type& __x, const param_type& __y)
4132 {return !(__x == __y);}
4139 // constructors and reset functions
4140 _LIBCPP_INLINE_VISIBILITY
4141 explicit exponential_distribution(result_type __lambda = 1)
4142 : __p_(param_type(__lambda)) {}
4143 _LIBCPP_INLINE_VISIBILITY
4144 explicit exponential_distribution(const param_type& __p) : __p_(__p) {}
4145 _LIBCPP_INLINE_VISIBILITY
4148 // generating functions
4149 template<class _URNG>
4150 _LIBCPP_INLINE_VISIBILITY
4151 result_type operator()(_URNG& __g)
4152 {return (*this)(__g, __p_);}
4153 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
4155 // property functions
4156 _LIBCPP_INLINE_VISIBILITY
4157 result_type lambda() const {return __p_.lambda();}
4159 _LIBCPP_INLINE_VISIBILITY
4160 param_type param() const {return __p_;}
4161 _LIBCPP_INLINE_VISIBILITY
4162 void param(const param_type& __p) {__p_ = __p;}
4164 _LIBCPP_INLINE_VISIBILITY
4165 result_type min() const {return 0;}
4166 _LIBCPP_INLINE_VISIBILITY
4167 result_type max() const {return numeric_limits<result_type>::infinity();}
4169 friend _LIBCPP_INLINE_VISIBILITY
4170 bool operator==(const exponential_distribution& __x,
4171 const exponential_distribution& __y)
4172 {return __x.__p_ == __y.__p_;}
4173 friend _LIBCPP_INLINE_VISIBILITY
4174 bool operator!=(const exponential_distribution& __x,
4175 const exponential_distribution& __y)
4176 {return !(__x == __y);}
4179 template <class _RealType>
4180 template<class _URNG>
4182 exponential_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
4187 _VSTD::generate_canonical<result_type,
4188 numeric_limits<result_type>::digits>(__g)
4193 template <class _CharT, class _Traits, class _RealType>
4194 basic_ostream<_CharT, _Traits>&
4195 operator<<(basic_ostream<_CharT, _Traits>& __os,
4196 const exponential_distribution<_RealType>& __x)
4198 __save_flags<_CharT, _Traits> __lx(__os);
4199 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
4200 ios_base::scientific);
4201 return __os << __x.lambda();
4204 template <class _CharT, class _Traits, class _RealType>
4205 basic_istream<_CharT, _Traits>&
4206 operator>>(basic_istream<_CharT, _Traits>& __is,
4207 exponential_distribution<_RealType>& __x)
4209 typedef exponential_distribution<_RealType> _Eng;
4210 typedef typename _Eng::result_type result_type;
4211 typedef typename _Eng::param_type param_type;
4212 __save_flags<_CharT, _Traits> __lx(__is);
4213 __is.flags(ios_base::dec | ios_base::skipws);
4214 result_type __lambda;
4217 __x.param(param_type(__lambda));
4221 // normal_distribution
4223 template<class _RealType = double>
4224 class _LIBCPP_TYPE_VIS normal_distribution
4228 typedef _RealType result_type;
4230 class _LIBCPP_TYPE_VIS param_type
4232 result_type __mean_;
4233 result_type __stddev_;
4235 typedef normal_distribution distribution_type;
4237 _LIBCPP_INLINE_VISIBILITY
4238 explicit param_type(result_type __mean = 0, result_type __stddev = 1)
4239 : __mean_(__mean), __stddev_(__stddev) {}
4241 _LIBCPP_INLINE_VISIBILITY
4242 result_type mean() const {return __mean_;}
4243 _LIBCPP_INLINE_VISIBILITY
4244 result_type stddev() const {return __stddev_;}
4246 friend _LIBCPP_INLINE_VISIBILITY
4247 bool operator==(const param_type& __x, const param_type& __y)
4248 {return __x.__mean_ == __y.__mean_ && __x.__stddev_ == __y.__stddev_;}
4249 friend _LIBCPP_INLINE_VISIBILITY
4250 bool operator!=(const param_type& __x, const param_type& __y)
4251 {return !(__x == __y);}
4260 // constructors and reset functions
4261 _LIBCPP_INLINE_VISIBILITY
4262 explicit normal_distribution(result_type __mean = 0, result_type __stddev = 1)
4263 : __p_(param_type(__mean, __stddev)), _V_hot_(false) {}
4264 _LIBCPP_INLINE_VISIBILITY
4265 explicit normal_distribution(const param_type& __p)
4266 : __p_(__p), _V_hot_(false) {}
4267 _LIBCPP_INLINE_VISIBILITY
4268 void reset() {_V_hot_ = false;}
4270 // generating functions
4271 template<class _URNG>
4272 _LIBCPP_INLINE_VISIBILITY
4273 result_type operator()(_URNG& __g)
4274 {return (*this)(__g, __p_);}
4275 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
4277 // property functions
4278 _LIBCPP_INLINE_VISIBILITY
4279 result_type mean() const {return __p_.mean();}
4280 _LIBCPP_INLINE_VISIBILITY
4281 result_type stddev() const {return __p_.stddev();}
4283 _LIBCPP_INLINE_VISIBILITY
4284 param_type param() const {return __p_;}
4285 _LIBCPP_INLINE_VISIBILITY
4286 void param(const param_type& __p) {__p_ = __p;}
4288 _LIBCPP_INLINE_VISIBILITY
4289 result_type min() const {return -numeric_limits<result_type>::infinity();}
4290 _LIBCPP_INLINE_VISIBILITY
4291 result_type max() const {return numeric_limits<result_type>::infinity();}
4293 friend _LIBCPP_INLINE_VISIBILITY
4294 bool operator==(const normal_distribution& __x,
4295 const normal_distribution& __y)
4296 {return __x.__p_ == __y.__p_ && __x._V_hot_ == __y._V_hot_ &&
4297 (!__x._V_hot_ || __x._V_ == __y._V_);}
4298 friend _LIBCPP_INLINE_VISIBILITY
4299 bool operator!=(const normal_distribution& __x,
4300 const normal_distribution& __y)
4301 {return !(__x == __y);}
4303 template <class _CharT, class _Traits, class _RT>
4305 basic_ostream<_CharT, _Traits>&
4306 operator<<(basic_ostream<_CharT, _Traits>& __os,
4307 const normal_distribution<_RT>& __x);
4309 template <class _CharT, class _Traits, class _RT>
4311 basic_istream<_CharT, _Traits>&
4312 operator>>(basic_istream<_CharT, _Traits>& __is,
4313 normal_distribution<_RT>& __x);
4316 template <class _RealType>
4317 template<class _URNG>
4319 normal_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
4329 uniform_real_distribution<result_type> _Uni(-1, 1);
4337 __s = __u * __u + __v * __v;
4338 } while (__s > 1 || __s == 0);
4339 result_type _Fp = _VSTD::sqrt(-2 * _VSTD::log(__s) / __s);
4344 return _Up * __p.stddev() + __p.mean();
4347 template <class _CharT, class _Traits, class _RT>
4348 basic_ostream<_CharT, _Traits>&
4349 operator<<(basic_ostream<_CharT, _Traits>& __os,
4350 const normal_distribution<_RT>& __x)
4352 __save_flags<_CharT, _Traits> __lx(__os);
4353 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
4354 ios_base::scientific);
4355 _CharT __sp = __os.widen(' ');
4357 __os << __x.mean() << __sp << __x.stddev() << __sp << __x._V_hot_;
4359 __os << __sp << __x._V_;
4363 template <class _CharT, class _Traits, class _RT>
4364 basic_istream<_CharT, _Traits>&
4365 operator>>(basic_istream<_CharT, _Traits>& __is,
4366 normal_distribution<_RT>& __x)
4368 typedef normal_distribution<_RT> _Eng;
4369 typedef typename _Eng::result_type result_type;
4370 typedef typename _Eng::param_type param_type;
4371 __save_flags<_CharT, _Traits> __lx(__is);
4372 __is.flags(ios_base::dec | ios_base::skipws);
4374 result_type __stddev;
4375 result_type _Vp = 0;
4376 bool _V_hot = false;
4377 __is >> __mean >> __stddev >> _V_hot;
4382 __x.param(param_type(__mean, __stddev));
4383 __x._V_hot_ = _V_hot;
4389 // lognormal_distribution
4391 template<class _RealType = double>
4392 class _LIBCPP_TYPE_VIS lognormal_distribution
4396 typedef _RealType result_type;
4398 class _LIBCPP_TYPE_VIS param_type
4400 normal_distribution<result_type> __nd_;
4402 typedef lognormal_distribution distribution_type;
4404 _LIBCPP_INLINE_VISIBILITY
4405 explicit param_type(result_type __m = 0, result_type __s = 1)
4406 : __nd_(__m, __s) {}
4408 _LIBCPP_INLINE_VISIBILITY
4409 result_type m() const {return __nd_.mean();}
4410 _LIBCPP_INLINE_VISIBILITY
4411 result_type s() const {return __nd_.stddev();}
4413 friend _LIBCPP_INLINE_VISIBILITY
4414 bool operator==(const param_type& __x, const param_type& __y)
4415 {return __x.__nd_ == __y.__nd_;}
4416 friend _LIBCPP_INLINE_VISIBILITY
4417 bool operator!=(const param_type& __x, const param_type& __y)
4418 {return !(__x == __y);}
4419 friend class lognormal_distribution;
4421 template <class _CharT, class _Traits, class _RT>
4423 basic_ostream<_CharT, _Traits>&
4424 operator<<(basic_ostream<_CharT, _Traits>& __os,
4425 const lognormal_distribution<_RT>& __x);
4427 template <class _CharT, class _Traits, class _RT>
4429 basic_istream<_CharT, _Traits>&
4430 operator>>(basic_istream<_CharT, _Traits>& __is,
4431 lognormal_distribution<_RT>& __x);
4438 // constructor and reset functions
4439 _LIBCPP_INLINE_VISIBILITY
4440 explicit lognormal_distribution(result_type __m = 0, result_type __s = 1)
4441 : __p_(param_type(__m, __s)) {}
4442 _LIBCPP_INLINE_VISIBILITY
4443 explicit lognormal_distribution(const param_type& __p)
4445 _LIBCPP_INLINE_VISIBILITY
4446 void reset() {__p_.__nd_.reset();}
4448 // generating functions
4449 template<class _URNG>
4450 _LIBCPP_INLINE_VISIBILITY
4451 result_type operator()(_URNG& __g)
4452 {return (*this)(__g, __p_);}
4453 template<class _URNG>
4454 _LIBCPP_INLINE_VISIBILITY
4455 result_type operator()(_URNG& __g, const param_type& __p)
4456 {return _VSTD::exp(const_cast<normal_distribution<result_type>&>(__p.__nd_)(__g));}
4458 // property functions
4459 _LIBCPP_INLINE_VISIBILITY
4460 result_type m() const {return __p_.m();}
4461 _LIBCPP_INLINE_VISIBILITY
4462 result_type s() const {return __p_.s();}
4464 _LIBCPP_INLINE_VISIBILITY
4465 param_type param() const {return __p_;}
4466 _LIBCPP_INLINE_VISIBILITY
4467 void param(const param_type& __p) {__p_ = __p;}
4469 _LIBCPP_INLINE_VISIBILITY
4470 result_type min() const {return 0;}
4471 _LIBCPP_INLINE_VISIBILITY
4472 result_type max() const {return numeric_limits<result_type>::infinity();}
4474 friend _LIBCPP_INLINE_VISIBILITY
4475 bool operator==(const lognormal_distribution& __x,
4476 const lognormal_distribution& __y)
4477 {return __x.__p_ == __y.__p_;}
4478 friend _LIBCPP_INLINE_VISIBILITY
4479 bool operator!=(const lognormal_distribution& __x,
4480 const lognormal_distribution& __y)
4481 {return !(__x == __y);}
4483 template <class _CharT, class _Traits, class _RT>
4485 basic_ostream<_CharT, _Traits>&
4486 operator<<(basic_ostream<_CharT, _Traits>& __os,
4487 const lognormal_distribution<_RT>& __x);
4489 template <class _CharT, class _Traits, class _RT>
4491 basic_istream<_CharT, _Traits>&
4492 operator>>(basic_istream<_CharT, _Traits>& __is,
4493 lognormal_distribution<_RT>& __x);
4496 template <class _CharT, class _Traits, class _RT>
4497 inline _LIBCPP_INLINE_VISIBILITY
4498 basic_ostream<_CharT, _Traits>&
4499 operator<<(basic_ostream<_CharT, _Traits>& __os,
4500 const lognormal_distribution<_RT>& __x)
4502 return __os << __x.__p_.__nd_;
4505 template <class _CharT, class _Traits, class _RT>
4506 inline _LIBCPP_INLINE_VISIBILITY
4507 basic_istream<_CharT, _Traits>&
4508 operator>>(basic_istream<_CharT, _Traits>& __is,
4509 lognormal_distribution<_RT>& __x)
4511 return __is >> __x.__p_.__nd_;
4514 // poisson_distribution
4516 template<class _IntType = int>
4517 class _LIBCPP_TYPE_VIS poisson_distribution
4521 typedef _IntType result_type;
4523 class _LIBCPP_TYPE_VIS param_type
4537 typedef poisson_distribution distribution_type;
4539 explicit param_type(double __mean = 1.0);
4541 _LIBCPP_INLINE_VISIBILITY
4542 double mean() const {return __mean_;}
4544 friend _LIBCPP_INLINE_VISIBILITY
4545 bool operator==(const param_type& __x, const param_type& __y)
4546 {return __x.__mean_ == __y.__mean_;}
4547 friend _LIBCPP_INLINE_VISIBILITY
4548 bool operator!=(const param_type& __x, const param_type& __y)
4549 {return !(__x == __y);}
4551 friend class poisson_distribution;
4558 // constructors and reset functions
4559 _LIBCPP_INLINE_VISIBILITY
4560 explicit poisson_distribution(double __mean = 1.0) : __p_(__mean) {}
4561 _LIBCPP_INLINE_VISIBILITY
4562 explicit poisson_distribution(const param_type& __p) : __p_(__p) {}
4563 _LIBCPP_INLINE_VISIBILITY
4566 // generating functions
4567 template<class _URNG>
4568 _LIBCPP_INLINE_VISIBILITY
4569 result_type operator()(_URNG& __g)
4570 {return (*this)(__g, __p_);}
4571 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
4573 // property functions
4574 _LIBCPP_INLINE_VISIBILITY
4575 double mean() const {return __p_.mean();}
4577 _LIBCPP_INLINE_VISIBILITY
4578 param_type param() const {return __p_;}
4579 _LIBCPP_INLINE_VISIBILITY
4580 void param(const param_type& __p) {__p_ = __p;}
4582 _LIBCPP_INLINE_VISIBILITY
4583 result_type min() const {return 0;}
4584 _LIBCPP_INLINE_VISIBILITY
4585 result_type max() const {return numeric_limits<result_type>::max();}
4587 friend _LIBCPP_INLINE_VISIBILITY
4588 bool operator==(const poisson_distribution& __x,
4589 const poisson_distribution& __y)
4590 {return __x.__p_ == __y.__p_;}
4591 friend _LIBCPP_INLINE_VISIBILITY
4592 bool operator!=(const poisson_distribution& __x,
4593 const poisson_distribution& __y)
4594 {return !(__x == __y);}
4597 template<class _IntType>
4598 poisson_distribution<_IntType>::param_type::param_type(double __mean)
4605 __l_ = _VSTD::exp(-__mean_);
4615 __s_ = _VSTD::sqrt(__mean_);
4616 __d_ = 6 * __mean_ * __mean_;
4617 __l_ = static_cast<result_type>(__mean_ - 1.1484);
4618 __omega_ = .3989423 / __s_;
4619 double __b1_ = .4166667E-1 / __mean_;
4620 double __b2_ = .3 * __b1_ * __b1_;
4621 __c3_ = .1428571 * __b1_ * __b2_;
4622 __c2_ = __b2_ - 15. * __c3_;
4623 __c1_ = __b1_ - 6. * __b2_ + 45. * __c3_;
4624 __c0_ = 1. - __b1_ + 3. * __b2_ - 15. * __c3_;
4625 __c_ = .1069 / __mean_;
4629 template <class _IntType>
4630 template<class _URNG>
4632 poisson_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr)
4635 uniform_real_distribution<double> __urd;
4636 if (__pr.__mean_ < 10)
4639 for (double __p = __urd(__urng); __p > __pr.__l_; ++__x)
4640 __p *= __urd(__urng);
4645 double __g = __pr.__mean_ + __pr.__s_ * normal_distribution<double>()(__urng);
4649 __x = static_cast<result_type>(__g);
4650 if (__x >= __pr.__l_)
4652 __difmuk = __pr.__mean_ - __x;
4653 __u = __urd(__urng);
4654 if (__pr.__d_ * __u >= __difmuk * __difmuk * __difmuk)
4657 exponential_distribution<double> __edist;
4658 for (bool __using_exp_dist = false; true; __using_exp_dist = true)
4661 if (__using_exp_dist || __g < 0)
4666 __e = __edist(__urng);
4667 __u = __urd(__urng);
4669 __t = 1.8 + (__u < 0 ? -__e : __e);
4670 } while (__t <= -.6744);
4671 __x = __pr.__mean_ + __pr.__s_ * __t;
4672 __difmuk = __pr.__mean_ - __x;
4673 __using_exp_dist = true;
4679 const result_type __fac[] = {1, 1, 2, 6, 24, 120, 720, 5040,
4681 __px = -__pr.__mean_;
4682 __py = _VSTD::pow(__pr.__mean_, (double)__x) / __fac[__x];
4686 double __del = .8333333E-1 / __x;
4687 __del -= 4.8 * __del * __del * __del;
4688 double __v = __difmuk / __x;
4689 if (_VSTD::abs(__v) > 0.25)
4690 __px = __x * _VSTD::log(1 + __v) - __difmuk - __del;
4692 __px = __x * __v * __v * (((((((.1250060 * __v + -.1384794) *
4693 __v + .1421878) * __v + -.1661269) * __v + .2000118) *
4694 __v + -.2500068) * __v + .3333333) * __v + -.5) - __del;
4695 __py = .3989423 / _VSTD::sqrt(__x);
4697 double __r = (0.5 - __difmuk) / __pr.__s_;
4698 double __r2 = __r * __r;
4699 double __fx = -0.5 * __r2;
4700 double __fy = __pr.__omega_ * (((__pr.__c3_ * __r2 + __pr.__c2_) *
4701 __r2 + __pr.__c1_) * __r2 + __pr.__c0_);
4702 if (__using_exp_dist)
4704 if (__pr.__c_ * _VSTD::abs(__u) <= __py * _VSTD::exp(__px + __e) -
4705 __fy * _VSTD::exp(__fx + __e))
4710 if (__fy - __u * __fy <= __py * _VSTD::exp(__px - __fx))
4718 template <class _CharT, class _Traits, class _IntType>
4719 basic_ostream<_CharT, _Traits>&
4720 operator<<(basic_ostream<_CharT, _Traits>& __os,
4721 const poisson_distribution<_IntType>& __x)
4723 __save_flags<_CharT, _Traits> __lx(__os);
4724 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
4725 ios_base::scientific);
4726 return __os << __x.mean();
4729 template <class _CharT, class _Traits, class _IntType>
4730 basic_istream<_CharT, _Traits>&
4731 operator>>(basic_istream<_CharT, _Traits>& __is,
4732 poisson_distribution<_IntType>& __x)
4734 typedef poisson_distribution<_IntType> _Eng;
4735 typedef typename _Eng::param_type param_type;
4736 __save_flags<_CharT, _Traits> __lx(__is);
4737 __is.flags(ios_base::dec | ios_base::skipws);
4741 __x.param(param_type(__mean));
4745 // weibull_distribution
4747 template<class _RealType = double>
4748 class _LIBCPP_TYPE_VIS weibull_distribution
4752 typedef _RealType result_type;
4754 class _LIBCPP_TYPE_VIS param_type
4759 typedef weibull_distribution distribution_type;
4761 _LIBCPP_INLINE_VISIBILITY
4762 explicit param_type(result_type __a = 1, result_type __b = 1)
4763 : __a_(__a), __b_(__b) {}
4765 _LIBCPP_INLINE_VISIBILITY
4766 result_type a() const {return __a_;}
4767 _LIBCPP_INLINE_VISIBILITY
4768 result_type b() const {return __b_;}
4770 friend _LIBCPP_INLINE_VISIBILITY
4771 bool operator==(const param_type& __x, const param_type& __y)
4772 {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
4773 friend _LIBCPP_INLINE_VISIBILITY
4774 bool operator!=(const param_type& __x, const param_type& __y)
4775 {return !(__x == __y);}
4782 // constructor and reset functions
4783 _LIBCPP_INLINE_VISIBILITY
4784 explicit weibull_distribution(result_type __a = 1, result_type __b = 1)
4785 : __p_(param_type(__a, __b)) {}
4786 _LIBCPP_INLINE_VISIBILITY
4787 explicit weibull_distribution(const param_type& __p)
4789 _LIBCPP_INLINE_VISIBILITY
4792 // generating functions
4793 template<class _URNG>
4794 _LIBCPP_INLINE_VISIBILITY
4795 result_type operator()(_URNG& __g)
4796 {return (*this)(__g, __p_);}
4797 template<class _URNG>
4798 _LIBCPP_INLINE_VISIBILITY
4799 result_type operator()(_URNG& __g, const param_type& __p)
4801 _VSTD::pow(exponential_distribution<result_type>()(__g), 1/__p.a());}
4803 // property functions
4804 _LIBCPP_INLINE_VISIBILITY
4805 result_type a() const {return __p_.a();}
4806 _LIBCPP_INLINE_VISIBILITY
4807 result_type b() const {return __p_.b();}
4809 _LIBCPP_INLINE_VISIBILITY
4810 param_type param() const {return __p_;}
4811 _LIBCPP_INLINE_VISIBILITY
4812 void param(const param_type& __p) {__p_ = __p;}
4814 _LIBCPP_INLINE_VISIBILITY
4815 result_type min() const {return 0;}
4816 _LIBCPP_INLINE_VISIBILITY
4817 result_type max() const {return numeric_limits<result_type>::infinity();}
4819 friend _LIBCPP_INLINE_VISIBILITY
4820 bool operator==(const weibull_distribution& __x,
4821 const weibull_distribution& __y)
4822 {return __x.__p_ == __y.__p_;}
4823 friend _LIBCPP_INLINE_VISIBILITY
4824 bool operator!=(const weibull_distribution& __x,
4825 const weibull_distribution& __y)
4826 {return !(__x == __y);}
4829 template <class _CharT, class _Traits, class _RT>
4830 basic_ostream<_CharT, _Traits>&
4831 operator<<(basic_ostream<_CharT, _Traits>& __os,
4832 const weibull_distribution<_RT>& __x)
4834 __save_flags<_CharT, _Traits> __lx(__os);
4835 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
4836 ios_base::scientific);
4837 _CharT __sp = __os.widen(' ');
4839 __os << __x.a() << __sp << __x.b();
4843 template <class _CharT, class _Traits, class _RT>
4844 basic_istream<_CharT, _Traits>&
4845 operator>>(basic_istream<_CharT, _Traits>& __is,
4846 weibull_distribution<_RT>& __x)
4848 typedef weibull_distribution<_RT> _Eng;
4849 typedef typename _Eng::result_type result_type;
4850 typedef typename _Eng::param_type param_type;
4851 __save_flags<_CharT, _Traits> __lx(__is);
4852 __is.flags(ios_base::dec | ios_base::skipws);
4857 __x.param(param_type(__a, __b));
4861 template<class _RealType = double>
4862 class _LIBCPP_TYPE_VIS extreme_value_distribution
4866 typedef _RealType result_type;
4868 class _LIBCPP_TYPE_VIS param_type
4873 typedef extreme_value_distribution distribution_type;
4875 _LIBCPP_INLINE_VISIBILITY
4876 explicit param_type(result_type __a = 0, result_type __b = 1)
4877 : __a_(__a), __b_(__b) {}
4879 _LIBCPP_INLINE_VISIBILITY
4880 result_type a() const {return __a_;}
4881 _LIBCPP_INLINE_VISIBILITY
4882 result_type b() const {return __b_;}
4884 friend _LIBCPP_INLINE_VISIBILITY
4885 bool operator==(const param_type& __x, const param_type& __y)
4886 {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
4887 friend _LIBCPP_INLINE_VISIBILITY
4888 bool operator!=(const param_type& __x, const param_type& __y)
4889 {return !(__x == __y);}
4896 // constructor and reset functions
4897 _LIBCPP_INLINE_VISIBILITY
4898 explicit extreme_value_distribution(result_type __a = 0, result_type __b = 1)
4899 : __p_(param_type(__a, __b)) {}
4900 _LIBCPP_INLINE_VISIBILITY
4901 explicit extreme_value_distribution(const param_type& __p)
4903 _LIBCPP_INLINE_VISIBILITY
4906 // generating functions
4907 template<class _URNG>
4908 _LIBCPP_INLINE_VISIBILITY
4909 result_type operator()(_URNG& __g)
4910 {return (*this)(__g, __p_);}
4911 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
4913 // property functions
4914 _LIBCPP_INLINE_VISIBILITY
4915 result_type a() const {return __p_.a();}
4916 _LIBCPP_INLINE_VISIBILITY
4917 result_type b() const {return __p_.b();}
4919 _LIBCPP_INLINE_VISIBILITY
4920 param_type param() const {return __p_;}
4921 _LIBCPP_INLINE_VISIBILITY
4922 void param(const param_type& __p) {__p_ = __p;}
4924 _LIBCPP_INLINE_VISIBILITY
4925 result_type min() const {return -numeric_limits<result_type>::infinity();}
4926 _LIBCPP_INLINE_VISIBILITY
4927 result_type max() const {return numeric_limits<result_type>::infinity();}
4929 friend _LIBCPP_INLINE_VISIBILITY
4930 bool operator==(const extreme_value_distribution& __x,
4931 const extreme_value_distribution& __y)
4932 {return __x.__p_ == __y.__p_;}
4933 friend _LIBCPP_INLINE_VISIBILITY
4934 bool operator!=(const extreme_value_distribution& __x,
4935 const extreme_value_distribution& __y)
4936 {return !(__x == __y);}
4939 template<class _RealType>
4940 template<class _URNG>
4942 extreme_value_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
4944 return __p.a() - __p.b() *
4945 _VSTD::log(-_VSTD::log(1-uniform_real_distribution<result_type>()(__g)));
4948 template <class _CharT, class _Traits, class _RT>
4949 basic_ostream<_CharT, _Traits>&
4950 operator<<(basic_ostream<_CharT, _Traits>& __os,
4951 const extreme_value_distribution<_RT>& __x)
4953 __save_flags<_CharT, _Traits> __lx(__os);
4954 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
4955 ios_base::scientific);
4956 _CharT __sp = __os.widen(' ');
4958 __os << __x.a() << __sp << __x.b();
4962 template <class _CharT, class _Traits, class _RT>
4963 basic_istream<_CharT, _Traits>&
4964 operator>>(basic_istream<_CharT, _Traits>& __is,
4965 extreme_value_distribution<_RT>& __x)
4967 typedef extreme_value_distribution<_RT> _Eng;
4968 typedef typename _Eng::result_type result_type;
4969 typedef typename _Eng::param_type param_type;
4970 __save_flags<_CharT, _Traits> __lx(__is);
4971 __is.flags(ios_base::dec | ios_base::skipws);
4976 __x.param(param_type(__a, __b));
4980 // gamma_distribution
4982 template<class _RealType = double>
4983 class _LIBCPP_TYPE_VIS gamma_distribution
4987 typedef _RealType result_type;
4989 class _LIBCPP_TYPE_VIS param_type
4991 result_type __alpha_;
4992 result_type __beta_;
4994 typedef gamma_distribution distribution_type;
4996 _LIBCPP_INLINE_VISIBILITY
4997 explicit param_type(result_type __alpha = 1, result_type __beta = 1)
4998 : __alpha_(__alpha), __beta_(__beta) {}
5000 _LIBCPP_INLINE_VISIBILITY
5001 result_type alpha() const {return __alpha_;}
5002 _LIBCPP_INLINE_VISIBILITY
5003 result_type beta() const {return __beta_;}
5005 friend _LIBCPP_INLINE_VISIBILITY
5006 bool operator==(const param_type& __x, const param_type& __y)
5007 {return __x.__alpha_ == __y.__alpha_ && __x.__beta_ == __y.__beta_;}
5008 friend _LIBCPP_INLINE_VISIBILITY
5009 bool operator!=(const param_type& __x, const param_type& __y)
5010 {return !(__x == __y);}
5017 // constructors and reset functions
5018 _LIBCPP_INLINE_VISIBILITY
5019 explicit gamma_distribution(result_type __alpha = 1, result_type __beta = 1)
5020 : __p_(param_type(__alpha, __beta)) {}
5021 _LIBCPP_INLINE_VISIBILITY
5022 explicit gamma_distribution(const param_type& __p)
5024 _LIBCPP_INLINE_VISIBILITY
5027 // generating functions
5028 template<class _URNG>
5029 _LIBCPP_INLINE_VISIBILITY
5030 result_type operator()(_URNG& __g)
5031 {return (*this)(__g, __p_);}
5032 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
5034 // property functions
5035 _LIBCPP_INLINE_VISIBILITY
5036 result_type alpha() const {return __p_.alpha();}
5037 _LIBCPP_INLINE_VISIBILITY
5038 result_type beta() const {return __p_.beta();}
5040 _LIBCPP_INLINE_VISIBILITY
5041 param_type param() const {return __p_;}
5042 _LIBCPP_INLINE_VISIBILITY
5043 void param(const param_type& __p) {__p_ = __p;}
5045 _LIBCPP_INLINE_VISIBILITY
5046 result_type min() const {return 0;}
5047 _LIBCPP_INLINE_VISIBILITY
5048 result_type max() const {return numeric_limits<result_type>::infinity();}
5050 friend _LIBCPP_INLINE_VISIBILITY
5051 bool operator==(const gamma_distribution& __x,
5052 const gamma_distribution& __y)
5053 {return __x.__p_ == __y.__p_;}
5054 friend _LIBCPP_INLINE_VISIBILITY
5055 bool operator!=(const gamma_distribution& __x,
5056 const gamma_distribution& __y)
5057 {return !(__x == __y);}
5060 template <class _RealType>
5061 template<class _URNG>
5063 gamma_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
5065 result_type __a = __p.alpha();
5066 uniform_real_distribution<result_type> __gen(0, 1);
5067 exponential_distribution<result_type> __egen;
5073 const result_type __b = __a - 1;
5074 const result_type __c = 3 * __a - result_type(0.75);
5077 const result_type __u = __gen(__g);
5078 const result_type __v = __gen(__g);
5079 const result_type __w = __u * (1 - __u);
5082 const result_type __y = _VSTD::sqrt(__c / __w) *
5083 (__u - result_type(0.5));
5087 const result_type __z = 64 * __w * __w * __w * __v * __v;
5088 if (__z <= 1 - 2 * __y * __y / __x)
5090 if (_VSTD::log(__z) <= 2 * (__b * _VSTD::log(__x / __b) - __y))
5100 const result_type __u = __gen(__g);
5101 const result_type __es = __egen(__g);
5104 __x = _VSTD::pow(__u, 1 / __a);
5110 const result_type __e = -_VSTD::log((1-__u)/__a);
5111 __x = _VSTD::pow(1 - __a + __a * __e, 1 / __a);
5112 if (__x <= __e + __es)
5117 return __x * __p.beta();
5120 template <class _CharT, class _Traits, class _RT>
5121 basic_ostream<_CharT, _Traits>&
5122 operator<<(basic_ostream<_CharT, _Traits>& __os,
5123 const gamma_distribution<_RT>& __x)
5125 __save_flags<_CharT, _Traits> __lx(__os);
5126 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
5127 ios_base::scientific);
5128 _CharT __sp = __os.widen(' ');
5130 __os << __x.alpha() << __sp << __x.beta();
5134 template <class _CharT, class _Traits, class _RT>
5135 basic_istream<_CharT, _Traits>&
5136 operator>>(basic_istream<_CharT, _Traits>& __is,
5137 gamma_distribution<_RT>& __x)
5139 typedef gamma_distribution<_RT> _Eng;
5140 typedef typename _Eng::result_type result_type;
5141 typedef typename _Eng::param_type param_type;
5142 __save_flags<_CharT, _Traits> __lx(__is);
5143 __is.flags(ios_base::dec | ios_base::skipws);
5144 result_type __alpha;
5146 __is >> __alpha >> __beta;
5148 __x.param(param_type(__alpha, __beta));
5152 // negative_binomial_distribution
5154 template<class _IntType = int>
5155 class _LIBCPP_TYPE_VIS negative_binomial_distribution
5159 typedef _IntType result_type;
5161 class _LIBCPP_TYPE_VIS param_type
5166 typedef negative_binomial_distribution distribution_type;
5168 _LIBCPP_INLINE_VISIBILITY
5169 explicit param_type(result_type __k = 1, double __p = 0.5)
5170 : __k_(__k), __p_(__p) {}
5172 _LIBCPP_INLINE_VISIBILITY
5173 result_type k() const {return __k_;}
5174 _LIBCPP_INLINE_VISIBILITY
5175 double p() const {return __p_;}
5177 friend _LIBCPP_INLINE_VISIBILITY
5178 bool operator==(const param_type& __x, const param_type& __y)
5179 {return __x.__k_ == __y.__k_ && __x.__p_ == __y.__p_;}
5180 friend _LIBCPP_INLINE_VISIBILITY
5181 bool operator!=(const param_type& __x, const param_type& __y)
5182 {return !(__x == __y);}
5189 // constructor and reset functions
5190 _LIBCPP_INLINE_VISIBILITY
5191 explicit negative_binomial_distribution(result_type __k = 1, double __p = 0.5)
5193 _LIBCPP_INLINE_VISIBILITY
5194 explicit negative_binomial_distribution(const param_type& __p) : __p_(__p) {}
5195 _LIBCPP_INLINE_VISIBILITY
5198 // generating functions
5199 template<class _URNG>
5200 _LIBCPP_INLINE_VISIBILITY
5201 result_type operator()(_URNG& __g)
5202 {return (*this)(__g, __p_);}
5203 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
5205 // property functions
5206 _LIBCPP_INLINE_VISIBILITY
5207 result_type k() const {return __p_.k();}
5208 _LIBCPP_INLINE_VISIBILITY
5209 double p() const {return __p_.p();}
5211 _LIBCPP_INLINE_VISIBILITY
5212 param_type param() const {return __p_;}
5213 _LIBCPP_INLINE_VISIBILITY
5214 void param(const param_type& __p) {__p_ = __p;}
5216 _LIBCPP_INLINE_VISIBILITY
5217 result_type min() const {return 0;}
5218 _LIBCPP_INLINE_VISIBILITY
5219 result_type max() const {return numeric_limits<result_type>::max();}
5221 friend _LIBCPP_INLINE_VISIBILITY
5222 bool operator==(const negative_binomial_distribution& __x,
5223 const negative_binomial_distribution& __y)
5224 {return __x.__p_ == __y.__p_;}
5225 friend _LIBCPP_INLINE_VISIBILITY
5226 bool operator!=(const negative_binomial_distribution& __x,
5227 const negative_binomial_distribution& __y)
5228 {return !(__x == __y);}
5231 template <class _IntType>
5232 template<class _URNG>
5234 negative_binomial_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr)
5236 result_type __k = __pr.k();
5237 double __p = __pr.p();
5238 if (__k <= 21 * __p)
5240 bernoulli_distribution __gen(__p);
5241 result_type __f = 0;
5242 result_type __s = 0;
5252 return poisson_distribution<result_type>(gamma_distribution<double>
5253 (__k, (1-__p)/__p)(__urng))(__urng);
5256 template <class _CharT, class _Traits, class _IntType>
5257 basic_ostream<_CharT, _Traits>&
5258 operator<<(basic_ostream<_CharT, _Traits>& __os,
5259 const negative_binomial_distribution<_IntType>& __x)
5261 __save_flags<_CharT, _Traits> __lx(__os);
5262 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
5263 ios_base::scientific);
5264 _CharT __sp = __os.widen(' ');
5266 return __os << __x.k() << __sp << __x.p();
5269 template <class _CharT, class _Traits, class _IntType>
5270 basic_istream<_CharT, _Traits>&
5271 operator>>(basic_istream<_CharT, _Traits>& __is,
5272 negative_binomial_distribution<_IntType>& __x)
5274 typedef negative_binomial_distribution<_IntType> _Eng;
5275 typedef typename _Eng::result_type result_type;
5276 typedef typename _Eng::param_type param_type;
5277 __save_flags<_CharT, _Traits> __lx(__is);
5278 __is.flags(ios_base::dec | ios_base::skipws);
5283 __x.param(param_type(__k, __p));
5287 // geometric_distribution
5289 template<class _IntType = int>
5290 class _LIBCPP_TYPE_VIS geometric_distribution
5294 typedef _IntType result_type;
5296 class _LIBCPP_TYPE_VIS param_type
5300 typedef geometric_distribution distribution_type;
5302 _LIBCPP_INLINE_VISIBILITY
5303 explicit param_type(double __p = 0.5) : __p_(__p) {}
5305 _LIBCPP_INLINE_VISIBILITY
5306 double p() const {return __p_;}
5308 friend _LIBCPP_INLINE_VISIBILITY
5309 bool operator==(const param_type& __x, const param_type& __y)
5310 {return __x.__p_ == __y.__p_;}
5311 friend _LIBCPP_INLINE_VISIBILITY
5312 bool operator!=(const param_type& __x, const param_type& __y)
5313 {return !(__x == __y);}
5320 // constructors and reset functions
5321 _LIBCPP_INLINE_VISIBILITY
5322 explicit geometric_distribution(double __p = 0.5) : __p_(__p) {}
5323 _LIBCPP_INLINE_VISIBILITY
5324 explicit geometric_distribution(const param_type& __p) : __p_(__p) {}
5325 _LIBCPP_INLINE_VISIBILITY
5328 // generating functions
5329 template<class _URNG>
5330 _LIBCPP_INLINE_VISIBILITY
5331 result_type operator()(_URNG& __g)
5332 {return (*this)(__g, __p_);}
5333 template<class _URNG>
5334 _LIBCPP_INLINE_VISIBILITY
5335 result_type operator()(_URNG& __g, const param_type& __p)
5336 {return negative_binomial_distribution<result_type>(1, __p.p())(__g);}
5338 // property functions
5339 _LIBCPP_INLINE_VISIBILITY
5340 double p() const {return __p_.p();}
5342 _LIBCPP_INLINE_VISIBILITY
5343 param_type param() const {return __p_;}
5344 _LIBCPP_INLINE_VISIBILITY
5345 void param(const param_type& __p) {__p_ = __p;}
5347 _LIBCPP_INLINE_VISIBILITY
5348 result_type min() const {return 0;}
5349 _LIBCPP_INLINE_VISIBILITY
5350 result_type max() const {return numeric_limits<result_type>::max();}
5352 friend _LIBCPP_INLINE_VISIBILITY
5353 bool operator==(const geometric_distribution& __x,
5354 const geometric_distribution& __y)
5355 {return __x.__p_ == __y.__p_;}
5356 friend _LIBCPP_INLINE_VISIBILITY
5357 bool operator!=(const geometric_distribution& __x,
5358 const geometric_distribution& __y)
5359 {return !(__x == __y);}
5362 template <class _CharT, class _Traits, class _IntType>
5363 basic_ostream<_CharT, _Traits>&
5364 operator<<(basic_ostream<_CharT, _Traits>& __os,
5365 const geometric_distribution<_IntType>& __x)
5367 __save_flags<_CharT, _Traits> __lx(__os);
5368 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
5369 ios_base::scientific);
5370 return __os << __x.p();
5373 template <class _CharT, class _Traits, class _IntType>
5374 basic_istream<_CharT, _Traits>&
5375 operator>>(basic_istream<_CharT, _Traits>& __is,
5376 geometric_distribution<_IntType>& __x)
5378 typedef geometric_distribution<_IntType> _Eng;
5379 typedef typename _Eng::param_type param_type;
5380 __save_flags<_CharT, _Traits> __lx(__is);
5381 __is.flags(ios_base::dec | ios_base::skipws);
5385 __x.param(param_type(__p));
5389 // chi_squared_distribution
5391 template<class _RealType = double>
5392 class _LIBCPP_TYPE_VIS chi_squared_distribution
5396 typedef _RealType result_type;
5398 class _LIBCPP_TYPE_VIS param_type
5402 typedef chi_squared_distribution distribution_type;
5404 _LIBCPP_INLINE_VISIBILITY
5405 explicit param_type(result_type __n = 1) : __n_(__n) {}
5407 _LIBCPP_INLINE_VISIBILITY
5408 result_type n() const {return __n_;}
5410 friend _LIBCPP_INLINE_VISIBILITY
5411 bool operator==(const param_type& __x, const param_type& __y)
5412 {return __x.__n_ == __y.__n_;}
5413 friend _LIBCPP_INLINE_VISIBILITY
5414 bool operator!=(const param_type& __x, const param_type& __y)
5415 {return !(__x == __y);}
5422 // constructor and reset functions
5423 _LIBCPP_INLINE_VISIBILITY
5424 explicit chi_squared_distribution(result_type __n = 1)
5425 : __p_(param_type(__n)) {}
5426 _LIBCPP_INLINE_VISIBILITY
5427 explicit chi_squared_distribution(const param_type& __p)
5429 _LIBCPP_INLINE_VISIBILITY
5432 // generating functions
5433 template<class _URNG>
5434 _LIBCPP_INLINE_VISIBILITY
5435 result_type operator()(_URNG& __g)
5436 {return (*this)(__g, __p_);}
5437 template<class _URNG>
5438 _LIBCPP_INLINE_VISIBILITY
5439 result_type operator()(_URNG& __g, const param_type& __p)
5440 {return gamma_distribution<result_type>(__p.n() / 2, 2)(__g);}
5442 // property functions
5443 _LIBCPP_INLINE_VISIBILITY
5444 result_type n() const {return __p_.n();}
5446 _LIBCPP_INLINE_VISIBILITY
5447 param_type param() const {return __p_;}
5448 _LIBCPP_INLINE_VISIBILITY
5449 void param(const param_type& __p) {__p_ = __p;}
5451 _LIBCPP_INLINE_VISIBILITY
5452 result_type min() const {return 0;}
5453 _LIBCPP_INLINE_VISIBILITY
5454 result_type max() const {return numeric_limits<result_type>::infinity();}
5456 friend _LIBCPP_INLINE_VISIBILITY
5457 bool operator==(const chi_squared_distribution& __x,
5458 const chi_squared_distribution& __y)
5459 {return __x.__p_ == __y.__p_;}
5460 friend _LIBCPP_INLINE_VISIBILITY
5461 bool operator!=(const chi_squared_distribution& __x,
5462 const chi_squared_distribution& __y)
5463 {return !(__x == __y);}
5466 template <class _CharT, class _Traits, class _RT>
5467 basic_ostream<_CharT, _Traits>&
5468 operator<<(basic_ostream<_CharT, _Traits>& __os,
5469 const chi_squared_distribution<_RT>& __x)
5471 __save_flags<_CharT, _Traits> __lx(__os);
5472 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
5473 ios_base::scientific);
5478 template <class _CharT, class _Traits, class _RT>
5479 basic_istream<_CharT, _Traits>&
5480 operator>>(basic_istream<_CharT, _Traits>& __is,
5481 chi_squared_distribution<_RT>& __x)
5483 typedef chi_squared_distribution<_RT> _Eng;
5484 typedef typename _Eng::result_type result_type;
5485 typedef typename _Eng::param_type param_type;
5486 __save_flags<_CharT, _Traits> __lx(__is);
5487 __is.flags(ios_base::dec | ios_base::skipws);
5491 __x.param(param_type(__n));
5495 // cauchy_distribution
5497 template<class _RealType = double>
5498 class _LIBCPP_TYPE_VIS cauchy_distribution
5502 typedef _RealType result_type;
5504 class _LIBCPP_TYPE_VIS param_type
5509 typedef cauchy_distribution distribution_type;
5511 _LIBCPP_INLINE_VISIBILITY
5512 explicit param_type(result_type __a = 0, result_type __b = 1)
5513 : __a_(__a), __b_(__b) {}
5515 _LIBCPP_INLINE_VISIBILITY
5516 result_type a() const {return __a_;}
5517 _LIBCPP_INLINE_VISIBILITY
5518 result_type b() const {return __b_;}
5520 friend _LIBCPP_INLINE_VISIBILITY
5521 bool operator==(const param_type& __x, const param_type& __y)
5522 {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
5523 friend _LIBCPP_INLINE_VISIBILITY
5524 bool operator!=(const param_type& __x, const param_type& __y)
5525 {return !(__x == __y);}
5532 // constructor and reset functions
5533 _LIBCPP_INLINE_VISIBILITY
5534 explicit cauchy_distribution(result_type __a = 0, result_type __b = 1)
5535 : __p_(param_type(__a, __b)) {}
5536 _LIBCPP_INLINE_VISIBILITY
5537 explicit cauchy_distribution(const param_type& __p)
5539 _LIBCPP_INLINE_VISIBILITY
5542 // generating functions
5543 template<class _URNG>
5544 _LIBCPP_INLINE_VISIBILITY
5545 result_type operator()(_URNG& __g)
5546 {return (*this)(__g, __p_);}
5547 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
5549 // property functions
5550 _LIBCPP_INLINE_VISIBILITY
5551 result_type a() const {return __p_.a();}
5552 _LIBCPP_INLINE_VISIBILITY
5553 result_type b() const {return __p_.b();}
5555 _LIBCPP_INLINE_VISIBILITY
5556 param_type param() const {return __p_;}
5557 _LIBCPP_INLINE_VISIBILITY
5558 void param(const param_type& __p) {__p_ = __p;}
5560 _LIBCPP_INLINE_VISIBILITY
5561 result_type min() const {return -numeric_limits<result_type>::infinity();}
5562 _LIBCPP_INLINE_VISIBILITY
5563 result_type max() const {return numeric_limits<result_type>::infinity();}
5565 friend _LIBCPP_INLINE_VISIBILITY
5566 bool operator==(const cauchy_distribution& __x,
5567 const cauchy_distribution& __y)
5568 {return __x.__p_ == __y.__p_;}
5569 friend _LIBCPP_INLINE_VISIBILITY
5570 bool operator!=(const cauchy_distribution& __x,
5571 const cauchy_distribution& __y)
5572 {return !(__x == __y);}
5575 template <class _RealType>
5576 template<class _URNG>
5577 inline _LIBCPP_INLINE_VISIBILITY
5579 cauchy_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
5581 uniform_real_distribution<result_type> __gen;
5582 // purposefully let tan arg get as close to pi/2 as it wants, tan will return a finite
5583 return __p.a() + __p.b() * _VSTD::tan(3.1415926535897932384626433832795 * __gen(__g));
5586 template <class _CharT, class _Traits, class _RT>
5587 basic_ostream<_CharT, _Traits>&
5588 operator<<(basic_ostream<_CharT, _Traits>& __os,
5589 const cauchy_distribution<_RT>& __x)
5591 __save_flags<_CharT, _Traits> __lx(__os);
5592 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
5593 ios_base::scientific);
5594 _CharT __sp = __os.widen(' ');
5596 __os << __x.a() << __sp << __x.b();
5600 template <class _CharT, class _Traits, class _RT>
5601 basic_istream<_CharT, _Traits>&
5602 operator>>(basic_istream<_CharT, _Traits>& __is,
5603 cauchy_distribution<_RT>& __x)
5605 typedef cauchy_distribution<_RT> _Eng;
5606 typedef typename _Eng::result_type result_type;
5607 typedef typename _Eng::param_type param_type;
5608 __save_flags<_CharT, _Traits> __lx(__is);
5609 __is.flags(ios_base::dec | ios_base::skipws);
5614 __x.param(param_type(__a, __b));
5618 // fisher_f_distribution
5620 template<class _RealType = double>
5621 class _LIBCPP_TYPE_VIS fisher_f_distribution
5625 typedef _RealType result_type;
5627 class _LIBCPP_TYPE_VIS param_type
5632 typedef fisher_f_distribution distribution_type;
5634 _LIBCPP_INLINE_VISIBILITY
5635 explicit param_type(result_type __m = 1, result_type __n = 1)
5636 : __m_(__m), __n_(__n) {}
5638 _LIBCPP_INLINE_VISIBILITY
5639 result_type m() const {return __m_;}
5640 _LIBCPP_INLINE_VISIBILITY
5641 result_type n() const {return __n_;}
5643 friend _LIBCPP_INLINE_VISIBILITY
5644 bool operator==(const param_type& __x, const param_type& __y)
5645 {return __x.__m_ == __y.__m_ && __x.__n_ == __y.__n_;}
5646 friend _LIBCPP_INLINE_VISIBILITY
5647 bool operator!=(const param_type& __x, const param_type& __y)
5648 {return !(__x == __y);}
5655 // constructor and reset functions
5656 _LIBCPP_INLINE_VISIBILITY
5657 explicit fisher_f_distribution(result_type __m = 1, result_type __n = 1)
5658 : __p_(param_type(__m, __n)) {}
5659 _LIBCPP_INLINE_VISIBILITY
5660 explicit fisher_f_distribution(const param_type& __p)
5662 _LIBCPP_INLINE_VISIBILITY
5665 // generating functions
5666 template<class _URNG>
5667 _LIBCPP_INLINE_VISIBILITY
5668 result_type operator()(_URNG& __g)
5669 {return (*this)(__g, __p_);}
5670 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
5672 // property functions
5673 _LIBCPP_INLINE_VISIBILITY
5674 result_type m() const {return __p_.m();}
5675 _LIBCPP_INLINE_VISIBILITY
5676 result_type n() const {return __p_.n();}
5678 _LIBCPP_INLINE_VISIBILITY
5679 param_type param() const {return __p_;}
5680 _LIBCPP_INLINE_VISIBILITY
5681 void param(const param_type& __p) {__p_ = __p;}
5683 _LIBCPP_INLINE_VISIBILITY
5684 result_type min() const {return 0;}
5685 _LIBCPP_INLINE_VISIBILITY
5686 result_type max() const {return numeric_limits<result_type>::infinity();}
5688 friend _LIBCPP_INLINE_VISIBILITY
5689 bool operator==(const fisher_f_distribution& __x,
5690 const fisher_f_distribution& __y)
5691 {return __x.__p_ == __y.__p_;}
5692 friend _LIBCPP_INLINE_VISIBILITY
5693 bool operator!=(const fisher_f_distribution& __x,
5694 const fisher_f_distribution& __y)
5695 {return !(__x == __y);}
5698 template <class _RealType>
5699 template<class _URNG>
5701 fisher_f_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
5703 gamma_distribution<result_type> __gdm(__p.m() * result_type(.5));
5704 gamma_distribution<result_type> __gdn(__p.n() * result_type(.5));
5705 return __p.n() * __gdm(__g) / (__p.m() * __gdn(__g));
5708 template <class _CharT, class _Traits, class _RT>
5709 basic_ostream<_CharT, _Traits>&
5710 operator<<(basic_ostream<_CharT, _Traits>& __os,
5711 const fisher_f_distribution<_RT>& __x)
5713 __save_flags<_CharT, _Traits> __lx(__os);
5714 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
5715 ios_base::scientific);
5716 _CharT __sp = __os.widen(' ');
5718 __os << __x.m() << __sp << __x.n();
5722 template <class _CharT, class _Traits, class _RT>
5723 basic_istream<_CharT, _Traits>&
5724 operator>>(basic_istream<_CharT, _Traits>& __is,
5725 fisher_f_distribution<_RT>& __x)
5727 typedef fisher_f_distribution<_RT> _Eng;
5728 typedef typename _Eng::result_type result_type;
5729 typedef typename _Eng::param_type param_type;
5730 __save_flags<_CharT, _Traits> __lx(__is);
5731 __is.flags(ios_base::dec | ios_base::skipws);
5736 __x.param(param_type(__m, __n));
5740 // student_t_distribution
5742 template<class _RealType = double>
5743 class _LIBCPP_TYPE_VIS student_t_distribution
5747 typedef _RealType result_type;
5749 class _LIBCPP_TYPE_VIS param_type
5753 typedef student_t_distribution distribution_type;
5755 _LIBCPP_INLINE_VISIBILITY
5756 explicit param_type(result_type __n = 1) : __n_(__n) {}
5758 _LIBCPP_INLINE_VISIBILITY
5759 result_type n() const {return __n_;}
5761 friend _LIBCPP_INLINE_VISIBILITY
5762 bool operator==(const param_type& __x, const param_type& __y)
5763 {return __x.__n_ == __y.__n_;}
5764 friend _LIBCPP_INLINE_VISIBILITY
5765 bool operator!=(const param_type& __x, const param_type& __y)
5766 {return !(__x == __y);}
5771 normal_distribution<result_type> __nd_;
5774 // constructor and reset functions
5775 _LIBCPP_INLINE_VISIBILITY
5776 explicit student_t_distribution(result_type __n = 1)
5777 : __p_(param_type(__n)) {}
5778 _LIBCPP_INLINE_VISIBILITY
5779 explicit student_t_distribution(const param_type& __p)
5781 _LIBCPP_INLINE_VISIBILITY
5782 void reset() {__nd_.reset();}
5784 // generating functions
5785 template<class _URNG>
5786 _LIBCPP_INLINE_VISIBILITY
5787 result_type operator()(_URNG& __g)
5788 {return (*this)(__g, __p_);}
5789 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
5791 // property functions
5792 _LIBCPP_INLINE_VISIBILITY
5793 result_type n() const {return __p_.n();}
5795 _LIBCPP_INLINE_VISIBILITY
5796 param_type param() const {return __p_;}
5797 _LIBCPP_INLINE_VISIBILITY
5798 void param(const param_type& __p) {__p_ = __p;}
5800 _LIBCPP_INLINE_VISIBILITY
5801 result_type min() const {return -numeric_limits<result_type>::infinity();}
5802 _LIBCPP_INLINE_VISIBILITY
5803 result_type max() const {return numeric_limits<result_type>::infinity();}
5805 friend _LIBCPP_INLINE_VISIBILITY
5806 bool operator==(const student_t_distribution& __x,
5807 const student_t_distribution& __y)
5808 {return __x.__p_ == __y.__p_;}
5809 friend _LIBCPP_INLINE_VISIBILITY
5810 bool operator!=(const student_t_distribution& __x,
5811 const student_t_distribution& __y)
5812 {return !(__x == __y);}
5815 template <class _RealType>
5816 template<class _URNG>
5818 student_t_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
5820 gamma_distribution<result_type> __gd(__p.n() * .5, 2);
5821 return __nd_(__g) * _VSTD::sqrt(__p.n()/__gd(__g));
5824 template <class _CharT, class _Traits, class _RT>
5825 basic_ostream<_CharT, _Traits>&
5826 operator<<(basic_ostream<_CharT, _Traits>& __os,
5827 const student_t_distribution<_RT>& __x)
5829 __save_flags<_CharT, _Traits> __lx(__os);
5830 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
5831 ios_base::scientific);
5836 template <class _CharT, class _Traits, class _RT>
5837 basic_istream<_CharT, _Traits>&
5838 operator>>(basic_istream<_CharT, _Traits>& __is,
5839 student_t_distribution<_RT>& __x)
5841 typedef student_t_distribution<_RT> _Eng;
5842 typedef typename _Eng::result_type result_type;
5843 typedef typename _Eng::param_type param_type;
5844 __save_flags<_CharT, _Traits> __lx(__is);
5845 __is.flags(ios_base::dec | ios_base::skipws);
5849 __x.param(param_type(__n));
5853 // discrete_distribution
5855 template<class _IntType = int>
5856 class _LIBCPP_TYPE_VIS discrete_distribution
5860 typedef _IntType result_type;
5862 class _LIBCPP_TYPE_VIS param_type
5864 vector<double> __p_;
5866 typedef discrete_distribution distribution_type;
5868 _LIBCPP_INLINE_VISIBILITY
5870 template<class _InputIterator>
5871 _LIBCPP_INLINE_VISIBILITY
5872 param_type(_InputIterator __f, _InputIterator __l)
5873 : __p_(__f, __l) {__init();}
5874 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
5875 _LIBCPP_INLINE_VISIBILITY
5876 param_type(initializer_list<double> __wl)
5877 : __p_(__wl.begin(), __wl.end()) {__init();}
5878 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
5879 template<class _UnaryOperation>
5880 param_type(size_t __nw, double __xmin, double __xmax,
5881 _UnaryOperation __fw);
5883 vector<double> probabilities() const;
5885 friend _LIBCPP_INLINE_VISIBILITY
5886 bool operator==(const param_type& __x, const param_type& __y)
5887 {return __x.__p_ == __y.__p_;}
5888 friend _LIBCPP_INLINE_VISIBILITY
5889 bool operator!=(const param_type& __x, const param_type& __y)
5890 {return !(__x == __y);}
5895 friend class discrete_distribution;
5897 template <class _CharT, class _Traits, class _IT>
5899 basic_ostream<_CharT, _Traits>&
5900 operator<<(basic_ostream<_CharT, _Traits>& __os,
5901 const discrete_distribution<_IT>& __x);
5903 template <class _CharT, class _Traits, class _IT>
5905 basic_istream<_CharT, _Traits>&
5906 operator>>(basic_istream<_CharT, _Traits>& __is,
5907 discrete_distribution<_IT>& __x);
5914 // constructor and reset functions
5915 _LIBCPP_INLINE_VISIBILITY
5916 discrete_distribution() {}
5917 template<class _InputIterator>
5918 _LIBCPP_INLINE_VISIBILITY
5919 discrete_distribution(_InputIterator __f, _InputIterator __l)
5921 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
5922 _LIBCPP_INLINE_VISIBILITY
5923 discrete_distribution(initializer_list<double> __wl)
5925 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
5926 template<class _UnaryOperation>
5927 _LIBCPP_INLINE_VISIBILITY
5928 discrete_distribution(size_t __nw, double __xmin, double __xmax,
5929 _UnaryOperation __fw)
5930 : __p_(__nw, __xmin, __xmax, __fw) {}
5931 explicit discrete_distribution(const param_type& __p)
5932 _LIBCPP_INLINE_VISIBILITY
5934 _LIBCPP_INLINE_VISIBILITY
5937 // generating functions
5938 template<class _URNG>
5939 _LIBCPP_INLINE_VISIBILITY
5940 result_type operator()(_URNG& __g)
5941 {return (*this)(__g, __p_);}
5942 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
5944 // property functions
5945 _LIBCPP_INLINE_VISIBILITY
5946 vector<double> probabilities() const {return __p_.probabilities();}
5948 _LIBCPP_INLINE_VISIBILITY
5949 param_type param() const {return __p_;}
5950 _LIBCPP_INLINE_VISIBILITY
5951 void param(const param_type& __p) {__p_ = __p;}
5953 _LIBCPP_INLINE_VISIBILITY
5954 result_type min() const {return 0;}
5955 _LIBCPP_INLINE_VISIBILITY
5956 result_type max() const {return __p_.__p_.size();}
5958 friend _LIBCPP_INLINE_VISIBILITY
5959 bool operator==(const discrete_distribution& __x,
5960 const discrete_distribution& __y)
5961 {return __x.__p_ == __y.__p_;}
5962 friend _LIBCPP_INLINE_VISIBILITY
5963 bool operator!=(const discrete_distribution& __x,
5964 const discrete_distribution& __y)
5965 {return !(__x == __y);}
5967 template <class _CharT, class _Traits, class _IT>
5969 basic_ostream<_CharT, _Traits>&
5970 operator<<(basic_ostream<_CharT, _Traits>& __os,
5971 const discrete_distribution<_IT>& __x);
5973 template <class _CharT, class _Traits, class _IT>
5975 basic_istream<_CharT, _Traits>&
5976 operator>>(basic_istream<_CharT, _Traits>& __is,
5977 discrete_distribution<_IT>& __x);
5980 template<class _IntType>
5981 template<class _UnaryOperation>
5982 discrete_distribution<_IntType>::param_type::param_type(size_t __nw,
5985 _UnaryOperation __fw)
5989 __p_.reserve(__nw - 1);
5990 double __d = (__xmax - __xmin) / __nw;
5991 double __d2 = __d / 2;
5992 for (size_t __k = 0; __k < __nw; ++__k)
5993 __p_.push_back(__fw(__xmin + __k * __d + __d2));
5998 template<class _IntType>
6000 discrete_distribution<_IntType>::param_type::__init()
6004 if (__p_.size() > 1)
6006 double __s = _VSTD::accumulate(__p_.begin(), __p_.end(), 0.0);
6007 for (_VSTD::vector<double>::iterator __i = __p_.begin(), __e = __p_.end();
6010 vector<double> __t(__p_.size() - 1);
6011 _VSTD::partial_sum(__p_.begin(), __p_.end() - 1, __t.begin());
6017 __p_.shrink_to_fit();
6022 template<class _IntType>
6024 discrete_distribution<_IntType>::param_type::probabilities() const
6026 size_t __n = __p_.size();
6027 _VSTD::vector<double> __p(__n+1);
6028 _VSTD::adjacent_difference(__p_.begin(), __p_.end(), __p.begin());
6030 __p[__n] = 1 - __p_[__n-1];
6036 template<class _IntType>
6037 template<class _URNG>
6039 discrete_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p)
6041 uniform_real_distribution<double> __gen;
6042 return static_cast<_IntType>(
6043 _VSTD::upper_bound(__p.__p_.begin(), __p.__p_.end(), __gen(__g)) -
6047 template <class _CharT, class _Traits, class _IT>
6048 basic_ostream<_CharT, _Traits>&
6049 operator<<(basic_ostream<_CharT, _Traits>& __os,
6050 const discrete_distribution<_IT>& __x)
6052 __save_flags<_CharT, _Traits> __lx(__os);
6053 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
6054 ios_base::scientific);
6055 _CharT __sp = __os.widen(' ');
6057 size_t __n = __x.__p_.__p_.size();
6059 for (size_t __i = 0; __i < __n; ++__i)
6060 __os << __sp << __x.__p_.__p_[__i];
6064 template <class _CharT, class _Traits, class _IT>
6065 basic_istream<_CharT, _Traits>&
6066 operator>>(basic_istream<_CharT, _Traits>& __is,
6067 discrete_distribution<_IT>& __x)
6069 typedef discrete_distribution<_IT> _Eng;
6070 typedef typename _Eng::result_type result_type;
6071 typedef typename _Eng::param_type param_type;
6072 __save_flags<_CharT, _Traits> __lx(__is);
6073 __is.flags(ios_base::dec | ios_base::skipws);
6076 vector<double> __p(__n);
6077 for (size_t __i = 0; __i < __n; ++__i)
6080 swap(__x.__p_.__p_, __p);
6084 // piecewise_constant_distribution
6086 template<class _RealType = double>
6087 class _LIBCPP_TYPE_VIS piecewise_constant_distribution
6091 typedef _RealType result_type;
6093 class _LIBCPP_TYPE_VIS param_type
6095 vector<result_type> __b_;
6096 vector<result_type> __densities_;
6097 vector<result_type> __areas_;
6099 typedef piecewise_constant_distribution distribution_type;
6102 template<class _InputIteratorB, class _InputIteratorW>
6103 param_type(_InputIteratorB __fB, _InputIteratorB __lB,
6104 _InputIteratorW __fW);
6105 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6106 template<class _UnaryOperation>
6107 param_type(initializer_list<result_type> __bl, _UnaryOperation __fw);
6108 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6109 template<class _UnaryOperation>
6110 param_type(size_t __nw, result_type __xmin, result_type __xmax,
6111 _UnaryOperation __fw);
6112 param_type & operator=(const param_type& __rhs);
6114 _LIBCPP_INLINE_VISIBILITY
6115 vector<result_type> intervals() const {return __b_;}
6116 _LIBCPP_INLINE_VISIBILITY
6117 vector<result_type> densities() const {return __densities_;}
6119 friend _LIBCPP_INLINE_VISIBILITY
6120 bool operator==(const param_type& __x, const param_type& __y)
6121 {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;}
6122 friend _LIBCPP_INLINE_VISIBILITY
6123 bool operator!=(const param_type& __x, const param_type& __y)
6124 {return !(__x == __y);}
6129 friend class piecewise_constant_distribution;
6131 template <class _CharT, class _Traits, class _RT>
6133 basic_ostream<_CharT, _Traits>&
6134 operator<<(basic_ostream<_CharT, _Traits>& __os,
6135 const piecewise_constant_distribution<_RT>& __x);
6137 template <class _CharT, class _Traits, class _RT>
6139 basic_istream<_CharT, _Traits>&
6140 operator>>(basic_istream<_CharT, _Traits>& __is,
6141 piecewise_constant_distribution<_RT>& __x);
6148 // constructor and reset functions
6149 _LIBCPP_INLINE_VISIBILITY
6150 piecewise_constant_distribution() {}
6151 template<class _InputIteratorB, class _InputIteratorW>
6152 _LIBCPP_INLINE_VISIBILITY
6153 piecewise_constant_distribution(_InputIteratorB __fB,
6154 _InputIteratorB __lB,
6155 _InputIteratorW __fW)
6156 : __p_(__fB, __lB, __fW) {}
6158 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6159 template<class _UnaryOperation>
6160 _LIBCPP_INLINE_VISIBILITY
6161 piecewise_constant_distribution(initializer_list<result_type> __bl,
6162 _UnaryOperation __fw)
6163 : __p_(__bl, __fw) {}
6164 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6166 template<class _UnaryOperation>
6167 _LIBCPP_INLINE_VISIBILITY
6168 piecewise_constant_distribution(size_t __nw, result_type __xmin,
6169 result_type __xmax, _UnaryOperation __fw)
6170 : __p_(__nw, __xmin, __xmax, __fw) {}
6172 _LIBCPP_INLINE_VISIBILITY
6173 explicit piecewise_constant_distribution(const param_type& __p)
6176 _LIBCPP_INLINE_VISIBILITY
6179 // generating functions
6180 template<class _URNG>
6181 _LIBCPP_INLINE_VISIBILITY
6182 result_type operator()(_URNG& __g)
6183 {return (*this)(__g, __p_);}
6184 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
6186 // property functions
6187 _LIBCPP_INLINE_VISIBILITY
6188 vector<result_type> intervals() const {return __p_.intervals();}
6189 _LIBCPP_INLINE_VISIBILITY
6190 vector<result_type> densities() const {return __p_.densities();}
6192 _LIBCPP_INLINE_VISIBILITY
6193 param_type param() const {return __p_;}
6194 _LIBCPP_INLINE_VISIBILITY
6195 void param(const param_type& __p) {__p_ = __p;}
6197 _LIBCPP_INLINE_VISIBILITY
6198 result_type min() const {return __p_.__b_.front();}
6199 _LIBCPP_INLINE_VISIBILITY
6200 result_type max() const {return __p_.__b_.back();}
6202 friend _LIBCPP_INLINE_VISIBILITY
6203 bool operator==(const piecewise_constant_distribution& __x,
6204 const piecewise_constant_distribution& __y)
6205 {return __x.__p_ == __y.__p_;}
6206 friend _LIBCPP_INLINE_VISIBILITY
6207 bool operator!=(const piecewise_constant_distribution& __x,
6208 const piecewise_constant_distribution& __y)
6209 {return !(__x == __y);}
6211 template <class _CharT, class _Traits, class _RT>
6213 basic_ostream<_CharT, _Traits>&
6214 operator<<(basic_ostream<_CharT, _Traits>& __os,
6215 const piecewise_constant_distribution<_RT>& __x);
6217 template <class _CharT, class _Traits, class _RT>
6219 basic_istream<_CharT, _Traits>&
6220 operator>>(basic_istream<_CharT, _Traits>& __is,
6221 piecewise_constant_distribution<_RT>& __x);
6224 template<class _RealType>
6225 typename piecewise_constant_distribution<_RealType>::param_type &
6226 piecewise_constant_distribution<_RealType>::param_type::operator=
6227 (const param_type& __rhs)
6230 __b_.reserve (__rhs.__b_.size ());
6231 __densities_.reserve(__rhs.__densities_.size());
6232 __areas_.reserve (__rhs.__areas_.size());
6234 // These can not throw
6236 __densities_ = __rhs.__densities_;
6237 __areas_ = __rhs.__areas_;
6241 template<class _RealType>
6243 piecewise_constant_distribution<_RealType>::param_type::__init()
6245 // __densities_ contains non-normalized areas
6246 result_type __total_area = _VSTD::accumulate(__densities_.begin(),
6249 for (size_t __i = 0; __i < __densities_.size(); ++__i)
6250 __densities_[__i] /= __total_area;
6251 // __densities_ contains normalized areas
6252 __areas_.assign(__densities_.size(), result_type());
6253 _VSTD::partial_sum(__densities_.begin(), __densities_.end() - 1,
6254 __areas_.begin() + 1);
6255 // __areas_ contains partial sums of normalized areas: [0, __densities_ - 1]
6256 __densities_.back() = 1 - __areas_.back(); // correct round off error
6257 for (size_t __i = 0; __i < __densities_.size(); ++__i)
6258 __densities_[__i] /= (__b_[__i+1] - __b_[__i]);
6259 // __densities_ now contains __densities_
6262 template<class _RealType>
6263 piecewise_constant_distribution<_RealType>::param_type::param_type()
6265 __densities_(1, 1.0),
6271 template<class _RealType>
6272 template<class _InputIteratorB, class _InputIteratorW>
6273 piecewise_constant_distribution<_RealType>::param_type::param_type(
6274 _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW)
6277 if (__b_.size() < 2)
6282 __densities_.assign(1, 1.0);
6283 __areas_.assign(1, 0.0);
6287 __densities_.reserve(__b_.size() - 1);
6288 for (size_t __i = 0; __i < __b_.size() - 1; ++__i, ++__fW)
6289 __densities_.push_back(*__fW);
6294 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6296 template<class _RealType>
6297 template<class _UnaryOperation>
6298 piecewise_constant_distribution<_RealType>::param_type::param_type(
6299 initializer_list<result_type> __bl, _UnaryOperation __fw)
6300 : __b_(__bl.begin(), __bl.end())
6302 if (__b_.size() < 2)
6307 __densities_.assign(1, 1.0);
6308 __areas_.assign(1, 0.0);
6312 __densities_.reserve(__b_.size() - 1);
6313 for (size_t __i = 0; __i < __b_.size() - 1; ++__i)
6314 __densities_.push_back(__fw((__b_[__i+1] + __b_[__i])*.5));
6319 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6321 template<class _RealType>
6322 template<class _UnaryOperation>
6323 piecewise_constant_distribution<_RealType>::param_type::param_type(
6324 size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw)
6325 : __b_(__nw == 0 ? 2 : __nw + 1)
6327 size_t __n = __b_.size() - 1;
6328 result_type __d = (__xmax - __xmin) / __n;
6329 __densities_.reserve(__n);
6330 for (size_t __i = 0; __i < __n; ++__i)
6332 __b_[__i] = __xmin + __i * __d;
6333 __densities_.push_back(__fw(__b_[__i] + __d*.5));
6339 template<class _RealType>
6340 template<class _URNG>
6342 piecewise_constant_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
6344 typedef uniform_real_distribution<result_type> _Gen;
6345 result_type __u = _Gen()(__g);
6346 ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(),
6347 __u) - __p.__areas_.begin() - 1;
6348 return (__u - __p.__areas_[__k]) / __p.__densities_[__k] + __p.__b_[__k];
6351 template <class _CharT, class _Traits, class _RT>
6352 basic_ostream<_CharT, _Traits>&
6353 operator<<(basic_ostream<_CharT, _Traits>& __os,
6354 const piecewise_constant_distribution<_RT>& __x)
6356 __save_flags<_CharT, _Traits> __lx(__os);
6357 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
6358 ios_base::scientific);
6359 _CharT __sp = __os.widen(' ');
6361 size_t __n = __x.__p_.__b_.size();
6363 for (size_t __i = 0; __i < __n; ++__i)
6364 __os << __sp << __x.__p_.__b_[__i];
6365 __n = __x.__p_.__densities_.size();
6366 __os << __sp << __n;
6367 for (size_t __i = 0; __i < __n; ++__i)
6368 __os << __sp << __x.__p_.__densities_[__i];
6369 __n = __x.__p_.__areas_.size();
6370 __os << __sp << __n;
6371 for (size_t __i = 0; __i < __n; ++__i)
6372 __os << __sp << __x.__p_.__areas_[__i];
6376 template <class _CharT, class _Traits, class _RT>
6377 basic_istream<_CharT, _Traits>&
6378 operator>>(basic_istream<_CharT, _Traits>& __is,
6379 piecewise_constant_distribution<_RT>& __x)
6381 typedef piecewise_constant_distribution<_RT> _Eng;
6382 typedef typename _Eng::result_type result_type;
6383 typedef typename _Eng::param_type param_type;
6384 __save_flags<_CharT, _Traits> __lx(__is);
6385 __is.flags(ios_base::dec | ios_base::skipws);
6388 vector<result_type> __b(__n);
6389 for (size_t __i = 0; __i < __n; ++__i)
6392 vector<result_type> __densities(__n);
6393 for (size_t __i = 0; __i < __n; ++__i)
6394 __is >> __densities[__i];
6396 vector<result_type> __areas(__n);
6397 for (size_t __i = 0; __i < __n; ++__i)
6398 __is >> __areas[__i];
6401 swap(__x.__p_.__b_, __b);
6402 swap(__x.__p_.__densities_, __densities);
6403 swap(__x.__p_.__areas_, __areas);
6408 // piecewise_linear_distribution
6410 template<class _RealType = double>
6411 class _LIBCPP_TYPE_VIS piecewise_linear_distribution
6415 typedef _RealType result_type;
6417 class _LIBCPP_TYPE_VIS param_type
6419 vector<result_type> __b_;
6420 vector<result_type> __densities_;
6421 vector<result_type> __areas_;
6423 typedef piecewise_linear_distribution distribution_type;
6426 template<class _InputIteratorB, class _InputIteratorW>
6427 param_type(_InputIteratorB __fB, _InputIteratorB __lB,
6428 _InputIteratorW __fW);
6429 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6430 template<class _UnaryOperation>
6431 param_type(initializer_list<result_type> __bl, _UnaryOperation __fw);
6432 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6433 template<class _UnaryOperation>
6434 param_type(size_t __nw, result_type __xmin, result_type __xmax,
6435 _UnaryOperation __fw);
6436 param_type & operator=(const param_type& __rhs);
6438 _LIBCPP_INLINE_VISIBILITY
6439 vector<result_type> intervals() const {return __b_;}
6440 _LIBCPP_INLINE_VISIBILITY
6441 vector<result_type> densities() const {return __densities_;}
6443 friend _LIBCPP_INLINE_VISIBILITY
6444 bool operator==(const param_type& __x, const param_type& __y)
6445 {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;}
6446 friend _LIBCPP_INLINE_VISIBILITY
6447 bool operator!=(const param_type& __x, const param_type& __y)
6448 {return !(__x == __y);}
6453 friend class piecewise_linear_distribution;
6455 template <class _CharT, class _Traits, class _RT>
6457 basic_ostream<_CharT, _Traits>&
6458 operator<<(basic_ostream<_CharT, _Traits>& __os,
6459 const piecewise_linear_distribution<_RT>& __x);
6461 template <class _CharT, class _Traits, class _RT>
6463 basic_istream<_CharT, _Traits>&
6464 operator>>(basic_istream<_CharT, _Traits>& __is,
6465 piecewise_linear_distribution<_RT>& __x);
6472 // constructor and reset functions
6473 _LIBCPP_INLINE_VISIBILITY
6474 piecewise_linear_distribution() {}
6475 template<class _InputIteratorB, class _InputIteratorW>
6476 _LIBCPP_INLINE_VISIBILITY
6477 piecewise_linear_distribution(_InputIteratorB __fB,
6478 _InputIteratorB __lB,
6479 _InputIteratorW __fW)
6480 : __p_(__fB, __lB, __fW) {}
6482 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6483 template<class _UnaryOperation>
6484 _LIBCPP_INLINE_VISIBILITY
6485 piecewise_linear_distribution(initializer_list<result_type> __bl,
6486 _UnaryOperation __fw)
6487 : __p_(__bl, __fw) {}
6488 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6490 template<class _UnaryOperation>
6491 _LIBCPP_INLINE_VISIBILITY
6492 piecewise_linear_distribution(size_t __nw, result_type __xmin,
6493 result_type __xmax, _UnaryOperation __fw)
6494 : __p_(__nw, __xmin, __xmax, __fw) {}
6496 _LIBCPP_INLINE_VISIBILITY
6497 explicit piecewise_linear_distribution(const param_type& __p)
6500 _LIBCPP_INLINE_VISIBILITY
6503 // generating functions
6504 template<class _URNG>
6505 _LIBCPP_INLINE_VISIBILITY
6506 result_type operator()(_URNG& __g)
6507 {return (*this)(__g, __p_);}
6508 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
6510 // property functions
6511 _LIBCPP_INLINE_VISIBILITY
6512 vector<result_type> intervals() const {return __p_.intervals();}
6513 _LIBCPP_INLINE_VISIBILITY
6514 vector<result_type> densities() const {return __p_.densities();}
6516 _LIBCPP_INLINE_VISIBILITY
6517 param_type param() const {return __p_;}
6518 _LIBCPP_INLINE_VISIBILITY
6519 void param(const param_type& __p) {__p_ = __p;}
6521 _LIBCPP_INLINE_VISIBILITY
6522 result_type min() const {return __p_.__b_.front();}
6523 _LIBCPP_INLINE_VISIBILITY
6524 result_type max() const {return __p_.__b_.back();}
6526 friend _LIBCPP_INLINE_VISIBILITY
6527 bool operator==(const piecewise_linear_distribution& __x,
6528 const piecewise_linear_distribution& __y)
6529 {return __x.__p_ == __y.__p_;}
6530 friend _LIBCPP_INLINE_VISIBILITY
6531 bool operator!=(const piecewise_linear_distribution& __x,
6532 const piecewise_linear_distribution& __y)
6533 {return !(__x == __y);}
6535 template <class _CharT, class _Traits, class _RT>
6537 basic_ostream<_CharT, _Traits>&
6538 operator<<(basic_ostream<_CharT, _Traits>& __os,
6539 const piecewise_linear_distribution<_RT>& __x);
6541 template <class _CharT, class _Traits, class _RT>
6543 basic_istream<_CharT, _Traits>&
6544 operator>>(basic_istream<_CharT, _Traits>& __is,
6545 piecewise_linear_distribution<_RT>& __x);
6548 template<class _RealType>
6549 typename piecewise_linear_distribution<_RealType>::param_type &
6550 piecewise_linear_distribution<_RealType>::param_type::operator=
6551 (const param_type& __rhs)
6554 __b_.reserve (__rhs.__b_.size ());
6555 __densities_.reserve(__rhs.__densities_.size());
6556 __areas_.reserve (__rhs.__areas_.size());
6558 // These can not throw
6560 __densities_ = __rhs.__densities_;
6561 __areas_ = __rhs.__areas_;
6566 template<class _RealType>
6568 piecewise_linear_distribution<_RealType>::param_type::__init()
6570 __areas_.assign(__densities_.size() - 1, result_type());
6571 result_type _Sp = 0;
6572 for (size_t __i = 0; __i < __areas_.size(); ++__i)
6574 __areas_[__i] = (__densities_[__i+1] + __densities_[__i]) *
6575 (__b_[__i+1] - __b_[__i]) * .5;
6576 _Sp += __areas_[__i];
6578 for (size_t __i = __areas_.size(); __i > 1;)
6581 __areas_[__i] = __areas_[__i-1] / _Sp;
6584 for (size_t __i = 1; __i < __areas_.size(); ++__i)
6585 __areas_[__i] += __areas_[__i-1];
6586 for (size_t __i = 0; __i < __densities_.size(); ++__i)
6587 __densities_[__i] /= _Sp;
6590 template<class _RealType>
6591 piecewise_linear_distribution<_RealType>::param_type::param_type()
6593 __densities_(2, 1.0),
6599 template<class _RealType>
6600 template<class _InputIteratorB, class _InputIteratorW>
6601 piecewise_linear_distribution<_RealType>::param_type::param_type(
6602 _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW)
6605 if (__b_.size() < 2)
6610 __densities_.assign(2, 1.0);
6611 __areas_.assign(1, 0.0);
6615 __densities_.reserve(__b_.size());
6616 for (size_t __i = 0; __i < __b_.size(); ++__i, ++__fW)
6617 __densities_.push_back(*__fW);
6622 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6624 template<class _RealType>
6625 template<class _UnaryOperation>
6626 piecewise_linear_distribution<_RealType>::param_type::param_type(
6627 initializer_list<result_type> __bl, _UnaryOperation __fw)
6628 : __b_(__bl.begin(), __bl.end())
6630 if (__b_.size() < 2)
6635 __densities_.assign(2, 1.0);
6636 __areas_.assign(1, 0.0);
6640 __densities_.reserve(__b_.size());
6641 for (size_t __i = 0; __i < __b_.size(); ++__i)
6642 __densities_.push_back(__fw(__b_[__i]));
6647 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6649 template<class _RealType>
6650 template<class _UnaryOperation>
6651 piecewise_linear_distribution<_RealType>::param_type::param_type(
6652 size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw)
6653 : __b_(__nw == 0 ? 2 : __nw + 1)
6655 size_t __n = __b_.size() - 1;
6656 result_type __d = (__xmax - __xmin) / __n;
6657 __densities_.reserve(__b_.size());
6658 for (size_t __i = 0; __i < __n; ++__i)
6660 __b_[__i] = __xmin + __i * __d;
6661 __densities_.push_back(__fw(__b_[__i]));
6664 __densities_.push_back(__fw(__b_[__n]));
6668 template<class _RealType>
6669 template<class _URNG>
6671 piecewise_linear_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
6673 typedef uniform_real_distribution<result_type> _Gen;
6674 result_type __u = _Gen()(__g);
6675 ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(),
6676 __u) - __p.__areas_.begin() - 1;
6677 __u -= __p.__areas_[__k];
6678 const result_type __dk = __p.__densities_[__k];
6679 const result_type __dk1 = __p.__densities_[__k+1];
6680 const result_type __deltad = __dk1 - __dk;
6681 const result_type __bk = __p.__b_[__k];
6683 return __u / __dk + __bk;
6684 const result_type __bk1 = __p.__b_[__k+1];
6685 const result_type __deltab = __bk1 - __bk;
6686 return (__bk * __dk1 - __bk1 * __dk +
6687 _VSTD::sqrt(__deltab * (__deltab * __dk * __dk + 2 * __deltad * __u))) /
6691 template <class _CharT, class _Traits, class _RT>
6692 basic_ostream<_CharT, _Traits>&
6693 operator<<(basic_ostream<_CharT, _Traits>& __os,
6694 const piecewise_linear_distribution<_RT>& __x)
6696 __save_flags<_CharT, _Traits> __lx(__os);
6697 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
6698 ios_base::scientific);
6699 _CharT __sp = __os.widen(' ');
6701 size_t __n = __x.__p_.__b_.size();
6703 for (size_t __i = 0; __i < __n; ++__i)
6704 __os << __sp << __x.__p_.__b_[__i];
6705 __n = __x.__p_.__densities_.size();
6706 __os << __sp << __n;
6707 for (size_t __i = 0; __i < __n; ++__i)
6708 __os << __sp << __x.__p_.__densities_[__i];
6709 __n = __x.__p_.__areas_.size();
6710 __os << __sp << __n;
6711 for (size_t __i = 0; __i < __n; ++__i)
6712 __os << __sp << __x.__p_.__areas_[__i];
6716 template <class _CharT, class _Traits, class _RT>
6717 basic_istream<_CharT, _Traits>&
6718 operator>>(basic_istream<_CharT, _Traits>& __is,
6719 piecewise_linear_distribution<_RT>& __x)
6721 typedef piecewise_linear_distribution<_RT> _Eng;
6722 typedef typename _Eng::result_type result_type;
6723 typedef typename _Eng::param_type param_type;
6724 __save_flags<_CharT, _Traits> __lx(__is);
6725 __is.flags(ios_base::dec | ios_base::skipws);
6728 vector<result_type> __b(__n);
6729 for (size_t __i = 0; __i < __n; ++__i)
6732 vector<result_type> __densities(__n);
6733 for (size_t __i = 0; __i < __n; ++__i)
6734 __is >> __densities[__i];
6736 vector<result_type> __areas(__n);
6737 for (size_t __i = 0; __i < __n; ++__i)
6738 __is >> __areas[__i];
6741 swap(__x.__p_.__b_, __b);
6742 swap(__x.__p_.__densities_, __densities);
6743 swap(__x.__p_.__areas_, __areas);
6748 _LIBCPP_END_NAMESPACE_STD
6750 #endif // _LIBCPP_RANDOM