35 namespace std _GLIBCXX_VISIBILITY(default)
37 _GLIBCXX_BEGIN_NAMESPACE_VERSION
50 template<
typename _Tp, _Tp __m, _Tp __a, _Tp __c>
52 _Mod<_Tp, __m, __a, __c, false, true>::
59 static const _Tp __q = __m / __a;
60 static const _Tp __r = __m % __a;
62 _Tp __t1 = __a * (__x % __q);
63 _Tp __t2 = __r * (__x / __q);
67 __x = __m - __t2 + __t1;
72 const _Tp __d = __m - __x;
81 template<
typename _InputIterator,
typename _OutputIterator,
84 __normalize(_InputIterator __first, _InputIterator __last,
85 _OutputIterator __result,
const _Tp& __factor)
87 for (; __first != __last; ++__first, ++__result)
88 *__result = *__first / __factor;
94 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
98 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
102 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
106 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
108 linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed;
114 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
119 if ((__detail::__mod<_UIntType, __m>(__c) == 0)
120 && (__detail::__mod<_UIntType, __m>(__s) == 0))
123 _M_x = __detail::__mod<_UIntType, __m>(__s);
129 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
130 template<
typename _Sseq>
134 -> _If_seed_seq<_Sseq>
138 const _UIntType __k = (__k0 + 31) / 32;
139 uint_least32_t __arr[__k + 3];
140 __q.generate(__arr + 0, __arr + __k + 3);
141 _UIntType __factor = 1u;
142 _UIntType __sum = 0u;
143 for (
size_t __j = 0; __j < __k; ++__j)
145 __sum += __arr[__j + 3] * __factor;
146 __factor *= __detail::_Shift<_UIntType, 32>::__value;
151 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m,
152 typename _CharT,
typename _Traits>
156 __a, __c, __m>& __lcr)
160 const typename __ios_base::fmtflags __flags = __os.
flags();
161 const _CharT __fill = __os.
fill();
172 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m,
173 typename _CharT,
typename _Traits>
176 linear_congruential_engine<_UIntType, __a, __c, __m>& __lcr)
178 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
180 const typename __ios_base::fmtflags __flags = __is.
flags();
190 template<
typename _UIntType,
191 size_t __w,
size_t __n,
size_t __m,
size_t __r,
192 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
193 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
196 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
197 __s, __b, __t, __c, __l, __f>::word_size;
199 template<
typename _UIntType,
200 size_t __w,
size_t __n,
size_t __m,
size_t __r,
201 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
202 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
205 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
206 __s, __b, __t, __c, __l, __f>::state_size;
208 template<
typename _UIntType,
209 size_t __w,
size_t __n,
size_t __m,
size_t __r,
210 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
211 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
214 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
215 __s, __b, __t, __c, __l, __f>::shift_size;
217 template<
typename _UIntType,
218 size_t __w,
size_t __n,
size_t __m,
size_t __r,
219 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
220 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
223 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
224 __s, __b, __t, __c, __l, __f>::mask_bits;
226 template<
typename _UIntType,
227 size_t __w,
size_t __n,
size_t __m,
size_t __r,
228 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
229 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
232 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
233 __s, __b, __t, __c, __l, __f>::xor_mask;
235 template<
typename _UIntType,
236 size_t __w,
size_t __n,
size_t __m,
size_t __r,
237 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
238 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
241 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
242 __s, __b, __t, __c, __l, __f>::tempering_u;
244 template<
typename _UIntType,
245 size_t __w,
size_t __n,
size_t __m,
size_t __r,
246 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
247 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
250 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
251 __s, __b, __t, __c, __l, __f>::tempering_d;
253 template<
typename _UIntType,
254 size_t __w,
size_t __n,
size_t __m,
size_t __r,
255 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
256 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
259 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
260 __s, __b, __t, __c, __l, __f>::tempering_s;
262 template<
typename _UIntType,
263 size_t __w,
size_t __n,
size_t __m,
size_t __r,
264 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
265 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
268 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
269 __s, __b, __t, __c, __l, __f>::tempering_b;
271 template<
typename _UIntType,
272 size_t __w,
size_t __n,
size_t __m,
size_t __r,
273 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
274 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
277 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
278 __s, __b, __t, __c, __l, __f>::tempering_t;
280 template<
typename _UIntType,
281 size_t __w,
size_t __n,
size_t __m,
size_t __r,
282 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
283 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
286 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
287 __s, __b, __t, __c, __l, __f>::tempering_c;
289 template<
typename _UIntType,
290 size_t __w,
size_t __n,
size_t __m,
size_t __r,
291 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
292 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
295 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
296 __s, __b, __t, __c, __l, __f>::tempering_l;
298 template<
typename _UIntType,
299 size_t __w,
size_t __n,
size_t __m,
size_t __r,
300 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
301 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
304 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
305 __s, __b, __t, __c, __l, __f>::
306 initialization_multiplier;
308 template<
typename _UIntType,
309 size_t __w,
size_t __n,
size_t __m,
size_t __r,
310 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
311 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
314 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
315 __s, __b, __t, __c, __l, __f>::default_seed;
317 template<
typename _UIntType,
318 size_t __w,
size_t __n,
size_t __m,
size_t __r,
319 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
320 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
323 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
324 __s, __b, __t, __c, __l, __f>::
325 seed(result_type __sd)
327 _M_x[0] = __detail::__mod<_UIntType,
328 __detail::_Shift<_UIntType, __w>::__value>(__sd);
330 for (
size_t __i = 1; __i < state_size; ++__i)
332 _UIntType __x = _M_x[__i - 1];
333 __x ^= __x >> (__w - 2);
335 __x += __detail::__mod<_UIntType, __n>(__i);
336 _M_x[__i] = __detail::__mod<_UIntType,
337 __detail::_Shift<_UIntType, __w>::__value>(__x);
342 template<
typename _UIntType,
343 size_t __w,
size_t __n,
size_t __m,
size_t __r,
344 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
345 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
347 template<
typename _Sseq>
349 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
350 __s, __b, __t, __c, __l, __f>::
352 -> _If_seed_seq<_Sseq>
354 const _UIntType __upper_mask = (~_UIntType()) << __r;
355 const size_t __k = (__w + 31) / 32;
356 uint_least32_t __arr[__n * __k];
357 __q.generate(__arr + 0, __arr + __n * __k);
360 for (
size_t __i = 0; __i < state_size; ++__i)
362 _UIntType __factor = 1u;
363 _UIntType __sum = 0u;
364 for (
size_t __j = 0; __j < __k; ++__j)
366 __sum += __arr[__k * __i + __j] * __factor;
367 __factor *= __detail::_Shift<_UIntType, 32>::__value;
369 _M_x[__i] = __detail::__mod<_UIntType,
370 __detail::_Shift<_UIntType, __w>::__value>(__sum);
376 if ((_M_x[0] & __upper_mask) != 0u)
379 else if (_M_x[__i] != 0u)
384 _M_x[0] = __detail::_Shift<_UIntType, __w - 1>::__value;
388 template<
typename _UIntType,
size_t __w,
389 size_t __n,
size_t __m,
size_t __r,
390 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
391 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
394 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
395 __s, __b, __t, __c, __l, __f>::
398 const _UIntType __upper_mask = (~_UIntType()) << __r;
399 const _UIntType __lower_mask = ~__upper_mask;
401 for (
size_t __k = 0; __k < (__n - __m); ++__k)
403 _UIntType __y = ((_M_x[__k] & __upper_mask)
404 | (_M_x[__k + 1] & __lower_mask));
405 _M_x[__k] = (_M_x[__k + __m] ^ (__y >> 1)
406 ^ ((__y & 0x01) ? __a : 0));
409 for (
size_t __k = (__n - __m); __k < (__n - 1); ++__k)
411 _UIntType __y = ((_M_x[__k] & __upper_mask)
412 | (_M_x[__k + 1] & __lower_mask));
413 _M_x[__k] = (_M_x[__k + (__m - __n)] ^ (__y >> 1)
414 ^ ((__y & 0x01) ? __a : 0));
417 _UIntType __y = ((_M_x[__n - 1] & __upper_mask)
418 | (_M_x[0] & __lower_mask));
419 _M_x[__n - 1] = (_M_x[__m - 1] ^ (__y >> 1)
420 ^ ((__y & 0x01) ? __a : 0));
424 template<
typename _UIntType,
size_t __w,
425 size_t __n,
size_t __m,
size_t __r,
426 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
427 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
430 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
431 __s, __b, __t, __c, __l, __f>::
432 discard(
unsigned long long __z)
434 while (__z > state_size - _M_p)
436 __z -= state_size - _M_p;
442 template<
typename _UIntType,
size_t __w,
443 size_t __n,
size_t __m,
size_t __r,
444 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
445 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
449 __s, __b, __t, __c, __l, __f>::result_type
451 __s, __b, __t, __c, __l, __f>::
455 if (_M_p >= state_size)
459 result_type __z = _M_x[_M_p++];
460 __z ^= (__z >> __u) & __d;
461 __z ^= (__z << __s) & __b;
462 __z ^= (__z << __t) & __c;
468 template<
typename _UIntType,
size_t __w,
469 size_t __n,
size_t __m,
size_t __r,
470 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
471 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
472 _UIntType __f,
typename _CharT,
typename _Traits>
475 const mersenne_twister_engine<_UIntType, __w, __n, __m,
476 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __x)
478 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
480 const typename __ios_base::fmtflags __flags = __os.
flags();
481 const _CharT __fill = __os.
fill();
482 const _CharT __space = __os.
widen(
' ');
486 for (
size_t __i = 0; __i < __n; ++__i)
487 __os << __x._M_x[__i] << __space;
495 template<
typename _UIntType,
size_t __w,
496 size_t __n,
size_t __m,
size_t __r,
497 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
498 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
499 _UIntType __f,
typename _CharT,
typename _Traits>
502 mersenne_twister_engine<_UIntType, __w, __n, __m,
503 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __x)
505 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
507 const typename __ios_base::fmtflags __flags = __is.
flags();
510 for (
size_t __i = 0; __i < __n; ++__i)
511 __is >> __x._M_x[__i];
519 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
521 subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size;
523 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
525 subtract_with_carry_engine<_UIntType, __w, __s, __r>::short_lag;
527 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
529 subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag;
531 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
533 subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed;
535 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
541 __lcg(__value == 0u ? default_seed : __value);
543 const size_t __n = (__w + 31) / 32;
545 for (
size_t __i = 0; __i < long_lag; ++__i)
547 _UIntType __sum = 0u;
548 _UIntType __factor = 1u;
549 for (
size_t __j = 0; __j < __n; ++__j)
551 __sum += __detail::__mod<uint_least32_t,
552 __detail::_Shift<uint_least32_t, 32>::__value>
553 (__lcg()) * __factor;
554 __factor *= __detail::_Shift<_UIntType, 32>::__value;
556 _M_x[__i] = __detail::__mod<_UIntType,
557 __detail::_Shift<_UIntType, __w>::__value>(__sum);
559 _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
563 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
564 template<
typename _Sseq>
568 -> _If_seed_seq<_Sseq>
570 const size_t __k = (__w + 31) / 32;
571 uint_least32_t __arr[__r * __k];
572 __q.generate(__arr + 0, __arr + __r * __k);
574 for (
size_t __i = 0; __i < long_lag; ++__i)
576 _UIntType __sum = 0u;
577 _UIntType __factor = 1u;
578 for (
size_t __j = 0; __j < __k; ++__j)
580 __sum += __arr[__k * __i + __j] * __factor;
581 __factor *= __detail::_Shift<_UIntType, 32>::__value;
583 _M_x[__i] = __detail::__mod<_UIntType,
584 __detail::_Shift<_UIntType, __w>::__value>(__sum);
586 _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
590 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
597 long __ps = _M_p - short_lag;
605 if (_M_x[__ps] >= _M_x[_M_p] + _M_carry)
607 __xi = _M_x[__ps] - _M_x[_M_p] - _M_carry;
612 __xi = (__detail::_Shift<_UIntType, __w>::__value
613 - _M_x[_M_p] - _M_carry + _M_x[__ps]);
619 if (++_M_p >= long_lag)
625 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r,
626 typename _CharT,
typename _Traits>
634 const typename __ios_base::fmtflags __flags = __os.
flags();
635 const _CharT __fill = __os.
fill();
636 const _CharT __space = __os.
widen(
' ');
640 for (
size_t __i = 0; __i < __r; ++__i)
641 __os << __x._M_x[__i] << __space;
642 __os << __x._M_carry << __space << __x._M_p;
649 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r,
650 typename _CharT,
typename _Traits>
653 subtract_with_carry_engine<_UIntType, __w, __s, __r>& __x)
655 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
657 const typename __ios_base::fmtflags __flags = __is.
flags();
660 for (
size_t __i = 0; __i < __r; ++__i)
661 __is >> __x._M_x[__i];
662 __is >> __x._M_carry;
670 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
672 discard_block_engine<_RandomNumberEngine, __p, __r>::block_size;
674 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
676 discard_block_engine<_RandomNumberEngine, __p, __r>::used_block;
678 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
679 typename discard_block_engine<_RandomNumberEngine,
680 __p, __r>::result_type
684 if (_M_n >= used_block)
686 _M_b.discard(block_size - _M_n);
693 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r,
694 typename _CharT,
typename _Traits>
702 const typename __ios_base::fmtflags __flags = __os.
flags();
703 const _CharT __fill = __os.
fill();
704 const _CharT __space = __os.
widen(
' ');
708 __os << __x.base() << __space << __x._M_n;
715 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r,
716 typename _CharT,
typename _Traits>
719 discard_block_engine<_RandomNumberEngine, __p, __r>& __x)
721 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
723 const typename __ios_base::fmtflags __flags = __is.
flags();
726 __is >> __x._M_b >> __x._M_n;
733 template<
typename _RandomNumberEngine,
size_t __w,
typename _UIntType>
734 typename independent_bits_engine<_RandomNumberEngine, __w, _UIntType>::
739 typedef typename _RandomNumberEngine::result_type _Eresult_type;
740 const _Eresult_type __r
742 ? _M_b.max() - _M_b.min() + 1 : 0);
744 const unsigned __m = __r ?
std::__lg(__r) : __edig;
751 __ctype __s0, __s1, __y0, __y1;
753 for (
size_t __i = 0; __i < 2; ++__i)
755 __n = (__w + __m - 1) / __m + __i;
756 __n0 = __n - __w % __n;
757 const unsigned __w0 = __w / __n;
763 __s0 = __ctype(1) << __w0;
771 __y0 = __s0 * (__r / __s0);
773 __y1 = __s1 * (__r / __s1);
775 if (__r - __y0 <= __y0 / __n)
783 for (
size_t __k = 0; __k < __n0; ++__k)
787 __u = _M_b() - _M_b.
min();
788 while (__y0 && __u >= __y0);
789 __sum = __s0 * __sum + (__s0 ? __u % __s0 : __u);
791 for (
size_t __k = __n0; __k < __n; ++__k)
795 __u = _M_b() - _M_b.min();
796 while (__y1 && __u >= __y1);
797 __sum = __s1 * __sum + (__s1 ? __u % __s1 : __u);
803 template<
typename _RandomNumberEngine,
size_t __k>
807 template<
typename _RandomNumberEngine,
size_t __k>
812 size_t __j = __k * ((_M_y - _M_b.min())
813 / (_M_b.max() - _M_b.min() + 1.0L));
820 template<
typename _RandomNumberEngine,
size_t __k,
821 typename _CharT,
typename _Traits>
828 const typename __ios_base::fmtflags __flags = __os.
flags();
829 const _CharT __fill = __os.
fill();
830 const _CharT __space = __os.
widen(
' ');
835 for (
size_t __i = 0; __i < __k; ++__i)
836 __os << __space << __x._M_v[__i];
837 __os << __space << __x._M_y;
844 template<
typename _RandomNumberEngine,
size_t __k,
845 typename _CharT,
typename _Traits>
852 const typename __ios_base::fmtflags __flags = __is.
flags();
856 for (
size_t __i = 0; __i < __k; ++__i)
857 __is >> __x._M_v[__i];
865 template<
typename _IntType,
typename _CharT,
typename _Traits>
868 const uniform_int_distribution<_IntType>& __x)
870 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
872 const typename __ios_base::fmtflags __flags = __os.
flags();
873 const _CharT __fill = __os.
fill();
874 const _CharT __space = __os.
widen(
' ');
878 __os << __x.a() << __space << __x.b();
885 template<
typename _IntType,
typename _CharT,
typename _Traits>
894 const typename __ios_base::fmtflags __flags = __is.
flags();
898 if (__is >> __a >> __b)
899 __x.
param(param_type(__a, __b));
906 template<
typename _RealType>
907 template<
typename _ForwardIterator,
908 typename _UniformRandomNumberGenerator>
912 _UniformRandomNumberGenerator& __urng,
913 const param_type& __p)
915 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
916 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
918 auto __range = __p.b() - __p.a();
920 *__f++ = __aurng() * __range + __p.a();
923 template<
typename _RealType,
typename _CharT,
typename _Traits>
926 const uniform_real_distribution<_RealType>& __x)
928 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
930 const typename __ios_base::fmtflags __flags = __os.
flags();
931 const _CharT __fill = __os.
fill();
933 const _CharT __space = __os.
widen(
' ');
938 __os << __x.a() << __space << __x.b();
946 template<
typename _RealType,
typename _CharT,
typename _Traits>
955 const typename __ios_base::fmtflags __flags = __is.
flags();
959 if (__is >> __a >> __b)
960 __x.
param(param_type(__a, __b));
967 template<
typename _ForwardIterator,
968 typename _UniformRandomNumberGenerator>
970 std::bernoulli_distribution::
971 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
972 _UniformRandomNumberGenerator& __urng,
973 const param_type& __p)
975 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
976 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
978 auto __limit = __p.p() * (__aurng.max() - __aurng.min());
981 *__f++ = (__aurng() - __aurng.min()) < __limit;
984 template<
typename _CharT,
typename _Traits>
987 const bernoulli_distribution& __x)
989 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
991 const typename __ios_base::fmtflags __flags = __os.
flags();
992 const _CharT __fill = __os.
fill();
1000 __os.
flags(__flags);
1007 template<
typename _IntType>
1008 template<
typename _UniformRandomNumberGenerator>
1011 operator()(_UniformRandomNumberGenerator& __urng,
1012 const param_type& __param)
1016 const double __naf =
1019 const double __thr =
1021 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1026 __cand = std::floor(
std::log(1.0 - __aurng()) / __param._M_log_1_p);
1027 while (__cand >= __thr);
1029 return result_type(__cand + __naf);
1032 template<
typename _IntType>
1033 template<
typename _ForwardIterator,
1034 typename _UniformRandomNumberGenerator>
1038 _UniformRandomNumberGenerator& __urng,
1039 const param_type& __param)
1041 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1044 const double __naf =
1047 const double __thr =
1049 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1056 __cand = std::floor(
std::log(1.0 - __aurng())
1057 / __param._M_log_1_p);
1058 while (__cand >= __thr);
1060 *__f++ = __cand + __naf;
1064 template<
typename _IntType,
1065 typename _CharT,
typename _Traits>
1068 const geometric_distribution<_IntType>& __x)
1070 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1072 const typename __ios_base::fmtflags __flags = __os.
flags();
1073 const _CharT __fill = __os.
fill();
1081 __os.
flags(__flags);
1087 template<
typename _IntType,
1088 typename _CharT,
typename _Traits>
1096 const typename __ios_base::fmtflags __flags = __is.
flags();
1101 __x.
param(param_type(__p));
1103 __is.
flags(__flags);
1108 template<
typename _IntType>
1109 template<
typename _UniformRandomNumberGenerator>
1112 operator()(_UniformRandomNumberGenerator& __urng)
1114 const double __y = _M_gd(__urng);
1118 return __poisson(__urng);
1121 template<
typename _IntType>
1122 template<
typename _UniformRandomNumberGenerator>
1125 operator()(_UniformRandomNumberGenerator& __urng,
1126 const param_type& __p)
1132 _M_gd(__urng, param_type(__p.k(), (1.0 - __p.p()) / __p.p()));
1135 return __poisson(__urng);
1138 template<
typename _IntType>
1139 template<
typename _ForwardIterator,
1140 typename _UniformRandomNumberGenerator>
1142 negative_binomial_distribution<_IntType>::
1143 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1144 _UniformRandomNumberGenerator& __urng)
1146 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1149 const double __y = _M_gd(__urng);
1153 *__f++ = __poisson(__urng);
1157 template<
typename _IntType>
1158 template<
typename _ForwardIterator,
1159 typename _UniformRandomNumberGenerator>
1161 negative_binomial_distribution<_IntType>::
1162 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1163 _UniformRandomNumberGenerator& __urng,
1164 const param_type& __p)
1166 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1168 __p2(__p.k(), (1.0 - __p.p()) / __p.p());
1172 const double __y = _M_gd(__urng, __p2);
1175 *__f++ = __poisson(__urng);
1179 template<
typename _IntType,
typename _CharT,
typename _Traits>
1182 const negative_binomial_distribution<_IntType>& __x)
1184 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1186 const typename __ios_base::fmtflags __flags = __os.
flags();
1187 const _CharT __fill = __os.
fill();
1189 const _CharT __space = __os.
widen(
' ');
1194 __os << __x.k() << __space << __x.p()
1195 << __space << __x._M_gd;
1197 __os.
flags(__flags);
1203 template<
typename _IntType,
typename _CharT,
typename _Traits>
1206 negative_binomial_distribution<_IntType>& __x)
1209 =
typename negative_binomial_distribution<_IntType>::param_type;
1210 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1212 const typename __ios_base::fmtflags __flags = __is.
flags();
1217 if (__is >> __k >> __p >> __x._M_gd)
1218 __x.param(param_type(__k, __p));
1220 __is.
flags(__flags);
1225 template<
typename _IntType>
1227 poisson_distribution<_IntType>::param_type::
1230 #if _GLIBCXX_USE_C99_MATH_TR1
1233 const double __m = std::floor(_M_mean);
1235 _M_lfm = std::lgamma(__m + 1);
1238 const double __pi_4 = 0.7853981633974483096156608458198757L;
1241 _M_d = std::round(std::max<double>(6.0,
std::min(__m, __dx)));
1242 const double __cx = 2 * __m + _M_d;
1247 _M_cb = 2 * __cx *
std::exp(-_M_d * _M_1cx * (1 + _M_d / 2))
1265 template<
typename _IntType>
1266 template<
typename _UniformRandomNumberGenerator>
1269 operator()(_UniformRandomNumberGenerator& __urng,
1272 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1274 #if _GLIBCXX_USE_C99_MATH_TR1
1275 if (__param.mean() >= 12)
1280 const double __naf =
1282 const double __thr =
1285 const double __m = std::floor(__param.mean());
1287 const double __spi_2 = 1.2533141373155002512078826424055226L;
1288 const double __c1 = __param._M_sm * __spi_2;
1289 const double __c2 = __param._M_c2b + __c1;
1290 const double __c3 = __c2 + 1;
1291 const double __c4 = __c3 + 1;
1293 const double __178 = 0.0128205128205128205128205128205128L;
1295 const double __e178 = 1.0129030479320018583185514777512983L;
1296 const double __c5 = __c4 + __e178;
1297 const double __c = __param._M_cb + __c5;
1298 const double __2cx = 2 * (2 * __m + __param._M_d);
1300 bool __reject =
true;
1303 const double __u = __c * __aurng();
1304 const double __e = -
std::log(1.0 - __aurng());
1310 const double __n = _M_nd(__urng);
1311 const double __y = -
std::abs(__n) * __param._M_sm - 1;
1312 __x = std::floor(__y);
1313 __w = -__n * __n / 2;
1317 else if (__u <= __c2)
1319 const double __n = _M_nd(__urng);
1320 const double __y = 1 +
std::abs(__n) * __param._M_scx;
1321 __x = std::ceil(__y);
1322 __w = __y * (2 - __y) * __param._M_1cx;
1323 if (__x > __param._M_d)
1326 else if (__u <= __c3)
1330 else if (__u <= __c4)
1332 else if (__u <= __c5)
1340 const double __v = -
std::log(1.0 - __aurng());
1341 const double __y = __param._M_d
1342 + __v * __2cx / __param._M_d;
1343 __x = std::ceil(__y);
1344 __w = -__param._M_d * __param._M_1cx * (1 + __y / 2);
1347 __reject = (__w - __e - __x * __param._M_lm_thr
1348 > __param._M_lfm - std::lgamma(__x + __m + 1));
1350 __reject |= __x + __m >= __thr;
1360 double __prod = 1.0;
1364 __prod *= __aurng();
1367 while (__prod > __param._M_lm_thr);
1373 template<
typename _IntType>
1374 template<
typename _ForwardIterator,
1375 typename _UniformRandomNumberGenerator>
1379 _UniformRandomNumberGenerator& __urng,
1380 const param_type& __param)
1382 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1388 template<
typename _IntType,
1389 typename _CharT,
typename _Traits>
1392 const poisson_distribution<_IntType>& __x)
1394 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1396 const typename __ios_base::fmtflags __flags = __os.
flags();
1397 const _CharT __fill = __os.
fill();
1399 const _CharT __space = __os.
widen(
' ');
1404 __os << __x.mean() << __space << __x._M_nd;
1406 __os.
flags(__flags);
1412 template<
typename _IntType,
1413 typename _CharT,
typename _Traits>
1416 poisson_distribution<_IntType>& __x)
1418 using param_type =
typename poisson_distribution<_IntType>::param_type;
1419 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1421 const typename __ios_base::fmtflags __flags = __is.
flags();
1425 if (__is >> __mean >> __x._M_nd)
1426 __x.param(param_type(__mean));
1428 __is.
flags(__flags);
1433 template<
typename _IntType>
1435 binomial_distribution<_IntType>::param_type::
1438 const double __p12 = _M_p <= 0.5 ? _M_p : 1.0 - _M_p;
1442 #if _GLIBCXX_USE_C99_MATH_TR1
1443 if (_M_t * __p12 >= 8)
1446 const double __np = std::floor(_M_t * __p12);
1447 const double __pa = __np / _M_t;
1448 const double __1p = 1 - __pa;
1450 const double __pi_4 = 0.7853981633974483096156608458198757L;
1451 const double __d1x =
1453 / (81 * __pi_4 * __1p)));
1454 _M_d1 = std::round(std::max<double>(1.0, __d1x));
1455 const double __d2x =
1457 / (__pi_4 * __pa)));
1458 _M_d2 = std::round(std::max<double>(1.0, __d2x));
1461 const double __spi_2 = 1.2533141373155002512078826424055226L;
1462 _M_s1 =
std::sqrt(__np * __1p) * (1 + _M_d1 / (4 * __np));
1463 _M_s2 =
std::sqrt(__np * __1p) * (1 + _M_d2 / (4 * _M_t * __1p));
1464 _M_c = 2 * _M_d1 / __np;
1465 _M_a1 =
std::exp(_M_c) * _M_s1 * __spi_2;
1466 const double __a12 = _M_a1 + _M_s2 * __spi_2;
1467 const double __s1s = _M_s1 * _M_s1;
1468 _M_a123 = __a12 + (
std::exp(_M_d1 / (_M_t * __1p))
1470 *
std::exp(-_M_d1 * _M_d1 / (2 * __s1s)));
1471 const double __s2s = _M_s2 * _M_s2;
1472 _M_s = (_M_a123 + 2 * __s2s / _M_d2
1473 *
std::exp(-_M_d2 * _M_d2 / (2 * __s2s)));
1474 _M_lf = (std::lgamma(__np + 1)
1475 + std::lgamma(_M_t - __np + 1));
1478 _M_q = -
std::log(1 - (__p12 - __pa) / __1p);
1485 template<
typename _IntType>
1486 template<
typename _UniformRandomNumberGenerator>
1488 binomial_distribution<_IntType>::
1489 _M_waiting(_UniformRandomNumberGenerator& __urng,
1490 _IntType __t,
double __q)
1494 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1501 const double __e = -
std::log(1.0 - __aurng());
1502 __sum += __e / (__t - __x);
1505 while (__sum <= __q);
1520 template<
typename _IntType>
1521 template<
typename _UniformRandomNumberGenerator>
1524 operator()(_UniformRandomNumberGenerator& __urng,
1528 const _IntType __t = __param.t();
1529 const double __p = __param.p();
1530 const double __p12 = __p <= 0.5 ? __p : 1.0 - __p;
1531 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1534 #if _GLIBCXX_USE_C99_MATH_TR1
1535 if (!__param._M_easy)
1540 const double __naf =
1542 const double __thr =
1545 const double __np = std::floor(__t * __p12);
1548 const double __spi_2 = 1.2533141373155002512078826424055226L;
1549 const double __a1 = __param._M_a1;
1550 const double __a12 = __a1 + __param._M_s2 * __spi_2;
1551 const double __a123 = __param._M_a123;
1552 const double __s1s = __param._M_s1 * __param._M_s1;
1553 const double __s2s = __param._M_s2 * __param._M_s2;
1558 const double __u = __param._M_s * __aurng();
1564 const double __n = _M_nd(__urng);
1565 const double __y = __param._M_s1 *
std::abs(__n);
1566 __reject = __y >= __param._M_d1;
1569 const double __e = -
std::log(1.0 - __aurng());
1570 __x = std::floor(__y);
1571 __v = -__e - __n * __n / 2 + __param._M_c;
1574 else if (__u <= __a12)
1576 const double __n = _M_nd(__urng);
1577 const double __y = __param._M_s2 *
std::abs(__n);
1578 __reject = __y >= __param._M_d2;
1581 const double __e = -
std::log(1.0 - __aurng());
1582 __x = std::floor(-__y);
1583 __v = -__e - __n * __n / 2;
1586 else if (__u <= __a123)
1588 const double __e1 = -
std::log(1.0 - __aurng());
1589 const double __e2 = -
std::log(1.0 - __aurng());
1591 const double __y = __param._M_d1
1592 + 2 * __s1s * __e1 / __param._M_d1;
1593 __x = std::floor(__y);
1594 __v = (-__e2 + __param._M_d1 * (1 / (__t - __np)
1595 -__y / (2 * __s1s)));
1600 const double __e1 = -
std::log(1.0 - __aurng());
1601 const double __e2 = -
std::log(1.0 - __aurng());
1603 const double __y = __param._M_d2
1604 + 2 * __s2s * __e1 / __param._M_d2;
1605 __x = std::floor(-__y);
1606 __v = -__e2 - __param._M_d2 * __y / (2 * __s2s);
1610 __reject = __reject || __x < -__np || __x > __t - __np;
1613 const double __lfx =
1614 std::lgamma(__np + __x + 1)
1615 + std::lgamma(__t - (__np + __x) + 1);
1616 __reject = __v > __param._M_lf - __lfx
1617 + __x * __param._M_lp1p;
1620 __reject |= __x + __np >= __thr;
1624 __x += __np + __naf;
1626 const _IntType __z = _M_waiting(__urng, __t - _IntType(__x),
1628 __ret = _IntType(__x) + __z;
1632 __ret = _M_waiting(__urng, __t, __param._M_q);
1635 __ret = __t - __ret;
1639 template<
typename _IntType>
1640 template<
typename _ForwardIterator,
1641 typename _UniformRandomNumberGenerator>
1645 _UniformRandomNumberGenerator& __urng,
1646 const param_type& __param)
1648 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1654 template<
typename _IntType,
1655 typename _CharT,
typename _Traits>
1658 const binomial_distribution<_IntType>& __x)
1660 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1662 const typename __ios_base::fmtflags __flags = __os.
flags();
1663 const _CharT __fill = __os.
fill();
1665 const _CharT __space = __os.
widen(
' ');
1670 __os << __x.t() << __space << __x.p()
1671 << __space << __x._M_nd;
1673 __os.
flags(__flags);
1679 template<
typename _IntType,
1680 typename _CharT,
typename _Traits>
1683 binomial_distribution<_IntType>& __x)
1685 using param_type =
typename binomial_distribution<_IntType>::param_type;
1686 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1688 const typename __ios_base::fmtflags __flags = __is.
flags();
1693 if (__is >> __t >> __p >> __x._M_nd)
1694 __x.param(param_type(__t, __p));
1696 __is.
flags(__flags);
1701 template<
typename _RealType>
1702 template<
typename _ForwardIterator,
1703 typename _UniformRandomNumberGenerator>
1707 _UniformRandomNumberGenerator& __urng,
1708 const param_type& __p)
1710 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1711 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1717 template<
typename _RealType,
typename _CharT,
typename _Traits>
1720 const exponential_distribution<_RealType>& __x)
1722 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1724 const typename __ios_base::fmtflags __flags = __os.
flags();
1725 const _CharT __fill = __os.
fill();
1731 __os << __x.lambda();
1733 __os.
flags(__flags);
1739 template<
typename _RealType,
typename _CharT,
typename _Traits>
1748 const typename __ios_base::fmtflags __flags = __is.
flags();
1752 if (__is >> __lambda)
1753 __x.
param(param_type(__lambda));
1755 __is.
flags(__flags);
1766 template<
typename _RealType>
1767 template<
typename _UniformRandomNumberGenerator>
1770 operator()(_UniformRandomNumberGenerator& __urng,
1774 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1777 if (_M_saved_available)
1779 _M_saved_available =
false;
1789 __r2 = __x * __x + __y * __y;
1791 while (__r2 > 1.0 || __r2 == 0.0);
1794 _M_saved = __x * __mult;
1795 _M_saved_available =
true;
1796 __ret = __y * __mult;
1799 __ret = __ret * __param.stddev() + __param.mean();
1803 template<
typename _RealType>
1804 template<
typename _ForwardIterator,
1805 typename _UniformRandomNumberGenerator>
1809 _UniformRandomNumberGenerator& __urng,
1810 const param_type& __param)
1812 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1817 if (_M_saved_available)
1819 _M_saved_available =
false;
1820 *__f++ = _M_saved * __param.stddev() + __param.mean();
1826 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1829 while (__f + 1 < __t)
1836 __r2 = __x * __x + __y * __y;
1838 while (__r2 > 1.0 || __r2 == 0.0);
1841 *__f++ = __y * __mult * __param.stddev() + __param.mean();
1842 *__f++ = __x * __mult * __param.stddev() + __param.mean();
1852 __r2 = __x * __x + __y * __y;
1854 while (__r2 > 1.0 || __r2 == 0.0);
1857 _M_saved = __x * __mult;
1858 _M_saved_available =
true;
1859 *__f = __y * __mult * __param.stddev() + __param.mean();
1863 template<
typename _RealType>
1868 if (__d1._M_param == __d2._M_param
1869 && __d1._M_saved_available == __d2._M_saved_available)
1871 if (__d1._M_saved_available
1872 && __d1._M_saved == __d2._M_saved)
1874 else if(!__d1._M_saved_available)
1883 template<
typename _RealType,
typename _CharT,
typename _Traits>
1886 const normal_distribution<_RealType>& __x)
1888 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1890 const typename __ios_base::fmtflags __flags = __os.
flags();
1891 const _CharT __fill = __os.
fill();
1893 const _CharT __space = __os.
widen(
' ');
1898 __os << __x.mean() << __space << __x.stddev()
1899 << __space << __x._M_saved_available;
1900 if (__x._M_saved_available)
1901 __os << __space << __x._M_saved;
1903 __os.
flags(__flags);
1909 template<
typename _RealType,
typename _CharT,
typename _Traits>
1912 normal_distribution<_RealType>& __x)
1914 using param_type =
typename normal_distribution<_RealType>::param_type;
1915 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1917 const typename __ios_base::fmtflags __flags = __is.
flags();
1920 double __mean, __stddev;
1922 if (__is >> __mean >> __stddev >> __saved_avail)
1924 if (!__saved_avail || (__is >> __x._M_saved))
1926 __x._M_saved_available = __saved_avail;
1927 __x.param(param_type(__mean, __stddev));
1931 __is.
flags(__flags);
1936 template<
typename _RealType>
1937 template<
typename _ForwardIterator,
1938 typename _UniformRandomNumberGenerator>
1940 lognormal_distribution<_RealType>::
1941 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1942 _UniformRandomNumberGenerator& __urng,
1943 const param_type& __p)
1945 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1947 *__f++ =
std::exp(__p.s() * _M_nd(__urng) + __p.m());
1950 template<
typename _RealType,
typename _CharT,
typename _Traits>
1953 const lognormal_distribution<_RealType>& __x)
1955 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1957 const typename __ios_base::fmtflags __flags = __os.
flags();
1958 const _CharT __fill = __os.
fill();
1960 const _CharT __space = __os.
widen(
' ');
1965 __os << __x.m() << __space << __x.s()
1966 << __space << __x._M_nd;
1968 __os.
flags(__flags);
1974 template<
typename _RealType,
typename _CharT,
typename _Traits>
1977 lognormal_distribution<_RealType>& __x)
1980 =
typename lognormal_distribution<_RealType>::param_type;
1981 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1983 const typename __ios_base::fmtflags __flags = __is.
flags();
1987 if (__is >> __m >> __s >> __x._M_nd)
1988 __x.param(param_type(__m, __s));
1990 __is.
flags(__flags);
1994 template<
typename _RealType>
1995 template<
typename _ForwardIterator,
1996 typename _UniformRandomNumberGenerator>
2000 _UniformRandomNumberGenerator& __urng)
2002 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2004 *__f++ = 2 * _M_gd(__urng);
2007 template<
typename _RealType>
2008 template<
typename _ForwardIterator,
2009 typename _UniformRandomNumberGenerator>
2013 _UniformRandomNumberGenerator& __urng,
2017 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2019 *__f++ = 2 * _M_gd(__urng, __p);
2022 template<
typename _RealType,
typename _CharT,
typename _Traits>
2025 const chi_squared_distribution<_RealType>& __x)
2027 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2029 const typename __ios_base::fmtflags __flags = __os.
flags();
2030 const _CharT __fill = __os.
fill();
2032 const _CharT __space = __os.
widen(
' ');
2037 __os << __x.n() << __space << __x._M_gd;
2039 __os.
flags(__flags);
2045 template<
typename _RealType,
typename _CharT,
typename _Traits>
2048 chi_squared_distribution<_RealType>& __x)
2051 =
typename chi_squared_distribution<_RealType>::param_type;
2052 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2054 const typename __ios_base::fmtflags __flags = __is.
flags();
2058 if (__is >> __n >> __x._M_gd)
2059 __x.param(param_type(__n));
2061 __is.
flags(__flags);
2066 template<
typename _RealType>
2067 template<
typename _UniformRandomNumberGenerator>
2070 operator()(_UniformRandomNumberGenerator& __urng,
2071 const param_type& __p)
2073 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2080 const _RealType __pi = 3.1415926535897932384626433832795029L;
2081 return __p.a() + __p.b() *
std::tan(__pi * __u);
2084 template<
typename _RealType>
2085 template<
typename _ForwardIterator,
2086 typename _UniformRandomNumberGenerator>
2090 _UniformRandomNumberGenerator& __urng,
2091 const param_type& __p)
2093 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2094 const _RealType __pi = 3.1415926535897932384626433832795029L;
2095 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2104 *__f++ = __p.a() + __p.b() *
std::tan(__pi * __u);
2108 template<
typename _RealType,
typename _CharT,
typename _Traits>
2111 const cauchy_distribution<_RealType>& __x)
2113 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2115 const typename __ios_base::fmtflags __flags = __os.
flags();
2116 const _CharT __fill = __os.
fill();
2118 const _CharT __space = __os.
widen(
' ');
2123 __os << __x.a() << __space << __x.b();
2125 __os.
flags(__flags);
2131 template<
typename _RealType,
typename _CharT,
typename _Traits>
2139 const typename __ios_base::fmtflags __flags = __is.
flags();
2143 if (__is >> __a >> __b)
2144 __x.
param(param_type(__a, __b));
2146 __is.
flags(__flags);
2151 template<
typename _RealType>
2152 template<
typename _ForwardIterator,
2153 typename _UniformRandomNumberGenerator>
2157 _UniformRandomNumberGenerator& __urng)
2159 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2161 *__f++ = ((_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()));
2164 template<
typename _RealType>
2165 template<
typename _ForwardIterator,
2166 typename _UniformRandomNumberGenerator>
2170 _UniformRandomNumberGenerator& __urng,
2171 const param_type& __p)
2173 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2176 param_type __p1(__p.m() / 2);
2177 param_type __p2(__p.n() / 2);
2179 *__f++ = ((_M_gd_x(__urng, __p1) * n())
2180 / (_M_gd_y(__urng, __p2) * m()));
2183 template<
typename _RealType,
typename _CharT,
typename _Traits>
2186 const fisher_f_distribution<_RealType>& __x)
2188 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2190 const typename __ios_base::fmtflags __flags = __os.
flags();
2191 const _CharT __fill = __os.
fill();
2193 const _CharT __space = __os.
widen(
' ');
2198 __os << __x.m() << __space << __x.n()
2199 << __space << __x._M_gd_x << __space << __x._M_gd_y;
2201 __os.
flags(__flags);
2207 template<
typename _RealType,
typename _CharT,
typename _Traits>
2210 fisher_f_distribution<_RealType>& __x)
2213 =
typename fisher_f_distribution<_RealType>::param_type;
2214 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2216 const typename __ios_base::fmtflags __flags = __is.
flags();
2220 if (__is >> __m >> __n >> __x._M_gd_x >> __x._M_gd_y)
2221 __x.param(param_type(__m, __n));
2223 __is.
flags(__flags);
2228 template<
typename _RealType>
2229 template<
typename _ForwardIterator,
2230 typename _UniformRandomNumberGenerator>
2234 _UniformRandomNumberGenerator& __urng)
2236 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2238 *__f++ = _M_nd(__urng) *
std::sqrt(n() / _M_gd(__urng));
2241 template<
typename _RealType>
2242 template<
typename _ForwardIterator,
2243 typename _UniformRandomNumberGenerator>
2247 _UniformRandomNumberGenerator& __urng,
2248 const param_type& __p)
2250 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2252 __p2(__p.n() / 2, 2);
2254 *__f++ = _M_nd(__urng) *
std::sqrt(__p.n() / _M_gd(__urng, __p2));
2257 template<
typename _RealType,
typename _CharT,
typename _Traits>
2260 const student_t_distribution<_RealType>& __x)
2262 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2264 const typename __ios_base::fmtflags __flags = __os.
flags();
2265 const _CharT __fill = __os.
fill();
2267 const _CharT __space = __os.
widen(
' ');
2272 __os << __x.n() << __space << __x._M_nd << __space << __x._M_gd;
2274 __os.
flags(__flags);
2280 template<
typename _RealType,
typename _CharT,
typename _Traits>
2283 student_t_distribution<_RealType>& __x)
2286 =
typename student_t_distribution<_RealType>::param_type;
2287 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2289 const typename __ios_base::fmtflags __flags = __is.
flags();
2293 if (__is >> __n >> __x._M_nd >> __x._M_gd)
2294 __x.param(param_type(__n));
2296 __is.
flags(__flags);
2301 template<
typename _RealType>
2303 gamma_distribution<_RealType>::param_type::
2306 _M_malpha = _M_alpha < 1.0 ? _M_alpha + _RealType(1.0) : _M_alpha;
2308 const _RealType __a1 = _M_malpha - _RealType(1.0) / _RealType(3.0);
2309 _M_a2 = _RealType(1.0) /
std::sqrt(_RealType(9.0) * __a1);
2317 template<
typename _RealType>
2318 template<
typename _UniformRandomNumberGenerator>
2321 operator()(_UniformRandomNumberGenerator& __urng,
2324 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2329 - _RealType(1.0) / _RealType(3.0));
2335 __n = _M_nd(__urng);
2340 __v = __v * __v * __v;
2343 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2344 && (
std::log(__u) > (0.5 * __n * __n + __a1
2347 if (__param.alpha() == __param._M_malpha)
2348 return __a1 * __v * __param.beta();
2356 * __a1 * __v * __param.beta());
2360 template<
typename _RealType>
2361 template<
typename _ForwardIterator,
2362 typename _UniformRandomNumberGenerator>
2366 _UniformRandomNumberGenerator& __urng,
2367 const param_type& __param)
2369 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2370 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2375 - _RealType(1.0) / _RealType(3.0));
2377 if (__param.alpha() == __param._M_malpha)
2384 __n = _M_nd(__urng);
2389 __v = __v * __v * __v;
2392 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2393 && (
std::log(__u) > (0.5 * __n * __n + __a1
2396 *__f++ = __a1 * __v * __param.beta();
2405 __n = _M_nd(__urng);
2410 __v = __v * __v * __v;
2413 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2414 && (
std::log(__u) > (0.5 * __n * __n + __a1
2422 * __a1 * __v * __param.beta());
2426 template<
typename _RealType,
typename _CharT,
typename _Traits>
2429 const gamma_distribution<_RealType>& __x)
2431 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2433 const typename __ios_base::fmtflags __flags = __os.
flags();
2434 const _CharT __fill = __os.
fill();
2436 const _CharT __space = __os.
widen(
' ');
2441 __os << __x.alpha() << __space << __x.beta()
2442 << __space << __x._M_nd;
2444 __os.
flags(__flags);
2450 template<
typename _RealType,
typename _CharT,
typename _Traits>
2453 gamma_distribution<_RealType>& __x)
2455 using param_type =
typename gamma_distribution<_RealType>::param_type;
2456 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2458 const typename __ios_base::fmtflags __flags = __is.
flags();
2461 _RealType __alpha_val, __beta_val;
2462 if (__is >> __alpha_val >> __beta_val >> __x._M_nd)
2463 __x.param(param_type(__alpha_val, __beta_val));
2465 __is.
flags(__flags);
2470 template<
typename _RealType>
2471 template<
typename _UniformRandomNumberGenerator>
2474 operator()(_UniformRandomNumberGenerator& __urng,
2475 const param_type& __p)
2477 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2483 template<
typename _RealType>
2484 template<
typename _ForwardIterator,
2485 typename _UniformRandomNumberGenerator>
2489 _UniformRandomNumberGenerator& __urng,
2490 const param_type& __p)
2492 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2493 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2502 template<
typename _RealType,
typename _CharT,
typename _Traits>
2505 const weibull_distribution<_RealType>& __x)
2507 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2509 const typename __ios_base::fmtflags __flags = __os.
flags();
2510 const _CharT __fill = __os.
fill();
2512 const _CharT __space = __os.
widen(
' ');
2517 __os << __x.a() << __space << __x.b();
2519 __os.
flags(__flags);
2525 template<
typename _RealType,
typename _CharT,
typename _Traits>
2533 const typename __ios_base::fmtflags __flags = __is.
flags();
2537 if (__is >> __a >> __b)
2538 __x.
param(param_type(__a, __b));
2540 __is.
flags(__flags);
2545 template<
typename _RealType>
2546 template<
typename _UniformRandomNumberGenerator>
2549 operator()(_UniformRandomNumberGenerator& __urng,
2550 const param_type& __p)
2552 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2558 template<
typename _RealType>
2559 template<
typename _ForwardIterator,
2560 typename _UniformRandomNumberGenerator>
2564 _UniformRandomNumberGenerator& __urng,
2565 const param_type& __p)
2567 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2568 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2576 template<
typename _RealType,
typename _CharT,
typename _Traits>
2579 const extreme_value_distribution<_RealType>& __x)
2581 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2583 const typename __ios_base::fmtflags __flags = __os.
flags();
2584 const _CharT __fill = __os.
fill();
2586 const _CharT __space = __os.
widen(
' ');
2591 __os << __x.a() << __space << __x.b();
2593 __os.
flags(__flags);
2599 template<
typename _RealType,
typename _CharT,
typename _Traits>
2608 const typename __ios_base::fmtflags __flags = __is.
flags();
2612 if (__is >> __a >> __b)
2613 __x.
param(param_type(__a, __b));
2615 __is.
flags(__flags);
2620 template<
typename _IntType>
2622 discrete_distribution<_IntType>::param_type::
2625 if (_M_prob.size() < 2)
2632 _M_prob.end(), 0.0);
2633 __glibcxx_assert(__sum > 0);
2635 __detail::__normalize(_M_prob.begin(), _M_prob.end(), _M_prob.begin(),
2638 _M_cp.reserve(_M_prob.size());
2642 _M_cp[_M_cp.size() - 1] = 1.0;
2645 template<
typename _IntType>
2646 template<
typename _Func>
2647 discrete_distribution<_IntType>::param_type::
2648 param_type(
size_t __nw,
double __xmin,
double __xmax, _Func __fw)
2649 : _M_prob(), _M_cp()
2651 const size_t __n = __nw == 0 ? 1 : __nw;
2652 const double __delta = (__xmax - __xmin) / __n;
2654 _M_prob.reserve(__n);
2655 for (
size_t __k = 0; __k < __nw; ++__k)
2656 _M_prob.push_back(__fw(__xmin + __k * __delta + 0.5 * __delta));
2661 template<
typename _IntType>
2662 template<
typename _UniformRandomNumberGenerator>
2663 typename discrete_distribution<_IntType>::result_type
2664 discrete_distribution<_IntType>::
2665 operator()(_UniformRandomNumberGenerator& __urng,
2666 const param_type& __param)
2668 if (__param._M_cp.empty())
2669 return result_type(0);
2671 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2674 const double __p = __aurng();
2675 auto __pos = std::lower_bound(__param._M_cp.begin(),
2676 __param._M_cp.end(), __p);
2678 return __pos - __param._M_cp.begin();
2681 template<
typename _IntType>
2682 template<
typename _ForwardIterator,
2683 typename _UniformRandomNumberGenerator>
2685 discrete_distribution<_IntType>::
2686 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2687 _UniformRandomNumberGenerator& __urng,
2688 const param_type& __param)
2690 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2692 if (__param._M_cp.empty())
2695 *__f++ = result_type(0);
2699 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2704 const double __p = __aurng();
2705 auto __pos = std::lower_bound(__param._M_cp.begin(),
2706 __param._M_cp.end(), __p);
2708 *__f++ = __pos - __param._M_cp.begin();
2712 template<
typename _IntType,
typename _CharT,
typename _Traits>
2715 const discrete_distribution<_IntType>& __x)
2717 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2719 const typename __ios_base::fmtflags __flags = __os.
flags();
2720 const _CharT __fill = __os.
fill();
2722 const _CharT __space = __os.
widen(
' ');
2728 __os << __prob.
size();
2729 for (
auto __dit = __prob.
begin(); __dit != __prob.
end(); ++__dit)
2730 __os << __space << *__dit;
2732 __os.
flags(__flags);
2740 template<
typename _ValT,
typename _CharT,
typename _Traits>
2741 basic_istream<_CharT, _Traits>&
2742 __extract_params(basic_istream<_CharT, _Traits>& __is,
2743 vector<_ValT>& __vals,
size_t __n)
2745 __vals.reserve(__n);
2750 __vals.push_back(__val);
2758 template<
typename _IntType,
typename _CharT,
typename _Traits>
2761 discrete_distribution<_IntType>& __x)
2763 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2765 const typename __ios_base::fmtflags __flags = __is.
flags();
2772 if (__detail::__extract_params(__is, __prob_vec, __n))
2773 __x.param({__prob_vec.
begin(), __prob_vec.
end()});
2776 __is.
flags(__flags);
2781 template<
typename _RealType>
2783 piecewise_constant_distribution<_RealType>::param_type::
2786 if (_M_int.size() < 2
2787 || (_M_int.size() == 2
2788 && _M_int[0] == _RealType(0)
2789 && _M_int[1] == _RealType(1)))
2798 __glibcxx_assert(__sum > 0);
2800 __detail::__normalize(_M_den.begin(), _M_den.end(), _M_den.begin(),
2803 _M_cp.reserve(_M_den.size());
2808 _M_cp[_M_cp.size() - 1] = 1.0;
2810 for (
size_t __k = 0; __k < _M_den.size(); ++__k)
2811 _M_den[__k] /= _M_int[__k + 1] - _M_int[__k];
2814 template<
typename _RealType>
2815 template<
typename _InputIteratorB,
typename _InputIteratorW>
2816 piecewise_constant_distribution<_RealType>::param_type::
2817 param_type(_InputIteratorB __bbegin,
2818 _InputIteratorB __bend,
2819 _InputIteratorW __wbegin)
2820 : _M_int(), _M_den(), _M_cp()
2822 if (__bbegin != __bend)
2826 _M_int.push_back(*__bbegin);
2828 if (__bbegin == __bend)
2831 _M_den.push_back(*__wbegin);
2839 template<
typename _RealType>
2840 template<
typename _Func>
2841 piecewise_constant_distribution<_RealType>::param_type::
2842 param_type(initializer_list<_RealType> __bl, _Func __fw)
2843 : _M_int(), _M_den(), _M_cp()
2845 _M_int.reserve(__bl.size());
2846 for (
auto __biter = __bl.begin(); __biter != __bl.end(); ++__biter)
2847 _M_int.push_back(*__biter);
2849 _M_den.reserve(_M_int.size() - 1);
2850 for (
size_t __k = 0; __k < _M_int.size() - 1; ++__k)
2851 _M_den.push_back(__fw(0.5 * (_M_int[__k + 1] + _M_int[__k])));
2856 template<
typename _RealType>
2857 template<
typename _Func>
2858 piecewise_constant_distribution<_RealType>::param_type::
2859 param_type(
size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
2860 : _M_int(), _M_den(), _M_cp()
2862 const size_t __n = __nw == 0 ? 1 : __nw;
2863 const _RealType __delta = (__xmax - __xmin) / __n;
2865 _M_int.reserve(__n + 1);
2866 for (
size_t __k = 0; __k <= __nw; ++__k)
2867 _M_int.push_back(__xmin + __k * __delta);
2869 _M_den.reserve(__n);
2870 for (
size_t __k = 0; __k < __nw; ++__k)
2871 _M_den.push_back(__fw(_M_int[__k] + 0.5 * __delta));
2876 template<
typename _RealType>
2877 template<
typename _UniformRandomNumberGenerator>
2878 typename piecewise_constant_distribution<_RealType>::result_type
2879 piecewise_constant_distribution<_RealType>::
2880 operator()(_UniformRandomNumberGenerator& __urng,
2881 const param_type& __param)
2883 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2886 const double __p = __aurng();
2887 if (__param._M_cp.empty())
2890 auto __pos = std::lower_bound(__param._M_cp.begin(),
2891 __param._M_cp.end(), __p);
2892 const size_t __i = __pos - __param._M_cp.begin();
2894 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
2896 return __param._M_int[__i] + (__p - __pref) / __param._M_den[__i];
2899 template<
typename _RealType>
2900 template<
typename _ForwardIterator,
2901 typename _UniformRandomNumberGenerator>
2903 piecewise_constant_distribution<_RealType>::
2904 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2905 _UniformRandomNumberGenerator& __urng,
2906 const param_type& __param)
2908 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2909 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2912 if (__param._M_cp.empty())
2921 const double __p = __aurng();
2923 auto __pos = std::lower_bound(__param._M_cp.begin(),
2924 __param._M_cp.end(), __p);
2925 const size_t __i = __pos - __param._M_cp.begin();
2927 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
2929 *__f++ = (__param._M_int[__i]
2930 + (__p - __pref) / __param._M_den[__i]);
2934 template<
typename _RealType,
typename _CharT,
typename _Traits>
2937 const piecewise_constant_distribution<_RealType>& __x)
2939 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2941 const typename __ios_base::fmtflags __flags = __os.
flags();
2942 const _CharT __fill = __os.
fill();
2944 const _CharT __space = __os.
widen(
' ');
2950 __os << __int.
size() - 1;
2952 for (
auto __xit = __int.
begin(); __xit != __int.
end(); ++__xit)
2953 __os << __space << *__xit;
2956 for (
auto __dit = __den.
begin(); __dit != __den.
end(); ++__dit)
2957 __os << __space << *__dit;
2959 __os.
flags(__flags);
2965 template<
typename _RealType,
typename _CharT,
typename _Traits>
2968 piecewise_constant_distribution<_RealType>& __x)
2970 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2972 const typename __ios_base::fmtflags __flags = __is.
flags();
2979 if (__detail::__extract_params(__is, __int_vec, __n + 1))
2982 if (__detail::__extract_params(__is, __den_vec, __n))
2984 __x.param({ __int_vec.
begin(), __int_vec.
end(),
2985 __den_vec.
begin() });
2990 __is.
flags(__flags);
2995 template<
typename _RealType>
2997 piecewise_linear_distribution<_RealType>::param_type::
3000 if (_M_int.size() < 2
3001 || (_M_int.size() == 2
3002 && _M_int[0] == _RealType(0)
3003 && _M_int[1] == _RealType(1)
3004 && _M_den[0] == _M_den[1]))
3012 _M_cp.reserve(_M_int.size() - 1);
3013 _M_m.reserve(_M_int.size() - 1);
3014 for (
size_t __k = 0; __k < _M_int.size() - 1; ++__k)
3016 const _RealType __delta = _M_int[__k + 1] - _M_int[__k];
3017 __sum += 0.5 * (_M_den[__k + 1] + _M_den[__k]) * __delta;
3018 _M_cp.push_back(__sum);
3019 _M_m.push_back((_M_den[__k + 1] - _M_den[__k]) / __delta);
3021 __glibcxx_assert(__sum > 0);
3024 __detail::__normalize(_M_den.begin(), _M_den.end(), _M_den.begin(),
3027 __detail::__normalize(_M_cp.begin(), _M_cp.end(), _M_cp.begin(), __sum);
3029 __detail::__normalize(_M_m.begin(), _M_m.end(), _M_m.begin(), __sum);
3032 _M_cp[_M_cp.size() - 1] = 1.0;
3035 template<
typename _RealType>
3036 template<
typename _InputIteratorB,
typename _InputIteratorW>
3037 piecewise_linear_distribution<_RealType>::param_type::
3038 param_type(_InputIteratorB __bbegin,
3039 _InputIteratorB __bend,
3040 _InputIteratorW __wbegin)
3041 : _M_int(), _M_den(), _M_cp(), _M_m()
3043 for (; __bbegin != __bend; ++__bbegin, ++__wbegin)
3045 _M_int.push_back(*__bbegin);
3046 _M_den.push_back(*__wbegin);
3052 template<
typename _RealType>
3053 template<
typename _Func>
3054 piecewise_linear_distribution<_RealType>::param_type::
3055 param_type(initializer_list<_RealType> __bl, _Func __fw)
3056 : _M_int(), _M_den(), _M_cp(), _M_m()
3058 _M_int.reserve(__bl.size());
3059 _M_den.reserve(__bl.size());
3060 for (
auto __biter = __bl.begin(); __biter != __bl.end(); ++__biter)
3062 _M_int.push_back(*__biter);
3063 _M_den.push_back(__fw(*__biter));
3069 template<
typename _RealType>
3070 template<
typename _Func>
3071 piecewise_linear_distribution<_RealType>::param_type::
3072 param_type(
size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
3073 : _M_int(), _M_den(), _M_cp(), _M_m()
3075 const size_t __n = __nw == 0 ? 1 : __nw;
3076 const _RealType __delta = (__xmax - __xmin) / __n;
3078 _M_int.reserve(__n + 1);
3079 _M_den.reserve(__n + 1);
3080 for (
size_t __k = 0; __k <= __nw; ++__k)
3082 _M_int.push_back(__xmin + __k * __delta);
3083 _M_den.push_back(__fw(_M_int[__k] + __delta));
3089 template<
typename _RealType>
3090 template<
typename _UniformRandomNumberGenerator>
3091 typename piecewise_linear_distribution<_RealType>::result_type
3092 piecewise_linear_distribution<_RealType>::
3093 operator()(_UniformRandomNumberGenerator& __urng,
3094 const param_type& __param)
3096 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
3099 const double __p = __aurng();
3100 if (__param._M_cp.empty())
3103 auto __pos = std::lower_bound(__param._M_cp.begin(),
3104 __param._M_cp.end(), __p);
3105 const size_t __i = __pos - __param._M_cp.begin();
3107 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
3109 const double __a = 0.5 * __param._M_m[__i];
3110 const double __b = __param._M_den[__i];
3111 const double __cm = __p - __pref;
3113 _RealType __x = __param._M_int[__i];
3118 const double __d = __b * __b + 4.0 * __a * __cm;
3119 __x += 0.5 * (
std::sqrt(__d) - __b) / __a;
3125 template<
typename _RealType>
3126 template<
typename _ForwardIterator,
3127 typename _UniformRandomNumberGenerator>
3129 piecewise_linear_distribution<_RealType>::
3130 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3131 _UniformRandomNumberGenerator& __urng,
3132 const param_type& __param)
3134 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3137 *__f++ = this->operator()(__urng, __param);
3140 template<
typename _RealType,
typename _CharT,
typename _Traits>
3143 const piecewise_linear_distribution<_RealType>& __x)
3145 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
3147 const typename __ios_base::fmtflags __flags = __os.
flags();
3148 const _CharT __fill = __os.
fill();
3150 const _CharT __space = __os.
widen(
' ');
3156 __os << __int.
size() - 1;
3158 for (
auto __xit = __int.
begin(); __xit != __int.
end(); ++__xit)
3159 __os << __space << *__xit;
3162 for (
auto __dit = __den.
begin(); __dit != __den.
end(); ++__dit)
3163 __os << __space << *__dit;
3165 __os.
flags(__flags);
3171 template<
typename _RealType,
typename _CharT,
typename _Traits>
3174 piecewise_linear_distribution<_RealType>& __x)
3176 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
3178 const typename __ios_base::fmtflags __flags = __is.
flags();
3184 vector<_RealType> __int_vec;
3185 if (__detail::__extract_params(__is, __int_vec, __n + 1))
3187 vector<double> __den_vec;
3188 if (__detail::__extract_params(__is, __den_vec, __n + 1))
3190 __x.param({ __int_vec.begin(), __int_vec.end(),
3191 __den_vec.begin() });
3195 __is.
flags(__flags);
3200 template<
typename _IntType,
typename>
3203 _M_v.reserve(__il.size());
3204 for (
auto __iter = __il.begin(); __iter != __il.end(); ++__iter)
3205 _M_v.push_back(__detail::__mod<result_type,
3206 __detail::_Shift<result_type, 32>::__value>(*__iter));
3209 template<
typename _InputIterator>
3210 seed_seq::seed_seq(_InputIterator __begin, _InputIterator __end)
3212 if _GLIBCXX17_CONSTEXPR (__is_random_access_iter<_InputIterator>::value)
3215 for (_InputIterator __iter = __begin; __iter != __end; ++__iter)
3216 _M_v.push_back(__detail::__mod<result_type,
3217 __detail::_Shift<result_type, 32>::__value>(*__iter));
3220 template<
typename _RandomAccessIterator>
3222 seed_seq::generate(_RandomAccessIterator __begin,
3223 _RandomAccessIterator __end)
3225 typedef typename iterator_traits<_RandomAccessIterator>::value_type
3228 if (__begin == __end)
3231 std::fill(__begin, __end, _Type(0x8b8b8b8bu));
3233 const size_t __n = __end - __begin;
3234 const size_t __s = _M_v.size();
3235 const size_t __t = (__n >= 623) ? 11
3240 const size_t __p = (__n - __t) / 2;
3241 const size_t __q = __p + __t;
3242 const size_t __m =
std::max(
size_t(__s + 1), __n);
3244 for (
size_t __k = 0; __k < __m; ++__k)
3246 _Type __arg = (__begin[__k % __n]
3247 ^ __begin[(__k + __p) % __n]
3248 ^ __begin[(__k - 1) % __n]);
3249 _Type __r1 = __arg ^ (__arg >> 27);
3250 __r1 = __detail::__mod<_Type,
3251 __detail::_Shift<_Type, 32>::__value>(1664525u * __r1);
3255 else if (__k <= __s)
3256 __r2 += __k % __n + _M_v[__k - 1];
3259 __r2 = __detail::__mod<_Type,
3260 __detail::_Shift<_Type, 32>::__value>(__r2);
3261 __begin[(__k + __p) % __n] += __r1;
3262 __begin[(__k + __q) % __n] += __r2;
3263 __begin[__k % __n] = __r2;
3266 for (
size_t __k = __m; __k < __m + __n; ++__k)
3268 _Type __arg = (__begin[__k % __n]
3269 + __begin[(__k + __p) % __n]
3270 + __begin[(__k - 1) % __n]);
3271 _Type __r3 = __arg ^ (__arg >> 27);
3272 __r3 = __detail::__mod<_Type,
3273 __detail::_Shift<_Type, 32>::__value>(1566083941u * __r3);
3274 _Type __r4 = __r3 - __k % __n;
3275 __r4 = __detail::__mod<_Type,
3276 __detail::_Shift<_Type, 32>::__value>(__r4);
3277 __begin[(__k + __p) % __n] ^= __r3;
3278 __begin[(__k + __q) % __n] ^= __r4;
3279 __begin[__k % __n] = __r4;
3283 template<
typename _RealType,
size_t __bits,
3284 typename _UniformRandomNumberGenerator>
3289 "template argument must be a floating point type");
3294 const long double __r =
static_cast<long double>(__urng.max())
3295 -
static_cast<long double>(__urng.min()) + 1.0L;
3297 const size_t __m = std::max<size_t>(1UL,
3298 (__b + __log2r - 1UL) / __log2r);
3300 _RealType __sum = _RealType(0);
3301 _RealType __tmp = _RealType(1);
3302 for (
size_t __k = __m; __k != 0; --__k)
3304 __sum += _RealType(__urng() - __urng.min()) * __tmp;
3307 __ret = __sum / __tmp;
3308 if (__builtin_expect(__ret >= _RealType(1), 0))
3310 #if _GLIBCXX_USE_C99_MATH_TR1
3311 __ret = std::nextafter(_RealType(1), _RealType(0));
3313 __ret = _RealType(1)
3320 _GLIBCXX_END_NAMESPACE_VERSION
complex< _Tp > log(const complex< _Tp > &)
Return complex natural logarithm of z.
complex< _Tp > tan(const complex< _Tp > &)
Return complex tangent of z.
_Tp abs(const complex< _Tp > &)
Return magnitude of z.
complex< _Tp > exp(const complex< _Tp > &)
Return complex base e exponential of z.
complex< _Tp > pow(const complex< _Tp > &, int)
Return x to the y'th power.
complex< _Tp > sqrt(const complex< _Tp > &)
Return complex square root of z.
constexpr const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
_RealType generate_canonical(_UniformRandomNumberGenerator &__g)
A function template for converting the output of a (integral) uniform random number generator to a fl...
basic_ostream< _Ch_type, _Ch_traits > & operator<<(basic_ostream< _Ch_type, _Ch_traits > &__os, const sub_match< _Bi_iter > &__m)
Inserts a matched string into an output stream.
constexpr back_insert_iterator< _Container > back_inserter(_Container &__x)
constexpr _Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
Accumulate values in a range.
constexpr _OutputIterator partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
Return list of partial sums.
ISO C++ entities toplevel namespace is std.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
ios_base & scientific(ios_base &__base)
Calls base.setf(ios_base::scientific, ios_base::floatfield).
ios_base & dec(ios_base &__base)
Calls base.setf(ios_base::dec, ios_base::basefield).
constexpr int __lg(int __n)
This is a helper function for the sort routines and for random.tcc.
ios_base & left(ios_base &__base)
Calls base.setf(ios_base::left, ios_base::adjustfield).
ios_base & skipws(ios_base &__base)
Calls base.setf(ios_base::skipws).
ios_base & fixed(ios_base &__base)
Calls base.setf(ios_base::fixed, ios_base::floatfield).
void clear(iostate __state=goodbit)
[Re]sets the error state.
char_type widen(char __c) const
Widens characters.
char_type fill() const
Retrieves the empty character.
Template class basic_istream.
Template class basic_ostream.
Properties of fundamental types.
static constexpr _Tp max() noexcept
static constexpr _Tp epsilon() noexcept
static constexpr _Tp min() noexcept
streamsize precision() const
Flags access.
fmtflags flags() const
Access to format flags.
A model of a linear congruential random number generator.
static constexpr result_type multiplier
static constexpr result_type modulus
void seed(result_type __s=default_seed)
Reseeds the linear_congruential_engine random number generator engine sequence to the seed __s.
static constexpr result_type increment
The Marsaglia-Zaman generator.
void seed(result_type __sd=default_seed)
Seeds the initial state of the random number generator.
result_type operator()()
Gets the next random number in the sequence.
result_type operator()()
Gets the next value in the generated random number sequence.
result_type operator()()
Gets the next value in the generated random number sequence.
Produces random numbers by combining random numbers from some base engine to produce random numbers w...
_RandomNumberEngine::result_type result_type
const _RandomNumberEngine & base() const noexcept
Uniform continuous distribution for random numbers.
param_type param() const
Returns the parameter set of the distribution.
A normal continuous distribution for random numbers.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
A gamma continuous distribution for random numbers.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
A chi_squared_distribution random number distribution.
A cauchy_distribution random number distribution.
param_type param() const
Returns the parameter set of the distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
A fisher_f_distribution random number distribution.
A student_t_distribution random number distribution.
A discrete binomial random number distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
A discrete geometric random number distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
param_type param() const
Returns the parameter set of the distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
A discrete Poisson random number distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
friend std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const std::poisson_distribution< _IntType1 > &__x)
Inserts a poisson_distribution random number distribution __x into the output stream __os.
friend bool operator==(const poisson_distribution &__d1, const poisson_distribution &__d2)
Return true if two Poisson distributions have the same parameters and the sequences that would be gen...
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, std::poisson_distribution< _IntType1 > &__x)
Extracts a poisson_distribution random number distribution __x from the input stream __is.
An exponential continuous distribution for random numbers.
param_type param() const
Returns the parameter set of the distribution.
A weibull_distribution random number distribution.
param_type param() const
Returns the parameter set of the distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
A extreme_value_distribution random number distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
param_type param() const
Returns the parameter set of the distribution.
iterator begin() noexcept
size_type size() const noexcept
Uniform discrete distribution for random numbers. A discrete random distribution on the range with e...
param_type param() const
Returns the parameter set of the distribution.