1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | #ifndef _RANDOM_H |
32 | #define _RANDOM_H 1 |
33 | |
34 | #include <vector> |
35 | #include <bits/uniform_int_dist.h> |
36 | |
37 | namespace std _GLIBCXX_VISIBILITY(default) |
38 | { |
39 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | template<typename _RealType, size_t __bits, |
57 | typename _UniformRandomNumberGenerator> |
58 | _RealType |
59 | generate_canonical(_UniformRandomNumberGenerator& __g); |
60 | |
61 | _GLIBCXX_END_NAMESPACE_VERSION |
62 | |
63 | |
64 | |
65 | |
66 | namespace __detail |
67 | { |
68 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
69 | |
70 | template<typename _UIntType, size_t __w, |
71 | bool = __w < static_cast<size_t> |
72 | (std::numeric_limits<_UIntType>::digits)> |
73 | struct _Shift |
74 | { static const _UIntType __value = 0; }; |
75 | |
76 | template<typename _UIntType, size_t __w> |
77 | struct _Shift<_UIntType, __w, true> |
78 | { static const _UIntType __value = _UIntType(1) << __w; }; |
79 | |
80 | template<int __s, |
81 | int __which = ((__s <= __CHAR_BIT__ * sizeof (int)) |
82 | + (__s <= __CHAR_BIT__ * sizeof (long)) |
83 | + (__s <= __CHAR_BIT__ * sizeof (long long)) |
84 | |
85 | + (__s <= 128))> |
86 | struct _Select_uint_least_t |
87 | { |
88 | static_assert(__which < 0, |
89 | "sorry, would be too much trouble for a slow result"); |
90 | }; |
91 | |
92 | template<int __s> |
93 | struct _Select_uint_least_t<__s, 4> |
94 | { typedef unsigned int type; }; |
95 | |
96 | template<int __s> |
97 | struct _Select_uint_least_t<__s, 3> |
98 | { typedef unsigned long type; }; |
99 | |
100 | template<int __s> |
101 | struct _Select_uint_least_t<__s, 2> |
102 | { typedef unsigned long long type; }; |
103 | |
104 | #ifdef _GLIBCXX_USE_INT128 |
105 | template<int __s> |
106 | struct _Select_uint_least_t<__s, 1> |
107 | { typedef unsigned __int128 type; }; |
108 | #endif |
109 | |
110 | |
111 | template<typename _Tp, _Tp __m, _Tp __a, _Tp __c, |
112 | bool __big_enough = (!(__m & (__m - 1)) |
113 | || (_Tp(-1) - __c) / __a >= __m - 1), |
114 | bool __schrage_ok = __m % __a < __m / __a> |
115 | struct _Mod |
116 | { |
117 | typedef typename _Select_uint_least_t<std::__lg(__a) |
118 | + std::__lg(__m) + 2>::type _Tp2; |
119 | static _Tp |
120 | __calc(_Tp __x) |
121 | { return static_cast<_Tp>((_Tp2(__a) * __x + __c) % __m); } |
122 | }; |
123 | |
124 | |
125 | template<typename _Tp, _Tp __m, _Tp __a, _Tp __c> |
126 | struct _Mod<_Tp, __m, __a, __c, false, true> |
127 | { |
128 | static _Tp |
129 | __calc(_Tp __x); |
130 | }; |
131 | |
132 | |
133 | |
134 | |
135 | template<typename _Tp, _Tp __m, _Tp __a, _Tp __c, bool __s> |
136 | struct _Mod<_Tp, __m, __a, __c, true, __s> |
137 | { |
138 | static _Tp |
139 | __calc(_Tp __x) |
140 | { |
141 | _Tp __res = __a * __x + __c; |
142 | if (__m) |
143 | __res %= __m; |
144 | return __res; |
145 | } |
146 | }; |
147 | |
148 | template<typename _Tp, _Tp __m, _Tp __a = 1, _Tp __c = 0> |
149 | inline _Tp |
150 | __mod(_Tp __x) |
151 | { return _Mod<_Tp, __m, __a, __c>::__calc(__x); } |
152 | |
153 | |
154 | |
155 | |
156 | |
157 | template<typename _Engine, typename _DInputType> |
158 | struct _Adaptor |
159 | { |
160 | static_assert(std::is_floating_point<_DInputType>::value, |
161 | "template argument must be a floating point type"); |
162 | |
163 | public: |
164 | _Adaptor(_Engine& __g) |
165 | : _M_g(__g) { } |
166 | |
167 | _DInputType |
168 | min() const |
169 | { return _DInputType(0); } |
170 | |
171 | _DInputType |
172 | max() const |
173 | { return _DInputType(1); } |
174 | |
175 | |
176 | |
177 | |
178 | |
179 | |
180 | _DInputType |
181 | operator()() |
182 | { |
183 | return std::generate_canonical<_DInputType, |
184 | std::numeric_limits<_DInputType>::digits, |
185 | _Engine>(_M_g); |
186 | } |
187 | |
188 | private: |
189 | _Engine& _M_g; |
190 | }; |
191 | |
192 | _GLIBCXX_END_NAMESPACE_VERSION |
193 | } |
194 | |
195 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
196 | |
197 | |
198 | |
199 | |
200 | |
201 | |
202 | |
203 | |
204 | |
205 | |
206 | |
207 | |
208 | |
209 | |
210 | |
211 | |
212 | |
213 | |
214 | |
215 | |
216 | |
217 | |
218 | |
219 | |
220 | |
221 | |
222 | |
223 | |
224 | |
225 | |
226 | |
227 | |
228 | |
229 | |
230 | |
231 | |
232 | |
233 | |
234 | |
235 | template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
236 | class linear_congruential_engine |
237 | { |
238 | static_assert(std::is_unsigned<_UIntType>::value, |
239 | "result_type must be an unsigned integral type"); |
240 | static_assert(__m == 0u || (__a < __m && __c < __m), |
241 | "template argument substituting __m out of bounds"); |
242 | |
243 | public: |
244 | |
245 | typedef _UIntType result_type; |
246 | |
247 | |
248 | static constexpr result_type multiplier = __a; |
249 | |
250 | static constexpr result_type increment = __c; |
251 | |
252 | static constexpr result_type modulus = __m; |
253 | static constexpr result_type default_seed = 1u; |
254 | |
255 | |
256 | |
257 | |
258 | |
259 | |
260 | |
261 | |
262 | explicit |
263 | linear_congruential_engine(result_type __s = default_seed) |
264 | { seed(__s); } |
265 | |
266 | |
267 | |
268 | |
269 | |
270 | |
271 | |
272 | template<typename _Sseq, typename = typename |
273 | std::enable_if<!std::is_same<_Sseq, linear_congruential_engine>::value> |
274 | ::type> |
275 | explicit |
276 | linear_congruential_engine(_Sseq& __q) |
277 | { seed(__q); } |
278 | |
279 | |
280 | |
281 | |
282 | |
283 | |
284 | |
285 | void |
286 | seed(result_type __s = default_seed); |
287 | |
288 | |
289 | |
290 | |
291 | |
292 | |
293 | |
294 | |
295 | template<typename _Sseq> |
296 | typename std::enable_if<std::is_class<_Sseq>::value>::type |
297 | seed(_Sseq& __q); |
298 | |
299 | |
300 | |
301 | |
302 | |
303 | |
304 | |
305 | static constexpr result_type |
306 | min() |
307 | { return __c == 0u ? 1u : 0u; } |
308 | |
309 | |
310 | |
311 | |
312 | static constexpr result_type |
313 | max() |
314 | { return __m - 1u; } |
315 | |
316 | |
317 | |
318 | |
319 | void |
320 | discard(unsigned long long __z) |
321 | { |
322 | for (; __z != 0ULL; --__z) |
323 | (*this)(); |
324 | } |
325 | |
326 | |
327 | |
328 | |
329 | result_type |
330 | operator()() |
331 | { |
332 | _M_x = __detail::__mod<_UIntType, __m, __a, __c>(_M_x); |
333 | return _M_x; |
334 | } |
335 | |
336 | |
337 | |
338 | |
339 | |
340 | |
341 | |
342 | |
343 | |
344 | |
345 | |
346 | |
347 | friend bool |
348 | operator==(const linear_congruential_engine& __lhs, |
349 | const linear_congruential_engine& __rhs) |
350 | { return __lhs._M_x == __rhs._M_x; } |
351 | |
352 | |
353 | |
354 | |
355 | |
356 | |
357 | |
358 | |
359 | |
360 | template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1, |
361 | _UIntType1 __m1, typename _CharT, typename _Traits> |
362 | friend std::basic_ostream<_CharT, _Traits>& |
363 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, |
364 | const std::linear_congruential_engine<_UIntType1, |
365 | __a1, __c1, __m1>& __lcr); |
366 | |
367 | |
368 | |
369 | |
370 | |
371 | |
372 | |
373 | |
374 | |
375 | |
376 | |
377 | |
378 | |
379 | |
380 | template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1, |
381 | _UIntType1 __m1, typename _CharT, typename _Traits> |
382 | friend std::basic_istream<_CharT, _Traits>& |
383 | operator>>(std::basic_istream<_CharT, _Traits>& __is, |
384 | std::linear_congruential_engine<_UIntType1, __a1, |
385 | __c1, __m1>& __lcr); |
386 | |
387 | private: |
388 | _UIntType _M_x; |
389 | }; |
390 | |
391 | |
392 | |
393 | |
394 | |
395 | |
396 | |
397 | |
398 | |
399 | |
400 | |
401 | |
402 | template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
403 | inline bool |
404 | operator!=(const std::linear_congruential_engine<_UIntType, __a, |
405 | __c, __m>& __lhs, |
406 | const std::linear_congruential_engine<_UIntType, __a, |
407 | __c, __m>& __rhs) |
408 | { return !(__lhs == __rhs); } |
409 | |
410 | |
411 | |
412 | |
413 | |
414 | |
415 | |
416 | |
417 | |
418 | |
419 | |
420 | |
421 | |
422 | |
423 | |
424 | |
425 | |
426 | |
427 | |
428 | |
429 | |
430 | |
431 | |
432 | |
433 | |
434 | |
435 | |
436 | |
437 | |
438 | |
439 | template<typename _UIntType, size_t __w, |
440 | size_t __n, size_t __m, size_t __r, |
441 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
442 | _UIntType __b, size_t __t, |
443 | _UIntType __c, size_t __l, _UIntType __f> |
444 | class mersenne_twister_engine |
445 | { |
446 | static_assert(std::is_unsigned<_UIntType>::value, |
447 | "result_type must be an unsigned integral type"); |
448 | static_assert(1u <= __m && __m <= __n, |
449 | "template argument substituting __m out of bounds"); |
450 | static_assert(__r <= __w, "template argument substituting " |
451 | "__r out of bound"); |
452 | static_assert(__u <= __w, "template argument substituting " |
453 | "__u out of bound"); |
454 | static_assert(__s <= __w, "template argument substituting " |
455 | "__s out of bound"); |
456 | static_assert(__t <= __w, "template argument substituting " |
457 | "__t out of bound"); |
458 | static_assert(__l <= __w, "template argument substituting " |
459 | "__l out of bound"); |
460 | static_assert(__w <= std::numeric_limits<_UIntType>::digits, |
461 | "template argument substituting __w out of bound"); |
462 | static_assert(__a <= (__detail::_Shift<_UIntType, __w>::__value - 1), |
463 | "template argument substituting __a out of bound"); |
464 | static_assert(__b <= (__detail::_Shift<_UIntType, __w>::__value - 1), |
465 | "template argument substituting __b out of bound"); |
466 | static_assert(__c <= (__detail::_Shift<_UIntType, __w>::__value - 1), |
467 | "template argument substituting __c out of bound"); |
468 | static_assert(__d <= (__detail::_Shift<_UIntType, __w>::__value - 1), |
469 | "template argument substituting __d out of bound"); |
470 | static_assert(__f <= (__detail::_Shift<_UIntType, __w>::__value - 1), |
471 | "template argument substituting __f out of bound"); |
472 | |
473 | public: |
474 | |
475 | typedef _UIntType result_type; |
476 | |
477 | |
478 | static constexpr size_t word_size = __w; |
479 | static constexpr size_t state_size = __n; |
480 | static constexpr size_t shift_size = __m; |
481 | static constexpr size_t mask_bits = __r; |
482 | static constexpr result_type xor_mask = __a; |
483 | static constexpr size_t tempering_u = __u; |
484 | static constexpr result_type tempering_d = __d; |
485 | static constexpr size_t tempering_s = __s; |
486 | static constexpr result_type tempering_b = __b; |
487 | static constexpr size_t tempering_t = __t; |
488 | static constexpr result_type tempering_c = __c; |
489 | static constexpr size_t tempering_l = __l; |
490 | static constexpr result_type initialization_multiplier = __f; |
491 | static constexpr result_type default_seed = 5489u; |
492 | |
493 | |
494 | explicit |
495 | mersenne_twister_engine(result_type __sd = default_seed) |
496 | { seed(__sd); } |
497 | |
498 | |
499 | |
500 | |
501 | |
502 | |
503 | |
504 | template<typename _Sseq, typename = typename |
505 | std::enable_if<!std::is_same<_Sseq, mersenne_twister_engine>::value> |
506 | ::type> |
507 | explicit |
508 | mersenne_twister_engine(_Sseq& __q) |
509 | { seed(__q); } |
510 | |
511 | void |
512 | seed(result_type __sd = default_seed); |
513 | |
514 | template<typename _Sseq> |
515 | typename std::enable_if<std::is_class<_Sseq>::value>::type |
516 | seed(_Sseq& __q); |
517 | |
518 | |
519 | |
520 | |
521 | static constexpr result_type |
522 | min() |
523 | { return 0; }; |
524 | |
525 | |
526 | |
527 | |
528 | static constexpr result_type |
529 | max() |
530 | { return __detail::_Shift<_UIntType, __w>::__value - 1; } |
531 | |
532 | |
533 | |
534 | |
535 | void |
536 | discard(unsigned long long __z); |
537 | |
538 | result_type |
539 | operator()(); |
540 | |
541 | |
542 | |
543 | |
544 | |
545 | |
546 | |
547 | |
548 | |
549 | |
550 | |
551 | |
552 | |
553 | friend bool |
554 | operator==(const mersenne_twister_engine& __lhs, |
555 | const mersenne_twister_engine& __rhs) |
556 | { return (std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x) |
557 | && __lhs._M_p == __rhs._M_p); } |
558 | |
559 | |
560 | |
561 | |
562 | |
563 | |
564 | |
565 | |
566 | |
567 | |
568 | |
569 | |
570 | |
571 | template<typename _UIntType1, |
572 | size_t __w1, size_t __n1, |
573 | size_t __m1, size_t __r1, |
574 | _UIntType1 __a1, size_t __u1, |
575 | _UIntType1 __d1, size_t __s1, |
576 | _UIntType1 __b1, size_t __t1, |
577 | _UIntType1 __c1, size_t __l1, _UIntType1 __f1, |
578 | typename _CharT, typename _Traits> |
579 | friend std::basic_ostream<_CharT, _Traits>& |
580 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, |
581 | const std::mersenne_twister_engine<_UIntType1, __w1, __n1, |
582 | __m1, __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1, |
583 | __l1, __f1>& __x); |
584 | |
585 | |
586 | |
587 | |
588 | |
589 | |
590 | |
591 | |
592 | |
593 | |
594 | |
595 | |
596 | |
597 | template<typename _UIntType1, |
598 | size_t __w1, size_t __n1, |
599 | size_t __m1, size_t __r1, |
600 | _UIntType1 __a1, size_t __u1, |
601 | _UIntType1 __d1, size_t __s1, |
602 | _UIntType1 __b1, size_t __t1, |
603 | _UIntType1 __c1, size_t __l1, _UIntType1 __f1, |
604 | typename _CharT, typename _Traits> |
605 | friend std::basic_istream<_CharT, _Traits>& |
606 | operator>>(std::basic_istream<_CharT, _Traits>& __is, |
607 | std::mersenne_twister_engine<_UIntType1, __w1, __n1, __m1, |
608 | __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1, |
609 | __l1, __f1>& __x); |
610 | |
611 | private: |
612 | void _M_gen_rand(); |
613 | |
614 | _UIntType _M_x[state_size]; |
615 | size_t _M_p; |
616 | }; |
617 | |
618 | |
619 | |
620 | |
621 | |
622 | |
623 | |
624 | |
625 | |
626 | |
627 | |
628 | |
629 | |
630 | template<typename _UIntType, size_t __w, |
631 | size_t __n, size_t __m, size_t __r, |
632 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
633 | _UIntType __b, size_t __t, |
634 | _UIntType __c, size_t __l, _UIntType __f> |
635 | inline bool |
636 | operator!=(const std::mersenne_twister_engine<_UIntType, __w, __n, __m, |
637 | __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __lhs, |
638 | const std::mersenne_twister_engine<_UIntType, __w, __n, __m, |
639 | __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __rhs) |
640 | { return !(__lhs == __rhs); } |
641 | |
642 | |
643 | |
644 | |
645 | |
646 | |
647 | |
648 | |
649 | |
650 | |
651 | |
652 | |
653 | |
654 | |
655 | |
656 | |
657 | |
658 | template<typename _UIntType, size_t __w, size_t __s, size_t __r> |
659 | class subtract_with_carry_engine |
660 | { |
661 | static_assert(std::is_unsigned<_UIntType>::value, |
662 | "result_type must be an unsigned integral type"); |
663 | static_assert(0u < __s && __s < __r, |
664 | "0 < s < r"); |
665 | static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits, |
666 | "template argument substituting __w out of bounds"); |
667 | |
668 | public: |
669 | |
670 | typedef _UIntType result_type; |
671 | |
672 | |
673 | static constexpr size_t word_size = __w; |
674 | static constexpr size_t short_lag = __s; |
675 | static constexpr size_t long_lag = __r; |
676 | static constexpr result_type default_seed = 19780503u; |
677 | |
678 | |
679 | |
680 | |
681 | |
682 | explicit |
683 | subtract_with_carry_engine(result_type __sd = default_seed) |
684 | { seed(__sd); } |
685 | |
686 | |
687 | |
688 | |
689 | |
690 | |
691 | |
692 | template<typename _Sseq, typename = typename |
693 | std::enable_if<!std::is_same<_Sseq, subtract_with_carry_engine>::value> |
694 | ::type> |
695 | explicit |
696 | subtract_with_carry_engine(_Sseq& __q) |
697 | { seed(__q); } |
698 | |
699 | |
700 | |
701 | |
702 | |
703 | |
704 | |
705 | |
706 | |
707 | |
708 | |
709 | |
710 | |
711 | void |
712 | seed(result_type __sd = default_seed); |
713 | |
714 | |
715 | |
716 | |
717 | |
718 | template<typename _Sseq> |
719 | typename std::enable_if<std::is_class<_Sseq>::value>::type |
720 | seed(_Sseq& __q); |
721 | |
722 | |
723 | |
724 | |
725 | |
726 | static constexpr result_type |
727 | min() |
728 | { return 0; } |
729 | |
730 | |
731 | |
732 | |
733 | |
734 | static constexpr result_type |
735 | max() |
736 | { return __detail::_Shift<_UIntType, __w>::__value - 1; } |
737 | |
738 | |
739 | |
740 | |
741 | void |
742 | discard(unsigned long long __z) |
743 | { |
744 | for (; __z != 0ULL; --__z) |
745 | (*this)(); |
746 | } |
747 | |
748 | |
749 | |
750 | |
751 | result_type |
752 | operator()(); |
753 | |
754 | |
755 | |
756 | |
757 | |
758 | |
759 | |
760 | |
761 | |
762 | |
763 | |
764 | |
765 | |
766 | friend bool |
767 | operator==(const subtract_with_carry_engine& __lhs, |
768 | const subtract_with_carry_engine& __rhs) |
769 | { return (std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x) |
770 | && __lhs._M_carry == __rhs._M_carry |
771 | && __lhs._M_p == __rhs._M_p); } |
772 | |
773 | |
774 | |
775 | |
776 | |
777 | |
778 | |
779 | |
780 | |
781 | |
782 | |
783 | |
784 | |
785 | template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1, |
786 | typename _CharT, typename _Traits> |
787 | friend std::basic_ostream<_CharT, _Traits>& |
788 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, |
789 | const std::subtract_with_carry_engine<_UIntType1, __w1, |
790 | __s1, __r1>& __x); |
791 | |
792 | |
793 | |
794 | |
795 | |
796 | |
797 | |
798 | |
799 | |
800 | |
801 | |
802 | |
803 | |
804 | template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1, |
805 | typename _CharT, typename _Traits> |
806 | friend std::basic_istream<_CharT, _Traits>& |
807 | operator>>(std::basic_istream<_CharT, _Traits>& __is, |
808 | std::subtract_with_carry_engine<_UIntType1, __w1, |
809 | __s1, __r1>& __x); |
810 | |
811 | private: |
812 | |
813 | _UIntType _M_x[long_lag]; |
814 | _UIntType _M_carry; |
815 | size_t _M_p; |
816 | }; |
817 | |
818 | |
819 | |
820 | |
821 | |
822 | |
823 | |
824 | |
825 | |
826 | |
827 | |
828 | |
829 | |
830 | template<typename _UIntType, size_t __w, size_t __s, size_t __r> |
831 | inline bool |
832 | operator!=(const std::subtract_with_carry_engine<_UIntType, __w, |
833 | __s, __r>& __lhs, |
834 | const std::subtract_with_carry_engine<_UIntType, __w, |
835 | __s, __r>& __rhs) |
836 | { return !(__lhs == __rhs); } |
837 | |
838 | |
839 | |
840 | |
841 | |
842 | |
843 | |
844 | |
845 | template<typename _RandomNumberEngine, size_t __p, size_t __r> |
846 | class discard_block_engine |
847 | { |
848 | static_assert(1 <= __r && __r <= __p, |
849 | "template argument substituting __r out of bounds"); |
850 | |
851 | public: |
852 | |
853 | typedef typename _RandomNumberEngine::result_type result_type; |
854 | |
855 | |
856 | static constexpr size_t block_size = __p; |
857 | static constexpr size_t used_block = __r; |
858 | |
859 | |
860 | |
861 | |
862 | |
863 | |
864 | discard_block_engine() |
865 | : _M_b(), _M_n(0) { } |
866 | |
867 | |
868 | |
869 | |
870 | |
871 | |
872 | |
873 | explicit |
874 | discard_block_engine(const _RandomNumberEngine& __rng) |
875 | : _M_b(__rng), _M_n(0) { } |
876 | |
877 | |
878 | |
879 | |
880 | |
881 | |
882 | |
883 | explicit |
884 | discard_block_engine(_RandomNumberEngine&& __rng) |
885 | : _M_b(std::move(__rng)), _M_n(0) { } |
886 | |
887 | |
888 | |
889 | |
890 | |
891 | |
892 | |
893 | explicit |
894 | discard_block_engine(result_type __s) |
895 | : _M_b(__s), _M_n(0) { } |
896 | |
897 | |
898 | |
899 | |
900 | |
901 | |
902 | template<typename _Sseq, typename = typename |
903 | std::enable_if<!std::is_same<_Sseq, discard_block_engine>::value |
904 | && !std::is_same<_Sseq, _RandomNumberEngine>::value> |
905 | ::type> |
906 | explicit |
907 | discard_block_engine(_Sseq& __q) |
908 | : _M_b(__q), _M_n(0) |
909 | { } |
910 | |
911 | |
912 | |
913 | |
914 | |
915 | void |
916 | seed() |
917 | { |
918 | _M_b.seed(); |
919 | _M_n = 0; |
920 | } |
921 | |
922 | |
923 | |
924 | |
925 | |
926 | void |
927 | seed(result_type __s) |
928 | { |
929 | _M_b.seed(__s); |
930 | _M_n = 0; |
931 | } |
932 | |
933 | |
934 | |
935 | |
936 | |
937 | |
938 | template<typename _Sseq> |
939 | void |
940 | seed(_Sseq& __q) |
941 | { |
942 | _M_b.seed(__q); |
943 | _M_n = 0; |
944 | } |
945 | |
946 | |
947 | |
948 | |
949 | |
950 | const _RandomNumberEngine& |
951 | base() const noexcept |
952 | { return _M_b; } |
953 | |
954 | |
955 | |
956 | |
957 | static constexpr result_type |
958 | min() |
959 | { return _RandomNumberEngine::min(); } |
960 | |
961 | |
962 | |
963 | |
964 | static constexpr result_type |
965 | max() |
966 | { return _RandomNumberEngine::max(); } |
967 | |
968 | |
969 | |
970 | |
971 | void |
972 | discard(unsigned long long __z) |
973 | { |
974 | for (; __z != 0ULL; --__z) |
975 | (*this)(); |
976 | } |
977 | |
978 | |
979 | |
980 | |
981 | result_type |
982 | operator()(); |
983 | |
984 | |
985 | |
986 | |
987 | |
988 | |
989 | |
990 | |
991 | |
992 | |
993 | |
994 | |
995 | friend bool |
996 | operator==(const discard_block_engine& __lhs, |
997 | const discard_block_engine& __rhs) |
998 | { return __lhs._M_b == __rhs._M_b && __lhs._M_n == __rhs._M_n; } |
999 | |
1000 | |
1001 | |
1002 | |
1003 | |
1004 | |
1005 | |
1006 | |
1007 | |
1008 | |
1009 | |
1010 | |
1011 | template<typename _RandomNumberEngine1, size_t __p1, size_t __r1, |
1012 | typename _CharT, typename _Traits> |
1013 | friend std::basic_ostream<_CharT, _Traits>& |
1014 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, |
1015 | const std::discard_block_engine<_RandomNumberEngine1, |
1016 | __p1, __r1>& __x); |
1017 | |
1018 | |
1019 | |
1020 | |
1021 | |
1022 | |
1023 | |
1024 | |
1025 | |
1026 | |
1027 | |
1028 | |
1029 | template<typename _RandomNumberEngine1, size_t __p1, size_t __r1, |
1030 | typename _CharT, typename _Traits> |
1031 | friend std::basic_istream<_CharT, _Traits>& |
1032 | operator>>(std::basic_istream<_CharT, _Traits>& __is, |
1033 | std::discard_block_engine<_RandomNumberEngine1, |
1034 | __p1, __r1>& __x); |
1035 | |
1036 | private: |
1037 | _RandomNumberEngine _M_b; |
1038 | size_t _M_n; |
1039 | }; |
1040 | |
1041 | |
1042 | |
1043 | |
1044 | |
1045 | |
1046 | |
1047 | |
1048 | |
1049 | |
1050 | |
1051 | |
1052 | template<typename _RandomNumberEngine, size_t __p, size_t __r> |
1053 | inline bool |
1054 | operator!=(const std::discard_block_engine<_RandomNumberEngine, __p, |
1055 | __r>& __lhs, |
1056 | const std::discard_block_engine<_RandomNumberEngine, __p, |
1057 | __r>& __rhs) |
1058 | { return !(__lhs == __rhs); } |
1059 | |
1060 | |
1061 | |
1062 | |
1063 | |
1064 | |
1065 | template<typename _RandomNumberEngine, size_t __w, typename _UIntType> |
1066 | class independent_bits_engine |
1067 | { |
1068 | static_assert(std::is_unsigned<_UIntType>::value, |
1069 | "result_type must be an unsigned integral type"); |
1070 | static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits, |
1071 | "template argument substituting __w out of bounds"); |
1072 | |
1073 | public: |
1074 | |
1075 | typedef _UIntType result_type; |
1076 | |
1077 | |
1078 | |
1079 | |
1080 | |
1081 | |
1082 | independent_bits_engine() |
1083 | : _M_b() { } |
1084 | |
1085 | |
1086 | |
1087 | |
1088 | |
1089 | |
1090 | |
1091 | explicit |
1092 | independent_bits_engine(const _RandomNumberEngine& __rng) |
1093 | : _M_b(__rng) { } |
1094 | |
1095 | |
1096 | |
1097 | |
1098 | |
1099 | |
1100 | |
1101 | explicit |
1102 | independent_bits_engine(_RandomNumberEngine&& __rng) |
1103 | : _M_b(std::move(__rng)) { } |
1104 | |
1105 | |
1106 | |
1107 | |
1108 | |
1109 | |
1110 | |
1111 | explicit |
1112 | independent_bits_engine(result_type __s) |
1113 | : _M_b(__s) { } |
1114 | |
1115 | |
1116 | |
1117 | |
1118 | |
1119 | |
1120 | template<typename _Sseq, typename = typename |
1121 | std::enable_if<!std::is_same<_Sseq, independent_bits_engine>::value |
1122 | && !std::is_same<_Sseq, _RandomNumberEngine>::value> |
1123 | ::type> |
1124 | explicit |
1125 | independent_bits_engine(_Sseq& __q) |
1126 | : _M_b(__q) |
1127 | { } |
1128 | |
1129 | |
1130 | |
1131 | |
1132 | |
1133 | void |
1134 | seed() |
1135 | { _M_b.seed(); } |
1136 | |
1137 | |
1138 | |
1139 | |
1140 | |
1141 | void |
1142 | seed(result_type __s) |
1143 | { _M_b.seed(__s); } |
1144 | |
1145 | |
1146 | |
1147 | |
1148 | |
1149 | |
1150 | template<typename _Sseq> |
1151 | void |
1152 | seed(_Sseq& __q) |
1153 | { _M_b.seed(__q); } |
1154 | |
1155 | |
1156 | |
1157 | |
1158 | |
1159 | const _RandomNumberEngine& |
1160 | base() const noexcept |
1161 | { return _M_b; } |
1162 | |
1163 | |
1164 | |
1165 | |
1166 | static constexpr result_type |
1167 | min() |
1168 | { return 0U; } |
1169 | |
1170 | |
1171 | |
1172 | |
1173 | static constexpr result_type |
1174 | max() |
1175 | { return __detail::_Shift<_UIntType, __w>::__value - 1; } |
1176 | |
1177 | |
1178 | |
1179 | |
1180 | void |
1181 | discard(unsigned long long __z) |
1182 | { |
1183 | for (; __z != 0ULL; --__z) |
1184 | (*this)(); |
1185 | } |
1186 | |
1187 | |
1188 | |
1189 | |
1190 | result_type |
1191 | operator()(); |
1192 | |
1193 | |
1194 | |
1195 | |
1196 | |
1197 | |
1198 | |
1199 | |
1200 | |
1201 | |
1202 | |
1203 | |
1204 | |
1205 | friend bool |
1206 | operator==(const independent_bits_engine& __lhs, |
1207 | const independent_bits_engine& __rhs) |
1208 | { return __lhs._M_b == __rhs._M_b; } |
1209 | |
1210 | |
1211 | |
1212 | |
1213 | |
1214 | |
1215 | |
1216 | |
1217 | |
1218 | |
1219 | |
1220 | |
1221 | |
1222 | template<typename _CharT, typename _Traits> |
1223 | friend std::basic_istream<_CharT, _Traits>& |
1224 | operator>>(std::basic_istream<_CharT, _Traits>& __is, |
1225 | std::independent_bits_engine<_RandomNumberEngine, |
1226 | __w, _UIntType>& __x) |
1227 | { |
1228 | __is >> __x._M_b; |
1229 | return __is; |
1230 | } |
1231 | |
1232 | private: |
1233 | _RandomNumberEngine _M_b; |
1234 | }; |
1235 | |
1236 | |
1237 | |
1238 | |
1239 | |
1240 | |
1241 | |
1242 | |
1243 | |
1244 | |
1245 | |
1246 | |
1247 | |
1248 | template<typename _RandomNumberEngine, size_t __w, typename _UIntType> |
1249 | inline bool |
1250 | operator!=(const std::independent_bits_engine<_RandomNumberEngine, __w, |
1251 | _UIntType>& __lhs, |
1252 | const std::independent_bits_engine<_RandomNumberEngine, __w, |
1253 | _UIntType>& __rhs) |
1254 | { return !(__lhs == __rhs); } |
1255 | |
1256 | |
1257 | |
1258 | |
1259 | |
1260 | |
1261 | |
1262 | |
1263 | |
1264 | |
1265 | |
1266 | template<typename _RandomNumberEngine, size_t __w, typename _UIntType, |
1267 | typename _CharT, typename _Traits> |
1268 | std::basic_ostream<_CharT, _Traits>& |
1269 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, |
1270 | const std::independent_bits_engine<_RandomNumberEngine, |
1271 | __w, _UIntType>& __x) |
1272 | { |
1273 | __os << __x.base(); |
1274 | return __os; |
1275 | } |
1276 | |
1277 | |
1278 | |
1279 | |
1280 | |
1281 | |
1282 | |
1283 | template<typename _RandomNumberEngine, size_t __k> |
1284 | class shuffle_order_engine |
1285 | { |
1286 | static_assert(1u <= __k, "template argument substituting " |
1287 | "__k out of bound"); |
1288 | |
1289 | public: |
1290 | |
1291 | typedef typename _RandomNumberEngine::result_type result_type; |
1292 | |
1293 | static constexpr size_t table_size = __k; |
1294 | |
1295 | |
1296 | |
1297 | |
1298 | |
1299 | |
1300 | shuffle_order_engine() |
1301 | : _M_b() |
1302 | { _M_initialize(); } |
1303 | |
1304 | |
1305 | |
1306 | |
1307 | |
1308 | |
1309 | |
1310 | explicit |
1311 | shuffle_order_engine(const _RandomNumberEngine& __rng) |
1312 | : _M_b(__rng) |
1313 | { _M_initialize(); } |
1314 | |
1315 | |
1316 | |
1317 | |
1318 | |
1319 | |
1320 | |
1321 | explicit |
1322 | shuffle_order_engine(_RandomNumberEngine&& __rng) |
1323 | : _M_b(std::move(__rng)) |
1324 | { _M_initialize(); } |
1325 | |
1326 | |
1327 | |
1328 | |
1329 | |
1330 | |
1331 | |
1332 | explicit |
1333 | shuffle_order_engine(result_type __s) |
1334 | : _M_b(__s) |
1335 | { _M_initialize(); } |
1336 | |
1337 | |
1338 | |
1339 | |
1340 | |
1341 | |
1342 | template<typename _Sseq, typename = typename |
1343 | std::enable_if<!std::is_same<_Sseq, shuffle_order_engine>::value |
1344 | && !std::is_same<_Sseq, _RandomNumberEngine>::value> |
1345 | ::type> |
1346 | explicit |
1347 | shuffle_order_engine(_Sseq& __q) |
1348 | : _M_b(__q) |
1349 | { _M_initialize(); } |
1350 | |
1351 | |
1352 | |
1353 | |
1354 | |
1355 | void |
1356 | seed() |
1357 | { |
1358 | _M_b.seed(); |
1359 | _M_initialize(); |
1360 | } |
1361 | |
1362 | |
1363 | |
1364 | |
1365 | |
1366 | void |
1367 | seed(result_type __s) |
1368 | { |
1369 | _M_b.seed(__s); |
1370 | _M_initialize(); |
1371 | } |
1372 | |
1373 | |
1374 | |
1375 | |
1376 | |
1377 | |
1378 | template<typename _Sseq> |
1379 | void |
1380 | seed(_Sseq& __q) |
1381 | { |
1382 | _M_b.seed(__q); |
1383 | _M_initialize(); |
1384 | } |
1385 | |
1386 | |
1387 | |
1388 | |
1389 | const _RandomNumberEngine& |
1390 | base() const noexcept |
1391 | { return _M_b; } |
1392 | |
1393 | |
1394 | |
1395 | |
1396 | static constexpr result_type |
1397 | min() |
1398 | { return _RandomNumberEngine::min(); } |
1399 | |
1400 | |
1401 | |
1402 | |
1403 | static constexpr result_type |
1404 | max() |
1405 | { return _RandomNumberEngine::max(); } |
1406 | |
1407 | |
1408 | |
1409 | |
1410 | void |
1411 | discard(unsigned long long __z) |
1412 | { |
1413 | for (; __z != 0ULL; --__z) |
1414 | (*this)(); |
1415 | } |
1416 | |
1417 | |
1418 | |
1419 | |
1420 | result_type |
1421 | operator()(); |
1422 | |
1423 | |
1424 | |
1425 | |
1426 | |
1427 | |
1428 | |
1429 | |
1430 | |
1431 | |
1432 | |
1433 | |
1434 | friend bool |
1435 | operator==(const shuffle_order_engine& __lhs, |
1436 | const shuffle_order_engine& __rhs) |
1437 | { return (__lhs._M_b == __rhs._M_b |
1438 | && std::equal(__lhs._M_v, __lhs._M_v + __k, __rhs._M_v) |
1439 | && __lhs._M_y == __rhs._M_y); } |
1440 | |
1441 | |
1442 | |
1443 | |
1444 | |
1445 | |
1446 | |
1447 | |
1448 | |
1449 | |
1450 | |
1451 | |
1452 | template<typename _RandomNumberEngine1, size_t __k1, |
1453 | typename _CharT, typename _Traits> |
1454 | friend std::basic_ostream<_CharT, _Traits>& |
1455 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, |
1456 | const std::shuffle_order_engine<_RandomNumberEngine1, |
1457 | __k1>& __x); |
1458 | |
1459 | |
1460 | |
1461 | |
1462 | |
1463 | |
1464 | |
1465 | |
1466 | |
1467 | |
1468 | |
1469 | |
1470 | template<typename _RandomNumberEngine1, size_t __k1, |
1471 | typename _CharT, typename _Traits> |
1472 | friend std::basic_istream<_CharT, _Traits>& |
1473 | operator>>(std::basic_istream<_CharT, _Traits>& __is, |
1474 | std::shuffle_order_engine<_RandomNumberEngine1, __k1>& __x); |
1475 | |
1476 | private: |
1477 | void _M_initialize() |
1478 | { |
1479 | for (size_t __i = 0; __i < __k; ++__i) |
1480 | _M_v[__i] = _M_b(); |
1481 | _M_y = _M_b(); |
1482 | } |
1483 | |
1484 | _RandomNumberEngine _M_b; |
1485 | result_type _M_v[__k]; |
1486 | result_type _M_y; |
1487 | }; |
1488 | |
1489 | |
1490 | |
1491 | |
1492 | |
1493 | |
1494 | |
1495 | |
1496 | |
1497 | |
1498 | |
1499 | |
1500 | template<typename _RandomNumberEngine, size_t __k> |
1501 | inline bool |
1502 | operator!=(const std::shuffle_order_engine<_RandomNumberEngine, |
1503 | __k>& __lhs, |
1504 | const std::shuffle_order_engine<_RandomNumberEngine, |
1505 | __k>& __rhs) |
1506 | { return !(__lhs == __rhs); } |
1507 | |
1508 | |
1509 | |
1510 | |
1511 | |
1512 | typedef linear_congruential_engine<uint_fast32_t, 16807UL, 0UL, 2147483647UL> |
1513 | minstd_rand0; |
1514 | |
1515 | |
1516 | |
1517 | |
1518 | typedef linear_congruential_engine<uint_fast32_t, 48271UL, 0UL, 2147483647UL> |
1519 | minstd_rand; |
1520 | |
1521 | |
1522 | |
1523 | |
1524 | |
1525 | |
1526 | |
1527 | |
1528 | |
1529 | typedef mersenne_twister_engine< |
1530 | uint_fast32_t, |
1531 | 32, 624, 397, 31, |
1532 | 0x9908b0dfUL, 11, |
1533 | 0xffffffffUL, 7, |
1534 | 0x9d2c5680UL, 15, |
1535 | 0xefc60000UL, 18, 1812433253UL> mt19937; |
1536 | |
1537 | |
1538 | |
1539 | |
1540 | typedef mersenne_twister_engine< |
1541 | uint_fast64_t, |
1542 | 64, 312, 156, 31, |
1543 | 0xb5026f5aa96619e9ULL, 29, |
1544 | 0x5555555555555555ULL, 17, |
1545 | 0x71d67fffeda60000ULL, 37, |
1546 | 0xfff7eee000000000ULL, 43, |
1547 | 6364136223846793005ULL> mt19937_64; |
1548 | |
1549 | typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> |
1550 | ranlux24_base; |
1551 | |
1552 | typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> |
1553 | ranlux48_base; |
1554 | |
1555 | typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24; |
1556 | |
1557 | typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48; |
1558 | |
1559 | typedef shuffle_order_engine<minstd_rand0, 256> knuth_b; |
1560 | |
1561 | typedef minstd_rand0 default_random_engine; |
1562 | |
1563 | |
1564 | |
1565 | |
1566 | |
1567 | class random_device |
1568 | { |
1569 | public: |
1570 | |
1571 | typedef unsigned int result_type; |
1572 | |
1573 | |
1574 | |
1575 | #ifdef _GLIBCXX_USE_RANDOM_TR1 |
1576 | |
1577 | explicit |
1578 | random_device(const std::string& __token = "default") |
1579 | { |
1580 | _M_init(__token); |
1581 | } |
1582 | |
1583 | ~random_device() |
1584 | { _M_fini(); } |
1585 | |
1586 | #else |
1587 | |
1588 | explicit |
1589 | random_device(const std::string& __token = "mt19937") |
1590 | { _M_init_pretr1(__token); } |
1591 | |
1592 | public: |
1593 | |
1594 | #endif |
1595 | |
1596 | static constexpr result_type |
1597 | min() |
1598 | { return std::numeric_limits<result_type>::min(); } |
1599 | |
1600 | static constexpr result_type |
1601 | max() |
1602 | { return std::numeric_limits<result_type>::max(); } |
1603 | |
1604 | double |
1605 | entropy() const noexcept |
1606 | { return 0.0; } |
1607 | |
1608 | result_type |
1609 | operator()() |
1610 | { |
1611 | #ifdef _GLIBCXX_USE_RANDOM_TR1 |
1612 | return this->_M_getval(); |
1613 | #else |
1614 | return this->_M_getval_pretr1(); |
1615 | #endif |
1616 | } |
1617 | |
1618 | |
1619 | random_device(const random_device&) = delete; |
1620 | void operator=(const random_device&) = delete; |
1621 | |
1622 | private: |
1623 | |
1624 | void _M_init(const std::string& __token); |
1625 | void _M_init_pretr1(const std::string& __token); |
1626 | void _M_fini(); |
1627 | |
1628 | result_type _M_getval(); |
1629 | result_type _M_getval_pretr1(); |
1630 | |
1631 | union |
1632 | { |
1633 | void* _M_file; |
1634 | mt19937 _M_mt; |
1635 | }; |
1636 | }; |
1637 | |
1638 | |
1639 | |
1640 | |
1641 | |
1642 | |
1643 | |
1644 | |
1645 | |
1646 | |
1647 | |
1648 | |
1649 | |
1650 | |
1651 | |
1652 | |
1653 | |
1654 | |
1655 | |
1656 | |
1657 | |
1658 | template<typename _IntType> |
1659 | inline bool |
1660 | operator!=(const std::uniform_int_distribution<_IntType>& __d1, |
1661 | const std::uniform_int_distribution<_IntType>& __d2) |
1662 | { return !(__d1 == __d2); } |
1663 | |
1664 | |
1665 | |
1666 | |
1667 | |
1668 | |
1669 | |
1670 | |
1671 | |
1672 | |
1673 | |
1674 | template<typename _IntType, typename _CharT, typename _Traits> |
1675 | std::basic_ostream<_CharT, _Traits>& |
1676 | operator<<(std::basic_ostream<_CharT, _Traits>&, |
1677 | const std::uniform_int_distribution<_IntType>&); |
1678 | |
1679 | |
1680 | |
1681 | |
1682 | |
1683 | |
1684 | |
1685 | |
1686 | |
1687 | |
1688 | template<typename _IntType, typename _CharT, typename _Traits> |
1689 | std::basic_istream<_CharT, _Traits>& |
1690 | operator>>(std::basic_istream<_CharT, _Traits>&, |
1691 | std::uniform_int_distribution<_IntType>&); |
1692 | |
1693 | |
1694 | |
1695 | |
1696 | |
1697 | |
1698 | |
1699 | |
1700 | |
1701 | template<typename _RealType = double> |
1702 | class uniform_real_distribution |
1703 | { |
1704 | static_assert(std::is_floating_point<_RealType>::value, |
1705 | "result_type must be a floating point type"); |
1706 | |
1707 | public: |
1708 | |
1709 | typedef _RealType result_type; |
1710 | |
1711 | |
1712 | struct param_type |
1713 | { |
1714 | typedef uniform_real_distribution<_RealType> distribution_type; |
1715 | |
1716 | explicit |
1717 | param_type(_RealType __a = _RealType(0), |
1718 | _RealType __b = _RealType(1)) |
1719 | : _M_a(__a), _M_b(__b) |
1720 | { |
1721 | __glibcxx_assert(_M_a <= _M_b); |
1722 | } |
1723 | |
1724 | result_type |
1725 | a() const |
1726 | { return _M_a; } |
1727 | |
1728 | result_type |
1729 | b() const |
1730 | { return _M_b; } |
1731 | |
1732 | friend bool |
1733 | operator==(const param_type& __p1, const param_type& __p2) |
1734 | { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; } |
1735 | |
1736 | friend bool |
1737 | operator!=(const param_type& __p1, const param_type& __p2) |
1738 | { return !(__p1 == __p2); } |
1739 | |
1740 | private: |
1741 | _RealType _M_a; |
1742 | _RealType _M_b; |
1743 | }; |
1744 | |
1745 | public: |
1746 | |
1747 | |
1748 | |
1749 | |
1750 | |
1751 | |
1752 | explicit |
1753 | uniform_real_distribution(_RealType __a = _RealType(0), |
1754 | _RealType __b = _RealType(1)) |
1755 | : _M_param(__a, __b) |
1756 | { } |
1757 | |
1758 | explicit |
1759 | uniform_real_distribution(const param_type& __p) |
1760 | : _M_param(__p) |
1761 | { } |
1762 | |
1763 | |
1764 | |
1765 | |
1766 | |
1767 | |
1768 | void |
1769 | reset() { } |
1770 | |
1771 | result_type |
1772 | a() const |
1773 | { return _M_param.a(); } |
1774 | |
1775 | result_type |
1776 | b() const |
1777 | { return _M_param.b(); } |
1778 | |
1779 | |
1780 | |
1781 | |
1782 | param_type |
1783 | param() const |
1784 | { return _M_param; } |
1785 | |
1786 | |
1787 | |
1788 | |
1789 | |
1790 | void |
1791 | param(const param_type& __param) |
1792 | { _M_param = __param; } |
1793 | |
1794 | |
1795 | |
1796 | |
1797 | result_type |
1798 | min() const |
1799 | { return this->a(); } |
1800 | |
1801 | |
1802 | |
1803 | |
1804 | result_type |
1805 | max() const |
1806 | { return this->b(); } |
1807 | |
1808 | |
1809 | |
1810 | |
1811 | template<typename _UniformRandomNumberGenerator> |
1812 | result_type |
1813 | operator()(_UniformRandomNumberGenerator& __urng) |
1814 | { return this->operator()(__urng, _M_param); } |
1815 | |
1816 | template<typename _UniformRandomNumberGenerator> |
1817 | result_type |
1818 | operator()(_UniformRandomNumberGenerator& __urng, |
1819 | const param_type& __p) |
1820 | { |
1821 | __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> |
1822 | __aurng(__urng); |
1823 | return (__aurng() * (__p.b() - __p.a())) + __p.a(); |
1824 | } |
1825 | |
1826 | template<typename _ForwardIterator, |
1827 | typename _UniformRandomNumberGenerator> |
1828 | void |
1829 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
1830 | _UniformRandomNumberGenerator& __urng) |
1831 | { this->__generate(__f, __t, __urng, _M_param); } |
1832 | |
1833 | template<typename _ForwardIterator, |
1834 | typename _UniformRandomNumberGenerator> |
1835 | void |
1836 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
1837 | _UniformRandomNumberGenerator& __urng, |
1838 | const param_type& __p) |
1839 | { this->__generate_impl(__f, __t, __urng, __p); } |
1840 | |
1841 | template<typename _UniformRandomNumberGenerator> |
1842 | void |
1843 | __generate(result_type* __f, result_type* __t, |
1844 | _UniformRandomNumberGenerator& __urng, |
1845 | const param_type& __p) |
1846 | { this->__generate_impl(__f, __t, __urng, __p); } |
1847 | |
1848 | |
1849 | |
1850 | |
1851 | |
1852 | friend bool |
1853 | operator==(const uniform_real_distribution& __d1, |
1854 | const uniform_real_distribution& __d2) |
1855 | { return __d1._M_param == __d2._M_param; } |
1856 | |
1857 | private: |
1858 | template<typename _ForwardIterator, |
1859 | typename _UniformRandomNumberGenerator> |
1860 | void |
1861 | __generate_impl(_ForwardIterator __f, _ForwardIterator __t, |
1862 | _UniformRandomNumberGenerator& __urng, |
1863 | const param_type& __p); |
1864 | |
1865 | param_type _M_param; |
1866 | }; |
1867 | |
1868 | |
1869 | |
1870 | |
1871 | |
1872 | template<typename _IntType> |
1873 | inline bool |
1874 | operator!=(const std::uniform_real_distribution<_IntType>& __d1, |
1875 | const std::uniform_real_distribution<_IntType>& __d2) |
1876 | { return !(__d1 == __d2); } |
1877 | |
1878 | |
1879 | |
1880 | |
1881 | |
1882 | |
1883 | |
1884 | |
1885 | |
1886 | |
1887 | |
1888 | template<typename _RealType, typename _CharT, typename _Traits> |
1889 | std::basic_ostream<_CharT, _Traits>& |
1890 | operator<<(std::basic_ostream<_CharT, _Traits>&, |
1891 | const std::uniform_real_distribution<_RealType>&); |
1892 | |
1893 | |
1894 | |
1895 | |
1896 | |
1897 | |
1898 | |
1899 | |
1900 | |
1901 | |
1902 | template<typename _RealType, typename _CharT, typename _Traits> |
1903 | std::basic_istream<_CharT, _Traits>& |
1904 | operator>>(std::basic_istream<_CharT, _Traits>&, |
1905 | std::uniform_real_distribution<_RealType>&); |
1906 | |
1907 | |
1908 | |
1909 | |
1910 | |
1911 | |
1912 | |
1913 | |
1914 | |
1915 | |
1916 | |
1917 | |
1918 | |
1919 | |
1920 | |
1921 | |
1922 | |
1923 | |
1924 | template<typename _RealType = double> |
1925 | class normal_distribution |
1926 | { |
1927 | static_assert(std::is_floating_point<_RealType>::value, |
1928 | "result_type must be a floating point type"); |
1929 | |
1930 | public: |
1931 | |
1932 | typedef _RealType result_type; |
1933 | |
1934 | |
1935 | struct param_type |
1936 | { |
1937 | typedef normal_distribution<_RealType> distribution_type; |
1938 | |
1939 | explicit |
1940 | param_type(_RealType __mean = _RealType(0), |
1941 | _RealType __stddev = _RealType(1)) |
1942 | : _M_mean(__mean), _M_stddev(__stddev) |
1943 | { |
1944 | __glibcxx_assert(_M_stddev > _RealType(0)); |
1945 | } |
1946 | |
1947 | _RealType |
1948 | mean() const |
1949 | { return _M_mean; } |
1950 | |
1951 | _RealType |
1952 | stddev() const |
1953 | { return _M_stddev; } |
1954 | |
1955 | friend bool |
1956 | operator==(const param_type& __p1, const param_type& __p2) |
1957 | { return (__p1._M_mean == __p2._M_mean |
1958 | && __p1._M_stddev == __p2._M_stddev); } |
1959 | |
1960 | friend bool |
1961 | operator!=(const param_type& __p1, const param_type& __p2) |
1962 | { return !(__p1 == __p2); } |
1963 | |
1964 | private: |
1965 | _RealType _M_mean; |
1966 | _RealType _M_stddev; |
1967 | }; |
1968 | |
1969 | public: |
1970 | |
1971 | |
1972 | |
1973 | |
1974 | explicit |
1975 | normal_distribution(result_type __mean = result_type(0), |
1976 | result_type __stddev = result_type(1)) |
1977 | : _M_param(__mean, __stddev), _M_saved_available(false) |
1978 | { } |
1979 | |
1980 | explicit |
1981 | normal_distribution(const param_type& __p) |
1982 | : _M_param(__p), _M_saved_available(false) |
1983 | { } |
1984 | |
1985 | |
1986 | |
1987 | |
1988 | void |
1989 | reset() |
1990 | { _M_saved_available = false; } |
1991 | |
1992 | |
1993 | |
1994 | |
1995 | _RealType |
1996 | mean() const |
1997 | { return _M_param.mean(); } |
1998 | |
1999 | |
2000 | |
2001 | |
2002 | _RealType |
2003 | stddev() const |
2004 | { return _M_param.stddev(); } |
2005 | |
2006 | |
2007 | |
2008 | |
2009 | param_type |
2010 | param() const |
2011 | { return _M_param; } |
2012 | |
2013 | |
2014 | |
2015 | |
2016 | |
2017 | void |
2018 | param(const param_type& __param) |
2019 | { _M_param = __param; } |
2020 | |
2021 | |
2022 | |
2023 | |
2024 | result_type |
2025 | min() const |
2026 | { return std::numeric_limits<result_type>::lowest(); } |
2027 | |
2028 | |
2029 | |
2030 | |
2031 | result_type |
2032 | max() const |
2033 | { return std::numeric_limits<result_type>::max(); } |
2034 | |
2035 | |
2036 | |
2037 | |
2038 | template<typename _UniformRandomNumberGenerator> |
2039 | result_type |
2040 | operator()(_UniformRandomNumberGenerator& __urng) |
2041 | { return this->operator()(__urng, _M_param); } |
2042 | |
2043 | template<typename _UniformRandomNumberGenerator> |
2044 | result_type |
2045 | operator()(_UniformRandomNumberGenerator& __urng, |
2046 | const param_type& __p); |
2047 | |
2048 | template<typename _ForwardIterator, |
2049 | typename _UniformRandomNumberGenerator> |
2050 | void |
2051 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
2052 | _UniformRandomNumberGenerator& __urng) |
2053 | { this->__generate(__f, __t, __urng, _M_param); } |
2054 | |
2055 | template<typename _ForwardIterator, |
2056 | typename _UniformRandomNumberGenerator> |
2057 | void |
2058 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
2059 | _UniformRandomNumberGenerator& __urng, |
2060 | const param_type& __p) |
2061 | { this->__generate_impl(__f, __t, __urng, __p); } |
2062 | |
2063 | template<typename _UniformRandomNumberGenerator> |
2064 | void |
2065 | __generate(result_type* __f, result_type* __t, |
2066 | _UniformRandomNumberGenerator& __urng, |
2067 | const param_type& __p) |
2068 | { this->__generate_impl(__f, __t, __urng, __p); } |
2069 | |
2070 | |
2071 | |
2072 | |
2073 | |
2074 | |
2075 | template<typename _RealType1> |
2076 | friend bool |
2077 | operator==(const std::normal_distribution<_RealType1>& __d1, |
2078 | const std::normal_distribution<_RealType1>& __d2); |
2079 | |
2080 | |
2081 | |
2082 | |
2083 | |
2084 | |
2085 | |
2086 | |
2087 | |
2088 | |
2089 | |
2090 | template<typename _RealType1, typename _CharT, typename _Traits> |
2091 | friend std::basic_ostream<_CharT, _Traits>& |
2092 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, |
2093 | const std::normal_distribution<_RealType1>& __x); |
2094 | |
2095 | |
2096 | |
2097 | |
2098 | |
2099 | |
2100 | |
2101 | |
2102 | |
2103 | |
2104 | |
2105 | template<typename _RealType1, typename _CharT, typename _Traits> |
2106 | friend std::basic_istream<_CharT, _Traits>& |
2107 | operator>>(std::basic_istream<_CharT, _Traits>& __is, |
2108 | std::normal_distribution<_RealType1>& __x); |
2109 | |
2110 | private: |
2111 | template<typename _ForwardIterator, |
2112 | typename _UniformRandomNumberGenerator> |
2113 | void |
2114 | __generate_impl(_ForwardIterator __f, _ForwardIterator __t, |
2115 | _UniformRandomNumberGenerator& __urng, |
2116 | const param_type& __p); |
2117 | |
2118 | param_type _M_param; |
2119 | result_type _M_saved; |
2120 | bool _M_saved_available; |
2121 | }; |
2122 | |
2123 | |
2124 | |
2125 | |
2126 | template<typename _RealType> |
2127 | inline bool |
2128 | operator!=(const std::normal_distribution<_RealType>& __d1, |
2129 | const std::normal_distribution<_RealType>& __d2) |
2130 | { return !(__d1 == __d2); } |
2131 | |
2132 | |
2133 | |
2134 | |
2135 | |
2136 | |
2137 | |
2138 | |
2139 | |
2140 | |
2141 | |
2142 | template<typename _RealType = double> |
2143 | class lognormal_distribution |
2144 | { |
2145 | static_assert(std::is_floating_point<_RealType>::value, |
2146 | "result_type must be a floating point type"); |
2147 | |
2148 | public: |
2149 | |
2150 | typedef _RealType result_type; |
2151 | |
2152 | |
2153 | struct param_type |
2154 | { |
2155 | typedef lognormal_distribution<_RealType> distribution_type; |
2156 | |
2157 | explicit |
2158 | param_type(_RealType __m = _RealType(0), |
2159 | _RealType __s = _RealType(1)) |
2160 | : _M_m(__m), _M_s(__s) |
2161 | { } |
2162 | |
2163 | _RealType |
2164 | m() const |
2165 | { return _M_m; } |
2166 | |
2167 | _RealType |
2168 | s() const |
2169 | { return _M_s; } |
2170 | |
2171 | friend bool |
2172 | operator==(const param_type& __p1, const param_type& __p2) |
2173 | { return __p1._M_m == __p2._M_m && __p1._M_s == __p2._M_s; } |
2174 | |
2175 | friend bool |
2176 | operator!=(const param_type& __p1, const param_type& __p2) |
2177 | { return !(__p1 == __p2); } |
2178 | |
2179 | private: |
2180 | _RealType _M_m; |
2181 | _RealType _M_s; |
2182 | }; |
2183 | |
2184 | explicit |
2185 | lognormal_distribution(_RealType __m = _RealType(0), |
2186 | _RealType __s = _RealType(1)) |
2187 | : _M_param(__m, __s), _M_nd() |
2188 | { } |
2189 | |
2190 | explicit |
2191 | lognormal_distribution(const param_type& __p) |
2192 | : _M_param(__p), _M_nd() |
2193 | { } |
2194 | |
2195 | |
2196 | |
2197 | |
2198 | void |
2199 | reset() |
2200 | { _M_nd.reset(); } |
2201 | |
2202 | |
2203 | |
2204 | |
2205 | _RealType |
2206 | m() const |
2207 | { return _M_param.m(); } |
2208 | |
2209 | _RealType |
2210 | s() const |
2211 | { return _M_param.s(); } |
2212 | |
2213 | |
2214 | |
2215 | |
2216 | param_type |
2217 | param() const |
2218 | { return _M_param; } |
2219 | |
2220 | |
2221 | |
2222 | |
2223 | |
2224 | void |
2225 | param(const param_type& __param) |
2226 | { _M_param = __param; } |
2227 | |
2228 | |
2229 | |
2230 | |
2231 | result_type |
2232 | min() const |
2233 | { return result_type(0); } |
2234 | |
2235 | |
2236 | |
2237 | |
2238 | result_type |
2239 | max() const |
2240 | { return std::numeric_limits<result_type>::max(); } |
2241 | |
2242 | |
2243 | |
2244 | |
2245 | template<typename _UniformRandomNumberGenerator> |
2246 | result_type |
2247 | operator()(_UniformRandomNumberGenerator& __urng) |
2248 | { return this->operator()(__urng, _M_param); } |
2249 | |
2250 | template<typename _UniformRandomNumberGenerator> |
2251 | result_type |
2252 | operator()(_UniformRandomNumberGenerator& __urng, |
2253 | const param_type& __p) |
2254 | { return std::exp(__p.s() * _M_nd(__urng) + __p.m()); } |
2255 | |
2256 | template<typename _ForwardIterator, |
2257 | typename _UniformRandomNumberGenerator> |
2258 | void |
2259 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
2260 | _UniformRandomNumberGenerator& __urng) |
2261 | { this->__generate(__f, __t, __urng, _M_param); } |
2262 | |
2263 | template<typename _ForwardIterator, |
2264 | typename _UniformRandomNumberGenerator> |
2265 | void |
2266 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
2267 | _UniformRandomNumberGenerator& __urng, |
2268 | const param_type& __p) |
2269 | { this->__generate_impl(__f, __t, __urng, __p); } |
2270 | |
2271 | template<typename _UniformRandomNumberGenerator> |
2272 | void |
2273 | __generate(result_type* __f, result_type* __t, |
2274 | _UniformRandomNumberGenerator& __urng, |
2275 | const param_type& __p) |
2276 | { this->__generate_impl(__f, __t, __urng, __p); } |
2277 | |
2278 | |
2279 | |
2280 | |
2281 | |
2282 | |
2283 | friend bool |
2284 | operator==(const lognormal_distribution& __d1, |
2285 | const lognormal_distribution& __d2) |
2286 | { return (__d1._M_param == __d2._M_param |
2287 | && __d1._M_nd == __d2._M_nd); } |
2288 | |
2289 | |
2290 | |
2291 | |
2292 | |
2293 | |
2294 | |
2295 | |
2296 | |
2297 | |
2298 | |
2299 | template<typename _RealType1, typename _CharT, typename _Traits> |
2300 | friend std::basic_ostream<_CharT, _Traits>& |
2301 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, |
2302 | const std::lognormal_distribution<_RealType1>& __x); |
2303 | |
2304 | |
2305 | |
2306 | |
2307 | |
2308 | |
2309 | |
2310 | |
2311 | |
2312 | |
2313 | |
2314 | template<typename _RealType1, typename _CharT, typename _Traits> |
2315 | friend std::basic_istream<_CharT, _Traits>& |
2316 | operator>>(std::basic_istream<_CharT, _Traits>& __is, |
2317 | std::lognormal_distribution<_RealType1>& __x); |
2318 | |
2319 | private: |
2320 | template<typename _ForwardIterator, |
2321 | typename _UniformRandomNumberGenerator> |
2322 | void |
2323 | __generate_impl(_ForwardIterator __f, _ForwardIterator __t, |
2324 | _UniformRandomNumberGenerator& __urng, |
2325 | const param_type& __p); |
2326 | |
2327 | param_type _M_param; |
2328 | |
2329 | std::normal_distribution<result_type> _M_nd; |
2330 | }; |
2331 | |
2332 | |
2333 | |
2334 | |
2335 | template<typename _RealType> |
2336 | inline bool |
2337 | operator!=(const std::lognormal_distribution<_RealType>& __d1, |
2338 | const std::lognormal_distribution<_RealType>& __d2) |
2339 | { return !(__d1 == __d2); } |
2340 | |
2341 | |
2342 | |
2343 | |
2344 | |
2345 | |
2346 | |
2347 | |
2348 | |
2349 | |
2350 | |
2351 | template<typename _RealType = double> |
2352 | class gamma_distribution |
2353 | { |
2354 | static_assert(std::is_floating_point<_RealType>::value, |
2355 | "result_type must be a floating point type"); |
2356 | |
2357 | public: |
2358 | |
2359 | typedef _RealType result_type; |
2360 | |
2361 | |
2362 | struct param_type |
2363 | { |
2364 | typedef gamma_distribution<_RealType> distribution_type; |
2365 | friend class gamma_distribution<_RealType>; |
2366 | |
2367 | explicit |
2368 | param_type(_RealType __alpha_val = _RealType(1), |
2369 | _RealType __beta_val = _RealType(1)) |
2370 | : _M_alpha(__alpha_val), _M_beta(__beta_val) |
2371 | { |
2372 | __glibcxx_assert(_M_alpha > _RealType(0)); |
2373 | _M_initialize(); |
2374 | } |
2375 | |
2376 | _RealType |
2377 | alpha() const |
2378 | { return _M_alpha; } |
2379 | |
2380 | _RealType |
2381 | beta() const |
2382 | { return _M_beta; } |
2383 | |
2384 | friend bool |
2385 | operator==(const param_type& __p1, const param_type& __p2) |
2386 | { return (__p1._M_alpha == __p2._M_alpha |
2387 | && __p1._M_beta == __p2._M_beta); } |
2388 | |
2389 | friend bool |
2390 | operator!=(const param_type& __p1, const param_type& __p2) |
2391 | { return !(__p1 == __p2); } |
2392 | |
2393 | private: |
2394 | void |
2395 | _M_initialize(); |
2396 | |
2397 | _RealType _M_alpha; |
2398 | _RealType _M_beta; |
2399 | |
2400 | _RealType _M_malpha, _M_a2; |
2401 | }; |
2402 | |
2403 | public: |
2404 | |
2405 | |
2406 | |
2407 | |
2408 | explicit |
2409 | gamma_distribution(_RealType __alpha_val = _RealType(1), |
2410 | _RealType __beta_val = _RealType(1)) |
2411 | : _M_param(__alpha_val, __beta_val), _M_nd() |
2412 | { } |
2413 | |
2414 | explicit |
2415 | gamma_distribution(const param_type& __p) |
2416 | : _M_param(__p), _M_nd() |
2417 | { } |
2418 | |
2419 | |
2420 | |
2421 | |
2422 | void |
2423 | reset() |
2424 | { _M_nd.reset(); } |
2425 | |
2426 | |
2427 | |
2428 | |
2429 | _RealType |
2430 | alpha() const |
2431 | { return _M_param.alpha(); } |
2432 | |
2433 | |
2434 | |
2435 | |
2436 | _RealType |
2437 | beta() const |
2438 | { return _M_param.beta(); } |
2439 | |
2440 | |
2441 | |
2442 | |
2443 | param_type |
2444 | param() const |
2445 | { return _M_param; } |
2446 | |
2447 | |
2448 | |
2449 | |
2450 | |
2451 | void |
2452 | param(const param_type& __param) |
2453 | { _M_param = __param; } |
2454 | |
2455 | |
2456 | |
2457 | |
2458 | result_type |
2459 | min() const |
2460 | { return result_type(0); } |
2461 | |
2462 | |
2463 | |
2464 | |
2465 | result_type |
2466 | max() const |
2467 | { return std::numeric_limits<result_type>::max(); } |
2468 | |
2469 | |
2470 | |
2471 | |
2472 | template<typename _UniformRandomNumberGenerator> |
2473 | result_type |
2474 | operator()(_UniformRandomNumberGenerator& __urng) |
2475 | { return this->operator()(__urng, _M_param); } |
2476 | |
2477 | template<typename _UniformRandomNumberGenerator> |
2478 | result_type |
2479 | operator()(_UniformRandomNumberGenerator& __urng, |
2480 | const param_type& __p); |
2481 | |
2482 | template<typename _ForwardIterator, |
2483 | typename _UniformRandomNumberGenerator> |
2484 | void |
2485 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
2486 | _UniformRandomNumberGenerator& __urng) |
2487 | { this->__generate(__f, __t, __urng, _M_param); } |
2488 | |
2489 | template<typename _ForwardIterator, |
2490 | typename _UniformRandomNumberGenerator> |
2491 | void |
2492 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
2493 | _UniformRandomNumberGenerator& __urng, |
2494 | const param_type& __p) |
2495 | { this->__generate_impl(__f, __t, __urng, __p); } |
2496 | |
2497 | template<typename _UniformRandomNumberGenerator> |
2498 | void |
2499 | __generate(result_type* __f, result_type* __t, |
2500 | _UniformRandomNumberGenerator& __urng, |
2501 | const param_type& __p) |
2502 | { this->__generate_impl(__f, __t, __urng, __p); } |
2503 | |
2504 | |
2505 | |
2506 | |
2507 | |
2508 | |
2509 | friend bool |
2510 | operator==(const gamma_distribution& __d1, |
2511 | const gamma_distribution& __d2) |
2512 | { return (__d1._M_param == __d2._M_param |
2513 | && __d1._M_nd == __d2._M_nd); } |
2514 | |
2515 | |
2516 | |
2517 | |
2518 | |
2519 | |
2520 | |
2521 | |
2522 | |
2523 | |
2524 | |
2525 | template<typename _RealType1, typename _CharT, typename _Traits> |
2526 | friend std::basic_ostream<_CharT, _Traits>& |
2527 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, |
2528 | const std::gamma_distribution<_RealType1>& __x); |
2529 | |
2530 | |
2531 | |
2532 | |
2533 | |
2534 | |
2535 | |
2536 | |
2537 | |
2538 | |
2539 | template<typename _RealType1, typename _CharT, typename _Traits> |
2540 | friend std::basic_istream<_CharT, _Traits>& |
2541 | operator>>(std::basic_istream<_CharT, _Traits>& __is, |
2542 | std::gamma_distribution<_RealType1>& __x); |
2543 | |
2544 | private: |
2545 | template<typename _ForwardIterator, |
2546 | typename _UniformRandomNumberGenerator> |
2547 | void |
2548 | __generate_impl(_ForwardIterator __f, _ForwardIterator __t, |
2549 | _UniformRandomNumberGenerator& __urng, |
2550 | const param_type& __p); |
2551 | |
2552 | param_type _M_param; |
2553 | |
2554 | std::normal_distribution<result_type> _M_nd; |
2555 | }; |
2556 | |
2557 | |
2558 | |
2559 | |
2560 | template<typename _RealType> |
2561 | inline bool |
2562 | operator!=(const std::gamma_distribution<_RealType>& __d1, |
2563 | const std::gamma_distribution<_RealType>& __d2) |
2564 | { return !(__d1 == __d2); } |
2565 | |
2566 | |
2567 | |
2568 | |
2569 | |
2570 | |
2571 | |
2572 | |
2573 | template<typename _RealType = double> |
2574 | class chi_squared_distribution |
2575 | { |
2576 | static_assert(std::is_floating_point<_RealType>::value, |
2577 | "result_type must be a floating point type"); |
2578 | |
2579 | public: |
2580 | |
2581 | typedef _RealType result_type; |
2582 | |
2583 | |
2584 | struct param_type |
2585 | { |
2586 | typedef chi_squared_distribution<_RealType> distribution_type; |
2587 | |
2588 | explicit |
2589 | param_type(_RealType __n = _RealType(1)) |
2590 | : _M_n(__n) |
2591 | { } |
2592 | |
2593 | _RealType |
2594 | n() const |
2595 | { return _M_n; } |
2596 | |
2597 | friend bool |
2598 | operator==(const param_type& __p1, const param_type& __p2) |
2599 | { return __p1._M_n == __p2._M_n; } |
2600 | |
2601 | friend bool |
2602 | operator!=(const param_type& __p1, const param_type& __p2) |
2603 | { return !(__p1 == __p2); } |
2604 | |
2605 | private: |
2606 | _RealType _M_n; |
2607 | }; |
2608 | |
2609 | explicit |
2610 | chi_squared_distribution(_RealType __n = _RealType(1)) |
2611 | : _M_param(__n), _M_gd(__n / 2) |
2612 | { } |
2613 | |
2614 | explicit |
2615 | chi_squared_distribution(const param_type& __p) |
2616 | : _M_param(__p), _M_gd(__p.n() / 2) |
2617 | { } |
2618 | |
2619 | |
2620 | |
2621 | |
2622 | void |
2623 | reset() |
2624 | { _M_gd.reset(); } |
2625 | |
2626 | |
2627 | |
2628 | |
2629 | _RealType |
2630 | n() const |
2631 | { return _M_param.n(); } |
2632 | |
2633 | |
2634 | |
2635 | |
2636 | param_type |
2637 | param() const |
2638 | { return _M_param; } |
2639 | |
2640 | |
2641 | |
2642 | |
2643 | |
2644 | void |
2645 | param(const param_type& __param) |
2646 | { |
2647 | _M_param = __param; |
2648 | typedef typename std::gamma_distribution<result_type>::param_type |
2649 | param_type; |
2650 | _M_gd.param(param_type{__param.n() / 2}); |
2651 | } |
2652 | |
2653 | |
2654 | |
2655 | |
2656 | result_type |
2657 | min() const |
2658 | { return result_type(0); } |
2659 | |
2660 | |
2661 | |
2662 | |
2663 | result_type |
2664 | max() const |
2665 | { return std::numeric_limits<result_type>::max(); } |
2666 | |
2667 | |
2668 | |
2669 | |
2670 | template<typename _UniformRandomNumberGenerator> |
2671 | result_type |
2672 | operator()(_UniformRandomNumberGenerator& __urng) |
2673 | { return 2 * _M_gd(__urng); } |
2674 | |
2675 | template<typename _UniformRandomNumberGenerator> |
2676 | result_type |
2677 | operator()(_UniformRandomNumberGenerator& __urng, |
2678 | const param_type& __p) |
2679 | { |
2680 | typedef typename std::gamma_distribution<result_type>::param_type |
2681 | param_type; |
2682 | return 2 * _M_gd(__urng, param_type(__p.n() / 2)); |
2683 | } |
2684 | |
2685 | template<typename _ForwardIterator, |
2686 | typename _UniformRandomNumberGenerator> |
2687 | void |
2688 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
2689 | _UniformRandomNumberGenerator& __urng) |
2690 | { this->__generate_impl(__f, __t, __urng); } |
2691 | |
2692 | template<typename _ForwardIterator, |
2693 | typename _UniformRandomNumberGenerator> |
2694 | void |
2695 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
2696 | _UniformRandomNumberGenerator& __urng, |
2697 | const param_type& __p) |
2698 | { typename std::gamma_distribution<result_type>::param_type |
2699 | __p2(__p.n() / 2); |
2700 | this->__generate_impl(__f, __t, __urng, __p2); } |
2701 | |
2702 | template<typename _UniformRandomNumberGenerator> |
2703 | void |
2704 | __generate(result_type* __f, result_type* __t, |
2705 | _UniformRandomNumberGenerator& __urng) |
2706 | { this->__generate_impl(__f, __t, __urng); } |
2707 | |
2708 | template<typename _UniformRandomNumberGenerator> |
2709 | void |
2710 | __generate(result_type* __f, result_type* __t, |
2711 | _UniformRandomNumberGenerator& __urng, |
2712 | const param_type& __p) |
2713 | { typename std::gamma_distribution<result_type>::param_type |
2714 | __p2(__p.n() / 2); |
2715 | this->__generate_impl(__f, __t, __urng, __p2); } |
2716 | |
2717 | |
2718 | |
2719 | |
2720 | |
2721 | |
2722 | friend bool |
2723 | operator==(const chi_squared_distribution& __d1, |
2724 | const chi_squared_distribution& __d2) |
2725 | { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; } |
2726 | |
2727 | |
2728 | |
2729 | |
2730 | |
2731 | |
2732 | |
2733 | |
2734 | |
2735 | |
2736 | |
2737 | template<typename _RealType1, typename _CharT, typename _Traits> |
2738 | friend std::basic_ostream<_CharT, _Traits>& |
2739 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, |
2740 | const std::chi_squared_distribution<_RealType1>& __x); |
2741 | |
2742 | |
2743 | |
2744 | |
2745 | |
2746 | |
2747 | |
2748 | |
2749 | |
2750 | |
2751 | |
2752 | template<typename _RealType1, typename _CharT, typename _Traits> |
2753 | friend std::basic_istream<_CharT, _Traits>& |
2754 | operator>>(std::basic_istream<_CharT, _Traits>& __is, |
2755 | std::chi_squared_distribution<_RealType1>& __x); |
2756 | |
2757 | private: |
2758 | template<typename _ForwardIterator, |
2759 | typename _UniformRandomNumberGenerator> |
2760 | void |
2761 | __generate_impl(_ForwardIterator __f, _ForwardIterator __t, |
2762 | _UniformRandomNumberGenerator& __urng); |
2763 | |
2764 | template<typename _ForwardIterator, |
2765 | typename _UniformRandomNumberGenerator> |
2766 | void |
2767 | __generate_impl(_ForwardIterator __f, _ForwardIterator __t, |
2768 | _UniformRandomNumberGenerator& __urng, |
2769 | const typename |
2770 | std::gamma_distribution<result_type>::param_type& __p); |
2771 | |
2772 | param_type _M_param; |
2773 | |
2774 | std::gamma_distribution<result_type> _M_gd; |
2775 | }; |
2776 | |
2777 | |
2778 | |
2779 | |
2780 | template<typename _RealType> |
2781 | inline bool |
2782 | operator!=(const std::chi_squared_distribution<_RealType>& __d1, |
2783 | const std::chi_squared_distribution<_RealType>& __d2) |
2784 | { return !(__d1 == __d2); } |
2785 | |
2786 | |
2787 | |
2788 | |
2789 | |
2790 | |
2791 | |
2792 | |
2793 | template<typename _RealType = double> |
2794 | class cauchy_distribution |
2795 | { |
2796 | static_assert(std::is_floating_point<_RealType>::value, |
2797 | "result_type must be a floating point type"); |
2798 | |
2799 | public: |
2800 | |
2801 | typedef _RealType result_type; |
2802 | |
2803 | |
2804 | struct param_type |
2805 | { |
2806 | typedef cauchy_distribution<_RealType> distribution_type; |
2807 | |
2808 | explicit |
2809 | param_type(_RealType __a = _RealType(0), |
2810 | _RealType __b = _RealType(1)) |
2811 | : _M_a(__a), _M_b(__b) |
2812 | { } |
2813 | |
2814 | _RealType |
2815 | a() const |
2816 | { return _M_a; } |
2817 | |
2818 | _RealType |
2819 | b() const |
2820 | { return _M_b; } |
2821 | |
2822 | friend bool |
2823 | operator==(const param_type& __p1, const param_type& __p2) |
2824 | { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; } |
2825 | |
2826 | friend bool |
2827 | operator!=(const param_type& __p1, const param_type& __p2) |
2828 | { return !(__p1 == __p2); } |
2829 | |
2830 | private: |
2831 | _RealType _M_a; |
2832 | _RealType _M_b; |
2833 | }; |
2834 | |
2835 | explicit |
2836 | cauchy_distribution(_RealType __a = _RealType(0), |
2837 | _RealType __b = _RealType(1)) |
2838 | : _M_param(__a, __b) |
2839 | { } |
2840 | |
2841 | explicit |
2842 | cauchy_distribution(const param_type& __p) |
2843 | : _M_param(__p) |
2844 | { } |
2845 | |
2846 | |
2847 | |
2848 | |
2849 | void |
2850 | reset() |
2851 | { } |
2852 | |
2853 | |
2854 | |
2855 | |
2856 | _RealType |
2857 | a() const |
2858 | { return _M_param.a(); } |
2859 | |
2860 | _RealType |
2861 | b() const |
2862 | { return _M_param.b(); } |
2863 | |
2864 | |
2865 | |
2866 | |
2867 | param_type |
2868 | param() const |
2869 | { return _M_param; } |
2870 | |
2871 | |
2872 | |
2873 | |
2874 | |
2875 | void |
2876 | param(const param_type& __param) |
2877 | { _M_param = __param; } |
2878 | |
2879 | |
2880 | |
2881 | |
2882 | result_type |
2883 | min() const |
2884 | { return std::numeric_limits<result_type>::lowest(); } |
2885 | |
2886 | |
2887 | |
2888 | |
2889 | result_type |
2890 | max() const |
2891 | { return std::numeric_limits<result_type>::max(); } |
2892 | |
2893 | |
2894 | |
2895 | |
2896 | template<typename _UniformRandomNumberGenerator> |
2897 | result_type |
2898 | operator()(_UniformRandomNumberGenerator& __urng) |
2899 | { return this->operator()(__urng, _M_param); } |
2900 | |
2901 | template<typename _UniformRandomNumberGenerator> |
2902 | result_type |
2903 | operator()(_UniformRandomNumberGenerator& __urng, |
2904 | const param_type& __p); |
2905 | |
2906 | template<typename _ForwardIterator, |
2907 | typename _UniformRandomNumberGenerator> |
2908 | void |
2909 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
2910 | _UniformRandomNumberGenerator& __urng) |
2911 | { this->__generate(__f, __t, __urng, _M_param); } |
2912 | |
2913 | template<typename _ForwardIterator, |
2914 | typename _UniformRandomNumberGenerator> |
2915 | void |
2916 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
2917 | _UniformRandomNumberGenerator& __urng, |
2918 | const param_type& __p) |
2919 | { this->__generate_impl(__f, __t, __urng, __p); } |
2920 | |
2921 | template<typename _UniformRandomNumberGenerator> |
2922 | void |
2923 | __generate(result_type* __f, result_type* __t, |
2924 | _UniformRandomNumberGenerator& __urng, |
2925 | const param_type& __p) |
2926 | { this->__generate_impl(__f, __t, __urng, __p); } |
2927 | |
2928 | |
2929 | |
2930 | |
2931 | |
2932 | friend bool |
2933 | operator==(const cauchy_distribution& __d1, |
2934 | const cauchy_distribution& __d2) |
2935 | { return __d1._M_param == __d2._M_param; } |
2936 | |
2937 | private: |
2938 | template<typename _ForwardIterator, |
2939 | typename _UniformRandomNumberGenerator> |
2940 | void |
2941 | __generate_impl(_ForwardIterator __f, _ForwardIterator __t, |
2942 | _UniformRandomNumberGenerator& __urng, |
2943 | const param_type& __p); |
2944 | |
2945 | param_type _M_param; |
2946 | }; |
2947 | |
2948 | |
2949 | |
2950 | |
2951 | |
2952 | template<typename _RealType> |
2953 | inline bool |
2954 | operator!=(const std::cauchy_distribution<_RealType>& __d1, |
2955 | const std::cauchy_distribution<_RealType>& __d2) |
2956 | { return !(__d1 == __d2); } |
2957 | |
2958 | |
2959 | |
2960 | |
2961 | |
2962 | |
2963 | |
2964 | |
2965 | |
2966 | |
2967 | |
2968 | template<typename _RealType, typename _CharT, typename _Traits> |
2969 | std::basic_ostream<_CharT, _Traits>& |
2970 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, |
2971 | const std::cauchy_distribution<_RealType>& __x); |
2972 | |
2973 | |
2974 | |
2975 | |
2976 | |
2977 | |
2978 | |
2979 | |
2980 | |
2981 | |
2982 | |
2983 | template<typename _RealType, typename _CharT, typename _Traits> |
2984 | std::basic_istream<_CharT, _Traits>& |
2985 | operator>>(std::basic_istream<_CharT, _Traits>& __is, |
2986 | std::cauchy_distribution<_RealType>& __x); |
2987 | |
2988 | |
2989 | |
2990 | |
2991 | |
2992 | |
2993 | |
2994 | |
2995 | |
2996 | |
2997 | |
2998 | |
2999 | template<typename _RealType = double> |
3000 | class fisher_f_distribution |
3001 | { |
3002 | static_assert(std::is_floating_point<_RealType>::value, |
3003 | "result_type must be a floating point type"); |
3004 | |
3005 | public: |
3006 | |
3007 | typedef _RealType result_type; |
3008 | |
3009 | |
3010 | struct param_type |
3011 | { |
3012 | typedef fisher_f_distribution<_RealType> distribution_type; |
3013 | |
3014 | explicit |
3015 | param_type(_RealType __m = _RealType(1), |
3016 | _RealType __n = _RealType(1)) |
3017 | : _M_m(__m), _M_n(__n) |
3018 | { } |
3019 | |
3020 | _RealType |
3021 | m() const |
3022 | { return _M_m; } |
3023 | |
3024 | _RealType |
3025 | n() const |
3026 | { return _M_n; } |
3027 | |
3028 | friend bool |
3029 | operator==(const param_type& __p1, const param_type& __p2) |
3030 | { return __p1._M_m == __p2._M_m && __p1._M_n == __p2._M_n; } |
3031 | |
3032 | friend bool |
3033 | operator!=(const param_type& __p1, const param_type& __p2) |
3034 | { return !(__p1 == __p2); } |
3035 | |
3036 | private: |
3037 | _RealType _M_m; |
3038 | _RealType _M_n; |
3039 | }; |
3040 | |
3041 | explicit |
3042 | fisher_f_distribution(_RealType __m = _RealType(1), |
3043 | _RealType __n = _RealType(1)) |
3044 | : _M_param(__m, __n), _M_gd_x(__m / 2), _M_gd_y(__n / 2) |
3045 | { } |
3046 | |
3047 | explicit |
3048 | fisher_f_distribution(const param_type& __p) |
3049 | : _M_param(__p), _M_gd_x(__p.m() / 2), _M_gd_y(__p.n() / 2) |
3050 | { } |
3051 | |
3052 | |
3053 | |
3054 | |
3055 | void |
3056 | reset() |
3057 | { |
3058 | _M_gd_x.reset(); |
3059 | _M_gd_y.reset(); |
3060 | } |
3061 | |
3062 | |
3063 | |
3064 | |
3065 | _RealType |
3066 | m() const |
3067 | { return _M_param.m(); } |
3068 | |
3069 | _RealType |
3070 | n() const |
3071 | { return _M_param.n(); } |
3072 | |
3073 | |
3074 | |
3075 | |
3076 | param_type |
3077 | param() const |
3078 | { return _M_param; } |
3079 | |
3080 | |
3081 | |
3082 | |
3083 | |
3084 | void |
3085 | param(const param_type& __param) |
3086 | { _M_param = __param; } |
3087 | |
3088 | |
3089 | |
3090 | |
3091 | result_type |
3092 | min() const |
3093 | { return result_type(0); } |
3094 | |
3095 | |
3096 | |
3097 | |
3098 | result_type |
3099 | max() const |
3100 | { return std::numeric_limits<result_type>::max(); } |
3101 | |
3102 | |
3103 | |
3104 | |
3105 | template<typename _UniformRandomNumberGenerator> |
3106 | result_type |
3107 | operator()(_UniformRandomNumberGenerator& __urng) |
3108 | { return (_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()); } |
3109 | |
3110 | template<typename _UniformRandomNumberGenerator> |
3111 | result_type |
3112 | operator()(_UniformRandomNumberGenerator& __urng, |
3113 | const param_type& __p) |
3114 | { |
3115 | typedef typename std::gamma_distribution<result_type>::param_type |
3116 | param_type; |
3117 | return ((_M_gd_x(__urng, param_type(__p.m() / 2)) * n()) |
3118 | / (_M_gd_y(__urng, param_type(__p.n() / 2)) * m())); |
3119 | } |
3120 | |
3121 | template<typename _ForwardIterator, |
3122 | typename _UniformRandomNumberGenerator> |
3123 | void |
3124 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
3125 | _UniformRandomNumberGenerator& __urng) |
3126 | { this->__generate_impl(__f, __t, __urng); } |
3127 | |
3128 | template<typename _ForwardIterator, |
3129 | typename _UniformRandomNumberGenerator> |
3130 | void |
3131 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
3132 | _UniformRandomNumberGenerator& __urng, |
3133 | const param_type& __p) |
3134 | { this->__generate_impl(__f, __t, __urng, __p); } |
3135 | |
3136 | template<typename _UniformRandomNumberGenerator> |
3137 | void |
3138 | __generate(result_type* __f, result_type* __t, |
3139 | _UniformRandomNumberGenerator& __urng) |
3140 | { this->__generate_impl(__f, __t, __urng); } |
3141 | |
3142 | template<typename _UniformRandomNumberGenerator> |
3143 | void |
3144 | __generate(result_type* __f, result_type* __t, |
3145 | _UniformRandomNumberGenerator& __urng, |
3146 | const param_type& __p) |
3147 | { this->__generate_impl(__f, __t, __urng, __p); } |
3148 | |
3149 | |
3150 | |
3151 | |
3152 | |
3153 | |
3154 | friend bool |
3155 | operator==(const fisher_f_distribution& __d1, |
3156 | const fisher_f_distribution& __d2) |
3157 | { return (__d1._M_param == __d2._M_param |
3158 | && __d1._M_gd_x == __d2._M_gd_x |
3159 | && __d1._M_gd_y == __d2._M_gd_y); } |
3160 | |
3161 | |
3162 | |
3163 | |
3164 | |
3165 | |
3166 | |
3167 | |
3168 | |
3169 | |
3170 | |
3171 | template<typename _RealType1, typename _CharT, typename _Traits> |
3172 | friend std::basic_ostream<_CharT, _Traits>& |
3173 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, |
3174 | const std::fisher_f_distribution<_RealType1>& __x); |
3175 | |
3176 | |
3177 | |
3178 | |
3179 | |
3180 | |
3181 | |
3182 | |
3183 | |
3184 | |
3185 | |
3186 | template<typename _RealType1, typename _CharT, typename _Traits> |
3187 | friend std::basic_istream<_CharT, _Traits>& |
3188 | operator>>(std::basic_istream<_CharT, _Traits>& __is, |
3189 | std::fisher_f_distribution<_RealType1>& __x); |
3190 | |
3191 | private: |
3192 | template<typename _ForwardIterator, |
3193 | typename _UniformRandomNumberGenerator> |
3194 | void |
3195 | __generate_impl(_ForwardIterator __f, _ForwardIterator __t, |
3196 | _UniformRandomNumberGenerator& __urng); |
3197 | |
3198 | template<typename _ForwardIterator, |
3199 | typename _UniformRandomNumberGenerator> |
3200 | void |
3201 | __generate_impl(_ForwardIterator __f, _ForwardIterator __t, |
3202 | _UniformRandomNumberGenerator& __urng, |
3203 | const param_type& __p); |
3204 | |
3205 | param_type _M_param; |
3206 | |
3207 | std::gamma_distribution<result_type> _M_gd_x, _M_gd_y; |
3208 | }; |
3209 | |
3210 | |
3211 | |
3212 | |
3213 | template<typename _RealType> |
3214 | inline bool |
3215 | operator!=(const std::fisher_f_distribution<_RealType>& __d1, |
3216 | const std::fisher_f_distribution<_RealType>& __d2) |
3217 | { return !(__d1 == __d2); } |
3218 | |
3219 | |
3220 | |
3221 | |
3222 | |
3223 | |
3224 | |
3225 | |
3226 | |
3227 | |
3228 | template<typename _RealType = double> |
3229 | class student_t_distribution |
3230 | { |
3231 | static_assert(std::is_floating_point<_RealType>::value, |
3232 | "result_type must be a floating point type"); |
3233 | |
3234 | public: |
3235 | |
3236 | typedef _RealType result_type; |
3237 | |
3238 | |
3239 | struct param_type |
3240 | { |
3241 | typedef student_t_distribution<_RealType> distribution_type; |
3242 | |
3243 | explicit |
3244 | param_type(_RealType __n = _RealType(1)) |
3245 | : _M_n(__n) |
3246 | { } |
3247 | |
3248 | _RealType |
3249 | n() const |
3250 | { return _M_n; } |
3251 | |
3252 | friend bool |
3253 | operator==(const param_type& __p1, const param_type& __p2) |
3254 | { return __p1._M_n == __p2._M_n; } |
3255 | |
3256 | friend bool |
3257 | operator!=(const param_type& __p1, const param_type& __p2) |
3258 | { return !(__p1 == __p2); } |
3259 | |
3260 | private: |
3261 | _RealType _M_n; |
3262 | }; |
3263 | |
3264 | explicit |
3265 | student_t_distribution(_RealType __n = _RealType(1)) |
3266 | : _M_param(__n), _M_nd(), _M_gd(__n / 2, 2) |
3267 | { } |
3268 | |
3269 | explicit |
3270 | student_t_distribution(const param_type& __p) |
3271 | : _M_param(__p), _M_nd(), _M_gd(__p.n() / 2, 2) |
3272 | { } |
3273 | |
3274 | |
3275 | |
3276 | |
3277 | void |
3278 | reset() |
3279 | { |
3280 | _M_nd.reset(); |
3281 | _M_gd.reset(); |
3282 | } |
3283 | |
3284 | |
3285 | |
3286 | |
3287 | _RealType |
3288 | n() const |
3289 | { return _M_param.n(); } |
3290 | |
3291 | |
3292 | |
3293 | |
3294 | param_type |
3295 | param() const |
3296 | { return _M_param; } |
3297 | |
3298 | |
3299 | |
3300 | |
3301 | |
3302 | void |
3303 | param(const param_type& __param) |
3304 | { _M_param = __param; } |
3305 | |
3306 | |
3307 | |
3308 | |
3309 | result_type |
3310 | min() const |
3311 | { return std::numeric_limits<result_type>::lowest(); } |
3312 | |
3313 | |
3314 | |
3315 | |
3316 | result_type |
3317 | max() const |
3318 | { return std::numeric_limits<result_type>::max(); } |
3319 | |
3320 | |
3321 | |
3322 | |
3323 | template<typename _UniformRandomNumberGenerator> |
3324 | result_type |
3325 | operator()(_UniformRandomNumberGenerator& __urng) |
3326 | { return _M_nd(__urng) * std::sqrt(n() / _M_gd(__urng)); } |
3327 | |
3328 | template<typename _UniformRandomNumberGenerator> |
3329 | result_type |
3330 | operator()(_UniformRandomNumberGenerator& __urng, |
3331 | const param_type& __p) |
3332 | { |
3333 | typedef typename std::gamma_distribution<result_type>::param_type |
3334 | param_type; |
3335 | |
3336 | const result_type __g = _M_gd(__urng, param_type(__p.n() / 2, 2)); |
3337 | return _M_nd(__urng) * std::sqrt(__p.n() / __g); |
3338 | } |
3339 | |
3340 | template<typename _ForwardIterator, |
3341 | typename _UniformRandomNumberGenerator> |
3342 | void |
3343 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
3344 | _UniformRandomNumberGenerator& __urng) |
3345 | { this->__generate_impl(__f, __t, __urng); } |
3346 | |
3347 | template<typename _ForwardIterator, |
3348 | typename _UniformRandomNumberGenerator> |
3349 | void |
3350 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
3351 | _UniformRandomNumberGenerator& __urng, |
3352 | const param_type& __p) |
3353 | { this->__generate_impl(__f, __t, __urng, __p); } |
3354 | |
3355 | template<typename _UniformRandomNumberGenerator> |
3356 | void |
3357 | __generate(result_type* __f, result_type* __t, |
3358 | _UniformRandomNumberGenerator& __urng) |
3359 | { this->__generate_impl(__f, __t, __urng); } |
3360 | |
3361 | template<typename _UniformRandomNumberGenerator> |
3362 | void |
3363 | __generate(result_type* __f, result_type* __t, |
3364 | _UniformRandomNumberGenerator& __urng, |
3365 | const param_type& __p) |
3366 | { this->__generate_impl(__f, __t, __urng, __p); } |
3367 | |
3368 | |
3369 | |
3370 | |
3371 | |
3372 | |
3373 | friend bool |
3374 | operator==(const student_t_distribution& __d1, |
3375 | const student_t_distribution& __d2) |
3376 | { return (__d1._M_param == __d2._M_param |
3377 | && __d1._M_nd == __d2._M_nd && __d1._M_gd == __d2._M_gd); } |
3378 | |
3379 | |
3380 | |
3381 | |
3382 | |
3383 | |
3384 | |
3385 | |
3386 | |
3387 | |
3388 | |
3389 | template<typename _RealType1, typename _CharT, typename _Traits> |
3390 | friend std::basic_ostream<_CharT, _Traits>& |
3391 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, |
3392 | const std::student_t_distribution<_RealType1>& __x); |
3393 | |
3394 | |
3395 | |
3396 | |
3397 | |
3398 | |
3399 | |
3400 | |
3401 | |
3402 | |
3403 | |
3404 | template<typename _RealType1, typename _CharT, typename _Traits> |
3405 | friend std::basic_istream<_CharT, _Traits>& |
3406 | operator>>(std::basic_istream<_CharT, _Traits>& __is, |
3407 | std::student_t_distribution<_RealType1>& __x); |
3408 | |
3409 | private: |
3410 | template<typename _ForwardIterator, |
3411 | typename _UniformRandomNumberGenerator> |
3412 | void |
3413 | __generate_impl(_ForwardIterator __f, _ForwardIterator __t, |
3414 | _UniformRandomNumberGenerator& __urng); |
3415 | template<typename _ForwardIterator, |
3416 | typename _UniformRandomNumberGenerator> |
3417 | void |
3418 | __generate_impl(_ForwardIterator __f, _ForwardIterator __t, |
3419 | _UniformRandomNumberGenerator& __urng, |
3420 | const param_type& __p); |
3421 | |
3422 | param_type _M_param; |
3423 | |
3424 | std::normal_distribution<result_type> _M_nd; |
3425 | std::gamma_distribution<result_type> _M_gd; |
3426 | }; |
3427 | |
3428 | |
3429 | |
3430 | |
3431 | template<typename _RealType> |
3432 | inline bool |
3433 | operator!=(const std::student_t_distribution<_RealType>& __d1, |
3434 | const std::student_t_distribution<_RealType>& __d2) |
3435 | { return !(__d1 == __d2); } |
3436 | |
3437 | |
3438 | |
3439 | |
3440 | |
3441 | |
3442 | |
3443 | |
3444 | |
3445 | |
3446 | |
3447 | |
3448 | |
3449 | |
3450 | |
3451 | |
3452 | class bernoulli_distribution |
3453 | { |
3454 | public: |
3455 | |
3456 | typedef bool result_type; |
3457 | |
3458 | |
3459 | struct param_type |
3460 | { |
3461 | typedef bernoulli_distribution distribution_type; |
3462 | |
3463 | explicit |
3464 | param_type(double __p = 0.5) |
3465 | : _M_p(__p) |
3466 | { |
3467 | __glibcxx_assert((_M_p >= 0.0) && (_M_p <= 1.0)); |
3468 | } |
3469 | |
3470 | double |
3471 | p() const |
3472 | { return _M_p; } |
3473 | |
3474 | friend bool |
3475 | operator==(const param_type& __p1, const param_type& __p2) |
3476 | { return __p1._M_p == __p2._M_p; } |
3477 | |
3478 | friend bool |
3479 | operator!=(const param_type& __p1, const param_type& __p2) |
3480 | { return !(__p1 == __p2); } |
3481 | |
3482 | private: |
3483 | double _M_p; |
3484 | }; |
3485 | |
3486 | public: |
3487 | |
3488 | |
3489 | |
3490 | |
3491 | |
3492 | |
3493 | explicit |
3494 | bernoulli_distribution(double __p = 0.5) |
3495 | : _M_param(__p) |
3496 | { } |
3497 | |
3498 | explicit |
3499 | bernoulli_distribution(const param_type& __p) |
3500 | : _M_param(__p) |
3501 | { } |
3502 | |
3503 | |
3504 | |
3505 | |
3506 | |
3507 | |
3508 | void |
3509 | reset() { } |
3510 | |
3511 | |
3512 | |
3513 | |
3514 | double |
3515 | p() const |
3516 | { return _M_param.p(); } |
3517 | |
3518 | |
3519 | |
3520 | |
3521 | param_type |
3522 | param() const |
3523 | { return _M_param; } |
3524 | |
3525 | |
3526 | |
3527 | |
3528 | |
3529 | void |
3530 | param(const param_type& __param) |
3531 | { _M_param = __param; } |
3532 | |
3533 | |
3534 | |
3535 | |
3536 | result_type |
3537 | min() const |
3538 | { return std::numeric_limits<result_type>::min(); } |
3539 | |
3540 | |
3541 | |
3542 | |
3543 | result_type |
3544 | max() const |
3545 | { return std::numeric_limits<result_type>::max(); } |
3546 | |
3547 | |
3548 | |
3549 | |
3550 | template<typename _UniformRandomNumberGenerator> |
3551 | result_type |
3552 | operator()(_UniformRandomNumberGenerator& __urng) |
3553 | { return this->operator()(__urng, _M_param); } |
3554 | |
3555 | template<typename _UniformRandomNumberGenerator> |
3556 | result_type |
3557 | operator()(_UniformRandomNumberGenerator& __urng, |
3558 | const param_type& __p) |
3559 | { |
3560 | __detail::_Adaptor<_UniformRandomNumberGenerator, double> |
3561 | __aurng(__urng); |
3562 | if ((__aurng() - __aurng.min()) |
3563 | < __p.p() * (__aurng.max() - __aurng.min())) |
3564 | return true; |
3565 | return false; |
3566 | } |
3567 | |
3568 | template<typename _ForwardIterator, |
3569 | typename _UniformRandomNumberGenerator> |
3570 | void |
3571 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
3572 | _UniformRandomNumberGenerator& __urng) |
3573 | { this->__generate(__f, __t, __urng, _M_param); } |
3574 | |
3575 | template<typename _ForwardIterator, |
3576 | typename _UniformRandomNumberGenerator> |
3577 | void |
3578 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
3579 | _UniformRandomNumberGenerator& __urng, const param_type& __p) |
3580 | { this->__generate_impl(__f, __t, __urng, __p); } |
3581 | |
3582 | template<typename _UniformRandomNumberGenerator> |
3583 | void |
3584 | __generate(result_type* __f, result_type* __t, |
3585 | _UniformRandomNumberGenerator& __urng, |
3586 | const param_type& __p) |
3587 | { this->__generate_impl(__f, __t, __urng, __p); } |
3588 | |
3589 | |
3590 | |
3591 | |
3592 | |
3593 | friend bool |
3594 | operator==(const bernoulli_distribution& __d1, |
3595 | const bernoulli_distribution& __d2) |
3596 | { return __d1._M_param == __d2._M_param; } |
3597 | |
3598 | private: |
3599 | template<typename _ForwardIterator, |
3600 | typename _UniformRandomNumberGenerator> |
3601 | void |
3602 | __generate_impl(_ForwardIterator __f, _ForwardIterator __t, |
3603 | _UniformRandomNumberGenerator& __urng, |
3604 | const param_type& __p); |
3605 | |
3606 | param_type _M_param; |
3607 | }; |
3608 | |
3609 | |
3610 | |
3611 | |
3612 | |
3613 | inline bool |
3614 | operator!=(const std::bernoulli_distribution& __d1, |
3615 | const std::bernoulli_distribution& __d2) |
3616 | { return !(__d1 == __d2); } |
3617 | |
3618 | |
3619 | |
3620 | |
3621 | |
3622 | |
3623 | |
3624 | |
3625 | |
3626 | |
3627 | |
3628 | template<typename _CharT, typename _Traits> |
3629 | std::basic_ostream<_CharT, _Traits>& |
3630 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, |
3631 | const std::bernoulli_distribution& __x); |
3632 | |
3633 | |
3634 | |
3635 | |
3636 | |
3637 | |
3638 | |
3639 | |
3640 | |
3641 | |
3642 | template<typename _CharT, typename _Traits> |
3643 | std::basic_istream<_CharT, _Traits>& |
3644 | operator>>(std::basic_istream<_CharT, _Traits>& __is, |
3645 | std::bernoulli_distribution& __x) |
3646 | { |
3647 | double __p; |
3648 | __is >> __p; |
3649 | __x.param(bernoulli_distribution::param_type(__p)); |
3650 | return __is; |
3651 | } |
3652 | |
3653 | |
3654 | |
3655 | |
3656 | |
3657 | |
3658 | |
3659 | |
3660 | |
3661 | template<typename _IntType = int> |
3662 | class binomial_distribution |
3663 | { |
3664 | static_assert(std::is_integral<_IntType>::value, |
3665 | "result_type must be an integral type"); |
3666 | |
3667 | public: |
3668 | |
3669 | typedef _IntType result_type; |
3670 | |
3671 | |
3672 | struct param_type |
3673 | { |
3674 | typedef binomial_distribution<_IntType> distribution_type; |
3675 | friend class binomial_distribution<_IntType>; |
3676 | |
3677 | explicit |
3678 | param_type(_IntType __t = _IntType(1), double __p = 0.5) |
3679 | : _M_t(__t), _M_p(__p) |
3680 | { |
3681 | __glibcxx_assert((_M_t >= _IntType(0)) |
3682 | && (_M_p >= 0.0) |
3683 | && (_M_p <= 1.0)); |
3684 | _M_initialize(); |
3685 | } |
3686 | |
3687 | _IntType |
3688 | t() const |
3689 | { return _M_t; } |
3690 | |
3691 | double |
3692 | p() const |
3693 | { return _M_p; } |
3694 | |
3695 | friend bool |
3696 | operator==(const param_type& __p1, const param_type& __p2) |
3697 | { return __p1._M_t == __p2._M_t && __p1._M_p == __p2._M_p; } |
3698 | |
3699 | friend bool |
3700 | operator!=(const param_type& __p1, const param_type& __p2) |
3701 | { return !(__p1 == __p2); } |
3702 | |
3703 | private: |
3704 | void |
3705 | _M_initialize(); |
3706 | |
3707 | _IntType _M_t; |
3708 | double _M_p; |
3709 | |
3710 | double _M_q; |
3711 | #if _GLIBCXX_USE_C99_MATH_TR1 |
3712 | double _M_d1, _M_d2, _M_s1, _M_s2, _M_c, |
3713 | _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p; |
3714 | #endif |
3715 | bool _M_easy; |
3716 | }; |
3717 | |
3718 | |
3719 | explicit |
3720 | binomial_distribution(_IntType __t = _IntType(1), |
3721 | double __p = 0.5) |
3722 | : _M_param(__t, __p), _M_nd() |
3723 | { } |
3724 | |
3725 | explicit |
3726 | binomial_distribution(const param_type& __p) |
3727 | : _M_param(__p), _M_nd() |
3728 | { } |
3729 | |
3730 | |
3731 | |
3732 | |
3733 | void |
3734 | reset() |
3735 | { _M_nd.reset(); } |
3736 | |
3737 | |
3738 | |
3739 | |
3740 | _IntType |
3741 | t() const |
3742 | { return _M_param.t(); } |
3743 | |
3744 | |
3745 | |
3746 | |
3747 | double |
3748 | p() const |
3749 | { return _M_param.p(); } |
3750 | |
3751 | |
3752 | |
3753 | |
3754 | param_type |
3755 | param() const |
3756 | { return _M_param; } |
3757 | |
3758 | |
3759 | |
3760 | |
3761 | |
3762 | void |
3763 | param(const param_type& __param) |
3764 | { _M_param = __param; } |
3765 | |
3766 | |
3767 | |
3768 | |
3769 | result_type |
3770 | min() const |
3771 | { return 0; } |
3772 | |
3773 | |
3774 | |
3775 | |
3776 | result_type |
3777 | max() const |
3778 | { return _M_param.t(); } |
3779 | |
3780 | |
3781 | |
3782 | |
3783 | template<typename _UniformRandomNumberGenerator> |
3784 | result_type |
3785 | operator()(_UniformRandomNumberGenerator& __urng) |
3786 | { return this->operator()(__urng, _M_param); } |
3787 | |
3788 | template<typename _UniformRandomNumberGenerator> |
3789 | result_type |
3790 | operator()(_UniformRandomNumberGenerator& __urng, |
3791 | const param_type& __p); |
3792 | |
3793 | template<typename _ForwardIterator, |
3794 | typename _UniformRandomNumberGenerator> |
3795 | void |
3796 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
3797 | _UniformRandomNumberGenerator& __urng) |
3798 | { this->__generate(__f, __t, __urng, _M_param); } |
3799 | |
3800 | template<typename _ForwardIterator, |
3801 | typename _UniformRandomNumberGenerator> |
3802 | void |
3803 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
3804 | _UniformRandomNumberGenerator& __urng, |
3805 | const param_type& __p) |
3806 | { this->__generate_impl(__f, __t, __urng, __p); } |
3807 | |
3808 | template<typename _UniformRandomNumberGenerator> |
3809 | void |
3810 | __generate(result_type* __f, result_type* __t, |
3811 | _UniformRandomNumberGenerator& __urng, |
3812 | const param_type& __p) |
3813 | { this->__generate_impl(__f, __t, __urng, __p); } |
3814 | |
3815 | |
3816 | |
3817 | |
3818 | |
3819 | |
3820 | friend bool |
3821 | operator==(const binomial_distribution& __d1, |
3822 | const binomial_distribution& __d2) |
3823 | #ifdef _GLIBCXX_USE_C99_MATH_TR1 |
3824 | { return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; } |
3825 | #else |
3826 | { return __d1._M_param == __d2._M_param; } |
3827 | #endif |
3828 | |
3829 | |
3830 | |
3831 | |
3832 | |
3833 | |
3834 | |
3835 | |
3836 | |
3837 | |
3838 | |
3839 | template<typename _IntType1, |
3840 | typename _CharT, typename _Traits> |
3841 | friend std::basic_ostream<_CharT, _Traits>& |
3842 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, |
3843 | const std::binomial_distribution<_IntType1>& __x); |
3844 | |
3845 | |
3846 | |
3847 | |
3848 | |
3849 | |
3850 | |
3851 | |
3852 | |
3853 | |
3854 | |
3855 | template<typename _IntType1, |
3856 | typename _CharT, typename _Traits> |
3857 | friend std::basic_istream<_CharT, _Traits>& |
3858 | operator>>(std::basic_istream<_CharT, _Traits>& __is, |
3859 | std::binomial_distribution<_IntType1>& __x); |
3860 | |
3861 | private: |
3862 | template<typename _ForwardIterator, |
3863 | typename _UniformRandomNumberGenerator> |
3864 | void |
3865 | __generate_impl(_ForwardIterator __f, _ForwardIterator __t, |
3866 | _UniformRandomNumberGenerator& __urng, |
3867 | const param_type& __p); |
3868 | |
3869 | template<typename _UniformRandomNumberGenerator> |
3870 | result_type |
3871 | _M_waiting(_UniformRandomNumberGenerator& __urng, |
3872 | _IntType __t, double __q); |
3873 | |
3874 | param_type _M_param; |
3875 | |
3876 | |
3877 | std::normal_distribution<double> _M_nd; |
3878 | }; |
3879 | |
3880 | |
3881 | |
3882 | |
3883 | template<typename _IntType> |
3884 | inline bool |
3885 | operator!=(const std::binomial_distribution<_IntType>& __d1, |
3886 | const std::binomial_distribution<_IntType>& __d2) |
3887 | { return !(__d1 == __d2); } |
3888 | |
3889 | |
3890 | |
3891 | |
3892 | |
3893 | |
3894 | |
3895 | |
3896 | |
3897 | template<typename _IntType = int> |
3898 | class geometric_distribution |
3899 | { |
3900 | static_assert(std::is_integral<_IntType>::value, |
3901 | "result_type must be an integral type"); |
3902 | |
3903 | public: |
3904 | |
3905 | typedef _IntType result_type; |
3906 | |
3907 | |
3908 | struct param_type |
3909 | { |
3910 | typedef geometric_distribution<_IntType> distribution_type; |
3911 | friend class geometric_distribution<_IntType>; |
3912 | |
3913 | explicit |
3914 | param_type(double __p = 0.5) |
3915 | : _M_p(__p) |
3916 | { |
3917 | __glibcxx_assert((_M_p > 0.0) && (_M_p < 1.0)); |
3918 | _M_initialize(); |
3919 | } |
3920 | |
3921 | double |
3922 | p() const |
3923 | { return _M_p; } |
3924 | |
3925 | friend bool |
3926 | operator==(const param_type& __p1, const param_type& __p2) |
3927 | { return __p1._M_p == __p2._M_p; } |
3928 | |
3929 | friend bool |
3930 | operator!=(const param_type& __p1, const param_type& __p2) |
3931 | { return !(__p1 == __p2); } |
3932 | |
3933 | private: |
3934 | void |
3935 | _M_initialize() |
3936 | { _M_log_1_p = std::log(1.0 - _M_p); } |
3937 | |
3938 | double _M_p; |
3939 | |
3940 | double _M_log_1_p; |
3941 | }; |
3942 | |
3943 | |
3944 | explicit |
3945 | geometric_distribution(double __p = 0.5) |
3946 | : _M_param(__p) |
3947 | { } |
3948 | |
3949 | explicit |
3950 | geometric_distribution(const param_type& __p) |
3951 | : _M_param(__p) |
3952 | { } |
3953 | |
3954 | |
3955 | |
3956 | |
3957 | |
3958 | |
3959 | void |
3960 | reset() { } |
3961 | |
3962 | |
3963 | |
3964 | |
3965 | double |
3966 | p() const |
3967 | { return _M_param.p(); } |
3968 | |
3969 | |
3970 | |
3971 | |
3972 | param_type |
3973 | param() const |
3974 | { return _M_param; } |
3975 | |
3976 | |
3977 | |
3978 | |
3979 | |
3980 | void |
3981 | param(const param_type& __param) |
3982 | { _M_param = __param; } |
3983 | |
3984 | |
3985 | |
3986 | |
3987 | result_type |
3988 | min() const |
3989 | { return 0; } |
3990 | |
3991 | |
3992 | |
3993 | |
3994 | result_type |
3995 | max() const |
3996 | { return std::numeric_limits<result_type>::max(); } |
3997 | |
3998 | |
3999 | |
4000 | |
4001 | template<typename _UniformRandomNumberGenerator> |
4002 | result_type |
4003 | operator()(_UniformRandomNumberGenerator& __urng) |
4004 | { return this->operator()(__urng, _M_param); } |
4005 | |
4006 | template<typename _UniformRandomNumberGenerator> |
4007 | result_type |
4008 | operator()(_UniformRandomNumberGenerator& __urng, |
4009 | const param_type& __p); |
4010 | |
4011 | template<typename _ForwardIterator, |
4012 | typename _UniformRandomNumberGenerator> |
4013 | void |
4014 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
4015 | _UniformRandomNumberGenerator& __urng) |
4016 | { this->__generate(__f, __t, __urng, _M_param); } |
4017 | |
4018 | template<typename _ForwardIterator, |
4019 | typename _UniformRandomNumberGenerator> |
4020 | void |
4021 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
4022 | _UniformRandomNumberGenerator& __urng, |
4023 | const param_type& __p) |
4024 | { this->__generate_impl(__f, __t, __urng, __p); } |
4025 | |
4026 | template<typename _UniformRandomNumberGenerator> |
4027 | void |
4028 | __generate(result_type* __f, result_type* __t, |
4029 | _UniformRandomNumberGenerator& __urng, |
4030 | const param_type& __p) |
4031 | { this->__generate_impl(__f, __t, __urng, __p); } |
4032 | |
4033 | |
4034 | |
4035 | |
4036 | |
4037 | friend bool |
4038 | operator==(const geometric_distribution& __d1, |
4039 | const geometric_distribution& __d2) |
4040 | { return __d1._M_param == __d2._M_param; } |
4041 | |
4042 | private: |
4043 | template<typename _ForwardIterator, |
4044 | typename _UniformRandomNumberGenerator> |
4045 | void |
4046 | __generate_impl(_ForwardIterator __f, _ForwardIterator __t, |
4047 | _UniformRandomNumberGenerator& __urng, |
4048 | const param_type& __p); |
4049 | |
4050 | param_type _M_param; |
4051 | }; |
4052 | |
4053 | |
4054 | |
4055 | |
4056 | |
4057 | template<typename _IntType> |
4058 | inline bool |
4059 | operator!=(const std::geometric_distribution<_IntType>& __d1, |
4060 | const std::geometric_distribution<_IntType>& __d2) |
4061 | { return !(__d1 == __d2); } |
4062 | |
4063 | |
4064 | |
4065 | |
4066 | |
4067 | |
4068 | |
4069 | |
4070 | |
4071 | |
4072 | |
4073 | template<typename _IntType, |
4074 | typename _CharT, typename _Traits> |
4075 | std::basic_ostream<_CharT, _Traits>& |
4076 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, |
4077 | const std::geometric_distribution<_IntType>& __x); |
4078 | |
4079 | |
4080 | |
4081 | |
4082 | |
4083 | |
4084 | |
4085 | |
4086 | |
4087 | |
4088 | template<typename _IntType, |
4089 | typename _CharT, typename _Traits> |
4090 | std::basic_istream<_CharT, _Traits>& |
4091 | operator>>(std::basic_istream<_CharT, _Traits>& __is, |
4092 | std::geometric_distribution<_IntType>& __x); |
4093 | |
4094 | |
4095 | |
4096 | |
4097 | |
4098 | |
4099 | |
4100 | |
4101 | |
4102 | template<typename _IntType = int> |
4103 | class negative_binomial_distribution |
4104 | { |
4105 | static_assert(std::is_integral<_IntType>::value, |
4106 | "result_type must be an integral type"); |
4107 | |
4108 | public: |
4109 | |
4110 | typedef _IntType result_type; |
4111 | |
4112 | |
4113 | struct param_type |
4114 | { |
4115 | typedef negative_binomial_distribution<_IntType> distribution_type; |
4116 | |
4117 | explicit |
4118 | param_type(_IntType __k = 1, double __p = 0.5) |
4119 | : _M_k(__k), _M_p(__p) |
4120 | { |
4121 | __glibcxx_assert((_M_k > 0) && (_M_p > 0.0) && (_M_p <= 1.0)); |
4122 | } |
4123 | |
4124 | _IntType |
4125 | k() const |
4126 | { return _M_k; } |
4127 | |
4128 | double |
4129 | p() const |
4130 | { return _M_p; } |
4131 | |
4132 | friend bool |
4133 | operator==(const param_type& __p1, const param_type& __p2) |
4134 | { return __p1._M_k == __p2._M_k && __p1._M_p == __p2._M_p; } |
4135 | |
4136 | friend bool |
4137 | operator!=(const param_type& __p1, const param_type& __p2) |
4138 | { return !(__p1 == __p2); } |
4139 | |
4140 | private: |
4141 | _IntType _M_k; |
4142 | double _M_p; |
4143 | }; |
4144 | |
4145 | explicit |
4146 | negative_binomial_distribution(_IntType __k = 1, double __p = 0.5) |
4147 | : _M_param(__k, __p), _M_gd(__k, (1.0 - __p) / __p) |
4148 | { } |
4149 | |
4150 | explicit |
4151 | negative_binomial_distribution(const param_type& __p) |
4152 | : _M_param(__p), _M_gd(__p.k(), (1.0 - __p.p()) / __p.p()) |
4153 | { } |
4154 | |
4155 | |
4156 | |
4157 | |
4158 | void |
4159 | reset() |
4160 | { _M_gd.reset(); } |
4161 | |
4162 | |
4163 | |
4164 | |
4165 | _IntType |
4166 | k() const |
4167 | { return _M_param.k(); } |
4168 | |
4169 | |
4170 | |
4171 | |
4172 | double |
4173 | p() const |
4174 | { return _M_param.p(); } |
4175 | |
4176 | |
4177 | |
4178 | |
4179 | param_type |
4180 | param() const |
4181 | { return _M_param; } |
4182 | |
4183 | |
4184 | |
4185 | |
4186 | |
4187 | void |
4188 | param(const param_type& __param) |
4189 | { _M_param = __param; } |
4190 | |
4191 | |
4192 | |
4193 | |
4194 | result_type |
4195 | min() const |
4196 | { return result_type(0); } |
4197 | |
4198 | |
4199 | |
4200 | |
4201 | result_type |
4202 | max() const |
4203 | { return std::numeric_limits<result_type>::max(); } |
4204 | |
4205 | |
4206 | |
4207 | |
4208 | template<typename _UniformRandomNumberGenerator> |
4209 | result_type |
4210 | operator()(_UniformRandomNumberGenerator& __urng); |
4211 | |
4212 | template<typename _UniformRandomNumberGenerator> |
4213 | result_type |
4214 | operator()(_UniformRandomNumberGenerator& __urng, |
4215 | const param_type& __p); |
4216 | |
4217 | template<typename _ForwardIterator, |
4218 | typename _UniformRandomNumberGenerator> |
4219 | void |
4220 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
4221 | _UniformRandomNumberGenerator& __urng) |
4222 | { this->__generate_impl(__f, __t, __urng); } |
4223 | |
4224 | template<typename _ForwardIterator, |
4225 | typename _UniformRandomNumberGenerator> |
4226 | void |
4227 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
4228 | _UniformRandomNumberGenerator& __urng, |
4229 | const param_type& __p) |
4230 | { this->__generate_impl(__f, __t, __urng, __p); } |
4231 | |
4232 | template<typename _UniformRandomNumberGenerator> |
4233 | void |
4234 | __generate(result_type* __f, result_type* __t, |
4235 | _UniformRandomNumberGenerator& __urng) |
4236 | { this->__generate_impl(__f, __t, __urng); } |
4237 | |
4238 | template<typename _UniformRandomNumberGenerator> |
4239 | void |
4240 | __generate(result_type* __f, result_type* __t, |
4241 | _UniformRandomNumberGenerator& __urng, |
4242 | const param_type& __p) |
4243 | { this->__generate_impl(__f, __t, __urng, __p); } |
4244 | |
4245 | |
4246 | |
4247 | |
4248 | |
4249 | |
4250 | friend bool |
4251 | operator==(const negative_binomial_distribution& __d1, |
4252 | const negative_binomial_distribution& __d2) |
4253 | { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; } |
4254 | |
4255 | |
4256 | |
4257 | |
4258 | |
4259 | |
4260 | |
4261 | |
4262 | |
4263 | |
4264 | |
4265 | |
4266 | template<typename _IntType1, typename _CharT, typename _Traits> |
4267 | friend std::basic_ostream<_CharT, _Traits>& |
4268 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, |
4269 | const std::negative_binomial_distribution<_IntType1>& __x); |
4270 | |
4271 | |
4272 | |
4273 | |
4274 | |
4275 | |
4276 | |
4277 | |
4278 | |
4279 | |
4280 | |
4281 | template<typename _IntType1, typename _CharT, typename _Traits> |
4282 | friend std::basic_istream<_CharT, _Traits>& |
4283 | operator>>(std::basic_istream<_CharT, _Traits>& __is, |
4284 | std::negative_binomial_distribution<_IntType1>& __x); |
4285 | |
4286 | private: |
4287 | template<typename _ForwardIterator, |
4288 | typename _UniformRandomNumberGenerator> |
4289 | void |
4290 | __generate_impl(_ForwardIterator __f, _ForwardIterator __t, |
4291 | _UniformRandomNumberGenerator& __urng); |
4292 | template<typename _ForwardIterator, |
4293 | typename _UniformRandomNumberGenerator> |
4294 | void |
4295 | __generate_impl(_ForwardIterator __f, _ForwardIterator __t, |
4296 | _UniformRandomNumberGenerator& __urng, |
4297 | const param_type& __p); |
4298 | |
4299 | param_type _M_param; |
4300 | |
4301 | std::gamma_distribution<double> _M_gd; |
4302 | }; |
4303 | |
4304 | |
4305 | |
4306 | |
4307 | template<typename _IntType> |
4308 | inline bool |
4309 | operator!=(const std::negative_binomial_distribution<_IntType>& __d1, |
4310 | const std::negative_binomial_distribution<_IntType>& __d2) |
4311 | { return !(__d1 == __d2); } |
4312 | |
4313 | |
4314 | |
4315 | |
4316 | |
4317 | |
4318 | |
4319 | |
4320 | |
4321 | |
4322 | |
4323 | |
4324 | |
4325 | |
4326 | |
4327 | |
4328 | |
4329 | template<typename _IntType = int> |
4330 | class poisson_distribution |
4331 | { |
4332 | static_assert(std::is_integral<_IntType>::value, |
4333 | "result_type must be an integral type"); |
4334 | |
4335 | public: |
4336 | |
4337 | typedef _IntType result_type; |
4338 | |
4339 | |
4340 | struct param_type |
4341 | { |
4342 | typedef poisson_distribution<_IntType> distribution_type; |
4343 | friend class poisson_distribution<_IntType>; |
4344 | |
4345 | explicit |
4346 | param_type(double __mean = 1.0) |
4347 | : _M_mean(__mean) |
4348 | { |
4349 | __glibcxx_assert(_M_mean > 0.0); |
4350 | _M_initialize(); |
4351 | } |
4352 | |
4353 | double |
4354 | mean() const |
4355 | { return _M_mean; } |
4356 | |
4357 | friend bool |
4358 | operator==(const param_type& __p1, const param_type& __p2) |
4359 | { return __p1._M_mean == __p2._M_mean; } |
4360 | |
4361 | friend bool |
4362 | operator!=(const param_type& __p1, const param_type& __p2) |
4363 | { return !(__p1 == __p2); } |
4364 | |
4365 | private: |
4366 | |
4367 | void |
4368 | _M_initialize(); |
4369 | |
4370 | double _M_mean; |
4371 | |
4372 | double _M_lm_thr; |
4373 | #if _GLIBCXX_USE_C99_MATH_TR1 |
4374 | double _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb; |
4375 | #endif |
4376 | }; |
4377 | |
4378 | |
4379 | explicit |
4380 | poisson_distribution(double __mean = 1.0) |
4381 | : _M_param(__mean), _M_nd() |
4382 | { } |
4383 | |
4384 | explicit |
4385 | poisson_distribution(const param_type& __p) |
4386 | : _M_param(__p), _M_nd() |
4387 | { } |
4388 | |
4389 | |
4390 | |
4391 | |
4392 | void |
4393 | reset() |
4394 | { _M_nd.reset(); } |
4395 | |
4396 | |
4397 | |
4398 | |
4399 | double |
4400 | mean() const |
4401 | { return _M_param.mean(); } |
4402 | |
4403 | |
4404 | |
4405 | |
4406 | param_type |
4407 | param() const |
4408 | { return _M_param; } |
4409 | |
4410 | |
4411 | |
4412 | |
4413 | |
4414 | void |
4415 | param(const param_type& __param) |
4416 | { _M_param = __param; } |
4417 | |
4418 | |
4419 | |
4420 | |
4421 | result_type |
4422 | min() const |
4423 | { return 0; } |
4424 | |
4425 | |
4426 | |
4427 | |
4428 | result_type |
4429 | max() const |
4430 | { return std::numeric_limits<result_type>::max(); } |
4431 | |
4432 | |
4433 | |
4434 | |
4435 | template<typename _UniformRandomNumberGenerator> |
4436 | result_type |
4437 | operator()(_UniformRandomNumberGenerator& __urng) |
4438 | { return this->operator()(__urng, _M_param); } |
4439 | |
4440 | template<typename _UniformRandomNumberGenerator> |
4441 | result_type |
4442 | operator()(_UniformRandomNumberGenerator& __urng, |
4443 | const param_type& __p); |
4444 | |
4445 | template<typename _ForwardIterator, |
4446 | typename _UniformRandomNumberGenerator> |
4447 | void |
4448 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
4449 | _UniformRandomNumberGenerator& __urng) |
4450 | { this->__generate(__f, __t, __urng, _M_param); } |
4451 | |
4452 | template<typename _ForwardIterator, |
4453 | typename _UniformRandomNumberGenerator> |
4454 | void |
4455 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
4456 | _UniformRandomNumberGenerator& __urng, |
4457 | const param_type& __p) |
4458 | { this->__generate_impl(__f, __t, __urng, __p); } |
4459 | |
4460 | template<typename _UniformRandomNumberGenerator> |
4461 | void |
4462 | __generate(result_type* __f, result_type* __t, |
4463 | _UniformRandomNumberGenerator& __urng, |
4464 | const param_type& __p) |
4465 | { this->__generate_impl(__f, __t, __urng, __p); } |
4466 | |
4467 | |
4468 | |
4469 | |
4470 | |
4471 | |
4472 | friend bool |
4473 | operator==(const poisson_distribution& __d1, |
4474 | const poisson_distribution& __d2) |
4475 | #ifdef _GLIBCXX_USE_C99_MATH_TR1 |
4476 | { return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; } |
4477 | #else |
4478 | { return __d1._M_param == __d2._M_param; } |
4479 | #endif |
4480 | |
4481 | |
4482 | |
4483 | |
4484 | |
4485 | |
4486 | |
4487 | |
4488 | |
4489 | |
4490 | |
4491 | template<typename _IntType1, typename _CharT, typename _Traits> |
4492 | friend std::basic_ostream<_CharT, _Traits>& |
4493 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, |
4494 | const std::poisson_distribution<_IntType1>& __x); |
4495 | |
4496 | |
4497 | |
4498 | |
4499 | |
4500 | |
4501 | |
4502 | |
4503 | |
4504 | |
4505 | |
4506 | template<typename _IntType1, typename _CharT, typename _Traits> |
4507 | friend std::basic_istream<_CharT, _Traits>& |
4508 | operator>>(std::basic_istream<_CharT, _Traits>& __is, |
4509 | std::poisson_distribution<_IntType1>& __x); |
4510 | |
4511 | private: |
4512 | template<typename _ForwardIterator, |
4513 | typename _UniformRandomNumberGenerator> |
4514 | void |
4515 | __generate_impl(_ForwardIterator __f, _ForwardIterator __t, |
4516 | _UniformRandomNumberGenerator& __urng, |
4517 | const param_type& __p); |
4518 | |
4519 | param_type _M_param; |
4520 | |
4521 | |
4522 | std::normal_distribution<double> _M_nd; |
4523 | }; |
4524 | |
4525 | |
4526 | |
4527 | |
4528 | template<typename _IntType> |
4529 | inline bool |
4530 | operator!=(const std::poisson_distribution<_IntType>& __d1, |
4531 | const std::poisson_distribution<_IntType>& __d2) |
4532 | { return !(__d1 == __d2); } |
4533 | |
4534 | |
4535 | |
4536 | |
4537 | |
4538 | |
4539 | |
4540 | |
4541 | |
4542 | |
4543 | |
4544 | |
4545 | |
4546 | |
4547 | |
4548 | |
4549 | |
4550 | template<typename _RealType = double> |
4551 | class exponential_distribution |
4552 | { |
4553 | static_assert(std::is_floating_point<_RealType>::value, |
4554 | "result_type must be a floating point type"); |
4555 | |
4556 | public: |
4557 | |
4558 | typedef _RealType result_type; |
4559 | |
4560 | |
4561 | struct param_type |
4562 | { |
4563 | typedef exponential_distribution<_RealType> distribution_type; |
4564 | |
4565 | explicit |
4566 | param_type(_RealType __lambda = _RealType(1)) |
4567 | : _M_lambda(__lambda) |
4568 | { |
4569 | __glibcxx_assert(_M_lambda > _RealType(0)); |
4570 | } |
4571 | |
4572 | _RealType |
4573 | lambda() const |
4574 | { return _M_lambda; } |
4575 | |
4576 | friend bool |
4577 | operator==(const param_type& __p1, const param_type& __p2) |
4578 | { return __p1._M_lambda == __p2._M_lambda; } |
4579 | |
4580 | friend bool |
4581 | operator!=(const param_type& __p1, const param_type& __p2) |
4582 | { return !(__p1 == __p2); } |
4583 | |
4584 | private: |
4585 | _RealType _M_lambda; |
4586 | }; |
4587 | |
4588 | public: |
4589 | |
4590 | |
4591 | |
4592 | |
4593 | explicit |
4594 | exponential_distribution(const result_type& __lambda = result_type(1)) |
4595 | : _M_param(__lambda) |
4596 | { } |
4597 | |
4598 | explicit |
4599 | exponential_distribution(const param_type& __p) |
4600 | : _M_param(__p) |
4601 | { } |
4602 | |
4603 | |
4604 | |
4605 | |
4606 | |
4607 | |
4608 | void |
4609 | reset() { } |
4610 | |
4611 | |
4612 | |
4613 | |
4614 | _RealType |
4615 | lambda() const |
4616 | { return _M_param.lambda(); } |
4617 | |
4618 | |
4619 | |
4620 | |
4621 | param_type |
4622 | param() const |
4623 | { return _M_param; } |
4624 | |
4625 | |
4626 | |
4627 | |
4628 | |
4629 | void |
4630 | param(const param_type& __param) |
4631 | { _M_param = __param; } |
4632 | |
4633 | |
4634 | |
4635 | |
4636 | result_type |
4637 | min() const |
4638 | { return result_type(0); } |
4639 | |
4640 | |
4641 | |
4642 | |
4643 | result_type |
4644 | max() const |
4645 | { return std::numeric_limits<result_type>::max(); } |
4646 | |
4647 | |
4648 | |
4649 | |
4650 | template<typename _UniformRandomNumberGenerator> |
4651 | result_type |
4652 | operator()(_UniformRandomNumberGenerator& __urng) |
4653 | { return this->operator()(__urng, _M_param); } |
4654 | |
4655 | template<typename _UniformRandomNumberGenerator> |
4656 | result_type |
4657 | operator()(_UniformRandomNumberGenerator& __urng, |
4658 | const param_type& __p) |
4659 | { |
4660 | __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> |
4661 | __aurng(__urng); |
4662 | return -std::log(result_type(1) - __aurng()) / __p.lambda(); |
4663 | } |
4664 | |
4665 | template<typename _ForwardIterator, |
4666 | typename _UniformRandomNumberGenerator> |
4667 | void |
4668 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
4669 | _UniformRandomNumberGenerator& __urng) |
4670 | { this->__generate(__f, __t, __urng, _M_param); } |
4671 | |
4672 | template<typename _ForwardIterator, |
4673 | typename _UniformRandomNumberGenerator> |
4674 | void |
4675 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
4676 | _UniformRandomNumberGenerator& __urng, |
4677 | const param_type& __p) |
4678 | { this->__generate_impl(__f, __t, __urng, __p); } |
4679 | |
4680 | template<typename _UniformRandomNumberGenerator> |
4681 | void |
4682 | __generate(result_type* __f, result_type* __t, |
4683 | _UniformRandomNumberGenerator& __urng, |
4684 | const param_type& __p) |
4685 | { this->__generate_impl(__f, __t, __urng, __p); } |
4686 | |
4687 | |
4688 | |
4689 | |
4690 | |
4691 | friend bool |
4692 | operator==(const exponential_distribution& __d1, |
4693 | const exponential_distribution& __d2) |
4694 | { return __d1._M_param == __d2._M_param; } |
4695 | |
4696 | private: |
4697 | template<typename _ForwardIterator, |
4698 | typename _UniformRandomNumberGenerator> |
4699 | void |
4700 | __generate_impl(_ForwardIterator __f, _ForwardIterator __t, |
4701 | _UniformRandomNumberGenerator& __urng, |
4702 | const param_type& __p); |
4703 | |
4704 | param_type _M_param; |
4705 | }; |
4706 | |
4707 | |
4708 | |
4709 | |
4710 | |
4711 | template<typename _RealType> |
4712 | inline bool |
4713 | operator!=(const std::exponential_distribution<_RealType>& __d1, |
4714 | const std::exponential_distribution<_RealType>& __d2) |
4715 | { return !(__d1 == __d2); } |
4716 | |
4717 | |
4718 | |
4719 | |
4720 | |
4721 | |
4722 | |
4723 | |
4724 | |
4725 | |
4726 | |
4727 | template<typename _RealType, typename _CharT, typename _Traits> |
4728 | std::basic_ostream<_CharT, _Traits>& |
4729 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, |
4730 | const std::exponential_distribution<_RealType>& __x); |
4731 | |
4732 | |
4733 | |
4734 | |
4735 | |
4736 | |
4737 | |
4738 | |
4739 | |
4740 | |
4741 | |
4742 | template<typename _RealType, typename _CharT, typename _Traits> |
4743 | std::basic_istream<_CharT, _Traits>& |
4744 | operator>>(std::basic_istream<_CharT, _Traits>& __is, |
4745 | std::exponential_distribution<_RealType>& __x); |
4746 | |
4747 | |
4748 | |
4749 | |
4750 | |
4751 | |
4752 | |
4753 | |
4754 | |
4755 | |
4756 | |
4757 | template<typename _RealType = double> |
4758 | class weibull_distribution |
4759 | { |
4760 | static_assert(std::is_floating_point<_RealType>::value, |
4761 | "result_type must be a floating point type"); |
4762 | |
4763 | public: |
4764 | |
4765 | typedef _RealType result_type; |
4766 | |
4767 | |
4768 | struct param_type |
4769 | { |
4770 | typedef weibull_distribution<_RealType> distribution_type; |
4771 | |
4772 | explicit |
4773 | param_type(_RealType __a = _RealType(1), |
4774 | _RealType __b = _RealType(1)) |
4775 | : _M_a(__a), _M_b(__b) |
4776 | { } |
4777 | |
4778 | _RealType |
4779 | a() const |
4780 | { return _M_a; } |
4781 | |
4782 | _RealType |
4783 | b() const |
4784 | { return _M_b; } |
4785 | |
4786 | friend bool |
4787 | operator==(const param_type& __p1, const param_type& __p2) |
4788 | { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; } |
4789 | |
4790 | friend bool |
4791 | operator!=(const param_type& __p1, const param_type& __p2) |
4792 | { return !(__p1 == __p2); } |
4793 | |
4794 | private: |
4795 | _RealType _M_a; |
4796 | _RealType _M_b; |
4797 | }; |
4798 | |
4799 | explicit |
4800 | weibull_distribution(_RealType __a = _RealType(1), |
4801 | _RealType __b = _RealType(1)) |
4802 | : _M_param(__a, __b) |
4803 | { } |
4804 | |
4805 | explicit |
4806 | weibull_distribution(const param_type& __p) |
4807 | : _M_param(__p) |
4808 | { } |
4809 | |
4810 | |
4811 | |
4812 | |
4813 | void |
4814 | reset() |
4815 | { } |
4816 | |
4817 | |
4818 | |
4819 | |
4820 | _RealType |
4821 | a() const |
4822 | { return _M_param.a(); } |
4823 | |
4824 | |
4825 | |
4826 | |
4827 | _RealType |
4828 | b() const |
4829 | { return _M_param.b(); } |
4830 | |
4831 | |
4832 | |
4833 | |
4834 | param_type |
4835 | param() const |
4836 | { return _M_param; } |
4837 | |
4838 | |
4839 | |
4840 | |
4841 | |
4842 | void |
4843 | param(const param_type& __param) |
4844 | { _M_param = __param; } |
4845 | |
4846 | |
4847 | |
4848 | |
4849 | result_type |
4850 | min() const |
4851 | { return result_type(0); } |
4852 | |
4853 | |
4854 | |
4855 | |
4856 | result_type |
4857 | max() const |
4858 | { return std::numeric_limits<result_type>::max(); } |
4859 | |
4860 | |
4861 | |
4862 | |
4863 | template<typename _UniformRandomNumberGenerator> |
4864 | result_type |
4865 | operator()(_UniformRandomNumberGenerator& __urng) |
4866 | { return this->operator()(__urng, _M_param); } |
4867 | |
4868 | template<typename _UniformRandomNumberGenerator> |
4869 | result_type |
4870 | operator()(_UniformRandomNumberGenerator& __urng, |
4871 | const param_type& __p); |
4872 | |
4873 | template<typename _ForwardIterator, |
4874 | typename _UniformRandomNumberGenerator> |
4875 | void |
4876 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
4877 | _UniformRandomNumberGenerator& __urng) |
4878 | { this->__generate(__f, __t, __urng, _M_param); } |
4879 | |
4880 | template<typename _ForwardIterator, |
4881 | typename _UniformRandomNumberGenerator> |
4882 | void |
4883 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
4884 | _UniformRandomNumberGenerator& __urng, |
4885 | const param_type& __p) |
4886 | { this->__generate_impl(__f, __t, __urng, __p); } |
4887 | |
4888 | template<typename _UniformRandomNumberGenerator> |
4889 | void |
4890 | __generate(result_type* __f, result_type* __t, |
4891 | _UniformRandomNumberGenerator& __urng, |
4892 | const param_type& __p) |
4893 | { this->__generate_impl(__f, __t, __urng, __p); } |
4894 | |
4895 | |
4896 | |
4897 | |
4898 | |
4899 | friend bool |
4900 | operator==(const weibull_distribution& __d1, |
4901 | const weibull_distribution& __d2) |
4902 | { return __d1._M_param == __d2._M_param; } |
4903 | |
4904 | private: |
4905 | template<typename _ForwardIterator, |
4906 | typename _UniformRandomNumberGenerator> |
4907 | void |
4908 | __generate_impl(_ForwardIterator __f, _ForwardIterator __t, |
4909 | _UniformRandomNumberGenerator& __urng, |
4910 | const param_type& __p); |
4911 | |
4912 | param_type _M_param; |
4913 | }; |
4914 | |
4915 | |
4916 | |
4917 | |
4918 | |
4919 | template<typename _RealType> |
4920 | inline bool |
4921 | operator!=(const std::weibull_distribution<_RealType>& __d1, |
4922 | const std::weibull_distribution<_RealType>& __d2) |
4923 | { return !(__d1 == __d2); } |
4924 | |
4925 | |
4926 | |
4927 | |
4928 | |
4929 | |
4930 | |
4931 | |
4932 | |
4933 | |
4934 | |
4935 | template<typename _RealType, typename _CharT, typename _Traits> |
4936 | std::basic_ostream<_CharT, _Traits>& |
4937 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, |
4938 | const std::weibull_distribution<_RealType>& __x); |
4939 | |
4940 | |
4941 | |
4942 | |
4943 | |
4944 | |
4945 | |
4946 | |
4947 | |
4948 | |
4949 | |
4950 | template<typename _RealType, typename _CharT, typename _Traits> |
4951 | std::basic_istream<_CharT, _Traits>& |
4952 | operator>>(std::basic_istream<_CharT, _Traits>& __is, |
4953 | std::weibull_distribution<_RealType>& __x); |
4954 | |
4955 | |
4956 | |
4957 | |
4958 | |
4959 | |
4960 | |
4961 | |
4962 | |
4963 | |
4964 | |
4965 | template<typename _RealType = double> |
4966 | class extreme_value_distribution |
4967 | { |
4968 | static_assert(std::is_floating_point<_RealType>::value, |
4969 | "result_type must be a floating point type"); |
4970 | |
4971 | public: |
4972 | |
4973 | typedef _RealType result_type; |
4974 | |
4975 | |
4976 | struct param_type |
4977 | { |
4978 | typedef extreme_value_distribution<_RealType> distribution_type; |
4979 | |
4980 | explicit |
4981 | param_type(_RealType __a = _RealType(0), |
4982 | _RealType __b = _RealType(1)) |
4983 | : _M_a(__a), _M_b(__b) |
4984 | { } |
4985 | |
4986 | _RealType |
4987 | a() const |
4988 | { return _M_a; } |
4989 | |
4990 | _RealType |
4991 | b() const |
4992 | { return _M_b; } |
4993 | |
4994 | friend bool |
4995 | operator==(const param_type& __p1, const param_type& __p2) |
4996 | { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; } |
4997 | |
4998 | friend bool |
4999 | operator!=(const param_type& __p1, const param_type& __p2) |
5000 | { return !(__p1 == __p2); } |
5001 | |
5002 | private: |
5003 | _RealType _M_a; |
5004 | _RealType _M_b; |
5005 | }; |
5006 | |
5007 | explicit |
5008 | extreme_value_distribution(_RealType __a = _RealType(0), |
5009 | _RealType __b = _RealType(1)) |
5010 | : _M_param(__a, __b) |
5011 | { } |
5012 | |
5013 | explicit |
5014 | extreme_value_distribution(const param_type& __p) |
5015 | : _M_param(__p) |
5016 | { } |
5017 | |
5018 | |
5019 | |
5020 | |
5021 | void |
5022 | reset() |
5023 | { } |
5024 | |
5025 | |
5026 | |
5027 | |
5028 | _RealType |
5029 | a() const |
5030 | { return _M_param.a(); } |
5031 | |
5032 | |
5033 | |
5034 | |
5035 | _RealType |
5036 | b() const |
5037 | { return _M_param.b(); } |
5038 | |
5039 | |
5040 | |
5041 | |
5042 | param_type |
5043 | param() const |
5044 | { return _M_param; } |
5045 | |
5046 | |
5047 | |
5048 | |
5049 | |
5050 | void |
5051 | param(const param_type& __param) |
5052 | { _M_param = __param; } |
5053 | |
5054 | |
5055 | |
5056 | |
5057 | result_type |
5058 | min() const |
5059 | { return std::numeric_limits<result_type>::lowest(); } |
5060 | |
5061 | |
5062 | |
5063 | |
5064 | result_type |
5065 | max() const |
5066 | { return std::numeric_limits<result_type>::max(); } |
5067 | |
5068 | |
5069 | |
5070 | |
5071 | template<typename _UniformRandomNumberGenerator> |
5072 | result_type |
5073 | operator()(_UniformRandomNumberGenerator& __urng) |
5074 | { return this->operator()(__urng, _M_param); } |
5075 | |
5076 | template<typename _UniformRandomNumberGenerator> |
5077 | result_type |
5078 | operator()(_UniformRandomNumberGenerator& __urng, |
5079 | const param_type& __p); |
5080 | |
5081 | template<typename _ForwardIterator, |
5082 | typename _UniformRandomNumberGenerator> |
5083 | void |
5084 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
5085 | _UniformRandomNumberGenerator& __urng) |
5086 | { this->__generate(__f, __t, __urng, _M_param); } |
5087 | |
5088 | template<typename _ForwardIterator, |
5089 | typename _UniformRandomNumberGenerator> |
5090 | void |
5091 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
5092 | _UniformRandomNumberGenerator& __urng, |
5093 | const param_type& __p) |
5094 | { this->__generate_impl(__f, __t, __urng, __p); } |
5095 | |
5096 | template<typename _UniformRandomNumberGenerator> |
5097 | void |
5098 | __generate(result_type* __f, result_type* __t, |
5099 | _UniformRandomNumberGenerator& __urng, |
5100 | const param_type& __p) |
5101 | { this->__generate_impl(__f, __t, __urng, __p); } |
5102 | |
5103 | |
5104 | |
5105 | |
5106 | |
5107 | friend bool |
5108 | operator==(const extreme_value_distribution& __d1, |
5109 | const extreme_value_distribution& __d2) |
5110 | { return __d1._M_param == __d2._M_param; } |
5111 | |
5112 | private: |
5113 | template<typename _ForwardIterator, |
5114 | typename _UniformRandomNumberGenerator> |
5115 | void |
5116 | __generate_impl(_ForwardIterator __f, _ForwardIterator __t, |
5117 | _UniformRandomNumberGenerator& __urng, |
5118 | const param_type& __p); |
5119 | |
5120 | param_type _M_param; |
5121 | }; |
5122 | |
5123 | |
5124 | |
5125 | |
5126 | |
5127 | template<typename _RealType> |
5128 | inline bool |
5129 | operator!=(const std::extreme_value_distribution<_RealType>& __d1, |
5130 | const std::extreme_value_distribution<_RealType>& __d2) |
5131 | { return !(__d1 == __d2); } |
5132 | |
5133 | |
5134 | |
5135 | |
5136 | |
5137 | |
5138 | |
5139 | |
5140 | |
5141 | |
5142 | |
5143 | template<typename _RealType, typename _CharT, typename _Traits> |
5144 | std::basic_ostream<_CharT, _Traits>& |
5145 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, |
5146 | const std::extreme_value_distribution<_RealType>& __x); |
5147 | |
5148 | |
5149 | |
5150 | |
5151 | |
5152 | |
5153 | |
5154 | |
5155 | |
5156 | |
5157 | |
5158 | template<typename _RealType, typename _CharT, typename _Traits> |
5159 | std::basic_istream<_CharT, _Traits>& |
5160 | operator>>(std::basic_istream<_CharT, _Traits>& __is, |
5161 | std::extreme_value_distribution<_RealType>& __x); |
5162 | |
5163 | |
5164 | |
5165 | |
5166 | |
5167 | |
5168 | |
5169 | |
5170 | template<typename _IntType = int> |
5171 | class discrete_distribution |
5172 | { |
5173 | static_assert(std::is_integral<_IntType>::value, |
5174 | "result_type must be an integral type"); |
5175 | |
5176 | public: |
5177 | |
5178 | typedef _IntType result_type; |
5179 | |
5180 | |
5181 | struct param_type |
5182 | { |
5183 | typedef discrete_distribution<_IntType> distribution_type; |
5184 | friend class discrete_distribution<_IntType>; |
5185 | |
5186 | param_type() |
5187 | : _M_prob(), _M_cp() |
5188 | { } |
5189 | |
5190 | template<typename _InputIterator> |
5191 | param_type(_InputIterator __wbegin, |
5192 | _InputIterator __wend) |
5193 | : _M_prob(__wbegin, __wend), _M_cp() |
5194 | { _M_initialize(); } |
5195 | |
5196 | param_type(initializer_list<double> __wil) |
5197 | : _M_prob(__wil.begin(), __wil.end()), _M_cp() |
5198 | { _M_initialize(); } |
5199 | |
5200 | template<typename _Func> |
5201 | param_type(size_t __nw, double __xmin, double __xmax, |
5202 | _Func __fw); |
5203 | |
5204 | |
5205 | param_type(const param_type&) = default; |
5206 | param_type& operator=(const param_type&) = default; |
5207 | |
5208 | std::vector<double> |
5209 | probabilities() const |
5210 | { return _M_prob.empty() ? std::vector<double>(1, 1.0) : _M_prob; } |
5211 | |
5212 | friend bool |
5213 | operator==(const param_type& __p1, const param_type& __p2) |
5214 | { return __p1._M_prob == __p2._M_prob; } |
5215 | |
5216 | friend bool |
5217 | operator!=(const param_type& __p1, const param_type& __p2) |
5218 | { return !(__p1 == __p2); } |
5219 | |
5220 | private: |
5221 | void |
5222 | _M_initialize(); |
5223 | |
5224 | std::vector<double> _M_prob; |
5225 | std::vector<double> _M_cp; |
5226 | }; |
5227 | |
5228 | discrete_distribution() |
5229 | : _M_param() |
5230 | { } |
5231 | |
5232 | template<typename _InputIterator> |
5233 | discrete_distribution(_InputIterator __wbegin, |
5234 | _InputIterator __wend) |
5235 | : _M_param(__wbegin, __wend) |
5236 | { } |
5237 | |
5238 | discrete_distribution(initializer_list<double> __wl) |
5239 | : _M_param(__wl) |
5240 | { } |
5241 | |
5242 | template<typename _Func> |
5243 | discrete_distribution(size_t __nw, double __xmin, double __xmax, |
5244 | _Func __fw) |
5245 | : _M_param(__nw, __xmin, __xmax, __fw) |
5246 | { } |
5247 | |
5248 | explicit |
5249 | discrete_distribution(const param_type& __p) |
5250 | : _M_param(__p) |
5251 | { } |
5252 | |
5253 | |
5254 | |
5255 | |
5256 | void |
5257 | reset() |
5258 | { } |
5259 | |
5260 | |
5261 | |
5262 | |
5263 | std::vector<double> |
5264 | probabilities() const |
5265 | { |
5266 | return _M_param._M_prob.empty() |
5267 | ? std::vector<double>(1, 1.0) : _M_param._M_prob; |
5268 | } |
5269 | |
5270 | |
5271 | |
5272 | |
5273 | param_type |
5274 | param() const |
5275 | { return _M_param; } |
5276 | |
5277 | |
5278 | |
5279 | |
5280 | |
5281 | void |
5282 | param(const param_type& __param) |
5283 | { _M_param = __param; } |
5284 | |
5285 | |
5286 | |
5287 | |
5288 | result_type |
5289 | min() const |
5290 | { return result_type(0); } |
5291 | |
5292 | |
5293 | |
5294 | |
5295 | result_type |
5296 | max() const |
5297 | { |
5298 | return _M_param._M_prob.empty() |
5299 | ? result_type(0) : result_type(_M_param._M_prob.size() - 1); |
5300 | } |
5301 | |
5302 | |
5303 | |
5304 | |
5305 | template<typename _UniformRandomNumberGenerator> |
5306 | result_type |
5307 | operator()(_UniformRandomNumberGenerator& __urng) |
5308 | { return this->operator()(__urng, _M_param); } |
5309 | |
5310 | template<typename _UniformRandomNumberGenerator> |
5311 | result_type |
5312 | operator()(_UniformRandomNumberGenerator& __urng, |
5313 | const param_type& __p); |
5314 | |
5315 | template<typename _ForwardIterator, |
5316 | typename _UniformRandomNumberGenerator> |
5317 | void |
5318 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
5319 | _UniformRandomNumberGenerator& __urng) |
5320 | { this->__generate(__f, __t, __urng, _M_param); } |
5321 | |
5322 | template<typename _ForwardIterator, |
5323 | typename _UniformRandomNumberGenerator> |
5324 | void |
5325 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
5326 | _UniformRandomNumberGenerator& __urng, |
5327 | const param_type& __p) |
5328 | { this->__generate_impl(__f, __t, __urng, __p); } |
5329 | |
5330 | template<typename _UniformRandomNumberGenerator> |
5331 | void |
5332 | __generate(result_type* __f, result_type* __t, |
5333 | _UniformRandomNumberGenerator& __urng, |
5334 | const param_type& __p) |
5335 | { this->__generate_impl(__f, __t, __urng, __p); } |
5336 | |
5337 | |
5338 | |
5339 | |
5340 | |
5341 | friend bool |
5342 | operator==(const discrete_distribution& __d1, |
5343 | const discrete_distribution& __d2) |
5344 | { return __d1._M_param == __d2._M_param; } |
5345 | |
5346 | |
5347 | |
5348 | |
5349 | |
5350 | |
5351 | |
5352 | |
5353 | |
5354 | |
5355 | |
5356 | template<typename _IntType1, typename _CharT, typename _Traits> |
5357 | friend std::basic_ostream<_CharT, _Traits>& |
5358 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, |
5359 | const std::discrete_distribution<_IntType1>& __x); |
5360 | |
5361 | |
5362 | |
5363 | |
5364 | |
5365 | |
5366 | |
5367 | |
5368 | |
5369 | |
5370 | |
5371 | |
5372 | template<typename _IntType1, typename _CharT, typename _Traits> |
5373 | friend std::basic_istream<_CharT, _Traits>& |
5374 | operator>>(std::basic_istream<_CharT, _Traits>& __is, |
5375 | std::discrete_distribution<_IntType1>& __x); |
5376 | |
5377 | private: |
5378 | template<typename _ForwardIterator, |
5379 | typename _UniformRandomNumberGenerator> |
5380 | void |
5381 | __generate_impl(_ForwardIterator __f, _ForwardIterator __t, |
5382 | _UniformRandomNumberGenerator& __urng, |
5383 | const param_type& __p); |
5384 | |
5385 | param_type _M_param; |
5386 | }; |
5387 | |
5388 | |
5389 | |
5390 | |
5391 | |
5392 | template<typename _IntType> |
5393 | inline bool |
5394 | operator!=(const std::discrete_distribution<_IntType>& __d1, |
5395 | const std::discrete_distribution<_IntType>& __d2) |
5396 | { return !(__d1 == __d2); } |
5397 | |
5398 | |
5399 | |
5400 | |
5401 | |
5402 | |
5403 | |
5404 | |
5405 | template<typename _RealType = double> |
5406 | class piecewise_constant_distribution |
5407 | { |
5408 | static_assert(std::is_floating_point<_RealType>::value, |
5409 | "result_type must be a floating point type"); |
5410 | |
5411 | public: |
5412 | |
5413 | typedef _RealType result_type; |
5414 | |
5415 | |
5416 | struct param_type |
5417 | { |
5418 | typedef piecewise_constant_distribution<_RealType> distribution_type; |
5419 | friend class piecewise_constant_distribution<_RealType>; |
5420 | |
5421 | param_type() |
5422 | : _M_int(), _M_den(), _M_cp() |
5423 | { } |
5424 | |
5425 | template<typename _InputIteratorB, typename _InputIteratorW> |
5426 | param_type(_InputIteratorB __bfirst, |
5427 | _InputIteratorB __bend, |
5428 | _InputIteratorW __wbegin); |
5429 | |
5430 | template<typename _Func> |
5431 | param_type(initializer_list<_RealType> __bi, _Func __fw); |
5432 | |
5433 | template<typename _Func> |
5434 | param_type(size_t __nw, _RealType __xmin, _RealType __xmax, |
5435 | _Func __fw); |
5436 | |
5437 | |
5438 | param_type(const param_type&) = default; |
5439 | param_type& operator=(const param_type&) = default; |
5440 | |
5441 | std::vector<_RealType> |
5442 | intervals() const |
5443 | { |
5444 | if (_M_int.empty()) |
5445 | { |
5446 | std::vector<_RealType> __tmp(2); |
5447 | __tmp[1] = _RealType(1); |
5448 | return __tmp; |
5449 | } |
5450 | else |
5451 | return _M_int; |
5452 | } |
5453 | |
5454 | std::vector<double> |
5455 | densities() const |
5456 | { return _M_den.empty() ? std::vector<double>(1, 1.0) : _M_den; } |
5457 | |
5458 | friend bool |
5459 | operator==(const param_type& __p1, const param_type& __p2) |
5460 | { return __p1._M_int == __p2._M_int && __p1._M_den == __p2._M_den; } |
5461 | |
5462 | friend bool |
5463 | operator!=(const param_type& __p1, const param_type& __p2) |
5464 | { return !(__p1 == __p2); } |
5465 | |
5466 | private: |
5467 | void |
5468 | _M_initialize(); |
5469 | |
5470 | std::vector<_RealType> _M_int; |
5471 | std::vector<double> _M_den; |
5472 | std::vector<double> _M_cp; |
5473 | }; |
5474 | |
5475 | explicit |
5476 | piecewise_constant_distribution() |
5477 | : _M_param() |
5478 | { } |
5479 | |
5480 | template<typename _InputIteratorB, typename _InputIteratorW> |
5481 | piecewise_constant_distribution(_InputIteratorB __bfirst, |
5482 | _InputIteratorB __bend, |
5483 | _InputIteratorW __wbegin) |
5484 | : _M_param(__bfirst, __bend, __wbegin) |
5485 | { } |
5486 | |
5487 | template<typename _Func> |
5488 | piecewise_constant_distribution(initializer_list<_RealType> __bl, |
5489 | _Func __fw) |
5490 | : _M_param(__bl, __fw) |
5491 | { } |
5492 | |
5493 | template<typename _Func> |
5494 | piecewise_constant_distribution(size_t __nw, |
5495 | _RealType __xmin, _RealType __xmax, |
5496 | _Func __fw) |
5497 | : _M_param(__nw, __xmin, __xmax, __fw) |
5498 | { } |
5499 | |
5500 | explicit |
5501 | piecewise_constant_distribution(const param_type& __p) |
5502 | : _M_param(__p) |
5503 | { } |
5504 | |
5505 | |
5506 | |
5507 | |
5508 | void |
5509 | reset() |
5510 | { } |
5511 | |
5512 | |
5513 | |
5514 | |
5515 | std::vector<_RealType> |
5516 | intervals() const |
5517 | { |
5518 | if (_M_param._M_int.empty()) |
5519 | { |
5520 | std::vector<_RealType> __tmp(2); |
5521 | __tmp[1] = _RealType(1); |
5522 | return __tmp; |
5523 | } |
5524 | else |
5525 | return _M_param._M_int; |
5526 | } |
5527 | |
5528 | |
5529 | |
5530 | |
5531 | std::vector<double> |
5532 | densities() const |
5533 | { |
5534 | return _M_param._M_den.empty() |
5535 | ? std::vector<double>(1, 1.0) : _M_param._M_den; |
5536 | } |
5537 | |
5538 | |
5539 | |
5540 | |
5541 | param_type |
5542 | param() const |
5543 | { return _M_param; } |
5544 | |
5545 | |
5546 | |
5547 | |
5548 | |
5549 | void |
5550 | param(const param_type& __param) |
5551 | { _M_param = __param; } |
5552 | |
5553 | |
5554 | |
5555 | |
5556 | result_type |
5557 | min() const |
5558 | { |
5559 | return _M_param._M_int.empty() |
5560 | ? result_type(0) : _M_param._M_int.front(); |
5561 | } |
5562 | |
5563 | |
5564 | |
5565 | |
5566 | result_type |
5567 | max() const |
5568 | { |
5569 | return _M_param._M_int.empty() |
5570 | ? result_type(1) : _M_param._M_int.back(); |
5571 | } |
5572 | |
5573 | |
5574 | |
5575 | |
5576 | template<typename _UniformRandomNumberGenerator> |
5577 | result_type |
5578 | operator()(_UniformRandomNumberGenerator& __urng) |
5579 | { return this->operator()(__urng, _M_param); } |
5580 | |
5581 | template<typename _UniformRandomNumberGenerator> |
5582 | result_type |
5583 | operator()(_UniformRandomNumberGenerator& __urng, |
5584 | const param_type& __p); |
5585 | |
5586 | template<typename _ForwardIterator, |
5587 | typename _UniformRandomNumberGenerator> |
5588 | void |
5589 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
5590 | _UniformRandomNumberGenerator& __urng) |
5591 | { this->__generate(__f, __t, __urng, _M_param); } |
5592 | |
5593 | template<typename _ForwardIterator, |
5594 | typename _UniformRandomNumberGenerator> |
5595 | void |
5596 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
5597 | _UniformRandomNumberGenerator& __urng, |
5598 | const param_type& __p) |
5599 | { this->__generate_impl(__f, __t, __urng, __p); } |
5600 | |
5601 | template<typename _UniformRandomNumberGenerator> |
5602 | void |
5603 | __generate(result_type* __f, result_type* __t, |
5604 | _UniformRandomNumberGenerator& __urng, |
5605 | const param_type& __p) |
5606 | { this->__generate_impl(__f, __t, __urng, __p); } |
5607 | |
5608 | |
5609 | |
5610 | |
5611 | |
5612 | friend bool |
5613 | operator==(const piecewise_constant_distribution& __d1, |
5614 | const piecewise_constant_distribution& __d2) |
5615 | { return __d1._M_param == __d2._M_param; } |
5616 | |
5617 | |
5618 | |
5619 | |
5620 | |
5621 | |
5622 | |
5623 | |
5624 | |
5625 | |
5626 | |
5627 | |
5628 | template<typename _RealType1, typename _CharT, typename _Traits> |
5629 | friend std::basic_ostream<_CharT, _Traits>& |
5630 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, |
5631 | const std::piecewise_constant_distribution<_RealType1>& __x); |
5632 | |
5633 | |
5634 | |
5635 | |
5636 | |
5637 | |
5638 | |
5639 | |
5640 | |
5641 | |
5642 | |
5643 | |
5644 | template<typename _RealType1, typename _CharT, typename _Traits> |
5645 | friend std::basic_istream<_CharT, _Traits>& |
5646 | operator>>(std::basic_istream<_CharT, _Traits>& __is, |
5647 | std::piecewise_constant_distribution<_RealType1>& __x); |
5648 | |
5649 | private: |
5650 | template<typename _ForwardIterator, |
5651 | typename _UniformRandomNumberGenerator> |
5652 | void |
5653 | __generate_impl(_ForwardIterator __f, _ForwardIterator __t, |
5654 | _UniformRandomNumberGenerator& __urng, |
5655 | const param_type& __p); |
5656 | |
5657 | param_type _M_param; |
5658 | }; |
5659 | |
5660 | |
5661 | |
5662 | |
5663 | |
5664 | template<typename _RealType> |
5665 | inline bool |
5666 | operator!=(const std::piecewise_constant_distribution<_RealType>& __d1, |
5667 | const std::piecewise_constant_distribution<_RealType>& __d2) |
5668 | { return !(__d1 == __d2); } |
5669 | |
5670 | |
5671 | |
5672 | |
5673 | |
5674 | |
5675 | |
5676 | |
5677 | template<typename _RealType = double> |
5678 | class piecewise_linear_distribution |
5679 | { |
5680 | static_assert(std::is_floating_point<_RealType>::value, |
5681 | "result_type must be a floating point type"); |
5682 | |
5683 | public: |
5684 | |
5685 | typedef _RealType result_type; |
5686 | |
5687 | |
5688 | struct param_type |
5689 | { |
5690 | typedef piecewise_linear_distribution<_RealType> distribution_type; |
5691 | friend class piecewise_linear_distribution<_RealType>; |
5692 | |
5693 | param_type() |
5694 | : _M_int(), _M_den(), _M_cp(), _M_m() |
5695 | { } |
5696 | |
5697 | template<typename _InputIteratorB, typename _InputIteratorW> |
5698 | param_type(_InputIteratorB __bfirst, |
5699 | _InputIteratorB __bend, |
5700 | _InputIteratorW __wbegin); |
5701 | |
5702 | template<typename _Func> |
5703 | param_type(initializer_list<_RealType> __bl, _Func __fw); |
5704 | |
5705 | template<typename _Func> |
5706 | param_type(size_t __nw, _RealType __xmin, _RealType __xmax, |
5707 | _Func __fw); |
5708 | |
5709 | |
5710 | param_type(const param_type&) = default; |
5711 | param_type& operator=(const param_type&) = default; |
5712 | |
5713 | std::vector<_RealType> |
5714 | intervals() const |
5715 | { |
5716 | if (_M_int.empty()) |
5717 | { |
5718 | std::vector<_RealType> __tmp(2); |
5719 | __tmp[1] = _RealType(1); |
5720 | return __tmp; |
5721 | } |
5722 | else |
5723 | return _M_int; |
5724 | } |
5725 | |
5726 | std::vector<double> |
5727 | densities() const |
5728 | { return _M_den.empty() ? std::vector<double>(2, 1.0) : _M_den; } |
5729 | |
5730 | friend bool |
5731 | operator==(const param_type& __p1, const param_type& __p2) |
5732 | { return __p1._M_int == __p2._M_int && __p1._M_den == __p2._M_den; } |
5733 | |
5734 | friend bool |
5735 | operator!=(const param_type& __p1, const param_type& __p2) |
5736 | { return !(__p1 == __p2); } |
5737 | |
5738 | private: |
5739 | void |
5740 | _M_initialize(); |
5741 | |
5742 | std::vector<_RealType> _M_int; |
5743 | std::vector<double> _M_den; |
5744 | std::vector<double> _M_cp; |
5745 | std::vector<double> _M_m; |
5746 | }; |
5747 | |
5748 | explicit |
5749 | piecewise_linear_distribution() |
5750 | : _M_param() |
5751 | { } |
5752 | |
5753 | template<typename _InputIteratorB, typename _InputIteratorW> |
5754 | piecewise_linear_distribution(_InputIteratorB __bfirst, |
5755 | _InputIteratorB __bend, |
5756 | _InputIteratorW __wbegin) |
5757 | : _M_param(__bfirst, __bend, __wbegin) |
5758 | { } |
5759 | |
5760 | template<typename _Func> |
5761 | piecewise_linear_distribution(initializer_list<_RealType> __bl, |
5762 | _Func __fw) |
5763 | : _M_param(__bl, __fw) |
5764 | { } |
5765 | |
5766 | template<typename _Func> |
5767 | piecewise_linear_distribution(size_t __nw, |
5768 | _RealType __xmin, _RealType __xmax, |
5769 | _Func __fw) |
5770 | : _M_param(__nw, __xmin, __xmax, __fw) |
5771 | { } |
5772 | |
5773 | explicit |
5774 | piecewise_linear_distribution(const param_type& __p) |
5775 | : _M_param(__p) |
5776 | { } |
5777 | |
5778 | |
5779 | |
5780 | |
5781 | void |
5782 | reset() |
5783 | { } |
5784 | |
5785 | |
5786 | |
5787 | |
5788 | std::vector<_RealType> |
5789 | intervals() const |
5790 | { |
5791 | if (_M_param._M_int.empty()) |
5792 | { |
5793 | std::vector<_RealType> __tmp(2); |
5794 | __tmp[1] = _RealType(1); |
5795 | return __tmp; |
5796 | } |
5797 | else |
5798 | return _M_param._M_int; |
5799 | } |
5800 | |
5801 | |
5802 | |
5803 | |
5804 | |
5805 | std::vector<double> |
5806 | densities() const |
5807 | { |
5808 | return _M_param._M_den.empty() |
5809 | ? std::vector<double>(2, 1.0) : _M_param._M_den; |
5810 | } |
5811 | |
5812 | |
5813 | |
5814 | |
5815 | param_type |
5816 | param() const |
5817 | { return _M_param; } |
5818 | |
5819 | |
5820 | |
5821 | |
5822 | |
5823 | void |
5824 | param(const param_type& __param) |
5825 | { _M_param = __param; } |
5826 | |
5827 | |
5828 | |
5829 | |
5830 | result_type |
5831 | min() const |
5832 | { |
5833 | return _M_param._M_int.empty() |
5834 | ? result_type(0) : _M_param._M_int.front(); |
5835 | } |
5836 | |
5837 | |
5838 | |
5839 | |
5840 | result_type |
5841 | max() const |
5842 | { |
5843 | return _M_param._M_int.empty() |
5844 | ? result_type(1) : _M_param._M_int.back(); |
5845 | } |
5846 | |
5847 | |
5848 | |
5849 | |
5850 | template<typename _UniformRandomNumberGenerator> |
5851 | result_type |
5852 | operator()(_UniformRandomNumberGenerator& __urng) |
5853 | { return this->operator()(__urng, _M_param); } |
5854 | |
5855 | template<typename _UniformRandomNumberGenerator> |
5856 | result_type |
5857 | operator()(_UniformRandomNumberGenerator& __urng, |
5858 | const param_type& __p); |
5859 | |
5860 | template<typename _ForwardIterator, |
5861 | typename _UniformRandomNumberGenerator> |
5862 | void |
5863 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
5864 | _UniformRandomNumberGenerator& __urng) |
5865 | { this->__generate(__f, __t, __urng, _M_param); } |
5866 | |
5867 | template<typename _ForwardIterator, |
5868 | typename _UniformRandomNumberGenerator> |
5869 | void |
5870 | __generate(_ForwardIterator __f, _ForwardIterator __t, |
5871 | _UniformRandomNumberGenerator& __urng, |
5872 | const param_type& __p) |
5873 | { this->__generate_impl(__f, __t, __urng, __p); } |
5874 | |
5875 | template<typename _UniformRandomNumberGenerator> |
5876 | void |
5877 | __generate(result_type* __f, result_type* __t, |
5878 | _UniformRandomNumberGenerator& __urng, |
5879 | const param_type& __p) |
5880 | { this->__generate_impl(__f, __t, __urng, __p); } |
5881 | |
5882 | |
5883 | |
5884 | |
5885 | |
5886 | friend bool |
5887 | operator==(const piecewise_linear_distribution& __d1, |
5888 | const piecewise_linear_distribution& __d2) |
5889 | { return __d1._M_param == __d2._M_param; } |
5890 | |
5891 | |
5892 | |
5893 | |
5894 | |
5895 | |
5896 | |
5897 | |
5898 | |
5899 | |
5900 | |
5901 | |
5902 | template<typename _RealType1, typename _CharT, typename _Traits> |
5903 | friend std::basic_ostream<_CharT, _Traits>& |
5904 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, |
5905 | const std::piecewise_linear_distribution<_RealType1>& __x); |
5906 | |
5907 | |
5908 | |
5909 | |
5910 | |
5911 | |
5912 | |
5913 | |
5914 | |
5915 | |
5916 | |
5917 | |
5918 | template<typename _RealType1, typename _CharT, typename _Traits> |
5919 | friend std::basic_istream<_CharT, _Traits>& |
5920 | operator>>(std::basic_istream<_CharT, _Traits>& __is, |
5921 | std::piecewise_linear_distribution<_RealType1>& __x); |
5922 | |
5923 | private: |
5924 | template<typename _ForwardIterator, |
5925 | typename _UniformRandomNumberGenerator> |
5926 | void |
5927 | __generate_impl(_ForwardIterator __f, _ForwardIterator __t, |
5928 | _UniformRandomNumberGenerator& __urng, |
5929 | const param_type& __p); |
5930 | |
5931 | param_type _M_param; |
5932 | }; |
5933 | |
5934 | |
5935 | |
5936 | |
5937 | |
5938 | template<typename _RealType> |
5939 | inline bool |
5940 | operator!=(const std::piecewise_linear_distribution<_RealType>& __d1, |
5941 | const std::piecewise_linear_distribution<_RealType>& __d2) |
5942 | { return !(__d1 == __d2); } |
5943 | |
5944 | |
5945 | |
5946 | |
5947 | |
5948 | |
5949 | |
5950 | |
5951 | |
5952 | |
5953 | |
5954 | |
5955 | |
5956 | |
5957 | |
5958 | |
5959 | class seed_seq |
5960 | { |
5961 | public: |
5962 | |
5963 | typedef uint_least32_t result_type; |
5964 | |
5965 | |
5966 | seed_seq() noexcept |
5967 | : _M_v() |
5968 | { } |
5969 | |
5970 | template<typename _IntType> |
5971 | seed_seq(std::initializer_list<_IntType> il); |
5972 | |
5973 | template<typename _InputIterator> |
5974 | seed_seq(_InputIterator __begin, _InputIterator __end); |
5975 | |
5976 | |
5977 | template<typename _RandomAccessIterator> |
5978 | void |
5979 | generate(_RandomAccessIterator __begin, _RandomAccessIterator __end); |
5980 | |
5981 | |
5982 | size_t size() const noexcept |
5983 | { return _M_v.size(); } |
5984 | |
5985 | template<typename _OutputIterator> |
5986 | void |
5987 | param(_OutputIterator __dest) const |
5988 | { std::copy(_M_v.begin(), _M_v.end(), __dest); } |
5989 | |
5990 | |
5991 | seed_seq(const seed_seq&) = delete; |
5992 | seed_seq& operator=(const seed_seq&) = delete; |
5993 | |
5994 | private: |
5995 | std::vector<result_type> _M_v; |
5996 | }; |
5997 | |
5998 | |
5999 | |
6000 | |
6001 | |
6002 | _GLIBCXX_END_NAMESPACE_VERSION |
6003 | } |
6004 | |
6005 | #endif |
6006 | |