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;
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;
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;
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;
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 linear_congruential_engine;
1818 template <class _CharT, class _Traits,
1819 class _Up, _Up _Ap, _Up _Cp, _Up _Np>
1820 basic_ostream<_CharT, _Traits>&
1821 operator<<(basic_ostream<_CharT, _Traits>& __os,
1822 const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&);
1824 template <class _CharT, class _Traits,
1825 class _Up, _Up _Ap, _Up _Cp, _Up _Np>
1826 basic_istream<_CharT, _Traits>&
1827 operator>>(basic_istream<_CharT, _Traits>& __is,
1828 linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x);
1830 template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
1831 class _LIBCPP_VISIBLE linear_congruential_engine
1835 typedef _UIntType result_type;
1840 static _LIBCPP_CONSTEXPR const result_type _Mp = result_type(~0);
1842 static_assert(__m == 0 || __a < __m, "linear_congruential_engine invalid parameters");
1843 static_assert(__m == 0 || __c < __m, "linear_congruential_engine invalid parameters");
1845 static _LIBCPP_CONSTEXPR const result_type _Min = __c == 0u ? 1u: 0u;
1846 static _LIBCPP_CONSTEXPR const result_type _Max = __m - 1u;
1847 static_assert(_Min < _Max, "linear_congruential_engine invalid parameters");
1849 // engine characteristics
1850 static _LIBCPP_CONSTEXPR const result_type multiplier = __a;
1851 static _LIBCPP_CONSTEXPR const result_type increment = __c;
1852 static _LIBCPP_CONSTEXPR const result_type modulus = __m;
1853 _LIBCPP_INLINE_VISIBILITY
1854 static _LIBCPP_CONSTEXPR result_type min() {return _Min;}
1855 _LIBCPP_INLINE_VISIBILITY
1856 static _LIBCPP_CONSTEXPR result_type max() {return _Max;}
1857 static _LIBCPP_CONSTEXPR const result_type default_seed = 1u;
1859 // constructors and seeding functions
1860 _LIBCPP_INLINE_VISIBILITY
1861 explicit linear_congruential_engine(result_type __s = default_seed)
1863 template<class _Sseq>
1864 _LIBCPP_INLINE_VISIBILITY
1865 explicit linear_congruential_engine(_Sseq& __q,
1866 typename enable_if<__is_seed_sequence<_Sseq, linear_congruential_engine>::value>::type* = 0)
1868 _LIBCPP_INLINE_VISIBILITY
1869 void seed(result_type __s = default_seed)
1870 {seed(integral_constant<bool, __m == 0>(),
1871 integral_constant<bool, __c == 0>(), __s);}
1872 template<class _Sseq>
1873 _LIBCPP_INLINE_VISIBILITY
1876 __is_seed_sequence<_Sseq, linear_congruential_engine>::value,
1880 {__seed(__q, integral_constant<unsigned,
1881 1 + (__m == 0 ? (sizeof(result_type) * __CHAR_BIT__ - 1)/32
1882 : (__m-1) / 0x100000000ull)>());}
1884 // generating functions
1885 _LIBCPP_INLINE_VISIBILITY
1886 result_type operator()()
1887 {return __x_ = static_cast<result_type>(__lce_ta<__a, __c, __m, _Mp>::next(__x_));}
1888 _LIBCPP_INLINE_VISIBILITY
1889 void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
1891 friend _LIBCPP_INLINE_VISIBILITY
1892 bool operator==(const linear_congruential_engine& __x,
1893 const linear_congruential_engine& __y)
1894 {return __x.__x_ == __y.__x_;}
1895 friend _LIBCPP_INLINE_VISIBILITY
1896 bool operator!=(const linear_congruential_engine& __x,
1897 const linear_congruential_engine& __y)
1898 {return !(__x == __y);}
1902 _LIBCPP_INLINE_VISIBILITY
1903 void seed(true_type, true_type, result_type __s) {__x_ = __s == 0 ? 1 : __s;}
1904 _LIBCPP_INLINE_VISIBILITY
1905 void seed(true_type, false_type, result_type __s) {__x_ = __s;}
1906 _LIBCPP_INLINE_VISIBILITY
1907 void seed(false_type, true_type, result_type __s) {__x_ = __s % __m == 0 ?
1909 _LIBCPP_INLINE_VISIBILITY
1910 void seed(false_type, false_type, result_type __s) {__x_ = __s % __m;}
1912 template<class _Sseq>
1913 void __seed(_Sseq& __q, integral_constant<unsigned, 1>);
1914 template<class _Sseq>
1915 void __seed(_Sseq& __q, integral_constant<unsigned, 2>);
1917 template <class _CharT, class _Traits,
1918 class _Up, _Up _Ap, _Up _Cp, _Up _Np>
1920 basic_ostream<_CharT, _Traits>&
1921 operator<<(basic_ostream<_CharT, _Traits>& __os,
1922 const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&);
1924 template <class _CharT, class _Traits,
1925 class _Up, _Up _Ap, _Up _Cp, _Up _Np>
1927 basic_istream<_CharT, _Traits>&
1928 operator>>(basic_istream<_CharT, _Traits>& __is,
1929 linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x);
1932 template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
1933 template<class _Sseq>
1935 linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q,
1936 integral_constant<unsigned, 1>)
1938 const unsigned __k = 1;
1939 uint32_t __ar[__k+3];
1940 __q.generate(__ar, __ar + __k + 3);
1941 result_type __s = static_cast<result_type>(__ar[3] % __m);
1942 __x_ = __c == 0 && __s == 0 ? result_type(1) : __s;
1945 template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
1946 template<class _Sseq>
1948 linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q,
1949 integral_constant<unsigned, 2>)
1951 const unsigned __k = 2;
1952 uint32_t __ar[__k+3];
1953 __q.generate(__ar, __ar + __k + 3);
1954 result_type __s = static_cast<result_type>((__ar[3] +
1955 (uint64_t)__ar[4] << 32) % __m);
1956 __x_ = __c == 0 && __s == 0 ? result_type(1) : __s;
1959 template <class _CharT, class _Traits>
1962 typedef basic_ios<_CharT, _Traits> __stream_type;
1963 typedef typename __stream_type::fmtflags fmtflags;
1965 __stream_type& __stream_;
1966 fmtflags __fmtflags_;
1969 __save_flags(const __save_flags&);
1970 __save_flags& operator=(const __save_flags&);
1972 _LIBCPP_INLINE_VISIBILITY
1973 explicit __save_flags(__stream_type& __stream)
1974 : __stream_(__stream),
1975 __fmtflags_(__stream.flags()),
1976 __fill_(__stream.fill())
1978 _LIBCPP_INLINE_VISIBILITY
1981 __stream_.flags(__fmtflags_);
1982 __stream_.fill(__fill_);
1986 template <class _CharT, class _Traits,
1987 class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
1988 inline _LIBCPP_INLINE_VISIBILITY
1989 basic_ostream<_CharT, _Traits>&
1990 operator<<(basic_ostream<_CharT, _Traits>& __os,
1991 const linear_congruential_engine<_UIntType, __a, __c, __m>& __x)
1993 __save_flags<_CharT, _Traits> _(__os);
1994 __os.flags(ios_base::dec | ios_base::left);
1995 __os.fill(__os.widen(' '));
1996 return __os << __x.__x_;
1999 template <class _CharT, class _Traits,
2000 class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
2001 basic_istream<_CharT, _Traits>&
2002 operator>>(basic_istream<_CharT, _Traits>& __is,
2003 linear_congruential_engine<_UIntType, __a, __c, __m>& __x)
2005 __save_flags<_CharT, _Traits> _(__is);
2006 __is.flags(ios_base::dec | ios_base::skipws);
2014 typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647>
2016 typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647>
2018 typedef minstd_rand default_random_engine;
2019 // mersenne_twister_engine
2021 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2022 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2023 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2024 class mersenne_twister_engine;
2026 template <class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2027 _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp,
2028 _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp>
2030 operator==(const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2031 _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
2032 const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2033 _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
2035 template <class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2036 _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp,
2037 _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp>
2039 operator!=(const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2040 _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
2041 const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2042 _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
2044 template <class _CharT, class _Traits,
2045 class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2046 _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp,
2047 _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp>
2048 basic_ostream<_CharT, _Traits>&
2049 operator<<(basic_ostream<_CharT, _Traits>& __os,
2050 const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2051 _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
2053 template <class _CharT, class _Traits,
2054 class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2055 _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp,
2056 _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp>
2057 basic_istream<_CharT, _Traits>&
2058 operator>>(basic_istream<_CharT, _Traits>& __is,
2059 mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2060 _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
2062 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2063 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2064 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2065 class _LIBCPP_VISIBLE mersenne_twister_engine
2069 typedef _UIntType result_type;
2072 result_type __x_[__n];
2075 static_assert( 0 < __m, "mersenne_twister_engine invalid parameters");
2076 static_assert(__m <= __n, "mersenne_twister_engine invalid parameters");
2077 static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits;
2078 static_assert(__w <= _Dt, "mersenne_twister_engine invalid parameters");
2079 static_assert( 2 <= __w, "mersenne_twister_engine invalid parameters");
2080 static_assert(__r <= __w, "mersenne_twister_engine invalid parameters");
2081 static_assert(__u <= __w, "mersenne_twister_engine invalid parameters");
2082 static_assert(__s <= __w, "mersenne_twister_engine invalid parameters");
2083 static_assert(__t <= __w, "mersenne_twister_engine invalid parameters");
2084 static_assert(__l <= __w, "mersenne_twister_engine invalid parameters");
2086 static _LIBCPP_CONSTEXPR const result_type _Min = 0;
2087 static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) :
2088 (result_type(1) << __w) - result_type(1);
2089 static_assert(_Min < _Max, "mersenne_twister_engine invalid parameters");
2090 static_assert(__a <= _Max, "mersenne_twister_engine invalid parameters");
2091 static_assert(__b <= _Max, "mersenne_twister_engine invalid parameters");
2092 static_assert(__c <= _Max, "mersenne_twister_engine invalid parameters");
2093 static_assert(__d <= _Max, "mersenne_twister_engine invalid parameters");
2094 static_assert(__f <= _Max, "mersenne_twister_engine invalid parameters");
2096 // engine characteristics
2097 static _LIBCPP_CONSTEXPR const size_t word_size = __w;
2098 static _LIBCPP_CONSTEXPR const size_t state_size = __n;
2099 static _LIBCPP_CONSTEXPR const size_t shift_size = __m;
2100 static _LIBCPP_CONSTEXPR const size_t mask_bits = __r;
2101 static _LIBCPP_CONSTEXPR const result_type xor_mask = __a;
2102 static _LIBCPP_CONSTEXPR const size_t tempering_u = __u;
2103 static _LIBCPP_CONSTEXPR const result_type tempering_d = __d;
2104 static _LIBCPP_CONSTEXPR const size_t tempering_s = __s;
2105 static _LIBCPP_CONSTEXPR const result_type tempering_b = __b;
2106 static _LIBCPP_CONSTEXPR const size_t tempering_t = __t;
2107 static _LIBCPP_CONSTEXPR const result_type tempering_c = __c;
2108 static _LIBCPP_CONSTEXPR const size_t tempering_l = __l;
2109 static _LIBCPP_CONSTEXPR const result_type initialization_multiplier = __f;
2110 _LIBCPP_INLINE_VISIBILITY
2111 static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
2112 _LIBCPP_INLINE_VISIBILITY
2113 static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
2114 static _LIBCPP_CONSTEXPR const result_type default_seed = 5489u;
2116 // constructors and seeding functions
2117 _LIBCPP_INLINE_VISIBILITY
2118 explicit mersenne_twister_engine(result_type __sd = default_seed)
2120 template<class _Sseq>
2121 _LIBCPP_INLINE_VISIBILITY
2122 explicit mersenne_twister_engine(_Sseq& __q,
2123 typename enable_if<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value>::type* = 0)
2125 void seed(result_type __sd = default_seed);
2126 template<class _Sseq>
2127 _LIBCPP_INLINE_VISIBILITY
2130 __is_seed_sequence<_Sseq, mersenne_twister_engine>::value,
2134 {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());}
2136 // generating functions
2137 result_type operator()();
2138 _LIBCPP_INLINE_VISIBILITY
2139 void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
2141 template <class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2142 _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp,
2143 _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp>
2146 operator==(const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2147 _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
2148 const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2149 _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
2151 template <class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2152 _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp,
2153 _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp>
2156 operator!=(const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2157 _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
2158 const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2159 _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
2161 template <class _CharT, class _Traits,
2162 class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2163 _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp,
2164 _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp>
2166 basic_ostream<_CharT, _Traits>&
2167 operator<<(basic_ostream<_CharT, _Traits>& __os,
2168 const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2169 _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
2171 template <class _CharT, class _Traits,
2172 class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2173 _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp,
2174 _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp>
2176 basic_istream<_CharT, _Traits>&
2177 operator>>(basic_istream<_CharT, _Traits>& __is,
2178 mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2179 _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
2182 template<class _Sseq>
2183 void __seed(_Sseq& __q, integral_constant<unsigned, 1>);
2184 template<class _Sseq>
2185 void __seed(_Sseq& __q, integral_constant<unsigned, 2>);
2187 template <size_t __count>
2188 _LIBCPP_INLINE_VISIBILITY
2195 __lshift(result_type __x) {return (__x << __count) & _Max;}
2197 template <size_t __count>
2198 _LIBCPP_INLINE_VISIBILITY
2205 __lshift(result_type) {return result_type(0);}
2207 template <size_t __count>
2208 _LIBCPP_INLINE_VISIBILITY
2215 __rshift(result_type __x) {return __x >> __count;}
2217 template <size_t __count>
2218 _LIBCPP_INLINE_VISIBILITY
2225 __rshift(result_type) {return result_type(0);}
2228 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2229 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2230 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2232 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
2233 __t, __c, __l, __f>::seed(result_type __sd)
2235 __x_[0] = __sd & _Max;
2236 for (size_t __i = 1; __i < __n; ++__i)
2237 __x_[__i] = (__f * (__x_[__i-1] ^ __rshift<__w - 2>(__x_[__i-1])) + __i) & _Max;
2241 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2242 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2243 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2244 template<class _Sseq>
2246 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
2247 __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 1>)
2249 const unsigned __k = 1;
2250 uint32_t __ar[__n * __k];
2251 __q.generate(__ar, __ar + __n * __k);
2252 for (size_t __i = 0; __i < __n; ++__i)
2253 __x_[__i] = static_cast<result_type>(__ar[__i] & _Max);
2254 const result_type __mask = __r == _Dt ? result_type(~0) :
2255 (result_type(1) << __r) - result_type(1);
2257 if ((__x_[0] & ~__mask) == 0)
2259 for (size_t __i = 1; __i < __n; ++__i)
2266 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2267 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2268 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2269 template<class _Sseq>
2271 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
2272 __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 2>)
2274 const unsigned __k = 2;
2275 uint32_t __ar[__n * __k];
2276 __q.generate(__ar, __ar + __n * __k);
2277 for (size_t __i = 0; __i < __n; ++__i)
2278 __x_[__i] = static_cast<result_type>(
2279 (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max);
2280 const result_type __mask = __r == _Dt ? result_type(~0) :
2281 (result_type(1) << __r) - result_type(1);
2283 if ((__x_[0] & ~__mask) == 0)
2285 for (size_t __i = 1; __i < __n; ++__i)
2292 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
2293 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
2294 _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
2296 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
2297 __t, __c, __l, __f>::operator()()
2299 const size_t __j = (__i_ + 1) % __n;
2300 const result_type __mask = __r == _Dt ? result_type(~0) :
2301 (result_type(1) << __r) - result_type(1);
2302 const result_type _Yp = (__x_[__i_] & ~__mask) | (__x_[__j] & __mask);
2303 const size_t __k = (__i_ + __m) % __n;
2304 __x_[__i_] = __x_[__k] ^ __rshift<1>(_Yp) ^ (__a * (_Yp & 1));
2305 result_type __z = __x_[__i_] ^ (__rshift<__u>(__x_[__i_]) & __d);
2307 __z ^= __lshift<__s>(__z) & __b;
2308 __z ^= __lshift<__t>(__z) & __c;
2309 return __z ^ __rshift<__l>(__z);
2312 template <class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2313 _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp,
2314 _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp>
2316 operator==(const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2317 _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
2318 const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2319 _Bp, _Tp, _Cp, _Lp, _Fp>& __y)
2321 if (__x.__i_ == __y.__i_)
2322 return _VSTD::equal(__x.__x_, __x.__x_ + _Np, __y.__x_);
2323 if (__x.__i_ == 0 || __y.__i_ == 0)
2325 size_t __j = _VSTD::min(_Np - __x.__i_, _Np - __y.__i_);
2326 if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j,
2327 __y.__x_ + __y.__i_))
2330 return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Np, __y.__x_);
2331 return _VSTD::equal(__x.__x_, __x.__x_ + (_Np - __j), __y.__x_ + __j);
2333 if (__x.__i_ < __y.__i_)
2335 size_t __j = _Np - __y.__i_;
2336 if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j),
2337 __y.__x_ + __y.__i_))
2339 if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Np,
2342 return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_,
2343 __y.__x_ + (_Np - (__x.__i_ + __j)));
2345 size_t __j = _Np - __x.__i_;
2346 if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j),
2347 __x.__x_ + __x.__i_))
2349 if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Np,
2352 return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_,
2353 __x.__x_ + (_Np - (__y.__i_ + __j)));
2356 template <class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2357 _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp,
2358 _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp>
2359 inline _LIBCPP_INLINE_VISIBILITY
2361 operator!=(const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2362 _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
2363 const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2364 _Bp, _Tp, _Cp, _Lp, _Fp>& __y)
2366 return !(__x == __y);
2369 template <class _CharT, class _Traits,
2370 class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2371 _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp,
2372 _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp>
2373 basic_ostream<_CharT, _Traits>&
2374 operator<<(basic_ostream<_CharT, _Traits>& __os,
2375 const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2376 _Bp, _Tp, _Cp, _Lp, _Fp>& __x)
2378 __save_flags<_CharT, _Traits> _(__os);
2379 __os.flags(ios_base::dec | ios_base::left);
2380 _CharT __sp = __os.widen(' ');
2382 __os << __x.__x_[__x.__i_];
2383 for (size_t __j = __x.__i_ + 1; __j < _Np; ++__j)
2384 __os << __sp << __x.__x_[__j];
2385 for (size_t __j = 0; __j < __x.__i_; ++__j)
2386 __os << __sp << __x.__x_[__j];
2390 template <class _CharT, class _Traits,
2391 class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
2392 _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp,
2393 _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp>
2394 basic_istream<_CharT, _Traits>&
2395 operator>>(basic_istream<_CharT, _Traits>& __is,
2396 mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
2397 _Bp, _Tp, _Cp, _Lp, _Fp>& __x)
2399 __save_flags<_CharT, _Traits> _(__is);
2400 __is.flags(ios_base::dec | ios_base::skipws);
2402 for (size_t __i = 0; __i < _Np; ++__i)
2406 for (size_t __i = 0; __i < _Np; ++__i)
2407 __x.__x_[__i] = __t[__i];
2413 typedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31,
2414 0x9908b0df, 11, 0xffffffff,
2417 18, 1812433253> mt19937;
2418 typedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31,
2419 0xb5026f5aa96619e9ULL, 29, 0x5555555555555555ULL,
2420 17, 0x71d67fffeda60000ULL,
2421 37, 0xfff7eee000000000ULL,
2422 43, 6364136223846793005ULL> mt19937_64;
2424 // subtract_with_carry_engine
2426 template<class _UIntType, size_t __w, size_t __s, size_t __r>
2427 class subtract_with_carry_engine;
2429 template<class _UI, size_t _Wp, size_t _Sp, size_t _Rp>
2432 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x,
2433 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __y);
2435 template<class _UI, size_t _Wp, size_t _Sp, size_t _Rp>
2438 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x,
2439 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __y);
2441 template <class _CharT, class _Traits,
2442 class _UI, size_t _Wp, size_t _Sp, size_t _Rp>
2443 basic_ostream<_CharT, _Traits>&
2444 operator<<(basic_ostream<_CharT, _Traits>& __os,
2445 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x);
2447 template <class _CharT, class _Traits,
2448 class _UI, size_t _Wp, size_t _Sp, size_t _Rp>
2449 basic_istream<_CharT, _Traits>&
2450 operator>>(basic_istream<_CharT, _Traits>& __is,
2451 subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x);
2453 template<class _UIntType, size_t __w, size_t __s, size_t __r>
2454 class _LIBCPP_VISIBLE subtract_with_carry_engine
2458 typedef _UIntType result_type;
2461 result_type __x_[__r];
2465 static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits;
2466 static_assert( 0 < __w, "subtract_with_carry_engine invalid parameters");
2467 static_assert(__w <= _Dt, "subtract_with_carry_engine invalid parameters");
2468 static_assert( 0 < __s, "subtract_with_carry_engine invalid parameters");
2469 static_assert(__s < __r, "subtract_with_carry_engine invalid parameters");
2471 static _LIBCPP_CONSTEXPR const result_type _Min = 0;
2472 static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) :
2473 (result_type(1) << __w) - result_type(1);
2474 static_assert(_Min < _Max, "subtract_with_carry_engine invalid parameters");
2476 // engine characteristics
2477 static _LIBCPP_CONSTEXPR const size_t word_size = __w;
2478 static _LIBCPP_CONSTEXPR const size_t short_lag = __s;
2479 static _LIBCPP_CONSTEXPR const size_t long_lag = __r;
2480 _LIBCPP_INLINE_VISIBILITY
2481 static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
2482 _LIBCPP_INLINE_VISIBILITY
2483 static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
2484 static _LIBCPP_CONSTEXPR const result_type default_seed = 19780503u;
2486 // constructors and seeding functions
2487 _LIBCPP_INLINE_VISIBILITY
2488 explicit subtract_with_carry_engine(result_type __sd = default_seed)
2490 template<class _Sseq>
2491 _LIBCPP_INLINE_VISIBILITY
2492 explicit subtract_with_carry_engine(_Sseq& __q,
2493 typename enable_if<__is_seed_sequence<_Sseq, subtract_with_carry_engine>::value>::type* = 0)
2495 _LIBCPP_INLINE_VISIBILITY
2496 void seed(result_type __sd = default_seed)
2497 {seed(__sd, integral_constant<unsigned, 1 + (__w - 1) / 32>());}
2498 template<class _Sseq>
2499 _LIBCPP_INLINE_VISIBILITY
2502 __is_seed_sequence<_Sseq, subtract_with_carry_engine>::value,
2506 {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());}
2508 // generating functions
2509 result_type operator()();
2510 _LIBCPP_INLINE_VISIBILITY
2511 void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
2513 template<class _UI, size_t _Wp, size_t _Sp, size_t _Rp>
2517 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x,
2518 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __y);
2520 template<class _UI, size_t _Wp, size_t _Sp, size_t _Rp>
2524 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x,
2525 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __y);
2527 template <class _CharT, class _Traits,
2528 class _UI, size_t _Wp, size_t _Sp, size_t _Rp>
2530 basic_ostream<_CharT, _Traits>&
2531 operator<<(basic_ostream<_CharT, _Traits>& __os,
2532 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x);
2534 template <class _CharT, class _Traits,
2535 class _UI, size_t _Wp, size_t _Sp, size_t _Rp>
2537 basic_istream<_CharT, _Traits>&
2538 operator>>(basic_istream<_CharT, _Traits>& __is,
2539 subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x);
2543 void seed(result_type __sd, integral_constant<unsigned, 1>);
2544 void seed(result_type __sd, integral_constant<unsigned, 2>);
2545 template<class _Sseq>
2546 void __seed(_Sseq& __q, integral_constant<unsigned, 1>);
2547 template<class _Sseq>
2548 void __seed(_Sseq& __q, integral_constant<unsigned, 2>);
2551 template<class _UIntType, size_t __w, size_t __s, size_t __r>
2553 subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd,
2554 integral_constant<unsigned, 1>)
2556 linear_congruential_engine<result_type, 40014u, 0u, 2147483563u>
2557 __e(__sd == 0u ? default_seed : __sd);
2558 for (size_t __i = 0; __i < __r; ++__i)
2559 __x_[__i] = static_cast<result_type>(__e() & _Max);
2560 __c_ = __x_[__r-1] == 0;
2564 template<class _UIntType, size_t __w, size_t __s, size_t __r>
2566 subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd,
2567 integral_constant<unsigned, 2>)
2569 linear_congruential_engine<result_type, 40014u, 0u, 2147483563u>
2570 __e(__sd == 0u ? default_seed : __sd);
2571 for (size_t __i = 0; __i < __r; ++__i)
2573 result_type __e0 = __e();
2574 __x_[__i] = static_cast<result_type>(
2575 (__e0 + ((uint64_t)__e() << 32)) & _Max);
2577 __c_ = __x_[__r-1] == 0;
2581 template<class _UIntType, size_t __w, size_t __s, size_t __r>
2582 template<class _Sseq>
2584 subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q,
2585 integral_constant<unsigned, 1>)
2587 const unsigned __k = 1;
2588 uint32_t __ar[__r * __k];
2589 __q.generate(__ar, __ar + __r * __k);
2590 for (size_t __i = 0; __i < __r; ++__i)
2591 __x_[__i] = static_cast<result_type>(__ar[__i] & _Max);
2592 __c_ = __x_[__r-1] == 0;
2596 template<class _UIntType, size_t __w, size_t __s, size_t __r>
2597 template<class _Sseq>
2599 subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q,
2600 integral_constant<unsigned, 2>)
2602 const unsigned __k = 2;
2603 uint32_t __ar[__r * __k];
2604 __q.generate(__ar, __ar + __r * __k);
2605 for (size_t __i = 0; __i < __r; ++__i)
2606 __x_[__i] = static_cast<result_type>(
2607 (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max);
2608 __c_ = __x_[__r-1] == 0;
2612 template<class _UIntType, size_t __w, size_t __s, size_t __r>
2614 subtract_with_carry_engine<_UIntType, __w, __s, __r>::operator()()
2616 const result_type& __xs = __x_[(__i_ + (__r - __s)) % __r];
2617 result_type& __xr = __x_[__i_];
2618 result_type __new_c = __c_ == 0 ? __xs < __xr : __xs != 0 ? __xs <= __xr : 1;
2619 __xr = (__xs - __xr - __c_) & _Max;
2621 __i_ = (__i_ + 1) % __r;
2625 template<class _UI, size_t _Wp, size_t _Sp, size_t _Rp>
2628 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x,
2629 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __y)
2631 if (__x.__c_ != __y.__c_)
2633 if (__x.__i_ == __y.__i_)
2634 return _VSTD::equal(__x.__x_, __x.__x_ + _Rp, __y.__x_);
2635 if (__x.__i_ == 0 || __y.__i_ == 0)
2637 size_t __j = _VSTD::min(_Rp - __x.__i_, _Rp - __y.__i_);
2638 if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j,
2639 __y.__x_ + __y.__i_))
2642 return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Rp, __y.__x_);
2643 return _VSTD::equal(__x.__x_, __x.__x_ + (_Rp - __j), __y.__x_ + __j);
2645 if (__x.__i_ < __y.__i_)
2647 size_t __j = _Rp - __y.__i_;
2648 if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j),
2649 __y.__x_ + __y.__i_))
2651 if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Rp,
2654 return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_,
2655 __y.__x_ + (_Rp - (__x.__i_ + __j)));
2657 size_t __j = _Rp - __x.__i_;
2658 if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j),
2659 __x.__x_ + __x.__i_))
2661 if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Rp,
2664 return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_,
2665 __x.__x_ + (_Rp - (__y.__i_ + __j)));
2668 template<class _UI, size_t _Wp, size_t _Sp, size_t _Rp>
2669 inline _LIBCPP_INLINE_VISIBILITY
2672 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x,
2673 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __y)
2675 return !(__x == __y);
2678 template <class _CharT, class _Traits,
2679 class _UI, size_t _Wp, size_t _Sp, size_t _Rp>
2680 basic_ostream<_CharT, _Traits>&
2681 operator<<(basic_ostream<_CharT, _Traits>& __os,
2682 const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x)
2684 __save_flags<_CharT, _Traits> _(__os);
2685 __os.flags(ios_base::dec | ios_base::left);
2686 _CharT __sp = __os.widen(' ');
2688 __os << __x.__x_[__x.__i_];
2689 for (size_t __j = __x.__i_ + 1; __j < _Rp; ++__j)
2690 __os << __sp << __x.__x_[__j];
2691 for (size_t __j = 0; __j < __x.__i_; ++__j)
2692 __os << __sp << __x.__x_[__j];
2693 __os << __sp << __x.__c_;
2697 template <class _CharT, class _Traits,
2698 class _UI, size_t _Wp, size_t _Sp, size_t _Rp>
2699 basic_istream<_CharT, _Traits>&
2700 operator>>(basic_istream<_CharT, _Traits>& __is,
2701 subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x)
2703 __save_flags<_CharT, _Traits> _(__is);
2704 __is.flags(ios_base::dec | ios_base::skipws);
2706 for (size_t __i = 0; __i < _Rp+1; ++__i)
2710 for (size_t __i = 0; __i < _Rp; ++__i)
2711 __x.__x_[__i] = __t[__i];
2712 __x.__c_ = __t[_Rp];
2718 typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> ranlux24_base;
2719 typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> ranlux48_base;
2721 // discard_block_engine
2723 template<class _Engine, size_t __p, size_t __r>
2724 class _LIBCPP_VISIBLE discard_block_engine
2729 static_assert( 0 < __r, "discard_block_engine invalid parameters");
2730 static_assert(__r <= __p, "discard_block_engine invalid parameters");
2733 typedef typename _Engine::result_type result_type;
2735 // engine characteristics
2736 static _LIBCPP_CONSTEXPR const size_t block_size = __p;
2737 static _LIBCPP_CONSTEXPR const size_t used_block = __r;
2739 #ifdef _LIBCPP_HAS_NO_CONSTEXPR
2740 static const result_type _Min = _Engine::_Min;
2741 static const result_type _Max = _Engine::_Max;
2743 static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min();
2744 static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max();
2747 _LIBCPP_INLINE_VISIBILITY
2748 static _LIBCPP_CONSTEXPR result_type min() { return _Engine::min(); }
2749 _LIBCPP_INLINE_VISIBILITY
2750 static _LIBCPP_CONSTEXPR result_type max() { return _Engine::max(); }
2752 // constructors and seeding functions
2753 _LIBCPP_INLINE_VISIBILITY
2754 discard_block_engine() : __n_(0) {}
2755 _LIBCPP_INLINE_VISIBILITY
2756 explicit discard_block_engine(const _Engine& __e)
2757 : __e_(__e), __n_(0) {}
2758 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2759 _LIBCPP_INLINE_VISIBILITY
2760 explicit discard_block_engine(_Engine&& __e)
2761 : __e_(_VSTD::move(__e)), __n_(0) {}
2762 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2763 _LIBCPP_INLINE_VISIBILITY
2764 explicit discard_block_engine(result_type __sd) : __e_(__sd), __n_(0) {}
2765 template<class _Sseq>
2766 _LIBCPP_INLINE_VISIBILITY
2767 explicit discard_block_engine(_Sseq& __q,
2768 typename enable_if<__is_seed_sequence<_Sseq, discard_block_engine>::value &&
2769 !is_convertible<_Sseq, _Engine>::value>::type* = 0)
2770 : __e_(__q), __n_(0) {}
2771 _LIBCPP_INLINE_VISIBILITY
2772 void seed() {__e_.seed(); __n_ = 0;}
2773 _LIBCPP_INLINE_VISIBILITY
2774 void seed(result_type __sd) {__e_.seed(__sd); __n_ = 0;}
2775 template<class _Sseq>
2776 _LIBCPP_INLINE_VISIBILITY
2779 __is_seed_sequence<_Sseq, discard_block_engine>::value,
2782 seed(_Sseq& __q) {__e_.seed(__q); __n_ = 0;}
2784 // generating functions
2785 result_type operator()();
2786 _LIBCPP_INLINE_VISIBILITY
2787 void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
2789 // property functions
2790 _LIBCPP_INLINE_VISIBILITY
2791 const _Engine& base() const {return __e_;}
2793 template<class _Eng, size_t _Pp, size_t _Rp>
2797 const discard_block_engine<_Eng, _Pp, _Rp>& __x,
2798 const discard_block_engine<_Eng, _Pp, _Rp>& __y);
2800 template<class _Eng, size_t _Pp, size_t _Rp>
2804 const discard_block_engine<_Eng, _Pp, _Rp>& __x,
2805 const discard_block_engine<_Eng, _Pp, _Rp>& __y);
2807 template <class _CharT, class _Traits,
2808 class _Eng, size_t _Pp, size_t _Rp>
2810 basic_ostream<_CharT, _Traits>&
2811 operator<<(basic_ostream<_CharT, _Traits>& __os,
2812 const discard_block_engine<_Eng, _Pp, _Rp>& __x);
2814 template <class _CharT, class _Traits,
2815 class _Eng, size_t _Pp, size_t _Rp>
2817 basic_istream<_CharT, _Traits>&
2818 operator>>(basic_istream<_CharT, _Traits>& __is,
2819 discard_block_engine<_Eng, _Pp, _Rp>& __x);
2822 template<class _Engine, size_t __p, size_t __r>
2823 typename discard_block_engine<_Engine, __p, __r>::result_type
2824 discard_block_engine<_Engine, __p, __r>::operator()()
2828 __e_.discard(__p - __r);
2835 template<class _Eng, size_t _Pp, size_t _Rp>
2836 inline _LIBCPP_INLINE_VISIBILITY
2838 operator==(const discard_block_engine<_Eng, _Pp, _Rp>& __x,
2839 const discard_block_engine<_Eng, _Pp, _Rp>& __y)
2841 return __x.__n_ == __y.__n_ && __x.__e_ == __y.__e_;
2844 template<class _Eng, size_t _Pp, size_t _Rp>
2845 inline _LIBCPP_INLINE_VISIBILITY
2847 operator!=(const discard_block_engine<_Eng, _Pp, _Rp>& __x,
2848 const discard_block_engine<_Eng, _Pp, _Rp>& __y)
2850 return !(__x == __y);
2853 template <class _CharT, class _Traits,
2854 class _Eng, size_t _Pp, size_t _Rp>
2855 basic_ostream<_CharT, _Traits>&
2856 operator<<(basic_ostream<_CharT, _Traits>& __os,
2857 const discard_block_engine<_Eng, _Pp, _Rp>& __x)
2859 __save_flags<_CharT, _Traits> _(__os);
2860 __os.flags(ios_base::dec | ios_base::left);
2861 _CharT __sp = __os.widen(' ');
2863 return __os << __x.__e_ << __sp << __x.__n_;
2866 template <class _CharT, class _Traits,
2867 class _Eng, size_t _Pp, size_t _Rp>
2868 basic_istream<_CharT, _Traits>&
2869 operator>>(basic_istream<_CharT, _Traits>& __is,
2870 discard_block_engine<_Eng, _Pp, _Rp>& __x)
2872 __save_flags<_CharT, _Traits> _(__is);
2873 __is.flags(ios_base::dec | ios_base::skipws);
2885 typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24;
2886 typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48;
2888 // independent_bits_engine
2890 template<class _Engine, size_t __w, class _UIntType>
2891 class _LIBCPP_VISIBLE independent_bits_engine
2893 template <class _UI, _UI _R0, size_t _Wp, size_t _Mp>
2896 static _LIBCPP_CONSTEXPR const size_t _Dt = numeric_limits<_UI>::digits;
2897 static _LIBCPP_CONSTEXPR const size_t _Np = _Wp / _Mp + (_Wp % _Mp != 0);
2898 static _LIBCPP_CONSTEXPR const size_t _W0 = _Wp / _Np;
2899 static _LIBCPP_CONSTEXPR const _UI _Y0 = _W0 >= _Dt ? 0 : (_R0 >> _W0) << _W0;
2901 static _LIBCPP_CONSTEXPR const size_t value = _R0 - _Y0 > _Y0 / _Np ? _Np + 1 : _Np;
2905 typedef _UIntType result_type;
2910 static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits;
2911 static_assert( 0 < __w, "independent_bits_engine invalid parameters");
2912 static_assert(__w <= _Dt, "independent_bits_engine invalid parameters");
2914 typedef typename _Engine::result_type _Engine_result_type;
2915 typedef typename conditional
2917 sizeof(_Engine_result_type) <= sizeof(result_type),
2920 >::type _Working_result_type;
2921 #ifdef _LIBCPP_HAS_NO_CONSTEXPR
2922 static const _Working_result_type _Rp = _Engine::_Max - _Engine::_Min
2923 + _Working_result_type(1);
2925 static _LIBCPP_CONSTEXPR const _Working_result_type _Rp = _Engine::max() - _Engine::min()
2926 + _Working_result_type(1);
2928 static _LIBCPP_CONSTEXPR const size_t __m = __log2<_Working_result_type, _Rp>::value;
2929 static _LIBCPP_CONSTEXPR const size_t __n = __get_n<_Working_result_type, _Rp, __w, __m>::value;
2930 static _LIBCPP_CONSTEXPR const size_t __w0 = __w / __n;
2931 static _LIBCPP_CONSTEXPR const size_t __n0 = __n - __w % __n;
2932 static _LIBCPP_CONSTEXPR const size_t _WDt = numeric_limits<_Working_result_type>::digits;
2933 static _LIBCPP_CONSTEXPR const size_t _EDt = numeric_limits<_Engine_result_type>::digits;
2934 static _LIBCPP_CONSTEXPR const _Working_result_type __y0 = __w0 >= _WDt ? 0 :
2935 (_Rp >> __w0) << __w0;
2936 static _LIBCPP_CONSTEXPR const _Working_result_type __y1 = __w0 >= _WDt - 1 ? 0 :
2937 (_Rp >> (__w0+1)) << (__w0+1);
2938 static _LIBCPP_CONSTEXPR const _Engine_result_type __mask0 = __w0 > 0 ?
2939 _Engine_result_type(~0) >> (_EDt - __w0) :
2940 _Engine_result_type(0);
2941 static _LIBCPP_CONSTEXPR const _Engine_result_type __mask1 = __w0 < _EDt - 1 ?
2942 _Engine_result_type(~0) >> (_EDt - (__w0 + 1)) :
2943 _Engine_result_type(~0);
2945 static _LIBCPP_CONSTEXPR const result_type _Min = 0;
2946 static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) :
2947 (result_type(1) << __w) - result_type(1);
2948 static_assert(_Min < _Max, "independent_bits_engine invalid parameters");
2950 // engine characteristics
2951 _LIBCPP_INLINE_VISIBILITY
2952 static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
2953 _LIBCPP_INLINE_VISIBILITY
2954 static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
2956 // constructors and seeding functions
2957 _LIBCPP_INLINE_VISIBILITY
2958 independent_bits_engine() {}
2959 _LIBCPP_INLINE_VISIBILITY
2960 explicit independent_bits_engine(const _Engine& __e)
2962 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2963 _LIBCPP_INLINE_VISIBILITY
2964 explicit independent_bits_engine(_Engine&& __e)
2965 : __e_(_VSTD::move(__e)) {}
2966 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2967 _LIBCPP_INLINE_VISIBILITY
2968 explicit independent_bits_engine(result_type __sd) : __e_(__sd) {}
2969 template<class _Sseq>
2970 _LIBCPP_INLINE_VISIBILITY
2971 explicit independent_bits_engine(_Sseq& __q,
2972 typename enable_if<__is_seed_sequence<_Sseq, independent_bits_engine>::value &&
2973 !is_convertible<_Sseq, _Engine>::value>::type* = 0)
2975 _LIBCPP_INLINE_VISIBILITY
2976 void seed() {__e_.seed();}
2977 _LIBCPP_INLINE_VISIBILITY
2978 void seed(result_type __sd) {__e_.seed(__sd);}
2979 template<class _Sseq>
2980 _LIBCPP_INLINE_VISIBILITY
2983 __is_seed_sequence<_Sseq, independent_bits_engine>::value,
2986 seed(_Sseq& __q) {__e_.seed(__q);}
2988 // generating functions
2989 _LIBCPP_INLINE_VISIBILITY
2990 result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());}
2991 _LIBCPP_INLINE_VISIBILITY
2992 void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
2994 // property functions
2995 _LIBCPP_INLINE_VISIBILITY
2996 const _Engine& base() const {return __e_;}
2998 template<class _Eng, size_t _Wp, class _UI>
3002 const independent_bits_engine<_Eng, _Wp, _UI>& __x,
3003 const independent_bits_engine<_Eng, _Wp, _UI>& __y);
3005 template<class _Eng, size_t _Wp, class _UI>
3009 const independent_bits_engine<_Eng, _Wp, _UI>& __x,
3010 const independent_bits_engine<_Eng, _Wp, _UI>& __y);
3012 template <class _CharT, class _Traits,
3013 class _Eng, size_t _Wp, class _UI>
3015 basic_ostream<_CharT, _Traits>&
3016 operator<<(basic_ostream<_CharT, _Traits>& __os,
3017 const independent_bits_engine<_Eng, _Wp, _UI>& __x);
3019 template <class _CharT, class _Traits,
3020 class _Eng, size_t _Wp, class _UI>
3022 basic_istream<_CharT, _Traits>&
3023 operator>>(basic_istream<_CharT, _Traits>& __is,
3024 independent_bits_engine<_Eng, _Wp, _UI>& __x);
3027 result_type __eval(false_type);
3028 result_type __eval(true_type);
3030 template <size_t __count>
3031 _LIBCPP_INLINE_VISIBILITY
3038 __lshift(result_type __x) {return __x << __count;}
3040 template <size_t __count>
3041 _LIBCPP_INLINE_VISIBILITY
3048 __lshift(result_type) {return result_type(0);}
3051 template<class _Engine, size_t __w, class _UIntType>
3052 inline _LIBCPP_INLINE_VISIBILITY
3054 independent_bits_engine<_Engine, __w, _UIntType>::__eval(false_type)
3056 return static_cast<result_type>(__e_() & __mask0);
3059 template<class _Engine, size_t __w, class _UIntType>
3061 independent_bits_engine<_Engine, __w, _UIntType>::__eval(true_type)
3063 result_type _Sp = 0;
3064 for (size_t __k = 0; __k < __n0; ++__k)
3066 _Engine_result_type __u;
3069 __u = __e_() - _Engine::min();
3070 } while (__u >= __y0);
3071 _Sp = static_cast<result_type>(__lshift<__w0>(_Sp) + (__u & __mask0));
3073 for (size_t __k = __n0; __k < __n; ++__k)
3075 _Engine_result_type __u;
3078 __u = __e_() - _Engine::min();
3079 } while (__u >= __y1);
3080 _Sp = static_cast<result_type>(__lshift<__w0+1>(_Sp) + (__u & __mask1));
3085 template<class _Eng, size_t _Wp, class _UI>
3086 inline _LIBCPP_INLINE_VISIBILITY
3089 const independent_bits_engine<_Eng, _Wp, _UI>& __x,
3090 const independent_bits_engine<_Eng, _Wp, _UI>& __y)
3092 return __x.base() == __y.base();
3095 template<class _Eng, size_t _Wp, class _UI>
3096 inline _LIBCPP_INLINE_VISIBILITY
3099 const independent_bits_engine<_Eng, _Wp, _UI>& __x,
3100 const independent_bits_engine<_Eng, _Wp, _UI>& __y)
3102 return !(__x == __y);
3105 template <class _CharT, class _Traits,
3106 class _Eng, size_t _Wp, class _UI>
3107 basic_ostream<_CharT, _Traits>&
3108 operator<<(basic_ostream<_CharT, _Traits>& __os,
3109 const independent_bits_engine<_Eng, _Wp, _UI>& __x)
3111 return __os << __x.base();
3114 template <class _CharT, class _Traits,
3115 class _Eng, size_t _Wp, class _UI>
3116 basic_istream<_CharT, _Traits>&
3117 operator>>(basic_istream<_CharT, _Traits>& __is,
3118 independent_bits_engine<_Eng, _Wp, _UI>& __x)
3127 // shuffle_order_engine
3129 template <uint64_t _Xp, uint64_t _Yp>
3132 static _LIBCPP_CONSTEXPR const uint64_t value = __ugcd<_Yp, _Xp % _Yp>::value;
3135 template <uint64_t _Xp>
3136 struct __ugcd<_Xp, 0>
3138 static _LIBCPP_CONSTEXPR const uint64_t value = _Xp;
3141 template <uint64_t _Np, uint64_t _Dp>
3144 static_assert(_Dp != 0, "__uratio divide by 0");
3145 static _LIBCPP_CONSTEXPR const uint64_t __gcd = __ugcd<_Np, _Dp>::value;
3147 static _LIBCPP_CONSTEXPR const uint64_t num = _Np / __gcd;
3148 static _LIBCPP_CONSTEXPR const uint64_t den = _Dp / __gcd;
3150 typedef __uratio<num, den> type;
3153 template<class _Engine, size_t __k>
3154 class _LIBCPP_VISIBLE shuffle_order_engine
3156 static_assert(0 < __k, "shuffle_order_engine invalid parameters");
3159 typedef typename _Engine::result_type result_type;
3163 result_type _V_[__k];
3167 // engine characteristics
3168 static _LIBCPP_CONSTEXPR const size_t table_size = __k;
3170 #ifdef _LIBCPP_HAS_NO_CONSTEXPR
3171 static const result_type _Min = _Engine::_Min;
3172 static const result_type _Max = _Engine::_Max;
3174 static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min();
3175 static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max();
3177 static_assert(_Min < _Max, "shuffle_order_engine invalid parameters");
3178 _LIBCPP_INLINE_VISIBILITY
3179 static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
3180 _LIBCPP_INLINE_VISIBILITY
3181 static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
3183 static _LIBCPP_CONSTEXPR const unsigned long long _Rp = _Max - _Min + 1ull;
3185 // constructors and seeding functions
3186 _LIBCPP_INLINE_VISIBILITY
3187 shuffle_order_engine() {__init();}
3188 _LIBCPP_INLINE_VISIBILITY
3189 explicit shuffle_order_engine(const _Engine& __e)
3190 : __e_(__e) {__init();}
3191 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3192 _LIBCPP_INLINE_VISIBILITY
3193 explicit shuffle_order_engine(_Engine&& __e)
3194 : __e_(_VSTD::move(__e)) {__init();}
3195 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3196 _LIBCPP_INLINE_VISIBILITY
3197 explicit shuffle_order_engine(result_type __sd) : __e_(__sd) {__init();}
3198 template<class _Sseq>
3199 _LIBCPP_INLINE_VISIBILITY
3200 explicit shuffle_order_engine(_Sseq& __q,
3201 typename enable_if<__is_seed_sequence<_Sseq, shuffle_order_engine>::value &&
3202 !is_convertible<_Sseq, _Engine>::value>::type* = 0)
3203 : __e_(__q) {__init();}
3204 _LIBCPP_INLINE_VISIBILITY
3205 void seed() {__e_.seed(); __init();}
3206 _LIBCPP_INLINE_VISIBILITY
3207 void seed(result_type __sd) {__e_.seed(__sd); __init();}
3208 template<class _Sseq>
3209 _LIBCPP_INLINE_VISIBILITY
3212 __is_seed_sequence<_Sseq, shuffle_order_engine>::value,
3215 seed(_Sseq& __q) {__e_.seed(__q); __init();}
3217 // generating functions
3218 _LIBCPP_INLINE_VISIBILITY
3219 result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());}
3220 _LIBCPP_INLINE_VISIBILITY
3221 void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
3223 // property functions
3224 _LIBCPP_INLINE_VISIBILITY
3225 const _Engine& base() const {return __e_;}
3228 template<class _Eng, size_t _Kp>
3232 const shuffle_order_engine<_Eng, _Kp>& __x,
3233 const shuffle_order_engine<_Eng, _Kp>& __y);
3235 template<class _Eng, size_t _Kp>
3239 const shuffle_order_engine<_Eng, _Kp>& __x,
3240 const shuffle_order_engine<_Eng, _Kp>& __y);
3242 template <class _CharT, class _Traits,
3243 class _Eng, size_t _Kp>
3245 basic_ostream<_CharT, _Traits>&
3246 operator<<(basic_ostream<_CharT, _Traits>& __os,
3247 const shuffle_order_engine<_Eng, _Kp>& __x);
3249 template <class _CharT, class _Traits,
3250 class _Eng, size_t _Kp>
3252 basic_istream<_CharT, _Traits>&
3253 operator>>(basic_istream<_CharT, _Traits>& __is,
3254 shuffle_order_engine<_Eng, _Kp>& __x);
3256 _LIBCPP_INLINE_VISIBILITY
3259 for (size_t __i = 0; __i < __k; ++__i)
3264 _LIBCPP_INLINE_VISIBILITY
3265 result_type __eval(false_type) {return __eval2(integral_constant<bool, __k & 1>());}
3266 _LIBCPP_INLINE_VISIBILITY
3267 result_type __eval(true_type) {return __eval(__uratio<__k, _Rp>());}
3269 _LIBCPP_INLINE_VISIBILITY
3270 result_type __eval2(false_type) {return __eval(__uratio<__k/2, 0x8000000000000000ull>());}
3271 _LIBCPP_INLINE_VISIBILITY
3272 result_type __eval2(true_type) {return __evalf<__k, 0>();}
3274 template <uint64_t _Np, uint64_t _Dp>
3275 _LIBCPP_INLINE_VISIBILITY
3278 (__uratio<_Np, _Dp>::num > 0xFFFFFFFFFFFFFFFFull / (_Max - _Min)),
3281 __eval(__uratio<_Np, _Dp>)
3282 {return __evalf<__uratio<_Np, _Dp>::num, __uratio<_Np, _Dp>::den>();}
3284 template <uint64_t _Np, uint64_t _Dp>
3285 _LIBCPP_INLINE_VISIBILITY
3288 __uratio<_Np, _Dp>::num <= 0xFFFFFFFFFFFFFFFFull / (_Max - _Min),
3291 __eval(__uratio<_Np, _Dp>)
3293 const size_t __j = static_cast<size_t>(__uratio<_Np, _Dp>::num * (_Y_ - _Min)
3294 / __uratio<_Np, _Dp>::den);
3300 template <uint64_t __n, uint64_t __d>
3301 _LIBCPP_INLINE_VISIBILITY
3302 result_type __evalf()
3304 const double _Fp = __d == 0 ?
3305 __n / (2. * 0x8000000000000000ull) :
3307 const size_t __j = static_cast<size_t>(_Fp * (_Y_ - _Min));
3314 template<class _Eng, size_t _Kp>
3317 const shuffle_order_engine<_Eng, _Kp>& __x,
3318 const shuffle_order_engine<_Eng, _Kp>& __y)
3320 return __x._Y_ == __y._Y_ && _VSTD::equal(__x._V_, __x._V_ + _Kp, __y._V_) &&
3321 __x.__e_ == __y.__e_;
3324 template<class _Eng, size_t _Kp>
3325 inline _LIBCPP_INLINE_VISIBILITY
3328 const shuffle_order_engine<_Eng, _Kp>& __x,
3329 const shuffle_order_engine<_Eng, _Kp>& __y)
3331 return !(__x == __y);
3334 template <class _CharT, class _Traits,
3335 class _Eng, size_t _Kp>
3336 basic_ostream<_CharT, _Traits>&
3337 operator<<(basic_ostream<_CharT, _Traits>& __os,
3338 const shuffle_order_engine<_Eng, _Kp>& __x)
3340 __save_flags<_CharT, _Traits> _(__os);
3341 __os.flags(ios_base::dec | ios_base::left);
3342 _CharT __sp = __os.widen(' ');
3344 __os << __x.__e_ << __sp << __x._V_[0];
3345 for (size_t __i = 1; __i < _Kp; ++__i)
3346 __os << __sp << __x._V_[__i];
3347 return __os << __sp << __x._Y_;
3350 template <class _CharT, class _Traits,
3351 class _Eng, size_t _Kp>
3352 basic_istream<_CharT, _Traits>&
3353 operator>>(basic_istream<_CharT, _Traits>& __is,
3354 shuffle_order_engine<_Eng, _Kp>& __x)
3356 typedef typename shuffle_order_engine<_Eng, _Kp>::result_type result_type;
3357 __save_flags<_CharT, _Traits> _(__is);
3358 __is.flags(ios_base::dec | ios_base::skipws);
3360 result_type _Vp[_Kp+1];
3362 for (size_t __i = 0; __i < _Kp+1; ++__i)
3367 for (size_t __i = 0; __i < _Kp; ++__i)
3368 __x._V_[__i] = _Vp[__i];
3374 typedef shuffle_order_engine<minstd_rand0, 256> knuth_b;
3378 class _LIBCPP_VISIBLE random_device
3383 typedef unsigned result_type;
3385 // generator characteristics
3386 static _LIBCPP_CONSTEXPR const result_type _Min = 0;
3387 static _LIBCPP_CONSTEXPR const result_type _Max = 0xFFFFFFFFu;
3389 _LIBCPP_INLINE_VISIBILITY
3390 static _LIBCPP_CONSTEXPR result_type min() { return _Min;}
3391 _LIBCPP_INLINE_VISIBILITY
3392 static _LIBCPP_CONSTEXPR result_type max() { return _Max;}
3395 explicit random_device(const string& __token = "/dev/urandom");
3398 // generating functions
3399 result_type operator()();
3401 // property functions
3402 double entropy() const;
3405 // no copy functions
3406 random_device(const random_device&); // = delete;
3407 random_device& operator=(const random_device&); // = delete;
3412 class _LIBCPP_VISIBLE seed_seq
3416 typedef uint32_t result_type;
3419 vector<result_type> __v_;
3421 template<class _InputIterator>
3422 void init(_InputIterator __first, _InputIterator __last);
3425 _LIBCPP_INLINE_VISIBILITY
3427 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
3429 _LIBCPP_INLINE_VISIBILITY
3430 seed_seq(initializer_list<_Tp> __il) {init(__il.begin(), __il.end());}
3431 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
3433 template<class _InputIterator>
3434 _LIBCPP_INLINE_VISIBILITY
3435 seed_seq(_InputIterator __first, _InputIterator __last)
3436 {init(__first, __last);}
3438 // generating functions
3439 template<class _RandomAccessIterator>
3440 void generate(_RandomAccessIterator __first, _RandomAccessIterator __last);
3442 // property functions
3443 _LIBCPP_INLINE_VISIBILITY
3444 size_t size() const {return __v_.size();}
3445 template<class _OutputIterator>
3446 _LIBCPP_INLINE_VISIBILITY
3447 void param(_OutputIterator __dest) const
3448 {_VSTD::copy(__v_.begin(), __v_.end(), __dest);}
3451 // no copy functions
3452 seed_seq(const seed_seq&); // = delete;
3453 void operator=(const seed_seq&); // = delete;
3455 _LIBCPP_INLINE_VISIBILITY
3456 static result_type _Tp(result_type __x) {return __x ^ (__x >> 27);}
3459 template<class _InputIterator>
3461 seed_seq::init(_InputIterator __first, _InputIterator __last)
3463 for (_InputIterator __s = __first; __s != __last; ++__s)
3464 __v_.push_back(*__s & 0xFFFFFFFF);
3467 template<class _RandomAccessIterator>
3469 seed_seq::generate(_RandomAccessIterator __first, _RandomAccessIterator __last)
3471 if (__first != __last)
3473 _VSTD::fill(__first, __last, 0x8b8b8b8b);
3474 const size_t __n = static_cast<size_t>(__last - __first);
3475 const size_t __s = __v_.size();
3476 const size_t __t = (__n >= 623) ? 11
3481 const size_t __p = (__n - __t) / 2;
3482 const size_t __q = __p + __t;
3483 const size_t __m = _VSTD::max(__s + 1, __n);
3486 result_type __r = 1664525 * _Tp(__first[0] ^ __first[__p]
3487 ^ __first[__n - 1]);
3488 __first[__p] += __r;
3490 __first[__q] += __r;
3493 for (size_t __k = 1; __k <= __s; ++__k)
3495 const size_t __kmodn = __k % __n;
3496 const size_t __kpmodn = (__k + __p) % __n;
3497 result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn]
3498 ^ __first[(__k - 1) % __n]);
3499 __first[__kpmodn] += __r;
3500 __r += __kmodn + __v_[__k-1];
3501 __first[(__k + __q) % __n] += __r;
3502 __first[__kmodn] = __r;
3504 for (size_t __k = __s + 1; __k < __m; ++__k)
3506 const size_t __kmodn = __k % __n;
3507 const size_t __kpmodn = (__k + __p) % __n;
3508 result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn]
3509 ^ __first[(__k - 1) % __n]);
3510 __first[__kpmodn] += __r;
3512 __first[(__k + __q) % __n] += __r;
3513 __first[__kmodn] = __r;
3515 for (size_t __k = __m; __k < __m + __n; ++__k)
3517 const size_t __kmodn = __k % __n;
3518 const size_t __kpmodn = (__k + __p) % __n;
3519 result_type __r = 1566083941 * _Tp(__first[__kmodn] +
3521 __first[(__k - 1) % __n]);
3522 __first[__kpmodn] ^= __r;
3524 __first[(__k + __q) % __n] ^= __r;
3525 __first[__kmodn] = __r;
3530 // generate_canonical
3532 template<class _RealType, size_t __bits, class _URNG>
3534 generate_canonical(_URNG& __g)
3536 const size_t _Dt = numeric_limits<_RealType>::digits;
3537 const size_t __b = _Dt < __bits ? _Dt : __bits;
3538 #ifdef _LIBCPP_HAS_NO_CONSTEXPR
3539 const size_t __logR = __log2<uint64_t, _URNG::_Max - _URNG::_Min + uint64_t(1)>::value;
3541 const size_t __logR = __log2<uint64_t, _URNG::max() - _URNG::min() + uint64_t(1)>::value;
3543 const size_t __k = __b / __logR + (__b % __logR != 0) + (__b == 0);
3544 const _RealType _Rp = _URNG::max() - _URNG::min() + _RealType(1);
3545 _RealType __base = _Rp;
3546 _RealType _Sp = __g() - _URNG::min();
3547 for (size_t __i = 1; __i < __k; ++__i, __base *= _Rp)
3548 _Sp += (__g() - _URNG::min()) * __base;
3549 return _Sp / __base;
3552 // uniform_int_distribution
3556 template <class _CharT, class _Traits, class _IT>
3557 basic_ostream<_CharT, _Traits>&
3558 operator<<(basic_ostream<_CharT, _Traits>& __os,
3559 const uniform_int_distribution<_IT>& __x)
3561 __save_flags<_CharT, _Traits> _(__os);
3562 __os.flags(ios_base::dec | ios_base::left);
3563 _CharT __sp = __os.widen(' ');
3565 return __os << __x.a() << __sp << __x.b();
3568 template <class _CharT, class _Traits, class _IT>
3569 basic_istream<_CharT, _Traits>&
3570 operator>>(basic_istream<_CharT, _Traits>& __is,
3571 uniform_int_distribution<_IT>& __x)
3573 typedef uniform_int_distribution<_IT> _Eng;
3574 typedef typename _Eng::result_type result_type;
3575 typedef typename _Eng::param_type param_type;
3576 __save_flags<_CharT, _Traits> _(__is);
3577 __is.flags(ios_base::dec | ios_base::skipws);
3582 __x.param(param_type(__a, __b));
3586 // uniform_real_distribution
3588 template<class _RealType = double>
3589 class _LIBCPP_VISIBLE uniform_real_distribution
3593 typedef _RealType result_type;
3595 class _LIBCPP_VISIBLE param_type
3600 typedef uniform_real_distribution distribution_type;
3602 _LIBCPP_INLINE_VISIBILITY
3603 explicit param_type(result_type __a = 0,
3604 result_type __b = 1)
3605 : __a_(__a), __b_(__b) {}
3607 _LIBCPP_INLINE_VISIBILITY
3608 result_type a() const {return __a_;}
3609 _LIBCPP_INLINE_VISIBILITY
3610 result_type b() const {return __b_;}
3612 friend _LIBCPP_INLINE_VISIBILITY
3613 bool operator==(const param_type& __x, const param_type& __y)
3614 {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
3615 friend _LIBCPP_INLINE_VISIBILITY
3616 bool operator!=(const param_type& __x, const param_type& __y)
3617 {return !(__x == __y);}
3624 // constructors and reset functions
3625 _LIBCPP_INLINE_VISIBILITY
3626 explicit uniform_real_distribution(result_type __a = 0, result_type __b = 1)
3627 : __p_(param_type(__a, __b)) {}
3628 _LIBCPP_INLINE_VISIBILITY
3629 explicit uniform_real_distribution(const param_type& __p) : __p_(__p) {}
3630 _LIBCPP_INLINE_VISIBILITY
3633 // generating functions
3634 template<class _URNG>
3635 _LIBCPP_INLINE_VISIBILITY
3636 result_type operator()(_URNG& __g)
3637 {return (*this)(__g, __p_);}
3638 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
3640 // property functions
3641 _LIBCPP_INLINE_VISIBILITY
3642 result_type a() const {return __p_.a();}
3643 _LIBCPP_INLINE_VISIBILITY
3644 result_type b() const {return __p_.b();}
3646 _LIBCPP_INLINE_VISIBILITY
3647 param_type param() const {return __p_;}
3648 _LIBCPP_INLINE_VISIBILITY
3649 void param(const param_type& __p) {__p_ = __p;}
3651 _LIBCPP_INLINE_VISIBILITY
3652 result_type min() const {return a();}
3653 _LIBCPP_INLINE_VISIBILITY
3654 result_type max() const {return b();}
3656 friend _LIBCPP_INLINE_VISIBILITY
3657 bool operator==(const uniform_real_distribution& __x,
3658 const uniform_real_distribution& __y)
3659 {return __x.__p_ == __y.__p_;}
3660 friend _LIBCPP_INLINE_VISIBILITY
3661 bool operator!=(const uniform_real_distribution& __x,
3662 const uniform_real_distribution& __y)
3663 {return !(__x == __y);}
3666 template<class _RealType>
3667 template<class _URNG>
3668 inline _LIBCPP_INLINE_VISIBILITY
3669 typename uniform_real_distribution<_RealType>::result_type
3670 uniform_real_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
3672 return (__p.b() - __p.a())
3673 * _VSTD::generate_canonical<_RealType, numeric_limits<_RealType>::digits>(__g)
3677 template <class _CharT, class _Traits, class _RT>
3678 basic_ostream<_CharT, _Traits>&
3679 operator<<(basic_ostream<_CharT, _Traits>& __os,
3680 const uniform_real_distribution<_RT>& __x)
3682 __save_flags<_CharT, _Traits> _(__os);
3683 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
3684 ios_base::scientific);
3685 _CharT __sp = __os.widen(' ');
3687 return __os << __x.a() << __sp << __x.b();
3690 template <class _CharT, class _Traits, class _RT>
3691 basic_istream<_CharT, _Traits>&
3692 operator>>(basic_istream<_CharT, _Traits>& __is,
3693 uniform_real_distribution<_RT>& __x)
3695 typedef uniform_real_distribution<_RT> _Eng;
3696 typedef typename _Eng::result_type result_type;
3697 typedef typename _Eng::param_type param_type;
3698 __save_flags<_CharT, _Traits> _(__is);
3699 __is.flags(ios_base::dec | ios_base::skipws);
3704 __x.param(param_type(__a, __b));
3708 // bernoulli_distribution
3710 class _LIBCPP_VISIBLE bernoulli_distribution
3714 typedef bool result_type;
3716 class _LIBCPP_VISIBLE param_type
3720 typedef bernoulli_distribution distribution_type;
3722 _LIBCPP_INLINE_VISIBILITY
3723 explicit param_type(double __p = 0.5) : __p_(__p) {}
3725 _LIBCPP_INLINE_VISIBILITY
3726 double p() const {return __p_;}
3728 friend _LIBCPP_INLINE_VISIBILITY
3729 bool operator==(const param_type& __x, const param_type& __y)
3730 {return __x.__p_ == __y.__p_;}
3731 friend _LIBCPP_INLINE_VISIBILITY
3732 bool operator!=(const param_type& __x, const param_type& __y)
3733 {return !(__x == __y);}
3740 // constructors and reset functions
3741 _LIBCPP_INLINE_VISIBILITY
3742 explicit bernoulli_distribution(double __p = 0.5)
3743 : __p_(param_type(__p)) {}
3744 _LIBCPP_INLINE_VISIBILITY
3745 explicit bernoulli_distribution(const param_type& __p) : __p_(__p) {}
3746 _LIBCPP_INLINE_VISIBILITY
3749 // generating functions
3750 template<class _URNG>
3751 _LIBCPP_INLINE_VISIBILITY
3752 result_type operator()(_URNG& __g)
3753 {return (*this)(__g, __p_);}
3754 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
3756 // property functions
3757 _LIBCPP_INLINE_VISIBILITY
3758 double p() const {return __p_.p();}
3760 _LIBCPP_INLINE_VISIBILITY
3761 param_type param() const {return __p_;}
3762 _LIBCPP_INLINE_VISIBILITY
3763 void param(const param_type& __p) {__p_ = __p;}
3765 _LIBCPP_INLINE_VISIBILITY
3766 result_type min() const {return false;}
3767 _LIBCPP_INLINE_VISIBILITY
3768 result_type max() const {return true;}
3770 friend _LIBCPP_INLINE_VISIBILITY
3771 bool operator==(const bernoulli_distribution& __x,
3772 const bernoulli_distribution& __y)
3773 {return __x.__p_ == __y.__p_;}
3774 friend _LIBCPP_INLINE_VISIBILITY
3775 bool operator!=(const bernoulli_distribution& __x,
3776 const bernoulli_distribution& __y)
3777 {return !(__x == __y);}
3780 template<class _URNG>
3781 inline _LIBCPP_INLINE_VISIBILITY
3782 bernoulli_distribution::result_type
3783 bernoulli_distribution::operator()(_URNG& __g, const param_type& __p)
3785 uniform_real_distribution<double> __gen;
3786 return __gen(__g) < __p.p();
3789 template <class _CharT, class _Traits>
3790 basic_ostream<_CharT, _Traits>&
3791 operator<<(basic_ostream<_CharT, _Traits>& __os, const bernoulli_distribution& __x)
3793 __save_flags<_CharT, _Traits> _(__os);
3794 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
3795 ios_base::scientific);
3796 _CharT __sp = __os.widen(' ');
3798 return __os << __x.p();
3801 template <class _CharT, class _Traits>
3802 basic_istream<_CharT, _Traits>&
3803 operator>>(basic_istream<_CharT, _Traits>& __is, bernoulli_distribution& __x)
3805 typedef bernoulli_distribution _Eng;
3806 typedef typename _Eng::param_type param_type;
3807 __save_flags<_CharT, _Traits> _(__is);
3808 __is.flags(ios_base::dec | ios_base::skipws);
3812 __x.param(param_type(__p));
3816 // binomial_distribution
3818 template<class _IntType = int>
3819 class _LIBCPP_VISIBLE binomial_distribution
3823 typedef _IntType result_type;
3825 class _LIBCPP_VISIBLE param_type
3830 double __odds_ratio_;
3833 typedef binomial_distribution distribution_type;
3835 explicit param_type(result_type __t = 1, double __p = 0.5);
3837 _LIBCPP_INLINE_VISIBILITY
3838 result_type t() const {return __t_;}
3839 _LIBCPP_INLINE_VISIBILITY
3840 double p() const {return __p_;}
3842 friend _LIBCPP_INLINE_VISIBILITY
3843 bool operator==(const param_type& __x, const param_type& __y)
3844 {return __x.__t_ == __y.__t_ && __x.__p_ == __y.__p_;}
3845 friend _LIBCPP_INLINE_VISIBILITY
3846 bool operator!=(const param_type& __x, const param_type& __y)
3847 {return !(__x == __y);}
3849 friend class binomial_distribution;
3856 // constructors and reset functions
3857 _LIBCPP_INLINE_VISIBILITY
3858 explicit binomial_distribution(result_type __t = 1, double __p = 0.5)
3859 : __p_(param_type(__t, __p)) {}
3860 _LIBCPP_INLINE_VISIBILITY
3861 explicit binomial_distribution(const param_type& __p) : __p_(__p) {}
3862 _LIBCPP_INLINE_VISIBILITY
3865 // generating functions
3866 template<class _URNG>
3867 _LIBCPP_INLINE_VISIBILITY
3868 result_type operator()(_URNG& __g)
3869 {return (*this)(__g, __p_);}
3870 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
3872 // property functions
3873 _LIBCPP_INLINE_VISIBILITY
3874 result_type t() const {return __p_.t();}
3875 _LIBCPP_INLINE_VISIBILITY
3876 double p() const {return __p_.p();}
3878 _LIBCPP_INLINE_VISIBILITY
3879 param_type param() const {return __p_;}
3880 _LIBCPP_INLINE_VISIBILITY
3881 void param(const param_type& __p) {__p_ = __p;}
3883 _LIBCPP_INLINE_VISIBILITY
3884 result_type min() const {return 0;}
3885 _LIBCPP_INLINE_VISIBILITY
3886 result_type max() const {return t();}
3888 friend _LIBCPP_INLINE_VISIBILITY
3889 bool operator==(const binomial_distribution& __x,
3890 const binomial_distribution& __y)
3891 {return __x.__p_ == __y.__p_;}
3892 friend _LIBCPP_INLINE_VISIBILITY
3893 bool operator!=(const binomial_distribution& __x,
3894 const binomial_distribution& __y)
3895 {return !(__x == __y);}
3898 template<class _IntType>
3899 binomial_distribution<_IntType>::param_type::param_type(result_type __t, double __p)
3900 : __t_(__t), __p_(__p)
3902 if (0 < __p_ && __p_ < 1)
3904 __r0_ = static_cast<result_type>((__t_ + 1) * __p_);
3905 __pr_ = _VSTD::exp(_VSTD::lgamma(__t_ + 1.) - _VSTD::lgamma(__r0_ + 1.) -
3906 _VSTD::lgamma(__t_ - __r0_ + 1.) + __r0_ * _VSTD::log(__p_) +
3907 (__t_ - __r0_) * _VSTD::log(1 - __p_));
3908 __odds_ratio_ = __p_ / (1 - __p_);
3912 template<class _IntType>
3913 template<class _URNG>
3915 binomial_distribution<_IntType>::operator()(_URNG& __g, const param_type& __pr)
3917 if (__pr.__t_ == 0 || __pr.__p_ == 0)
3921 uniform_real_distribution<double> __gen;
3922 double __u = __gen(__g) - __pr.__pr_;
3925 double __pu = __pr.__pr_;
3927 result_type __ru = __pr.__r0_;
3928 result_type __rd = __ru;
3933 __pd *= __rd / (__pr.__odds_ratio_ * (__pr.__t_ - __rd + 1));
3940 if (__ru <= __pr.__t_)
3942 __pu *= (__pr.__t_ - __ru + 1) * __pr.__odds_ratio_ / __ru;
3950 template <class _CharT, class _Traits, class _IntType>
3951 basic_ostream<_CharT, _Traits>&
3952 operator<<(basic_ostream<_CharT, _Traits>& __os,
3953 const binomial_distribution<_IntType>& __x)
3955 __save_flags<_CharT, _Traits> _(__os);
3956 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
3957 ios_base::scientific);
3958 _CharT __sp = __os.widen(' ');
3960 return __os << __x.t() << __sp << __x.p();
3963 template <class _CharT, class _Traits, class _IntType>
3964 basic_istream<_CharT, _Traits>&
3965 operator>>(basic_istream<_CharT, _Traits>& __is,
3966 binomial_distribution<_IntType>& __x)
3968 typedef binomial_distribution<_IntType> _Eng;
3969 typedef typename _Eng::result_type result_type;
3970 typedef typename _Eng::param_type param_type;
3971 __save_flags<_CharT, _Traits> _(__is);
3972 __is.flags(ios_base::dec | ios_base::skipws);
3977 __x.param(param_type(__t, __p));
3981 // exponential_distribution
3983 template<class _RealType = double>
3984 class _LIBCPP_VISIBLE exponential_distribution
3988 typedef _RealType result_type;
3990 class _LIBCPP_VISIBLE param_type
3992 result_type __lambda_;
3994 typedef exponential_distribution distribution_type;
3996 _LIBCPP_INLINE_VISIBILITY
3997 explicit param_type(result_type __lambda = 1) : __lambda_(__lambda) {}
3999 _LIBCPP_INLINE_VISIBILITY
4000 result_type lambda() const {return __lambda_;}
4002 friend _LIBCPP_INLINE_VISIBILITY
4003 bool operator==(const param_type& __x, const param_type& __y)
4004 {return __x.__lambda_ == __y.__lambda_;}
4005 friend _LIBCPP_INLINE_VISIBILITY
4006 bool operator!=(const param_type& __x, const param_type& __y)
4007 {return !(__x == __y);}
4014 // constructors and reset functions
4015 _LIBCPP_INLINE_VISIBILITY
4016 explicit exponential_distribution(result_type __lambda = 1)
4017 : __p_(param_type(__lambda)) {}
4018 _LIBCPP_INLINE_VISIBILITY
4019 explicit exponential_distribution(const param_type& __p) : __p_(__p) {}
4020 _LIBCPP_INLINE_VISIBILITY
4023 // generating functions
4024 template<class _URNG>
4025 _LIBCPP_INLINE_VISIBILITY
4026 result_type operator()(_URNG& __g)
4027 {return (*this)(__g, __p_);}
4028 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
4030 // property functions
4031 _LIBCPP_INLINE_VISIBILITY
4032 result_type lambda() const {return __p_.lambda();}
4034 _LIBCPP_INLINE_VISIBILITY
4035 param_type param() const {return __p_;}
4036 _LIBCPP_INLINE_VISIBILITY
4037 void param(const param_type& __p) {__p_ = __p;}
4039 _LIBCPP_INLINE_VISIBILITY
4040 result_type min() const {return 0;}
4041 _LIBCPP_INLINE_VISIBILITY
4042 result_type max() const {return numeric_limits<result_type>::infinity();}
4044 friend _LIBCPP_INLINE_VISIBILITY
4045 bool operator==(const exponential_distribution& __x,
4046 const exponential_distribution& __y)
4047 {return __x.__p_ == __y.__p_;}
4048 friend _LIBCPP_INLINE_VISIBILITY
4049 bool operator!=(const exponential_distribution& __x,
4050 const exponential_distribution& __y)
4051 {return !(__x == __y);}
4054 template <class _RealType>
4055 template<class _URNG>
4057 exponential_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
4062 _VSTD::generate_canonical<result_type,
4063 numeric_limits<result_type>::digits>(__g)
4068 template <class _CharT, class _Traits, class _RealType>
4069 basic_ostream<_CharT, _Traits>&
4070 operator<<(basic_ostream<_CharT, _Traits>& __os,
4071 const exponential_distribution<_RealType>& __x)
4073 __save_flags<_CharT, _Traits> _(__os);
4074 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
4075 ios_base::scientific);
4076 return __os << __x.lambda();
4079 template <class _CharT, class _Traits, class _RealType>
4080 basic_istream<_CharT, _Traits>&
4081 operator>>(basic_istream<_CharT, _Traits>& __is,
4082 exponential_distribution<_RealType>& __x)
4084 typedef exponential_distribution<_RealType> _Eng;
4085 typedef typename _Eng::result_type result_type;
4086 typedef typename _Eng::param_type param_type;
4087 __save_flags<_CharT, _Traits> _(__is);
4088 __is.flags(ios_base::dec | ios_base::skipws);
4089 result_type __lambda;
4092 __x.param(param_type(__lambda));
4096 // normal_distribution
4098 template<class _RealType = double>
4099 class _LIBCPP_VISIBLE normal_distribution
4103 typedef _RealType result_type;
4105 class _LIBCPP_VISIBLE param_type
4107 result_type __mean_;
4108 result_type __stddev_;
4110 typedef normal_distribution distribution_type;
4112 _LIBCPP_INLINE_VISIBILITY
4113 explicit param_type(result_type __mean = 0, result_type __stddev = 1)
4114 : __mean_(__mean), __stddev_(__stddev) {}
4116 _LIBCPP_INLINE_VISIBILITY
4117 result_type mean() const {return __mean_;}
4118 _LIBCPP_INLINE_VISIBILITY
4119 result_type stddev() const {return __stddev_;}
4121 friend _LIBCPP_INLINE_VISIBILITY
4122 bool operator==(const param_type& __x, const param_type& __y)
4123 {return __x.__mean_ == __y.__mean_ && __x.__stddev_ == __y.__stddev_;}
4124 friend _LIBCPP_INLINE_VISIBILITY
4125 bool operator!=(const param_type& __x, const param_type& __y)
4126 {return !(__x == __y);}
4135 // constructors and reset functions
4136 _LIBCPP_INLINE_VISIBILITY
4137 explicit normal_distribution(result_type __mean = 0, result_type __stddev = 1)
4138 : __p_(param_type(__mean, __stddev)), _V_hot_(false) {}
4139 _LIBCPP_INLINE_VISIBILITY
4140 explicit normal_distribution(const param_type& __p)
4141 : __p_(__p), _V_hot_(false) {}
4142 _LIBCPP_INLINE_VISIBILITY
4143 void reset() {_V_hot_ = false;}
4145 // generating functions
4146 template<class _URNG>
4147 _LIBCPP_INLINE_VISIBILITY
4148 result_type operator()(_URNG& __g)
4149 {return (*this)(__g, __p_);}
4150 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
4152 // property functions
4153 _LIBCPP_INLINE_VISIBILITY
4154 result_type mean() const {return __p_.mean();}
4155 _LIBCPP_INLINE_VISIBILITY
4156 result_type stddev() const {return __p_.stddev();}
4158 _LIBCPP_INLINE_VISIBILITY
4159 param_type param() const {return __p_;}
4160 _LIBCPP_INLINE_VISIBILITY
4161 void param(const param_type& __p) {__p_ = __p;}
4163 _LIBCPP_INLINE_VISIBILITY
4164 result_type min() const {return -numeric_limits<result_type>::infinity();}
4165 _LIBCPP_INLINE_VISIBILITY
4166 result_type max() const {return numeric_limits<result_type>::infinity();}
4168 friend _LIBCPP_INLINE_VISIBILITY
4169 bool operator==(const normal_distribution& __x,
4170 const normal_distribution& __y)
4171 {return __x.__p_ == __y.__p_ && __x._V_hot_ == __y._V_hot_ &&
4172 (!__x._V_hot_ || __x._V_ == __y._V_);}
4173 friend _LIBCPP_INLINE_VISIBILITY
4174 bool operator!=(const normal_distribution& __x,
4175 const normal_distribution& __y)
4176 {return !(__x == __y);}
4178 template <class _CharT, class _Traits, class _RT>
4180 basic_ostream<_CharT, _Traits>&
4181 operator<<(basic_ostream<_CharT, _Traits>& __os,
4182 const normal_distribution<_RT>& __x);
4184 template <class _CharT, class _Traits, class _RT>
4186 basic_istream<_CharT, _Traits>&
4187 operator>>(basic_istream<_CharT, _Traits>& __is,
4188 normal_distribution<_RT>& __x);
4191 template <class _RealType>
4192 template<class _URNG>
4194 normal_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
4204 uniform_real_distribution<result_type> _Uni(-1, 1);
4212 __s = __u * __u + __v * __v;
4213 } while (__s > 1 || __s == 0);
4214 result_type _Fp = _VSTD::sqrt(-2 * _VSTD::log(__s) / __s);
4219 return _Up * __p.stddev() + __p.mean();
4222 template <class _CharT, class _Traits, class _RT>
4223 basic_ostream<_CharT, _Traits>&
4224 operator<<(basic_ostream<_CharT, _Traits>& __os,
4225 const normal_distribution<_RT>& __x)
4227 __save_flags<_CharT, _Traits> _(__os);
4228 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
4229 ios_base::scientific);
4230 _CharT __sp = __os.widen(' ');
4232 __os << __x.mean() << __sp << __x.stddev() << __sp << __x._V_hot_;
4234 __os << __sp << __x._V_;
4238 template <class _CharT, class _Traits, class _RT>
4239 basic_istream<_CharT, _Traits>&
4240 operator>>(basic_istream<_CharT, _Traits>& __is,
4241 normal_distribution<_RT>& __x)
4243 typedef normal_distribution<_RT> _Eng;
4244 typedef typename _Eng::result_type result_type;
4245 typedef typename _Eng::param_type param_type;
4246 __save_flags<_CharT, _Traits> _(__is);
4247 __is.flags(ios_base::dec | ios_base::skipws);
4249 result_type __stddev;
4250 result_type _Vp = 0;
4251 bool _V_hot = false;
4252 __is >> __mean >> __stddev >> _V_hot;
4257 __x.param(param_type(__mean, __stddev));
4258 __x._V_hot_ = _V_hot;
4264 // lognormal_distribution
4266 template<class _RealType = double>
4267 class _LIBCPP_VISIBLE lognormal_distribution
4271 typedef _RealType result_type;
4273 class _LIBCPP_VISIBLE param_type
4275 normal_distribution<result_type> __nd_;
4277 typedef lognormal_distribution distribution_type;
4279 _LIBCPP_INLINE_VISIBILITY
4280 explicit param_type(result_type __m = 0, result_type __s = 1)
4281 : __nd_(__m, __s) {}
4283 _LIBCPP_INLINE_VISIBILITY
4284 result_type m() const {return __nd_.mean();}
4285 _LIBCPP_INLINE_VISIBILITY
4286 result_type s() const {return __nd_.stddev();}
4288 friend _LIBCPP_INLINE_VISIBILITY
4289 bool operator==(const param_type& __x, const param_type& __y)
4290 {return __x.__nd_ == __y.__nd_;}
4291 friend _LIBCPP_INLINE_VISIBILITY
4292 bool operator!=(const param_type& __x, const param_type& __y)
4293 {return !(__x == __y);}
4294 friend class lognormal_distribution;
4296 template <class _CharT, class _Traits, class _RT>
4298 basic_ostream<_CharT, _Traits>&
4299 operator<<(basic_ostream<_CharT, _Traits>& __os,
4300 const lognormal_distribution<_RT>& __x);
4302 template <class _CharT, class _Traits, class _RT>
4304 basic_istream<_CharT, _Traits>&
4305 operator>>(basic_istream<_CharT, _Traits>& __is,
4306 lognormal_distribution<_RT>& __x);
4313 // constructor and reset functions
4314 _LIBCPP_INLINE_VISIBILITY
4315 explicit lognormal_distribution(result_type __m = 0, result_type __s = 1)
4316 : __p_(param_type(__m, __s)) {}
4317 _LIBCPP_INLINE_VISIBILITY
4318 explicit lognormal_distribution(const param_type& __p)
4320 _LIBCPP_INLINE_VISIBILITY
4321 void reset() {__p_.__nd_.reset();}
4323 // generating functions
4324 template<class _URNG>
4325 _LIBCPP_INLINE_VISIBILITY
4326 result_type operator()(_URNG& __g)
4327 {return (*this)(__g, __p_);}
4328 template<class _URNG>
4329 _LIBCPP_INLINE_VISIBILITY
4330 result_type operator()(_URNG& __g, const param_type& __p)
4331 {return _VSTD::exp(const_cast<normal_distribution<result_type>&>(__p.__nd_)(__g));}
4333 // property functions
4334 _LIBCPP_INLINE_VISIBILITY
4335 result_type m() const {return __p_.m();}
4336 _LIBCPP_INLINE_VISIBILITY
4337 result_type s() const {return __p_.s();}
4339 _LIBCPP_INLINE_VISIBILITY
4340 param_type param() const {return __p_;}
4341 _LIBCPP_INLINE_VISIBILITY
4342 void param(const param_type& __p) {__p_ = __p;}
4344 _LIBCPP_INLINE_VISIBILITY
4345 result_type min() const {return 0;}
4346 _LIBCPP_INLINE_VISIBILITY
4347 result_type max() const {return numeric_limits<result_type>::infinity();}
4349 friend _LIBCPP_INLINE_VISIBILITY
4350 bool operator==(const lognormal_distribution& __x,
4351 const lognormal_distribution& __y)
4352 {return __x.__p_ == __y.__p_;}
4353 friend _LIBCPP_INLINE_VISIBILITY
4354 bool operator!=(const lognormal_distribution& __x,
4355 const lognormal_distribution& __y)
4356 {return !(__x == __y);}
4358 template <class _CharT, class _Traits, class _RT>
4360 basic_ostream<_CharT, _Traits>&
4361 operator<<(basic_ostream<_CharT, _Traits>& __os,
4362 const lognormal_distribution<_RT>& __x);
4364 template <class _CharT, class _Traits, class _RT>
4366 basic_istream<_CharT, _Traits>&
4367 operator>>(basic_istream<_CharT, _Traits>& __is,
4368 lognormal_distribution<_RT>& __x);
4371 template <class _CharT, class _Traits, class _RT>
4372 inline _LIBCPP_INLINE_VISIBILITY
4373 basic_ostream<_CharT, _Traits>&
4374 operator<<(basic_ostream<_CharT, _Traits>& __os,
4375 const lognormal_distribution<_RT>& __x)
4377 return __os << __x.__p_.__nd_;
4380 template <class _CharT, class _Traits, class _RT>
4381 inline _LIBCPP_INLINE_VISIBILITY
4382 basic_istream<_CharT, _Traits>&
4383 operator>>(basic_istream<_CharT, _Traits>& __is,
4384 lognormal_distribution<_RT>& __x)
4386 return __is >> __x.__p_.__nd_;
4389 // poisson_distribution
4391 template<class _IntType = int>
4392 class _LIBCPP_VISIBLE poisson_distribution
4396 typedef _IntType result_type;
4398 class _LIBCPP_VISIBLE param_type
4412 typedef poisson_distribution distribution_type;
4414 explicit param_type(double __mean = 1.0);
4416 _LIBCPP_INLINE_VISIBILITY
4417 double mean() const {return __mean_;}
4419 friend _LIBCPP_INLINE_VISIBILITY
4420 bool operator==(const param_type& __x, const param_type& __y)
4421 {return __x.__mean_ == __y.__mean_;}
4422 friend _LIBCPP_INLINE_VISIBILITY
4423 bool operator!=(const param_type& __x, const param_type& __y)
4424 {return !(__x == __y);}
4426 friend class poisson_distribution;
4433 // constructors and reset functions
4434 _LIBCPP_INLINE_VISIBILITY
4435 explicit poisson_distribution(double __mean = 1.0) : __p_(__mean) {}
4436 _LIBCPP_INLINE_VISIBILITY
4437 explicit poisson_distribution(const param_type& __p) : __p_(__p) {}
4438 _LIBCPP_INLINE_VISIBILITY
4441 // generating functions
4442 template<class _URNG>
4443 _LIBCPP_INLINE_VISIBILITY
4444 result_type operator()(_URNG& __g)
4445 {return (*this)(__g, __p_);}
4446 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
4448 // property functions
4449 _LIBCPP_INLINE_VISIBILITY
4450 double mean() const {return __p_.mean();}
4452 _LIBCPP_INLINE_VISIBILITY
4453 param_type param() const {return __p_;}
4454 _LIBCPP_INLINE_VISIBILITY
4455 void param(const param_type& __p) {__p_ = __p;}
4457 _LIBCPP_INLINE_VISIBILITY
4458 result_type min() const {return 0;}
4459 _LIBCPP_INLINE_VISIBILITY
4460 result_type max() const {return numeric_limits<result_type>::max();}
4462 friend _LIBCPP_INLINE_VISIBILITY
4463 bool operator==(const poisson_distribution& __x,
4464 const poisson_distribution& __y)
4465 {return __x.__p_ == __y.__p_;}
4466 friend _LIBCPP_INLINE_VISIBILITY
4467 bool operator!=(const poisson_distribution& __x,
4468 const poisson_distribution& __y)
4469 {return !(__x == __y);}
4472 template<class _IntType>
4473 poisson_distribution<_IntType>::param_type::param_type(double __mean)
4480 __l_ = _VSTD::exp(-__mean_);
4490 __s_ = _VSTD::sqrt(__mean_);
4491 __d_ = 6 * __mean_ * __mean_;
4492 __l_ = static_cast<result_type>(__mean_ - 1.1484);
4493 __omega_ = .3989423 / __s_;
4494 double __b1_ = .4166667E-1 / __mean_;
4495 double __b2_ = .3 * __b1_ * __b1_;
4496 __c3_ = .1428571 * __b1_ * __b2_;
4497 __c2_ = __b2_ - 15. * __c3_;
4498 __c1_ = __b1_ - 6. * __b2_ + 45. * __c3_;
4499 __c0_ = 1. - __b1_ + 3. * __b2_ - 15. * __c3_;
4500 __c_ = .1069 / __mean_;
4504 template <class _IntType>
4505 template<class _URNG>
4507 poisson_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr)
4510 uniform_real_distribution<double> __urd;
4511 if (__pr.__mean_ < 10)
4514 for (double __p = __urd(__urng); __p > __pr.__l_; ++__x)
4515 __p *= __urd(__urng);
4520 double __g = __pr.__mean_ + __pr.__s_ * normal_distribution<double>()(__urng);
4524 __x = static_cast<result_type>(__g);
4525 if (__x >= __pr.__l_)
4527 __difmuk = __pr.__mean_ - __x;
4528 __u = __urd(__urng);
4529 if (__pr.__d_ * __u >= __difmuk * __difmuk * __difmuk)
4532 exponential_distribution<double> __edist;
4533 for (bool __using_exp_dist = false; true; __using_exp_dist = true)
4536 if (__using_exp_dist || __g < 0)
4541 __e = __edist(__urng);
4542 __u = __urd(__urng);
4544 __t = 1.8 + (__u < 0 ? -__e : __e);
4545 } while (__t <= -.6744);
4546 __x = __pr.__mean_ + __pr.__s_ * __t;
4547 __difmuk = __pr.__mean_ - __x;
4548 __using_exp_dist = true;
4554 const result_type __fac[] = {1, 1, 2, 6, 24, 120, 720, 5040,
4556 __px = -__pr.__mean_;
4557 __py = _VSTD::pow(__pr.__mean_, (double)__x) / __fac[__x];
4561 double __del = .8333333E-1 / __x;
4562 __del -= 4.8 * __del * __del * __del;
4563 double __v = __difmuk / __x;
4564 if (_VSTD::abs(__v) > 0.25)
4565 __px = __x * _VSTD::log(1 + __v) - __difmuk - __del;
4567 __px = __x * __v * __v * (((((((.1250060 * __v + -.1384794) *
4568 __v + .1421878) * __v + -.1661269) * __v + .2000118) *
4569 __v + -.2500068) * __v + .3333333) * __v + -.5) - __del;
4570 __py = .3989423 / _VSTD::sqrt(__x);
4572 double __r = (0.5 - __difmuk) / __pr.__s_;
4573 double __r2 = __r * __r;
4574 double __fx = -0.5 * __r2;
4575 double __fy = __pr.__omega_ * (((__pr.__c3_ * __r2 + __pr.__c2_) *
4576 __r2 + __pr.__c1_) * __r2 + __pr.__c0_);
4577 if (__using_exp_dist)
4579 if (__pr.__c_ * _VSTD::abs(__u) <= __py * _VSTD::exp(__px + __e) -
4580 __fy * _VSTD::exp(__fx + __e))
4585 if (__fy - __u * __fy <= __py * _VSTD::exp(__px - __fx))
4593 template <class _CharT, class _Traits, class _IntType>
4594 basic_ostream<_CharT, _Traits>&
4595 operator<<(basic_ostream<_CharT, _Traits>& __os,
4596 const poisson_distribution<_IntType>& __x)
4598 __save_flags<_CharT, _Traits> _(__os);
4599 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
4600 ios_base::scientific);
4601 return __os << __x.mean();
4604 template <class _CharT, class _Traits, class _IntType>
4605 basic_istream<_CharT, _Traits>&
4606 operator>>(basic_istream<_CharT, _Traits>& __is,
4607 poisson_distribution<_IntType>& __x)
4609 typedef poisson_distribution<_IntType> _Eng;
4610 typedef typename _Eng::param_type param_type;
4611 __save_flags<_CharT, _Traits> _(__is);
4612 __is.flags(ios_base::dec | ios_base::skipws);
4616 __x.param(param_type(__mean));
4620 // weibull_distribution
4622 template<class _RealType = double>
4623 class _LIBCPP_VISIBLE weibull_distribution
4627 typedef _RealType result_type;
4629 class _LIBCPP_VISIBLE param_type
4634 typedef weibull_distribution distribution_type;
4636 _LIBCPP_INLINE_VISIBILITY
4637 explicit param_type(result_type __a = 1, result_type __b = 1)
4638 : __a_(__a), __b_(__b) {}
4640 _LIBCPP_INLINE_VISIBILITY
4641 result_type a() const {return __a_;}
4642 _LIBCPP_INLINE_VISIBILITY
4643 result_type b() const {return __b_;}
4645 friend _LIBCPP_INLINE_VISIBILITY
4646 bool operator==(const param_type& __x, const param_type& __y)
4647 {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
4648 friend _LIBCPP_INLINE_VISIBILITY
4649 bool operator!=(const param_type& __x, const param_type& __y)
4650 {return !(__x == __y);}
4657 // constructor and reset functions
4658 _LIBCPP_INLINE_VISIBILITY
4659 explicit weibull_distribution(result_type __a = 1, result_type __b = 1)
4660 : __p_(param_type(__a, __b)) {}
4661 _LIBCPP_INLINE_VISIBILITY
4662 explicit weibull_distribution(const param_type& __p)
4664 _LIBCPP_INLINE_VISIBILITY
4667 // generating functions
4668 template<class _URNG>
4669 _LIBCPP_INLINE_VISIBILITY
4670 result_type operator()(_URNG& __g)
4671 {return (*this)(__g, __p_);}
4672 template<class _URNG>
4673 _LIBCPP_INLINE_VISIBILITY
4674 result_type operator()(_URNG& __g, const param_type& __p)
4676 _VSTD::pow(exponential_distribution<result_type>()(__g), 1/__p.a());}
4678 // property functions
4679 _LIBCPP_INLINE_VISIBILITY
4680 result_type a() const {return __p_.a();}
4681 _LIBCPP_INLINE_VISIBILITY
4682 result_type b() const {return __p_.b();}
4684 _LIBCPP_INLINE_VISIBILITY
4685 param_type param() const {return __p_;}
4686 _LIBCPP_INLINE_VISIBILITY
4687 void param(const param_type& __p) {__p_ = __p;}
4689 _LIBCPP_INLINE_VISIBILITY
4690 result_type min() const {return 0;}
4691 _LIBCPP_INLINE_VISIBILITY
4692 result_type max() const {return numeric_limits<result_type>::infinity();}
4694 friend _LIBCPP_INLINE_VISIBILITY
4695 bool operator==(const weibull_distribution& __x,
4696 const weibull_distribution& __y)
4697 {return __x.__p_ == __y.__p_;}
4698 friend _LIBCPP_INLINE_VISIBILITY
4699 bool operator!=(const weibull_distribution& __x,
4700 const weibull_distribution& __y)
4701 {return !(__x == __y);}
4704 template <class _CharT, class _Traits, class _RT>
4705 basic_ostream<_CharT, _Traits>&
4706 operator<<(basic_ostream<_CharT, _Traits>& __os,
4707 const weibull_distribution<_RT>& __x)
4709 __save_flags<_CharT, _Traits> _(__os);
4710 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
4711 ios_base::scientific);
4712 _CharT __sp = __os.widen(' ');
4714 __os << __x.a() << __sp << __x.b();
4718 template <class _CharT, class _Traits, class _RT>
4719 basic_istream<_CharT, _Traits>&
4720 operator>>(basic_istream<_CharT, _Traits>& __is,
4721 weibull_distribution<_RT>& __x)
4723 typedef weibull_distribution<_RT> _Eng;
4724 typedef typename _Eng::result_type result_type;
4725 typedef typename _Eng::param_type param_type;
4726 __save_flags<_CharT, _Traits> _(__is);
4727 __is.flags(ios_base::dec | ios_base::skipws);
4732 __x.param(param_type(__a, __b));
4736 template<class _RealType = double>
4737 class _LIBCPP_VISIBLE extreme_value_distribution
4741 typedef _RealType result_type;
4743 class _LIBCPP_VISIBLE param_type
4748 typedef extreme_value_distribution distribution_type;
4750 _LIBCPP_INLINE_VISIBILITY
4751 explicit param_type(result_type __a = 0, result_type __b = 1)
4752 : __a_(__a), __b_(__b) {}
4754 _LIBCPP_INLINE_VISIBILITY
4755 result_type a() const {return __a_;}
4756 _LIBCPP_INLINE_VISIBILITY
4757 result_type b() const {return __b_;}
4759 friend _LIBCPP_INLINE_VISIBILITY
4760 bool operator==(const param_type& __x, const param_type& __y)
4761 {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
4762 friend _LIBCPP_INLINE_VISIBILITY
4763 bool operator!=(const param_type& __x, const param_type& __y)
4764 {return !(__x == __y);}
4771 // constructor and reset functions
4772 _LIBCPP_INLINE_VISIBILITY
4773 explicit extreme_value_distribution(result_type __a = 0, result_type __b = 1)
4774 : __p_(param_type(__a, __b)) {}
4775 _LIBCPP_INLINE_VISIBILITY
4776 explicit extreme_value_distribution(const param_type& __p)
4778 _LIBCPP_INLINE_VISIBILITY
4781 // generating functions
4782 template<class _URNG>
4783 _LIBCPP_INLINE_VISIBILITY
4784 result_type operator()(_URNG& __g)
4785 {return (*this)(__g, __p_);}
4786 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
4788 // property functions
4789 _LIBCPP_INLINE_VISIBILITY
4790 result_type a() const {return __p_.a();}
4791 _LIBCPP_INLINE_VISIBILITY
4792 result_type b() const {return __p_.b();}
4794 _LIBCPP_INLINE_VISIBILITY
4795 param_type param() const {return __p_;}
4796 _LIBCPP_INLINE_VISIBILITY
4797 void param(const param_type& __p) {__p_ = __p;}
4799 _LIBCPP_INLINE_VISIBILITY
4800 result_type min() const {return -numeric_limits<result_type>::infinity();}
4801 _LIBCPP_INLINE_VISIBILITY
4802 result_type max() const {return numeric_limits<result_type>::infinity();}
4804 friend _LIBCPP_INLINE_VISIBILITY
4805 bool operator==(const extreme_value_distribution& __x,
4806 const extreme_value_distribution& __y)
4807 {return __x.__p_ == __y.__p_;}
4808 friend _LIBCPP_INLINE_VISIBILITY
4809 bool operator!=(const extreme_value_distribution& __x,
4810 const extreme_value_distribution& __y)
4811 {return !(__x == __y);}
4814 template<class _RealType>
4815 template<class _URNG>
4817 extreme_value_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
4819 return __p.a() - __p.b() *
4820 _VSTD::log(-_VSTD::log(1-uniform_real_distribution<result_type>()(__g)));
4823 template <class _CharT, class _Traits, class _RT>
4824 basic_ostream<_CharT, _Traits>&
4825 operator<<(basic_ostream<_CharT, _Traits>& __os,
4826 const extreme_value_distribution<_RT>& __x)
4828 __save_flags<_CharT, _Traits> _(__os);
4829 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
4830 ios_base::scientific);
4831 _CharT __sp = __os.widen(' ');
4833 __os << __x.a() << __sp << __x.b();
4837 template <class _CharT, class _Traits, class _RT>
4838 basic_istream<_CharT, _Traits>&
4839 operator>>(basic_istream<_CharT, _Traits>& __is,
4840 extreme_value_distribution<_RT>& __x)
4842 typedef extreme_value_distribution<_RT> _Eng;
4843 typedef typename _Eng::result_type result_type;
4844 typedef typename _Eng::param_type param_type;
4845 __save_flags<_CharT, _Traits> _(__is);
4846 __is.flags(ios_base::dec | ios_base::skipws);
4851 __x.param(param_type(__a, __b));
4855 // gamma_distribution
4857 template<class _RealType = double>
4858 class _LIBCPP_VISIBLE gamma_distribution
4862 typedef _RealType result_type;
4864 class _LIBCPP_VISIBLE param_type
4866 result_type __alpha_;
4867 result_type __beta_;
4869 typedef gamma_distribution distribution_type;
4871 _LIBCPP_INLINE_VISIBILITY
4872 explicit param_type(result_type __alpha = 1, result_type __beta = 1)
4873 : __alpha_(__alpha), __beta_(__beta) {}
4875 _LIBCPP_INLINE_VISIBILITY
4876 result_type alpha() const {return __alpha_;}
4877 _LIBCPP_INLINE_VISIBILITY
4878 result_type beta() const {return __beta_;}
4880 friend _LIBCPP_INLINE_VISIBILITY
4881 bool operator==(const param_type& __x, const param_type& __y)
4882 {return __x.__alpha_ == __y.__alpha_ && __x.__beta_ == __y.__beta_;}
4883 friend _LIBCPP_INLINE_VISIBILITY
4884 bool operator!=(const param_type& __x, const param_type& __y)
4885 {return !(__x == __y);}
4892 // constructors and reset functions
4893 _LIBCPP_INLINE_VISIBILITY
4894 explicit gamma_distribution(result_type __alpha = 1, result_type __beta = 1)
4895 : __p_(param_type(__alpha, __beta)) {}
4896 _LIBCPP_INLINE_VISIBILITY
4897 explicit gamma_distribution(const param_type& __p)
4899 _LIBCPP_INLINE_VISIBILITY
4902 // generating functions
4903 template<class _URNG>
4904 _LIBCPP_INLINE_VISIBILITY
4905 result_type operator()(_URNG& __g)
4906 {return (*this)(__g, __p_);}
4907 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
4909 // property functions
4910 _LIBCPP_INLINE_VISIBILITY
4911 result_type alpha() const {return __p_.alpha();}
4912 _LIBCPP_INLINE_VISIBILITY
4913 result_type beta() const {return __p_.beta();}
4915 _LIBCPP_INLINE_VISIBILITY
4916 param_type param() const {return __p_;}
4917 _LIBCPP_INLINE_VISIBILITY
4918 void param(const param_type& __p) {__p_ = __p;}
4920 _LIBCPP_INLINE_VISIBILITY
4921 result_type min() const {return 0;}
4922 _LIBCPP_INLINE_VISIBILITY
4923 result_type max() const {return numeric_limits<result_type>::infinity();}
4925 friend _LIBCPP_INLINE_VISIBILITY
4926 bool operator==(const gamma_distribution& __x,
4927 const gamma_distribution& __y)
4928 {return __x.__p_ == __y.__p_;}
4929 friend _LIBCPP_INLINE_VISIBILITY
4930 bool operator!=(const gamma_distribution& __x,
4931 const gamma_distribution& __y)
4932 {return !(__x == __y);}
4935 template <class _RealType>
4936 template<class _URNG>
4938 gamma_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
4940 result_type __a = __p.alpha();
4941 uniform_real_distribution<result_type> __gen(0, 1);
4942 exponential_distribution<result_type> __egen;
4948 const result_type __b = __a - 1;
4949 const result_type __c = 3 * __a - result_type(0.75);
4952 const result_type __u = __gen(__g);
4953 const result_type __v = __gen(__g);
4954 const result_type __w = __u * (1 - __u);
4957 const result_type __y = _VSTD::sqrt(__c / __w) *
4958 (__u - result_type(0.5));
4962 const result_type __z = 64 * __w * __w * __w * __v * __v;
4963 if (__z <= 1 - 2 * __y * __y / __x)
4965 if (_VSTD::log(__z) <= 2 * (__b * _VSTD::log(__x / __b) - __y))
4975 const result_type __u = __gen(__g);
4976 const result_type __es = __egen(__g);
4979 __x = _VSTD::pow(__u, 1 / __a);
4985 const result_type __e = -_VSTD::log((1-__u)/__a);
4986 __x = _VSTD::pow(1 - __a + __a * __e, 1 / __a);
4987 if (__x <= __e + __es)
4992 return __x * __p.beta();
4995 template <class _CharT, class _Traits, class _RT>
4996 basic_ostream<_CharT, _Traits>&
4997 operator<<(basic_ostream<_CharT, _Traits>& __os,
4998 const gamma_distribution<_RT>& __x)
5000 __save_flags<_CharT, _Traits> _(__os);
5001 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
5002 ios_base::scientific);
5003 _CharT __sp = __os.widen(' ');
5005 __os << __x.alpha() << __sp << __x.beta();
5009 template <class _CharT, class _Traits, class _RT>
5010 basic_istream<_CharT, _Traits>&
5011 operator>>(basic_istream<_CharT, _Traits>& __is,
5012 gamma_distribution<_RT>& __x)
5014 typedef gamma_distribution<_RT> _Eng;
5015 typedef typename _Eng::result_type result_type;
5016 typedef typename _Eng::param_type param_type;
5017 __save_flags<_CharT, _Traits> _(__is);
5018 __is.flags(ios_base::dec | ios_base::skipws);
5019 result_type __alpha;
5021 __is >> __alpha >> __beta;
5023 __x.param(param_type(__alpha, __beta));
5027 // negative_binomial_distribution
5029 template<class _IntType = int>
5030 class _LIBCPP_VISIBLE negative_binomial_distribution
5034 typedef _IntType result_type;
5036 class _LIBCPP_VISIBLE param_type
5041 typedef negative_binomial_distribution distribution_type;
5043 _LIBCPP_INLINE_VISIBILITY
5044 explicit param_type(result_type __k = 1, double __p = 0.5)
5045 : __k_(__k), __p_(__p) {}
5047 _LIBCPP_INLINE_VISIBILITY
5048 result_type k() const {return __k_;}
5049 _LIBCPP_INLINE_VISIBILITY
5050 double p() const {return __p_;}
5052 friend _LIBCPP_INLINE_VISIBILITY
5053 bool operator==(const param_type& __x, const param_type& __y)
5054 {return __x.__k_ == __y.__k_ && __x.__p_ == __y.__p_;}
5055 friend _LIBCPP_INLINE_VISIBILITY
5056 bool operator!=(const param_type& __x, const param_type& __y)
5057 {return !(__x == __y);}
5064 // constructor and reset functions
5065 _LIBCPP_INLINE_VISIBILITY
5066 explicit negative_binomial_distribution(result_type __k = 1, double __p = 0.5)
5068 _LIBCPP_INLINE_VISIBILITY
5069 explicit negative_binomial_distribution(const param_type& __p) : __p_(__p) {}
5070 _LIBCPP_INLINE_VISIBILITY
5073 // generating functions
5074 template<class _URNG>
5075 _LIBCPP_INLINE_VISIBILITY
5076 result_type operator()(_URNG& __g)
5077 {return (*this)(__g, __p_);}
5078 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
5080 // property functions
5081 _LIBCPP_INLINE_VISIBILITY
5082 result_type k() const {return __p_.k();}
5083 _LIBCPP_INLINE_VISIBILITY
5084 double p() const {return __p_.p();}
5086 _LIBCPP_INLINE_VISIBILITY
5087 param_type param() const {return __p_;}
5088 _LIBCPP_INLINE_VISIBILITY
5089 void param(const param_type& __p) {__p_ = __p;}
5091 _LIBCPP_INLINE_VISIBILITY
5092 result_type min() const {return 0;}
5093 _LIBCPP_INLINE_VISIBILITY
5094 result_type max() const {return numeric_limits<result_type>::max();}
5096 friend _LIBCPP_INLINE_VISIBILITY
5097 bool operator==(const negative_binomial_distribution& __x,
5098 const negative_binomial_distribution& __y)
5099 {return __x.__p_ == __y.__p_;}
5100 friend _LIBCPP_INLINE_VISIBILITY
5101 bool operator!=(const negative_binomial_distribution& __x,
5102 const negative_binomial_distribution& __y)
5103 {return !(__x == __y);}
5106 template <class _IntType>
5107 template<class _URNG>
5109 negative_binomial_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr)
5111 result_type __k = __pr.k();
5112 double __p = __pr.p();
5113 if (__k <= 21 * __p)
5115 bernoulli_distribution __gen(__p);
5116 result_type __f = 0;
5117 result_type __s = 0;
5127 return poisson_distribution<result_type>(gamma_distribution<double>
5128 (__k, (1-__p)/__p)(__urng))(__urng);
5131 template <class _CharT, class _Traits, class _IntType>
5132 basic_ostream<_CharT, _Traits>&
5133 operator<<(basic_ostream<_CharT, _Traits>& __os,
5134 const negative_binomial_distribution<_IntType>& __x)
5136 __save_flags<_CharT, _Traits> _(__os);
5137 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
5138 ios_base::scientific);
5139 _CharT __sp = __os.widen(' ');
5141 return __os << __x.k() << __sp << __x.p();
5144 template <class _CharT, class _Traits, class _IntType>
5145 basic_istream<_CharT, _Traits>&
5146 operator>>(basic_istream<_CharT, _Traits>& __is,
5147 negative_binomial_distribution<_IntType>& __x)
5149 typedef negative_binomial_distribution<_IntType> _Eng;
5150 typedef typename _Eng::result_type result_type;
5151 typedef typename _Eng::param_type param_type;
5152 __save_flags<_CharT, _Traits> _(__is);
5153 __is.flags(ios_base::dec | ios_base::skipws);
5158 __x.param(param_type(__k, __p));
5162 // geometric_distribution
5164 template<class _IntType = int>
5165 class _LIBCPP_VISIBLE geometric_distribution
5169 typedef _IntType result_type;
5171 class _LIBCPP_VISIBLE param_type
5175 typedef geometric_distribution distribution_type;
5177 _LIBCPP_INLINE_VISIBILITY
5178 explicit param_type(double __p = 0.5) : __p_(__p) {}
5180 _LIBCPP_INLINE_VISIBILITY
5181 double p() const {return __p_;}
5183 friend _LIBCPP_INLINE_VISIBILITY
5184 bool operator==(const param_type& __x, const param_type& __y)
5185 {return __x.__p_ == __y.__p_;}
5186 friend _LIBCPP_INLINE_VISIBILITY
5187 bool operator!=(const param_type& __x, const param_type& __y)
5188 {return !(__x == __y);}
5195 // constructors and reset functions
5196 _LIBCPP_INLINE_VISIBILITY
5197 explicit geometric_distribution(double __p = 0.5) : __p_(__p) {}
5198 _LIBCPP_INLINE_VISIBILITY
5199 explicit geometric_distribution(const param_type& __p) : __p_(__p) {}
5200 _LIBCPP_INLINE_VISIBILITY
5203 // generating functions
5204 template<class _URNG>
5205 _LIBCPP_INLINE_VISIBILITY
5206 result_type operator()(_URNG& __g)
5207 {return (*this)(__g, __p_);}
5208 template<class _URNG>
5209 _LIBCPP_INLINE_VISIBILITY
5210 result_type operator()(_URNG& __g, const param_type& __p)
5211 {return negative_binomial_distribution<result_type>(1, __p.p())(__g);}
5213 // property functions
5214 _LIBCPP_INLINE_VISIBILITY
5215 double p() const {return __p_.p();}
5217 _LIBCPP_INLINE_VISIBILITY
5218 param_type param() const {return __p_;}
5219 _LIBCPP_INLINE_VISIBILITY
5220 void param(const param_type& __p) {__p_ = __p;}
5222 _LIBCPP_INLINE_VISIBILITY
5223 result_type min() const {return 0;}
5224 _LIBCPP_INLINE_VISIBILITY
5225 result_type max() const {return numeric_limits<result_type>::max();}
5227 friend _LIBCPP_INLINE_VISIBILITY
5228 bool operator==(const geometric_distribution& __x,
5229 const geometric_distribution& __y)
5230 {return __x.__p_ == __y.__p_;}
5231 friend _LIBCPP_INLINE_VISIBILITY
5232 bool operator!=(const geometric_distribution& __x,
5233 const geometric_distribution& __y)
5234 {return !(__x == __y);}
5237 template <class _CharT, class _Traits, class _IntType>
5238 basic_ostream<_CharT, _Traits>&
5239 operator<<(basic_ostream<_CharT, _Traits>& __os,
5240 const geometric_distribution<_IntType>& __x)
5242 __save_flags<_CharT, _Traits> _(__os);
5243 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
5244 ios_base::scientific);
5245 return __os << __x.p();
5248 template <class _CharT, class _Traits, class _IntType>
5249 basic_istream<_CharT, _Traits>&
5250 operator>>(basic_istream<_CharT, _Traits>& __is,
5251 geometric_distribution<_IntType>& __x)
5253 typedef geometric_distribution<_IntType> _Eng;
5254 typedef typename _Eng::param_type param_type;
5255 __save_flags<_CharT, _Traits> _(__is);
5256 __is.flags(ios_base::dec | ios_base::skipws);
5260 __x.param(param_type(__p));
5264 // chi_squared_distribution
5266 template<class _RealType = double>
5267 class _LIBCPP_VISIBLE chi_squared_distribution
5271 typedef _RealType result_type;
5273 class _LIBCPP_VISIBLE param_type
5277 typedef chi_squared_distribution distribution_type;
5279 _LIBCPP_INLINE_VISIBILITY
5280 explicit param_type(result_type __n = 1) : __n_(__n) {}
5282 _LIBCPP_INLINE_VISIBILITY
5283 result_type n() const {return __n_;}
5285 friend _LIBCPP_INLINE_VISIBILITY
5286 bool operator==(const param_type& __x, const param_type& __y)
5287 {return __x.__n_ == __y.__n_;}
5288 friend _LIBCPP_INLINE_VISIBILITY
5289 bool operator!=(const param_type& __x, const param_type& __y)
5290 {return !(__x == __y);}
5297 // constructor and reset functions
5298 _LIBCPP_INLINE_VISIBILITY
5299 explicit chi_squared_distribution(result_type __n = 1)
5300 : __p_(param_type(__n)) {}
5301 _LIBCPP_INLINE_VISIBILITY
5302 explicit chi_squared_distribution(const param_type& __p)
5304 _LIBCPP_INLINE_VISIBILITY
5307 // generating functions
5308 template<class _URNG>
5309 _LIBCPP_INLINE_VISIBILITY
5310 result_type operator()(_URNG& __g)
5311 {return (*this)(__g, __p_);}
5312 template<class _URNG>
5313 _LIBCPP_INLINE_VISIBILITY
5314 result_type operator()(_URNG& __g, const param_type& __p)
5315 {return gamma_distribution<result_type>(__p.n() / 2, 2)(__g);}
5317 // property functions
5318 _LIBCPP_INLINE_VISIBILITY
5319 result_type n() const {return __p_.n();}
5321 _LIBCPP_INLINE_VISIBILITY
5322 param_type param() const {return __p_;}
5323 _LIBCPP_INLINE_VISIBILITY
5324 void param(const param_type& __p) {__p_ = __p;}
5326 _LIBCPP_INLINE_VISIBILITY
5327 result_type min() const {return 0;}
5328 _LIBCPP_INLINE_VISIBILITY
5329 result_type max() const {return numeric_limits<result_type>::infinity();}
5331 friend _LIBCPP_INLINE_VISIBILITY
5332 bool operator==(const chi_squared_distribution& __x,
5333 const chi_squared_distribution& __y)
5334 {return __x.__p_ == __y.__p_;}
5335 friend _LIBCPP_INLINE_VISIBILITY
5336 bool operator!=(const chi_squared_distribution& __x,
5337 const chi_squared_distribution& __y)
5338 {return !(__x == __y);}
5341 template <class _CharT, class _Traits, class _RT>
5342 basic_ostream<_CharT, _Traits>&
5343 operator<<(basic_ostream<_CharT, _Traits>& __os,
5344 const chi_squared_distribution<_RT>& __x)
5346 __save_flags<_CharT, _Traits> _(__os);
5347 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
5348 ios_base::scientific);
5353 template <class _CharT, class _Traits, class _RT>
5354 basic_istream<_CharT, _Traits>&
5355 operator>>(basic_istream<_CharT, _Traits>& __is,
5356 chi_squared_distribution<_RT>& __x)
5358 typedef chi_squared_distribution<_RT> _Eng;
5359 typedef typename _Eng::result_type result_type;
5360 typedef typename _Eng::param_type param_type;
5361 __save_flags<_CharT, _Traits> _(__is);
5362 __is.flags(ios_base::dec | ios_base::skipws);
5366 __x.param(param_type(__n));
5370 // cauchy_distribution
5372 template<class _RealType = double>
5373 class _LIBCPP_VISIBLE cauchy_distribution
5377 typedef _RealType result_type;
5379 class _LIBCPP_VISIBLE param_type
5384 typedef cauchy_distribution distribution_type;
5386 _LIBCPP_INLINE_VISIBILITY
5387 explicit param_type(result_type __a = 0, result_type __b = 1)
5388 : __a_(__a), __b_(__b) {}
5390 _LIBCPP_INLINE_VISIBILITY
5391 result_type a() const {return __a_;}
5392 _LIBCPP_INLINE_VISIBILITY
5393 result_type b() const {return __b_;}
5395 friend _LIBCPP_INLINE_VISIBILITY
5396 bool operator==(const param_type& __x, const param_type& __y)
5397 {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
5398 friend _LIBCPP_INLINE_VISIBILITY
5399 bool operator!=(const param_type& __x, const param_type& __y)
5400 {return !(__x == __y);}
5407 // constructor and reset functions
5408 _LIBCPP_INLINE_VISIBILITY
5409 explicit cauchy_distribution(result_type __a = 0, result_type __b = 1)
5410 : __p_(param_type(__a, __b)) {}
5411 _LIBCPP_INLINE_VISIBILITY
5412 explicit cauchy_distribution(const param_type& __p)
5414 _LIBCPP_INLINE_VISIBILITY
5417 // generating functions
5418 template<class _URNG>
5419 _LIBCPP_INLINE_VISIBILITY
5420 result_type operator()(_URNG& __g)
5421 {return (*this)(__g, __p_);}
5422 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
5424 // property functions
5425 _LIBCPP_INLINE_VISIBILITY
5426 result_type a() const {return __p_.a();}
5427 _LIBCPP_INLINE_VISIBILITY
5428 result_type b() const {return __p_.b();}
5430 _LIBCPP_INLINE_VISIBILITY
5431 param_type param() const {return __p_;}
5432 _LIBCPP_INLINE_VISIBILITY
5433 void param(const param_type& __p) {__p_ = __p;}
5435 _LIBCPP_INLINE_VISIBILITY
5436 result_type min() const {return -numeric_limits<result_type>::infinity();}
5437 _LIBCPP_INLINE_VISIBILITY
5438 result_type max() const {return numeric_limits<result_type>::infinity();}
5440 friend _LIBCPP_INLINE_VISIBILITY
5441 bool operator==(const cauchy_distribution& __x,
5442 const cauchy_distribution& __y)
5443 {return __x.__p_ == __y.__p_;}
5444 friend _LIBCPP_INLINE_VISIBILITY
5445 bool operator!=(const cauchy_distribution& __x,
5446 const cauchy_distribution& __y)
5447 {return !(__x == __y);}
5450 template <class _RealType>
5451 template<class _URNG>
5452 inline _LIBCPP_INLINE_VISIBILITY
5454 cauchy_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
5456 uniform_real_distribution<result_type> __gen;
5457 // purposefully let tan arg get as close to pi/2 as it wants, tan will return a finite
5458 return __p.a() + __p.b() * _VSTD::tan(3.1415926535897932384626433832795 * __gen(__g));
5461 template <class _CharT, class _Traits, class _RT>
5462 basic_ostream<_CharT, _Traits>&
5463 operator<<(basic_ostream<_CharT, _Traits>& __os,
5464 const cauchy_distribution<_RT>& __x)
5466 __save_flags<_CharT, _Traits> _(__os);
5467 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
5468 ios_base::scientific);
5469 _CharT __sp = __os.widen(' ');
5471 __os << __x.a() << __sp << __x.b();
5475 template <class _CharT, class _Traits, class _RT>
5476 basic_istream<_CharT, _Traits>&
5477 operator>>(basic_istream<_CharT, _Traits>& __is,
5478 cauchy_distribution<_RT>& __x)
5480 typedef cauchy_distribution<_RT> _Eng;
5481 typedef typename _Eng::result_type result_type;
5482 typedef typename _Eng::param_type param_type;
5483 __save_flags<_CharT, _Traits> _(__is);
5484 __is.flags(ios_base::dec | ios_base::skipws);
5489 __x.param(param_type(__a, __b));
5493 // fisher_f_distribution
5495 template<class _RealType = double>
5496 class _LIBCPP_VISIBLE fisher_f_distribution
5500 typedef _RealType result_type;
5502 class _LIBCPP_VISIBLE param_type
5507 typedef fisher_f_distribution distribution_type;
5509 _LIBCPP_INLINE_VISIBILITY
5510 explicit param_type(result_type __m = 1, result_type __n = 1)
5511 : __m_(__m), __n_(__n) {}
5513 _LIBCPP_INLINE_VISIBILITY
5514 result_type m() const {return __m_;}
5515 _LIBCPP_INLINE_VISIBILITY
5516 result_type n() const {return __n_;}
5518 friend _LIBCPP_INLINE_VISIBILITY
5519 bool operator==(const param_type& __x, const param_type& __y)
5520 {return __x.__m_ == __y.__m_ && __x.__n_ == __y.__n_;}
5521 friend _LIBCPP_INLINE_VISIBILITY
5522 bool operator!=(const param_type& __x, const param_type& __y)
5523 {return !(__x == __y);}
5530 // constructor and reset functions
5531 _LIBCPP_INLINE_VISIBILITY
5532 explicit fisher_f_distribution(result_type __m = 1, result_type __n = 1)
5533 : __p_(param_type(__m, __n)) {}
5534 _LIBCPP_INLINE_VISIBILITY
5535 explicit fisher_f_distribution(const param_type& __p)
5537 _LIBCPP_INLINE_VISIBILITY
5540 // generating functions
5541 template<class _URNG>
5542 _LIBCPP_INLINE_VISIBILITY
5543 result_type operator()(_URNG& __g)
5544 {return (*this)(__g, __p_);}
5545 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
5547 // property functions
5548 _LIBCPP_INLINE_VISIBILITY
5549 result_type m() const {return __p_.m();}
5550 _LIBCPP_INLINE_VISIBILITY
5551 result_type n() const {return __p_.n();}
5553 _LIBCPP_INLINE_VISIBILITY
5554 param_type param() const {return __p_;}
5555 _LIBCPP_INLINE_VISIBILITY
5556 void param(const param_type& __p) {__p_ = __p;}
5558 _LIBCPP_INLINE_VISIBILITY
5559 result_type min() const {return 0;}
5560 _LIBCPP_INLINE_VISIBILITY
5561 result_type max() const {return numeric_limits<result_type>::infinity();}
5563 friend _LIBCPP_INLINE_VISIBILITY
5564 bool operator==(const fisher_f_distribution& __x,
5565 const fisher_f_distribution& __y)
5566 {return __x.__p_ == __y.__p_;}
5567 friend _LIBCPP_INLINE_VISIBILITY
5568 bool operator!=(const fisher_f_distribution& __x,
5569 const fisher_f_distribution& __y)
5570 {return !(__x == __y);}
5573 template <class _RealType>
5574 template<class _URNG>
5576 fisher_f_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
5578 gamma_distribution<result_type> __gdm(__p.m() * result_type(.5));
5579 gamma_distribution<result_type> __gdn(__p.n() * result_type(.5));
5580 return __p.n() * __gdm(__g) / (__p.m() * __gdn(__g));
5583 template <class _CharT, class _Traits, class _RT>
5584 basic_ostream<_CharT, _Traits>&
5585 operator<<(basic_ostream<_CharT, _Traits>& __os,
5586 const fisher_f_distribution<_RT>& __x)
5588 __save_flags<_CharT, _Traits> _(__os);
5589 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
5590 ios_base::scientific);
5591 _CharT __sp = __os.widen(' ');
5593 __os << __x.m() << __sp << __x.n();
5597 template <class _CharT, class _Traits, class _RT>
5598 basic_istream<_CharT, _Traits>&
5599 operator>>(basic_istream<_CharT, _Traits>& __is,
5600 fisher_f_distribution<_RT>& __x)
5602 typedef fisher_f_distribution<_RT> _Eng;
5603 typedef typename _Eng::result_type result_type;
5604 typedef typename _Eng::param_type param_type;
5605 __save_flags<_CharT, _Traits> _(__is);
5606 __is.flags(ios_base::dec | ios_base::skipws);
5611 __x.param(param_type(__m, __n));
5615 // student_t_distribution
5617 template<class _RealType = double>
5618 class _LIBCPP_VISIBLE student_t_distribution
5622 typedef _RealType result_type;
5624 class _LIBCPP_VISIBLE param_type
5628 typedef student_t_distribution distribution_type;
5630 _LIBCPP_INLINE_VISIBILITY
5631 explicit param_type(result_type __n = 1) : __n_(__n) {}
5633 _LIBCPP_INLINE_VISIBILITY
5634 result_type n() const {return __n_;}
5636 friend _LIBCPP_INLINE_VISIBILITY
5637 bool operator==(const param_type& __x, const param_type& __y)
5638 {return __x.__n_ == __y.__n_;}
5639 friend _LIBCPP_INLINE_VISIBILITY
5640 bool operator!=(const param_type& __x, const param_type& __y)
5641 {return !(__x == __y);}
5646 normal_distribution<result_type> __nd_;
5649 // constructor and reset functions
5650 _LIBCPP_INLINE_VISIBILITY
5651 explicit student_t_distribution(result_type __n = 1)
5652 : __p_(param_type(__n)) {}
5653 _LIBCPP_INLINE_VISIBILITY
5654 explicit student_t_distribution(const param_type& __p)
5656 _LIBCPP_INLINE_VISIBILITY
5657 void reset() {__nd_.reset();}
5659 // generating functions
5660 template<class _URNG>
5661 _LIBCPP_INLINE_VISIBILITY
5662 result_type operator()(_URNG& __g)
5663 {return (*this)(__g, __p_);}
5664 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
5666 // property functions
5667 _LIBCPP_INLINE_VISIBILITY
5668 result_type n() const {return __p_.n();}
5670 _LIBCPP_INLINE_VISIBILITY
5671 param_type param() const {return __p_;}
5672 _LIBCPP_INLINE_VISIBILITY
5673 void param(const param_type& __p) {__p_ = __p;}
5675 _LIBCPP_INLINE_VISIBILITY
5676 result_type min() const {return -numeric_limits<result_type>::infinity();}
5677 _LIBCPP_INLINE_VISIBILITY
5678 result_type max() const {return numeric_limits<result_type>::infinity();}
5680 friend _LIBCPP_INLINE_VISIBILITY
5681 bool operator==(const student_t_distribution& __x,
5682 const student_t_distribution& __y)
5683 {return __x.__p_ == __y.__p_;}
5684 friend _LIBCPP_INLINE_VISIBILITY
5685 bool operator!=(const student_t_distribution& __x,
5686 const student_t_distribution& __y)
5687 {return !(__x == __y);}
5690 template <class _RealType>
5691 template<class _URNG>
5693 student_t_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
5695 gamma_distribution<result_type> __gd(__p.n() * .5, 2);
5696 return __nd_(__g) * _VSTD::sqrt(__p.n()/__gd(__g));
5699 template <class _CharT, class _Traits, class _RT>
5700 basic_ostream<_CharT, _Traits>&
5701 operator<<(basic_ostream<_CharT, _Traits>& __os,
5702 const student_t_distribution<_RT>& __x)
5704 __save_flags<_CharT, _Traits> _(__os);
5705 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
5706 ios_base::scientific);
5711 template <class _CharT, class _Traits, class _RT>
5712 basic_istream<_CharT, _Traits>&
5713 operator>>(basic_istream<_CharT, _Traits>& __is,
5714 student_t_distribution<_RT>& __x)
5716 typedef student_t_distribution<_RT> _Eng;
5717 typedef typename _Eng::result_type result_type;
5718 typedef typename _Eng::param_type param_type;
5719 __save_flags<_CharT, _Traits> _(__is);
5720 __is.flags(ios_base::dec | ios_base::skipws);
5724 __x.param(param_type(__n));
5728 // discrete_distribution
5730 template<class _IntType = int>
5731 class _LIBCPP_VISIBLE discrete_distribution
5735 typedef _IntType result_type;
5737 class _LIBCPP_VISIBLE param_type
5739 vector<double> __p_;
5741 typedef discrete_distribution distribution_type;
5743 _LIBCPP_INLINE_VISIBILITY
5745 template<class _InputIterator>
5746 _LIBCPP_INLINE_VISIBILITY
5747 param_type(_InputIterator __f, _InputIterator __l)
5748 : __p_(__f, __l) {__init();}
5749 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
5750 _LIBCPP_INLINE_VISIBILITY
5751 param_type(initializer_list<double> __wl)
5752 : __p_(__wl.begin(), __wl.end()) {__init();}
5753 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
5754 template<class _UnaryOperation>
5755 param_type(size_t __nw, double __xmin, double __xmax,
5756 _UnaryOperation __fw);
5758 vector<double> probabilities() const;
5760 friend _LIBCPP_INLINE_VISIBILITY
5761 bool operator==(const param_type& __x, const param_type& __y)
5762 {return __x.__p_ == __y.__p_;}
5763 friend _LIBCPP_INLINE_VISIBILITY
5764 bool operator!=(const param_type& __x, const param_type& __y)
5765 {return !(__x == __y);}
5770 friend class discrete_distribution;
5772 template <class _CharT, class _Traits, class _IT>
5774 basic_ostream<_CharT, _Traits>&
5775 operator<<(basic_ostream<_CharT, _Traits>& __os,
5776 const discrete_distribution<_IT>& __x);
5778 template <class _CharT, class _Traits, class _IT>
5780 basic_istream<_CharT, _Traits>&
5781 operator>>(basic_istream<_CharT, _Traits>& __is,
5782 discrete_distribution<_IT>& __x);
5789 // constructor and reset functions
5790 _LIBCPP_INLINE_VISIBILITY
5791 discrete_distribution() {}
5792 template<class _InputIterator>
5793 _LIBCPP_INLINE_VISIBILITY
5794 discrete_distribution(_InputIterator __f, _InputIterator __l)
5796 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
5797 _LIBCPP_INLINE_VISIBILITY
5798 discrete_distribution(initializer_list<double> __wl)
5800 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
5801 template<class _UnaryOperation>
5802 _LIBCPP_INLINE_VISIBILITY
5803 discrete_distribution(size_t __nw, double __xmin, double __xmax,
5804 _UnaryOperation __fw)
5805 : __p_(__nw, __xmin, __xmax, __fw) {}
5806 explicit discrete_distribution(const param_type& __p)
5807 _LIBCPP_INLINE_VISIBILITY
5809 _LIBCPP_INLINE_VISIBILITY
5812 // generating functions
5813 template<class _URNG>
5814 _LIBCPP_INLINE_VISIBILITY
5815 result_type operator()(_URNG& __g)
5816 {return (*this)(__g, __p_);}
5817 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
5819 // property functions
5820 _LIBCPP_INLINE_VISIBILITY
5821 vector<double> probabilities() const {return __p_.probabilities();}
5823 _LIBCPP_INLINE_VISIBILITY
5824 param_type param() const {return __p_;}
5825 _LIBCPP_INLINE_VISIBILITY
5826 void param(const param_type& __p) {__p_ = __p;}
5828 _LIBCPP_INLINE_VISIBILITY
5829 result_type min() const {return 0;}
5830 _LIBCPP_INLINE_VISIBILITY
5831 result_type max() const {return __p_.__p_.size();}
5833 friend _LIBCPP_INLINE_VISIBILITY
5834 bool operator==(const discrete_distribution& __x,
5835 const discrete_distribution& __y)
5836 {return __x.__p_ == __y.__p_;}
5837 friend _LIBCPP_INLINE_VISIBILITY
5838 bool operator!=(const discrete_distribution& __x,
5839 const discrete_distribution& __y)
5840 {return !(__x == __y);}
5842 template <class _CharT, class _Traits, class _IT>
5844 basic_ostream<_CharT, _Traits>&
5845 operator<<(basic_ostream<_CharT, _Traits>& __os,
5846 const discrete_distribution<_IT>& __x);
5848 template <class _CharT, class _Traits, class _IT>
5850 basic_istream<_CharT, _Traits>&
5851 operator>>(basic_istream<_CharT, _Traits>& __is,
5852 discrete_distribution<_IT>& __x);
5855 template<class _IntType>
5856 template<class _UnaryOperation>
5857 discrete_distribution<_IntType>::param_type::param_type(size_t __nw,
5860 _UnaryOperation __fw)
5864 __p_.reserve(__nw - 1);
5865 double __d = (__xmax - __xmin) / __nw;
5866 double __d2 = __d / 2;
5867 for (size_t __k = 0; __k < __nw; ++__k)
5868 __p_.push_back(__fw(__xmin + __k * __d + __d2));
5873 template<class _IntType>
5875 discrete_distribution<_IntType>::param_type::__init()
5879 if (__p_.size() > 1)
5881 double __s = _VSTD::accumulate(__p_.begin(), __p_.end(), 0.0);
5882 for (_VSTD::vector<double>::iterator __i = __p_.begin(), __e = __p_.end();
5885 vector<double> __t(__p_.size() - 1);
5886 _VSTD::partial_sum(__p_.begin(), __p_.end() - 1, __t.begin());
5892 __p_.shrink_to_fit();
5897 template<class _IntType>
5899 discrete_distribution<_IntType>::param_type::probabilities() const
5901 size_t __n = __p_.size();
5902 _VSTD::vector<double> __p(__n+1);
5903 _VSTD::adjacent_difference(__p_.begin(), __p_.end(), __p.begin());
5905 __p[__n] = 1 - __p_[__n-1];
5911 template<class _IntType>
5912 template<class _URNG>
5914 discrete_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p)
5916 uniform_real_distribution<double> __gen;
5917 return static_cast<_IntType>(
5918 _VSTD::upper_bound(__p.__p_.begin(), __p.__p_.end(), __gen(__g)) -
5922 template <class _CharT, class _Traits, class _IT>
5923 basic_ostream<_CharT, _Traits>&
5924 operator<<(basic_ostream<_CharT, _Traits>& __os,
5925 const discrete_distribution<_IT>& __x)
5927 __save_flags<_CharT, _Traits> _(__os);
5928 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
5929 ios_base::scientific);
5930 _CharT __sp = __os.widen(' ');
5932 size_t __n = __x.__p_.__p_.size();
5934 for (size_t __i = 0; __i < __n; ++__i)
5935 __os << __sp << __x.__p_.__p_[__i];
5939 template <class _CharT, class _Traits, class _IT>
5940 basic_istream<_CharT, _Traits>&
5941 operator>>(basic_istream<_CharT, _Traits>& __is,
5942 discrete_distribution<_IT>& __x)
5944 typedef discrete_distribution<_IT> _Eng;
5945 typedef typename _Eng::result_type result_type;
5946 typedef typename _Eng::param_type param_type;
5947 __save_flags<_CharT, _Traits> _(__is);
5948 __is.flags(ios_base::dec | ios_base::skipws);
5951 vector<double> __p(__n);
5952 for (size_t __i = 0; __i < __n; ++__i)
5955 swap(__x.__p_.__p_, __p);
5959 // piecewise_constant_distribution
5961 template<class _RealType = double>
5962 class _LIBCPP_VISIBLE piecewise_constant_distribution
5966 typedef _RealType result_type;
5968 class _LIBCPP_VISIBLE param_type
5970 vector<result_type> __b_;
5971 vector<result_type> __densities_;
5972 vector<result_type> __areas_;
5974 typedef piecewise_constant_distribution distribution_type;
5977 template<class _InputIteratorB, class _InputIteratorW>
5978 param_type(_InputIteratorB __fB, _InputIteratorB __lB,
5979 _InputIteratorW __fW);
5980 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
5981 template<class _UnaryOperation>
5982 param_type(initializer_list<result_type> __bl, _UnaryOperation __fw);
5983 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
5984 template<class _UnaryOperation>
5985 param_type(size_t __nw, result_type __xmin, result_type __xmax,
5986 _UnaryOperation __fw);
5987 param_type & operator=(const param_type& __rhs);
5989 _LIBCPP_INLINE_VISIBILITY
5990 vector<result_type> intervals() const {return __b_;}
5991 _LIBCPP_INLINE_VISIBILITY
5992 vector<result_type> densities() const {return __densities_;}
5994 friend _LIBCPP_INLINE_VISIBILITY
5995 bool operator==(const param_type& __x, const param_type& __y)
5996 {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;}
5997 friend _LIBCPP_INLINE_VISIBILITY
5998 bool operator!=(const param_type& __x, const param_type& __y)
5999 {return !(__x == __y);}
6004 friend class piecewise_constant_distribution;
6006 template <class _CharT, class _Traits, class _RT>
6008 basic_ostream<_CharT, _Traits>&
6009 operator<<(basic_ostream<_CharT, _Traits>& __os,
6010 const piecewise_constant_distribution<_RT>& __x);
6012 template <class _CharT, class _Traits, class _RT>
6014 basic_istream<_CharT, _Traits>&
6015 operator>>(basic_istream<_CharT, _Traits>& __is,
6016 piecewise_constant_distribution<_RT>& __x);
6023 // constructor and reset functions
6024 _LIBCPP_INLINE_VISIBILITY
6025 piecewise_constant_distribution() {}
6026 template<class _InputIteratorB, class _InputIteratorW>
6027 _LIBCPP_INLINE_VISIBILITY
6028 piecewise_constant_distribution(_InputIteratorB __fB,
6029 _InputIteratorB __lB,
6030 _InputIteratorW __fW)
6031 : __p_(__fB, __lB, __fW) {}
6033 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6034 template<class _UnaryOperation>
6035 _LIBCPP_INLINE_VISIBILITY
6036 piecewise_constant_distribution(initializer_list<result_type> __bl,
6037 _UnaryOperation __fw)
6038 : __p_(__bl, __fw) {}
6039 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6041 template<class _UnaryOperation>
6042 _LIBCPP_INLINE_VISIBILITY
6043 piecewise_constant_distribution(size_t __nw, result_type __xmin,
6044 result_type __xmax, _UnaryOperation __fw)
6045 : __p_(__nw, __xmin, __xmax, __fw) {}
6047 _LIBCPP_INLINE_VISIBILITY
6048 explicit piecewise_constant_distribution(const param_type& __p)
6051 _LIBCPP_INLINE_VISIBILITY
6054 // generating functions
6055 template<class _URNG>
6056 _LIBCPP_INLINE_VISIBILITY
6057 result_type operator()(_URNG& __g)
6058 {return (*this)(__g, __p_);}
6059 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
6061 // property functions
6062 _LIBCPP_INLINE_VISIBILITY
6063 vector<result_type> intervals() const {return __p_.intervals();}
6064 _LIBCPP_INLINE_VISIBILITY
6065 vector<result_type> densities() const {return __p_.densities();}
6067 _LIBCPP_INLINE_VISIBILITY
6068 param_type param() const {return __p_;}
6069 _LIBCPP_INLINE_VISIBILITY
6070 void param(const param_type& __p) {__p_ = __p;}
6072 _LIBCPP_INLINE_VISIBILITY
6073 result_type min() const {return __p_.__b_.front();}
6074 _LIBCPP_INLINE_VISIBILITY
6075 result_type max() const {return __p_.__b_.back();}
6077 friend _LIBCPP_INLINE_VISIBILITY
6078 bool operator==(const piecewise_constant_distribution& __x,
6079 const piecewise_constant_distribution& __y)
6080 {return __x.__p_ == __y.__p_;}
6081 friend _LIBCPP_INLINE_VISIBILITY
6082 bool operator!=(const piecewise_constant_distribution& __x,
6083 const piecewise_constant_distribution& __y)
6084 {return !(__x == __y);}
6086 template <class _CharT, class _Traits, class _RT>
6088 basic_ostream<_CharT, _Traits>&
6089 operator<<(basic_ostream<_CharT, _Traits>& __os,
6090 const piecewise_constant_distribution<_RT>& __x);
6092 template <class _CharT, class _Traits, class _RT>
6094 basic_istream<_CharT, _Traits>&
6095 operator>>(basic_istream<_CharT, _Traits>& __is,
6096 piecewise_constant_distribution<_RT>& __x);
6099 template<class _RealType>
6100 typename piecewise_constant_distribution<_RealType>::param_type &
6101 piecewise_constant_distribution<_RealType>::param_type::operator=
6102 (const param_type& __rhs)
6105 __b_.reserve (__rhs.__b_.size ());
6106 __densities_.reserve(__rhs.__densities_.size());
6107 __areas_.reserve (__rhs.__areas_.size());
6109 // These can not throw
6111 __densities_ = __rhs.__densities_;
6112 __areas_ = __rhs.__areas_;
6116 template<class _RealType>
6118 piecewise_constant_distribution<_RealType>::param_type::__init()
6120 // __densities_ contains non-normalized areas
6121 result_type __total_area = _VSTD::accumulate(__densities_.begin(),
6124 for (size_t __i = 0; __i < __densities_.size(); ++__i)
6125 __densities_[__i] /= __total_area;
6126 // __densities_ contains normalized areas
6127 __areas_.assign(__densities_.size(), result_type());
6128 _VSTD::partial_sum(__densities_.begin(), __densities_.end() - 1,
6129 __areas_.begin() + 1);
6130 // __areas_ contains partial sums of normalized areas: [0, __densities_ - 1]
6131 __densities_.back() = 1 - __areas_.back(); // correct round off error
6132 for (size_t __i = 0; __i < __densities_.size(); ++__i)
6133 __densities_[__i] /= (__b_[__i+1] - __b_[__i]);
6134 // __densities_ now contains __densities_
6137 template<class _RealType>
6138 piecewise_constant_distribution<_RealType>::param_type::param_type()
6140 __densities_(1, 1.0),
6146 template<class _RealType>
6147 template<class _InputIteratorB, class _InputIteratorW>
6148 piecewise_constant_distribution<_RealType>::param_type::param_type(
6149 _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW)
6152 if (__b_.size() < 2)
6157 __densities_.assign(1, 1.0);
6158 __areas_.assign(1, 0.0);
6162 __densities_.reserve(__b_.size() - 1);
6163 for (size_t __i = 0; __i < __b_.size() - 1; ++__i, ++__fW)
6164 __densities_.push_back(*__fW);
6169 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6171 template<class _RealType>
6172 template<class _UnaryOperation>
6173 piecewise_constant_distribution<_RealType>::param_type::param_type(
6174 initializer_list<result_type> __bl, _UnaryOperation __fw)
6175 : __b_(__bl.begin(), __bl.end())
6177 if (__b_.size() < 2)
6182 __densities_.assign(1, 1.0);
6183 __areas_.assign(1, 0.0);
6187 __densities_.reserve(__b_.size() - 1);
6188 for (size_t __i = 0; __i < __b_.size() - 1; ++__i)
6189 __densities_.push_back(__fw((__b_[__i+1] + __b_[__i])*.5));
6194 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6196 template<class _RealType>
6197 template<class _UnaryOperation>
6198 piecewise_constant_distribution<_RealType>::param_type::param_type(
6199 size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw)
6200 : __b_(__nw == 0 ? 2 : __nw + 1)
6202 size_t __n = __b_.size() - 1;
6203 result_type __d = (__xmax - __xmin) / __n;
6204 __densities_.reserve(__n);
6205 for (size_t __i = 0; __i < __n; ++__i)
6207 __b_[__i] = __xmin + __i * __d;
6208 __densities_.push_back(__fw(__b_[__i] + __d*.5));
6214 template<class _RealType>
6215 template<class _URNG>
6217 piecewise_constant_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
6219 typedef uniform_real_distribution<result_type> _Gen;
6220 result_type __u = _Gen()(__g);
6221 ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(),
6222 __u) - __p.__areas_.begin() - 1;
6223 return (__u - __p.__areas_[__k]) / __p.__densities_[__k] + __p.__b_[__k];
6226 template <class _CharT, class _Traits, class _RT>
6227 basic_ostream<_CharT, _Traits>&
6228 operator<<(basic_ostream<_CharT, _Traits>& __os,
6229 const piecewise_constant_distribution<_RT>& __x)
6231 __save_flags<_CharT, _Traits> _(__os);
6232 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
6233 ios_base::scientific);
6234 _CharT __sp = __os.widen(' ');
6236 size_t __n = __x.__p_.__b_.size();
6238 for (size_t __i = 0; __i < __n; ++__i)
6239 __os << __sp << __x.__p_.__b_[__i];
6240 __n = __x.__p_.__densities_.size();
6241 __os << __sp << __n;
6242 for (size_t __i = 0; __i < __n; ++__i)
6243 __os << __sp << __x.__p_.__densities_[__i];
6244 __n = __x.__p_.__areas_.size();
6245 __os << __sp << __n;
6246 for (size_t __i = 0; __i < __n; ++__i)
6247 __os << __sp << __x.__p_.__areas_[__i];
6251 template <class _CharT, class _Traits, class _RT>
6252 basic_istream<_CharT, _Traits>&
6253 operator>>(basic_istream<_CharT, _Traits>& __is,
6254 piecewise_constant_distribution<_RT>& __x)
6256 typedef piecewise_constant_distribution<_RT> _Eng;
6257 typedef typename _Eng::result_type result_type;
6258 typedef typename _Eng::param_type param_type;
6259 __save_flags<_CharT, _Traits> _(__is);
6260 __is.flags(ios_base::dec | ios_base::skipws);
6263 vector<result_type> __b(__n);
6264 for (size_t __i = 0; __i < __n; ++__i)
6267 vector<result_type> __densities(__n);
6268 for (size_t __i = 0; __i < __n; ++__i)
6269 __is >> __densities[__i];
6271 vector<result_type> __areas(__n);
6272 for (size_t __i = 0; __i < __n; ++__i)
6273 __is >> __areas[__i];
6276 swap(__x.__p_.__b_, __b);
6277 swap(__x.__p_.__densities_, __densities);
6278 swap(__x.__p_.__areas_, __areas);
6283 // piecewise_linear_distribution
6285 template<class _RealType = double>
6286 class _LIBCPP_VISIBLE piecewise_linear_distribution
6290 typedef _RealType result_type;
6292 class _LIBCPP_VISIBLE param_type
6294 vector<result_type> __b_;
6295 vector<result_type> __densities_;
6296 vector<result_type> __areas_;
6298 typedef piecewise_linear_distribution distribution_type;
6301 template<class _InputIteratorB, class _InputIteratorW>
6302 param_type(_InputIteratorB __fB, _InputIteratorB __lB,
6303 _InputIteratorW __fW);
6304 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6305 template<class _UnaryOperation>
6306 param_type(initializer_list<result_type> __bl, _UnaryOperation __fw);
6307 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6308 template<class _UnaryOperation>
6309 param_type(size_t __nw, result_type __xmin, result_type __xmax,
6310 _UnaryOperation __fw);
6311 param_type & operator=(const param_type& __rhs);
6313 _LIBCPP_INLINE_VISIBILITY
6314 vector<result_type> intervals() const {return __b_;}
6315 _LIBCPP_INLINE_VISIBILITY
6316 vector<result_type> densities() const {return __densities_;}
6318 friend _LIBCPP_INLINE_VISIBILITY
6319 bool operator==(const param_type& __x, const param_type& __y)
6320 {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;}
6321 friend _LIBCPP_INLINE_VISIBILITY
6322 bool operator!=(const param_type& __x, const param_type& __y)
6323 {return !(__x == __y);}
6328 friend class piecewise_linear_distribution;
6330 template <class _CharT, class _Traits, class _RT>
6332 basic_ostream<_CharT, _Traits>&
6333 operator<<(basic_ostream<_CharT, _Traits>& __os,
6334 const piecewise_linear_distribution<_RT>& __x);
6336 template <class _CharT, class _Traits, class _RT>
6338 basic_istream<_CharT, _Traits>&
6339 operator>>(basic_istream<_CharT, _Traits>& __is,
6340 piecewise_linear_distribution<_RT>& __x);
6347 // constructor and reset functions
6348 _LIBCPP_INLINE_VISIBILITY
6349 piecewise_linear_distribution() {}
6350 template<class _InputIteratorB, class _InputIteratorW>
6351 _LIBCPP_INLINE_VISIBILITY
6352 piecewise_linear_distribution(_InputIteratorB __fB,
6353 _InputIteratorB __lB,
6354 _InputIteratorW __fW)
6355 : __p_(__fB, __lB, __fW) {}
6357 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6358 template<class _UnaryOperation>
6359 _LIBCPP_INLINE_VISIBILITY
6360 piecewise_linear_distribution(initializer_list<result_type> __bl,
6361 _UnaryOperation __fw)
6362 : __p_(__bl, __fw) {}
6363 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6365 template<class _UnaryOperation>
6366 _LIBCPP_INLINE_VISIBILITY
6367 piecewise_linear_distribution(size_t __nw, result_type __xmin,
6368 result_type __xmax, _UnaryOperation __fw)
6369 : __p_(__nw, __xmin, __xmax, __fw) {}
6371 _LIBCPP_INLINE_VISIBILITY
6372 explicit piecewise_linear_distribution(const param_type& __p)
6375 _LIBCPP_INLINE_VISIBILITY
6378 // generating functions
6379 template<class _URNG>
6380 _LIBCPP_INLINE_VISIBILITY
6381 result_type operator()(_URNG& __g)
6382 {return (*this)(__g, __p_);}
6383 template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
6385 // property functions
6386 _LIBCPP_INLINE_VISIBILITY
6387 vector<result_type> intervals() const {return __p_.intervals();}
6388 _LIBCPP_INLINE_VISIBILITY
6389 vector<result_type> densities() const {return __p_.densities();}
6391 _LIBCPP_INLINE_VISIBILITY
6392 param_type param() const {return __p_;}
6393 _LIBCPP_INLINE_VISIBILITY
6394 void param(const param_type& __p) {__p_ = __p;}
6396 _LIBCPP_INLINE_VISIBILITY
6397 result_type min() const {return __p_.__b_.front();}
6398 _LIBCPP_INLINE_VISIBILITY
6399 result_type max() const {return __p_.__b_.back();}
6401 friend _LIBCPP_INLINE_VISIBILITY
6402 bool operator==(const piecewise_linear_distribution& __x,
6403 const piecewise_linear_distribution& __y)
6404 {return __x.__p_ == __y.__p_;}
6405 friend _LIBCPP_INLINE_VISIBILITY
6406 bool operator!=(const piecewise_linear_distribution& __x,
6407 const piecewise_linear_distribution& __y)
6408 {return !(__x == __y);}
6410 template <class _CharT, class _Traits, class _RT>
6412 basic_ostream<_CharT, _Traits>&
6413 operator<<(basic_ostream<_CharT, _Traits>& __os,
6414 const piecewise_linear_distribution<_RT>& __x);
6416 template <class _CharT, class _Traits, class _RT>
6418 basic_istream<_CharT, _Traits>&
6419 operator>>(basic_istream<_CharT, _Traits>& __is,
6420 piecewise_linear_distribution<_RT>& __x);
6423 template<class _RealType>
6424 typename piecewise_linear_distribution<_RealType>::param_type &
6425 piecewise_linear_distribution<_RealType>::param_type::operator=
6426 (const param_type& __rhs)
6429 __b_.reserve (__rhs.__b_.size ());
6430 __densities_.reserve(__rhs.__densities_.size());
6431 __areas_.reserve (__rhs.__areas_.size());
6433 // These can not throw
6435 __densities_ = __rhs.__densities_;
6436 __areas_ = __rhs.__areas_;
6441 template<class _RealType>
6443 piecewise_linear_distribution<_RealType>::param_type::__init()
6445 __areas_.assign(__densities_.size() - 1, result_type());
6446 result_type _Sp = 0;
6447 for (size_t __i = 0; __i < __areas_.size(); ++__i)
6449 __areas_[__i] = (__densities_[__i+1] + __densities_[__i]) *
6450 (__b_[__i+1] - __b_[__i]) * .5;
6451 _Sp += __areas_[__i];
6453 for (size_t __i = __areas_.size(); __i > 1;)
6456 __areas_[__i] = __areas_[__i-1] / _Sp;
6459 for (size_t __i = 1; __i < __areas_.size(); ++__i)
6460 __areas_[__i] += __areas_[__i-1];
6461 for (size_t __i = 0; __i < __densities_.size(); ++__i)
6462 __densities_[__i] /= _Sp;
6465 template<class _RealType>
6466 piecewise_linear_distribution<_RealType>::param_type::param_type()
6468 __densities_(2, 1.0),
6474 template<class _RealType>
6475 template<class _InputIteratorB, class _InputIteratorW>
6476 piecewise_linear_distribution<_RealType>::param_type::param_type(
6477 _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW)
6480 if (__b_.size() < 2)
6485 __densities_.assign(2, 1.0);
6486 __areas_.assign(1, 0.0);
6490 __densities_.reserve(__b_.size());
6491 for (size_t __i = 0; __i < __b_.size(); ++__i, ++__fW)
6492 __densities_.push_back(*__fW);
6497 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6499 template<class _RealType>
6500 template<class _UnaryOperation>
6501 piecewise_linear_distribution<_RealType>::param_type::param_type(
6502 initializer_list<result_type> __bl, _UnaryOperation __fw)
6503 : __b_(__bl.begin(), __bl.end())
6505 if (__b_.size() < 2)
6510 __densities_.assign(2, 1.0);
6511 __areas_.assign(1, 0.0);
6515 __densities_.reserve(__b_.size());
6516 for (size_t __i = 0; __i < __b_.size(); ++__i)
6517 __densities_.push_back(__fw(__b_[__i]));
6522 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6524 template<class _RealType>
6525 template<class _UnaryOperation>
6526 piecewise_linear_distribution<_RealType>::param_type::param_type(
6527 size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw)
6528 : __b_(__nw == 0 ? 2 : __nw + 1)
6530 size_t __n = __b_.size() - 1;
6531 result_type __d = (__xmax - __xmin) / __n;
6532 __densities_.reserve(__b_.size());
6533 for (size_t __i = 0; __i < __n; ++__i)
6535 __b_[__i] = __xmin + __i * __d;
6536 __densities_.push_back(__fw(__b_[__i]));
6539 __densities_.push_back(__fw(__b_[__n]));
6543 template<class _RealType>
6544 template<class _URNG>
6546 piecewise_linear_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
6548 typedef uniform_real_distribution<result_type> _Gen;
6549 result_type __u = _Gen()(__g);
6550 ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(),
6551 __u) - __p.__areas_.begin() - 1;
6552 __u -= __p.__areas_[__k];
6553 const result_type __dk = __p.__densities_[__k];
6554 const result_type __dk1 = __p.__densities_[__k+1];
6555 const result_type __deltad = __dk1 - __dk;
6556 const result_type __bk = __p.__b_[__k];
6558 return __u / __dk + __bk;
6559 const result_type __bk1 = __p.__b_[__k+1];
6560 const result_type __deltab = __bk1 - __bk;
6561 return (__bk * __dk1 - __bk1 * __dk +
6562 _VSTD::sqrt(__deltab * (__deltab * __dk * __dk + 2 * __deltad * __u))) /
6566 template <class _CharT, class _Traits, class _RT>
6567 basic_ostream<_CharT, _Traits>&
6568 operator<<(basic_ostream<_CharT, _Traits>& __os,
6569 const piecewise_linear_distribution<_RT>& __x)
6571 __save_flags<_CharT, _Traits> _(__os);
6572 __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
6573 ios_base::scientific);
6574 _CharT __sp = __os.widen(' ');
6576 size_t __n = __x.__p_.__b_.size();
6578 for (size_t __i = 0; __i < __n; ++__i)
6579 __os << __sp << __x.__p_.__b_[__i];
6580 __n = __x.__p_.__densities_.size();
6581 __os << __sp << __n;
6582 for (size_t __i = 0; __i < __n; ++__i)
6583 __os << __sp << __x.__p_.__densities_[__i];
6584 __n = __x.__p_.__areas_.size();
6585 __os << __sp << __n;
6586 for (size_t __i = 0; __i < __n; ++__i)
6587 __os << __sp << __x.__p_.__areas_[__i];
6591 template <class _CharT, class _Traits, class _RT>
6592 basic_istream<_CharT, _Traits>&
6593 operator>>(basic_istream<_CharT, _Traits>& __is,
6594 piecewise_linear_distribution<_RT>& __x)
6596 typedef piecewise_linear_distribution<_RT> _Eng;
6597 typedef typename _Eng::result_type result_type;
6598 typedef typename _Eng::param_type param_type;
6599 __save_flags<_CharT, _Traits> _(__is);
6600 __is.flags(ios_base::dec | ios_base::skipws);
6603 vector<result_type> __b(__n);
6604 for (size_t __i = 0; __i < __n; ++__i)
6607 vector<result_type> __densities(__n);
6608 for (size_t __i = 0; __i < __n; ++__i)
6609 __is >> __densities[__i];
6611 vector<result_type> __areas(__n);
6612 for (size_t __i = 0; __i < __n; ++__i)
6613 __is >> __areas[__i];
6616 swap(__x.__p_.__b_, __b);
6617 swap(__x.__p_.__densities_, __densities);
6618 swap(__x.__p_.__areas_, __areas);
6623 _LIBCPP_END_NAMESPACE_STD
6625 #endif // _LIBCPP_RANDOM