35namespace std _GLIBCXX_VISIBILITY(default)
37_GLIBCXX_BEGIN_NAMESPACE_VERSION
49 template<
typename _Tp, _Tp __m, _Tp __a, _Tp __c>
51 _Mod<_Tp, __m, __a, __c, false, true>::
58 static const _Tp __q = __m / __a;
59 static const _Tp __r = __m % __a;
61 _Tp __t1 = __a * (__x % __q);
62 _Tp __t2 = __r * (__x / __q);
66 __x = __m - __t2 + __t1;
71 const _Tp __d = __m - __x;
80 template<
typename _InputIterator,
typename _OutputIterator,
83 __normalize(_InputIterator __first, _InputIterator __last,
84 _OutputIterator __result,
const _Tp& __factor)
86 for (; __first != __last; ++__first, (void) ++__result)
87 *__result = *__first / __factor;
94#if ! __cpp_inline_variables
95 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
99 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
103 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
107 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
109 linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed;
116 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
121 if ((__detail::__mod<_UIntType, __m>(__c) == 0)
122 && (__detail::__mod<_UIntType, __m>(__s) == 0))
125 _M_x = __detail::__mod<_UIntType, __m>(__s);
131 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
132 template<
typename _Sseq>
136 -> _If_seed_seq<_Sseq>
140 const _UIntType __k = (__k0 + 31) / 32;
141 uint_least32_t __arr[__k + 3];
142 __q.generate(__arr + 0, __arr + __k + 3);
143 _UIntType __factor = 1u;
144 _UIntType __sum = 0u;
145 for (
size_t __j = 0; __j < __k; ++__j)
147 __sum += __arr[__j + 3] * __factor;
148 __factor *= __detail::_Shift<_UIntType, 32>::__value;
153 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m,
154 typename _CharT,
typename _Traits>
158 __a, __c, __m>& __lcr)
160 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
162 const typename __ios_base::fmtflags __flags = __os.
flags();
163 const _CharT __fill = __os.
fill();
164 __os.
flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
174 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m,
175 typename _CharT,
typename _Traits>
178 linear_congruential_engine<_UIntType, __a, __c, __m>& __lcr)
180 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
182 const typename __ios_base::fmtflags __flags = __is.
flags();
183 __is.
flags(__ios_base::dec);
191#if ! __cpp_inline_variables
192 template<
typename _UIntType,
193 size_t __w,
size_t __n,
size_t __m,
size_t __r,
194 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
195 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
199 __s, __b, __t, __c, __l, __f>::word_size;
201 template<
typename _UIntType,
202 size_t __w,
size_t __n,
size_t __m,
size_t __r,
203 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
204 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
208 __s, __b, __t, __c, __l, __f>::state_size;
210 template<
typename _UIntType,
211 size_t __w,
size_t __n,
size_t __m,
size_t __r,
212 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
213 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
217 __s, __b, __t, __c, __l, __f>::shift_size;
219 template<
typename _UIntType,
220 size_t __w,
size_t __n,
size_t __m,
size_t __r,
221 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
222 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
226 __s, __b, __t, __c, __l, __f>::mask_bits;
228 template<
typename _UIntType,
229 size_t __w,
size_t __n,
size_t __m,
size_t __r,
230 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
231 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
235 __s, __b, __t, __c, __l, __f>::xor_mask;
237 template<
typename _UIntType,
238 size_t __w,
size_t __n,
size_t __m,
size_t __r,
239 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
240 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
244 __s, __b, __t, __c, __l, __f>::tempering_u;
246 template<
typename _UIntType,
247 size_t __w,
size_t __n,
size_t __m,
size_t __r,
248 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
249 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
253 __s, __b, __t, __c, __l, __f>::tempering_d;
255 template<
typename _UIntType,
256 size_t __w,
size_t __n,
size_t __m,
size_t __r,
257 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
258 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
262 __s, __b, __t, __c, __l, __f>::tempering_s;
264 template<
typename _UIntType,
265 size_t __w,
size_t __n,
size_t __m,
size_t __r,
266 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
267 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
271 __s, __b, __t, __c, __l, __f>::tempering_b;
273 template<
typename _UIntType,
274 size_t __w,
size_t __n,
size_t __m,
size_t __r,
275 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
276 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
280 __s, __b, __t, __c, __l, __f>::tempering_t;
282 template<
typename _UIntType,
283 size_t __w,
size_t __n,
size_t __m,
size_t __r,
284 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
285 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
289 __s, __b, __t, __c, __l, __f>::tempering_c;
291 template<
typename _UIntType,
292 size_t __w,
size_t __n,
size_t __m,
size_t __r,
293 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
294 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
298 __s, __b, __t, __c, __l, __f>::tempering_l;
300 template<
typename _UIntType,
301 size_t __w,
size_t __n,
size_t __m,
size_t __r,
302 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
303 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
307 __s, __b, __t, __c, __l, __f>::
308 initialization_multiplier;
310 template<
typename _UIntType,
311 size_t __w,
size_t __n,
size_t __m,
size_t __r,
312 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
313 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
317 __s, __b, __t, __c, __l, __f>::default_seed;
320 template<
typename _UIntType,
321 size_t __w,
size_t __n,
size_t __m,
size_t __r,
322 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
323 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
327 __s, __b, __t, __c, __l, __f>::
328 seed(result_type __sd)
330 _M_x[0] = __detail::__mod<_UIntType,
331 __detail::_Shift<_UIntType, __w>::__value>(__sd);
333 for (
size_t __i = 1; __i < state_size; ++__i)
335 _UIntType __x = _M_x[__i - 1];
336 __x ^= __x >> (__w - 2);
338 __x += __detail::__mod<_UIntType, __n>(__i);
339 _M_x[__i] = __detail::__mod<_UIntType,
340 __detail::_Shift<_UIntType, __w>::__value>(__x);
345 template<
typename _UIntType,
346 size_t __w,
size_t __n,
size_t __m,
size_t __r,
347 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
348 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
350 template<
typename _Sseq>
353 __s, __b, __t, __c, __l, __f>::
355 -> _If_seed_seq<_Sseq>
357 const _UIntType __upper_mask = (~_UIntType()) << __r;
358 const size_t __k = (__w + 31) / 32;
359 uint_least32_t __arr[__n * __k];
360 __q.generate(__arr + 0, __arr + __n * __k);
363 for (
size_t __i = 0; __i < state_size; ++__i)
365 _UIntType __factor = 1u;
366 _UIntType __sum = 0u;
367 for (
size_t __j = 0; __j < __k; ++__j)
369 __sum += __arr[__k * __i + __j] * __factor;
370 __factor *= __detail::_Shift<_UIntType, 32>::__value;
372 _M_x[__i] = __detail::__mod<_UIntType,
373 __detail::_Shift<_UIntType, __w>::__value>(__sum);
379 if ((_M_x[0] & __upper_mask) != 0u)
382 else if (_M_x[__i] != 0u)
387 _M_x[0] = __detail::_Shift<_UIntType, __w - 1>::__value;
391 template<
typename _UIntType,
size_t __w,
392 size_t __n,
size_t __m,
size_t __r,
393 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
394 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
398 __s, __b, __t, __c, __l, __f>::
401 const _UIntType __upper_mask = (~_UIntType()) << __r;
402 const _UIntType __lower_mask = ~__upper_mask;
404 for (
size_t __k = 0; __k < (__n - __m); ++__k)
406 _UIntType __y = ((_M_x[__k] & __upper_mask)
407 | (_M_x[__k + 1] & __lower_mask));
408 _M_x[__k] = (_M_x[__k + __m] ^ (__y >> 1)
409 ^ ((__y & 0x01) ? __a : 0));
412 for (
size_t __k = (__n - __m); __k < (__n - 1); ++__k)
414 _UIntType __y = ((_M_x[__k] & __upper_mask)
415 | (_M_x[__k + 1] & __lower_mask));
416 _M_x[__k] = (_M_x[__k + (__m - __n)] ^ (__y >> 1)
417 ^ ((__y & 0x01) ? __a : 0));
420 _UIntType __y = ((_M_x[__n - 1] & __upper_mask)
421 | (_M_x[0] & __lower_mask));
422 _M_x[__n - 1] = (_M_x[__m - 1] ^ (__y >> 1)
423 ^ ((__y & 0x01) ? __a : 0));
427 template<
typename _UIntType,
size_t __w,
428 size_t __n,
size_t __m,
size_t __r,
429 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
430 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
434 __s, __b, __t, __c, __l, __f>::
435 discard(
unsigned long long __z)
437 while (__z > state_size - _M_p)
439 __z -= state_size - _M_p;
445 template<
typename _UIntType,
size_t __w,
446 size_t __n,
size_t __m,
size_t __r,
447 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
448 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
452 __s, __b, __t, __c, __l, __f>::result_type
454 __s, __b, __t, __c, __l, __f>::
458 if (_M_p >= state_size)
462 result_type __z = _M_x[_M_p++];
463 __z ^= (__z >> __u) & __d;
464 __z ^= (__z << __s) & __b;
465 __z ^= (__z << __t) & __c;
471 template<
typename _UIntType,
size_t __w,
472 size_t __n,
size_t __m,
size_t __r,
473 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
474 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
475 _UIntType __f,
typename _CharT,
typename _Traits>
478 const mersenne_twister_engine<_UIntType, __w, __n, __m,
479 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __x)
481 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
483 const typename __ios_base::fmtflags __flags = __os.
flags();
484 const _CharT __fill = __os.
fill();
485 const _CharT __space = __os.
widen(
' ');
486 __os.
flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
489 for (
size_t __i = 0; __i < __n; ++__i)
490 __os << __x._M_x[__i] << __space;
498 template<
typename _UIntType,
size_t __w,
499 size_t __n,
size_t __m,
size_t __r,
500 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
501 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
502 _UIntType __f,
typename _CharT,
typename _Traits>
503 std::basic_istream<_CharT, _Traits>&
504 operator>>(std::basic_istream<_CharT, _Traits>& __is,
506 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __x)
508 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
510 const typename __ios_base::fmtflags __flags = __is.
flags();
511 __is.
flags(__ios_base::dec | __ios_base::skipws);
513 for (
size_t __i = 0; __i < __n; ++__i)
514 __is >> __x._M_x[__i];
521#if ! __cpp_inline_variables
522 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
524 subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size;
526 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
528 subtract_with_carry_engine<_UIntType, __w, __s, __r>::short_lag;
530 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
532 subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag;
534 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
535 constexpr uint_least32_t
536 subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed;
539 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
548 __lcg(__value == 0u ? default_seed : __value % 2147483563u);
550 const size_t __n = (__w + 31) / 32;
552 for (
size_t __i = 0; __i < long_lag; ++__i)
554 _UIntType __sum = 0u;
555 _UIntType __factor = 1u;
556 for (
size_t __j = 0; __j < __n; ++__j)
558 __sum += __detail::__mod<uint_least32_t,
559 __detail::_Shift<uint_least32_t, 32>::__value>
560 (__lcg()) * __factor;
561 __factor *= __detail::_Shift<_UIntType, 32>::__value;
563 _M_x[__i] = __detail::__mod<_UIntType,
564 __detail::_Shift<_UIntType, __w>::__value>(__sum);
566 _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
570 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
571 template<
typename _Sseq>
575 -> _If_seed_seq<_Sseq>
577 const size_t __k = (__w + 31) / 32;
578 uint_least32_t __arr[__r * __k];
579 __q.generate(__arr + 0, __arr + __r * __k);
581 for (
size_t __i = 0; __i < long_lag; ++__i)
583 _UIntType __sum = 0u;
584 _UIntType __factor = 1u;
585 for (
size_t __j = 0; __j < __k; ++__j)
587 __sum += __arr[__k * __i + __j] * __factor;
588 __factor *= __detail::_Shift<_UIntType, 32>::__value;
590 _M_x[__i] = __detail::__mod<_UIntType,
591 __detail::_Shift<_UIntType, __w>::__value>(__sum);
593 _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
597 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
604 long __ps = _M_p - short_lag;
612 if (_M_x[__ps] >= _M_x[_M_p] + _M_carry)
614 __xi = _M_x[__ps] - _M_x[_M_p] - _M_carry;
619 __xi = (__detail::_Shift<_UIntType, __w>::__value
620 - _M_x[_M_p] - _M_carry + _M_x[__ps]);
626 if (++_M_p >= long_lag)
632 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r,
633 typename _CharT,
typename _Traits>
639 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
641 const typename __ios_base::fmtflags __flags = __os.
flags();
642 const _CharT __fill = __os.
fill();
643 const _CharT __space = __os.
widen(
' ');
644 __os.
flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
647 for (
size_t __i = 0; __i < __r; ++__i)
648 __os << __x._M_x[__i] << __space;
649 __os << __x._M_carry << __space << __x._M_p;
656 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r,
657 typename _CharT,
typename _Traits>
660 subtract_with_carry_engine<_UIntType, __w, __s, __r>& __x)
662 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
664 const typename __ios_base::fmtflags __flags = __is.
flags();
665 __is.
flags(__ios_base::dec | __ios_base::skipws);
667 for (
size_t __i = 0; __i < __r; ++__i)
668 __is >> __x._M_x[__i];
669 __is >> __x._M_carry;
676#if ! __cpp_inline_variables
677 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
679 discard_block_engine<_RandomNumberEngine, __p, __r>::block_size;
681 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
683 discard_block_engine<_RandomNumberEngine, __p, __r>::used_block;
686 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
692 if (_M_n >= used_block)
694 _M_b.discard(block_size - _M_n);
701 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r,
702 typename _CharT,
typename _Traits>
708 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
710 const typename __ios_base::fmtflags __flags = __os.
flags();
711 const _CharT __fill = __os.
fill();
712 const _CharT __space = __os.
widen(
' ');
713 __os.
flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
716 __os << __x.base() << __space << __x._M_n;
723 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r,
724 typename _CharT,
typename _Traits>
727 discard_block_engine<_RandomNumberEngine, __p, __r>& __x)
729 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
731 const typename __ios_base::fmtflags __flags = __is.
flags();
732 __is.
flags(__ios_base::dec | __ios_base::skipws);
734 __is >> __x._M_b >> __x._M_n;
741 template<
typename _RandomNumberEngine,
size_t __w,
typename _UIntType>
747 typedef typename _RandomNumberEngine::result_type _Eresult_type;
748 const _Eresult_type __r
750 ? _M_b.max() - _M_b.min() + 1 : 0);
752 const unsigned __m = __r ?
std::__lg(__r) : __edig;
759 __ctype __s0, __s1, __y0, __y1;
761 for (
size_t __i = 0; __i < 2; ++__i)
763 __n = (__w + __m - 1) / __m + __i;
764 __n0 = __n - __w % __n;
765 const unsigned __w0 = __w / __n;
771 __s0 = __ctype(1) << __w0;
779 __y0 = __s0 * (__r / __s0);
781 __y1 = __s1 * (__r / __s1);
783 if (__r - __y0 <= __y0 / __n)
791 for (
size_t __k = 0; __k < __n0; ++__k)
795 __u = _M_b() - _M_b.min();
796 while (__y0 && __u >= __y0);
797 __sum = __s0 * __sum + (__s0 ? __u % __s0 : __u);
799 for (
size_t __k = __n0; __k < __n; ++__k)
803 __u = _M_b() - _M_b.min();
804 while (__y1 && __u >= __y1);
805 __sum = __s1 * __sum + (__s1 ? __u % __s1 : __u);
810#if ! __cpp_inline_variables
811 template<
typename _RandomNumberEngine,
size_t __k>
813 shuffle_order_engine<_RandomNumberEngine, __k>::table_size;
819 template<
typename _Tp>
821 __representable_as_double(_Tp __x)
noexcept
826 return (__x <= (1ull << __DBL_MANT_DIG__))
828 || (!(__x & 1) && __detail::__representable_as_double(__x >> 1));
832 template<
typename _Tp>
834 __p1_representable_as_double(_Tp __x)
noexcept
840 && __detail::__representable_as_double(__x + 1u));
844 template<
typename _RandomNumberEngine,
size_t __k>
852#pragma GCC diagnostic push
853#pragma GCC diagnostic ignored "-Wc++17-extensions"
855 if constexpr (__detail::__p1_representable_as_double(__range))
856 __j *= __y / (__range + 1.0);
858 __j *= __y / (__range + 1.0L);
859#pragma GCC diagnostic pop
866 template<
typename _RandomNumberEngine,
size_t __k,
867 typename _CharT,
typename _Traits>
872 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
874 const typename __ios_base::fmtflags __flags = __os.
flags();
875 const _CharT __fill = __os.
fill();
876 const _CharT __space = __os.
widen(
' ');
877 __os.
flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
881 for (
size_t __i = 0; __i < __k; ++__i)
882 __os << __space << __x._M_v[__i];
883 __os << __space << __x._M_y;
890 template<
typename _RandomNumberEngine,
size_t __k,
891 typename _CharT,
typename _Traits>
896 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
898 const typename __ios_base::fmtflags __flags = __is.
flags();
899 __is.
flags(__ios_base::dec | __ios_base::skipws);
902 for (
size_t __i = 0; __i < __k; ++__i)
903 __is >> __x._M_v[__i];
910#if __glibcxx_philox_engine
912 template<
typename _UIntType,
size_t __w,
size_t __n,
size_t __r,
913 _UIntType... __consts>
915 philox_engine<_UIntType, __w, __n, __r, __consts...>::
916 _S_mulhi(_UIntType __a, _UIntType __b)
918 const __uint128_t __num =
919 static_cast<__uint128_t
>(__a) *
static_cast<__uint128_t
>(__b);
920 return static_cast<_UIntType
>((__num >> __w) &
max());
923 template<
typename _UIntType,
size_t __w,
size_t __n,
size_t __r,
924 _UIntType... __consts>
926 philox_engine<_UIntType, __w, __n, __r, __consts...>::
927 _S_mullo(_UIntType __a, _UIntType __b)
929 return static_cast<_UIntType
>((__a * __b) &
max());
932 template<
typename _UIntType,
size_t __w,
size_t __n,
size_t __r,
933 _UIntType... __consts>
935 philox_engine<_UIntType, __w, __n, __r, __consts...>::_M_transition()
942 if constexpr (__n == 4)
945 (
static_cast<__uint128_t
>(_M_x[1]) << __w)
946 | (
static_cast<__uint128_t
>(_M_x[0]) + 1);
948 ((
static_cast<__uint128_t
>(_M_x[3]) << __w)
950 __uint128_t __bigMask =
951 (
static_cast<__uint128_t
>(1) << ((2 * __w) - 1))
952 | ((
static_cast<__uint128_t
>(1) << ((2 * __w) - 1)) - 1);
953 if ((__uh & __bigMask) == 0)
958 _M_x[0] = __uh &
max();
959 _M_x[1] = (__uh >> (__w)) &
max();
960 _M_x[2] = __lh &
max();
961 _M_x[3] = (__lh >> (__w)) &
max();
966 (
static_cast<__uint128_t
>(_M_x[1]) << __w)
967 | (
static_cast<__uint128_t
>(_M_x[0]) + 1);
968 _M_x[0] = __num &
max();
969 _M_x[1] = (__num >> __w) &
max();
974 template<
typename _UIntType,
size_t __w,
size_t __n,
size_t __r,
975 _UIntType... __consts>
977 philox_engine<_UIntType, __w, __n, __r, __consts...>::_M_philox()
980 for (
size_t __j = 0; __j < __r; ++__j)
983 if constexpr (__n == 4)
985 __intermedSeq[0] = __outputSeq[2];
986 __intermedSeq[1] = __outputSeq[1];
987 __intermedSeq[2] = __outputSeq[0];
988 __intermedSeq[3] = __outputSeq[3];
992 __intermedSeq[0] = __outputSeq[0];
993 __intermedSeq[1] = __outputSeq[1];
995 for (
unsigned long __k = 0; __k < (__n/2); ++__k)
998 = _S_mulhi(__intermedSeq[2*__k], multipliers[__k])
999 ^ (((_M_k[__k] + (__j * round_consts[__k])) &
max()))
1000 ^ __intermedSeq[2*__k+1];
1002 __outputSeq[(2*__k)+1]
1003 = _S_mullo(__intermedSeq[2*__k], multipliers[__k]);
1009 template<
typename _UIntType,
size_t __w,
size_t __n,
size_t __r,
1010 _UIntType... __consts>
1011 template<
typename _Sseq>
1013 philox_engine<_UIntType, __w, __n, __r, __consts...>::seed(_Sseq& __q)
1014 requires __is_seed_seq<_Sseq>
1018 const unsigned __p = 1 + ((__w - 1) / 32);
1019 uint_least32_t __tmpArr[(__n/2) * __p];
1020 __q.generate(__tmpArr + 0, __tmpArr + ((__n/2) * __p));
1021 for (
unsigned __k = 0; __k < (__n/2); ++__k)
1023 unsigned long long __precalc = 0;
1024 for (
unsigned __j = 0; __j < __p; ++__j)
1026 unsigned long long __multiplicand = (1ull << (32 * __j));
1027 __precalc += (__tmpArr[__k * __p + __j] * __multiplicand) &
max();
1029 _M_k[__k] = __precalc;
1034 template<
typename _IntType,
typename _CharT,
typename _Traits>
1035 std::basic_ostream<_CharT, _Traits>&
1036 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1039 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1041 const typename __ios_base::fmtflags __flags = __os.
flags();
1042 const _CharT __fill = __os.
fill();
1043 const _CharT __space = __os.
widen(
' ');
1044 __os.
flags(__ios_base::scientific | __ios_base::left);
1047 __os << __x.a() << __space << __x.b();
1049 __os.
flags(__flags);
1054 template<
typename _IntType,
typename _CharT,
typename _Traits>
1055 std::basic_istream<_CharT, _Traits>&
1061 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1063 const typename __ios_base::fmtflags __flags = __is.
flags();
1064 __is.
flags(__ios_base::dec | __ios_base::skipws);
1067 if (__is >> __a >> __b)
1068 __x.
param(param_type(__a, __b));
1070 __is.
flags(__flags);
1075 template<
typename _RealType>
1076 template<
typename _ForwardIterator,
1077 typename _UniformRandomNumberGenerator>
1081 _UniformRandomNumberGenerator& __urng,
1082 const param_type& __p)
1084 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1085 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1087 auto __range = __p.b() - __p.a();
1089 *__f++ = __aurng() * __range + __p.a();
1092 template<
typename _RealType,
typename _CharT,
typename _Traits>
1095 const uniform_real_distribution<_RealType>& __x)
1097 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1099 const typename __ios_base::fmtflags __flags = __os.
flags();
1100 const _CharT __fill = __os.
fill();
1102 const _CharT __space = __os.
widen(
' ');
1103 __os.
flags(__ios_base::scientific | __ios_base::left);
1107 __os << __x.a() << __space << __x.b();
1109 __os.
flags(__flags);
1115 template<
typename _RealType,
typename _CharT,
typename _Traits>
1116 std::basic_istream<_CharT, _Traits>&
1122 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1124 const typename __ios_base::fmtflags __flags = __is.
flags();
1125 __is.
flags(__ios_base::skipws);
1128 if (__is >> __a >> __b)
1129 __x.
param(param_type(__a, __b));
1131 __is.
flags(__flags);
1136 template<
typename _ForwardIterator,
1137 typename _UniformRandomNumberGenerator>
1139 std::bernoulli_distribution::
1140 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1141 _UniformRandomNumberGenerator& __urng,
1142 const param_type& __p)
1144 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1145 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1147 auto __limit = __p.p() * (__aurng.max() - __aurng.min());
1150 *__f++ = (__aurng() - __aurng.min()) < __limit;
1153 template<
typename _CharT,
typename _Traits>
1158 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1160 const typename __ios_base::fmtflags __flags = __os.
flags();
1161 const _CharT __fill = __os.
fill();
1163 __os.
flags(__ios_base::scientific | __ios_base::left);
1169 __os.
flags(__flags);
1176 template<
typename _IntType>
1177 template<
typename _UniformRandomNumberGenerator>
1178 typename geometric_distribution<_IntType>::result_type
1180 operator()(_UniformRandomNumberGenerator& __urng,
1181 const param_type& __param)
1185 const double __naf =
1188 const double __thr =
1190 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1195 __cand = std::floor(
std::log(1.0 - __aurng()) / __param._M_log_1_p);
1196 while (__cand >= __thr);
1198 return result_type(__cand + __naf);
1201 template<
typename _IntType>
1202 template<
typename _ForwardIterator,
1203 typename _UniformRandomNumberGenerator>
1207 _UniformRandomNumberGenerator& __urng,
1208 const param_type& __param)
1210 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1213 const double __naf =
1216 const double __thr =
1218 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1225 __cand = std::floor(
std::log(1.0 - __aurng())
1226 / __param._M_log_1_p);
1227 while (__cand >= __thr);
1229 *__f++ = __cand + __naf;
1233 template<
typename _IntType,
1234 typename _CharT,
typename _Traits>
1237 const geometric_distribution<_IntType>& __x)
1239 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1241 const typename __ios_base::fmtflags __flags = __os.
flags();
1242 const _CharT __fill = __os.
fill();
1244 __os.
flags(__ios_base::scientific | __ios_base::left);
1250 __os.
flags(__flags);
1256 template<
typename _IntType,
1257 typename _CharT,
typename _Traits>
1258 std::basic_istream<_CharT, _Traits>&
1263 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1265 const typename __ios_base::fmtflags __flags = __is.
flags();
1266 __is.
flags(__ios_base::skipws);
1270 __x.
param(param_type(__p));
1272 __is.
flags(__flags);
1277 template<
typename _IntType>
1278 template<
typename _UniformRandomNumberGenerator>
1279 typename negative_binomial_distribution<_IntType>::result_type
1281 operator()(_UniformRandomNumberGenerator& __urng)
1283 const double __y = _M_gd(__urng);
1287 return __poisson(__urng);
1290 template<
typename _IntType>
1291 template<
typename _UniformRandomNumberGenerator>
1294 operator()(_UniformRandomNumberGenerator& __urng,
1295 const param_type& __p)
1301 _M_gd(__urng, param_type(__p.k(), (1.0 - __p.p()) / __p.p()));
1304 return __poisson(__urng);
1307 template<
typename _IntType>
1308 template<
typename _ForwardIterator,
1309 typename _UniformRandomNumberGenerator>
1311 negative_binomial_distribution<_IntType>::
1312 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1313 _UniformRandomNumberGenerator& __urng)
1315 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1318 const double __y = _M_gd(__urng);
1322 *__f++ = __poisson(__urng);
1326 template<
typename _IntType>
1327 template<
typename _ForwardIterator,
1328 typename _UniformRandomNumberGenerator>
1332 _UniformRandomNumberGenerator& __urng,
1333 const param_type& __p)
1335 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1336 typename std::gamma_distribution<result_type>::param_type
1337 __p2(__p.k(), (1.0 - __p.p()) / __p.p());
1341 const double __y = _M_gd(__urng, __p2);
1343 std::poisson_distribution<result_type> __poisson(__y);
1344 *__f++ = __poisson(__urng);
1348 template<
typename _IntType,
typename _CharT,
typename _Traits>
1349 std::basic_ostream<_CharT, _Traits>&
1350 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1353 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1355 const typename __ios_base::fmtflags __flags = __os.
flags();
1356 const _CharT __fill = __os.
fill();
1358 const _CharT __space = __os.
widen(
' ');
1359 __os.
flags(__ios_base::scientific | __ios_base::left);
1361 __os.
precision(std::numeric_limits<double>::max_digits10);
1363 __os << __x.k() << __space << __x.p()
1364 << __space << __x._M_gd;
1366 __os.
flags(__flags);
1372 template<
typename _IntType,
typename _CharT,
typename _Traits>
1373 std::basic_istream<_CharT, _Traits>&
1374 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1379 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1381 const typename __ios_base::fmtflags __flags = __is.
flags();
1382 __is.
flags(__ios_base::skipws);
1386 if (__is >> __k >> __p >> __x._M_gd)
1387 __x.param(param_type(__k, __p));
1389 __is.
flags(__flags);
1394 template<
typename _IntType>
1399#if _GLIBCXX_USE_C99_MATH_FUNCS
1402 const double __m = std::floor(_M_mean);
1404 _M_lfm = std::lgamma(__m + 1);
1407 const double __pi_4 = 0.7853981633974483096156608458198757L;
1411 const double __cx = 2 * __m + _M_d;
1416 _M_cb = 2 * __cx *
std::exp(-_M_d * _M_1cx * (1 + _M_d / 2))
1434 template<
typename _IntType>
1435 template<
typename _UniformRandomNumberGenerator>
1436 typename poisson_distribution<_IntType>::result_type
1438 operator()(_UniformRandomNumberGenerator& __urng,
1441 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1443#if _GLIBCXX_USE_C99_MATH_FUNCS
1444 if (__param.mean() >= 12)
1449 const double __naf =
1451 const double __thr =
1454 const double __m = std::floor(__param.mean());
1456 const double __spi_2 = 1.2533141373155002512078826424055226L;
1457 const double __c1 = __param._M_sm * __spi_2;
1458 const double __c2 = __param._M_c2b + __c1;
1459 const double __c3 = __c2 + 1;
1460 const double __c4 = __c3 + 1;
1462 const double __178 = 0.0128205128205128205128205128205128L;
1464 const double __e178 = 1.0129030479320018583185514777512983L;
1465 const double __c5 = __c4 + __e178;
1466 const double __c = __param._M_cb + __c5;
1467 const double __2cx = 2 * (2 * __m + __param._M_d);
1469 bool __reject =
true;
1472 const double __u = __c * __aurng();
1473 const double __e = -
std::log(1.0 - __aurng());
1479 const double __n = _M_nd(__urng);
1480 const double __y = -
std::abs(__n) * __param._M_sm - 1;
1481 __x = std::floor(__y);
1482 __w = -__n * __n / 2;
1486 else if (__u <= __c2)
1488 const double __n = _M_nd(__urng);
1489 const double __y = 1 +
std::abs(__n) * __param._M_scx;
1490 __x = std::ceil(__y);
1491 __w = __y * (2 - __y) * __param._M_1cx;
1492 if (__x > __param._M_d)
1495 else if (__u <= __c3)
1499 else if (__u <= __c4)
1501 else if (__u <= __c5)
1509 const double __v = -
std::log(1.0 - __aurng());
1510 const double __y = __param._M_d
1511 + __v * __2cx / __param._M_d;
1512 __x = std::ceil(__y);
1513 __w = -__param._M_d * __param._M_1cx * (1 + __y / 2);
1516 __reject = (__w - __e - __x * __param._M_lm_thr
1517 > __param._M_lfm - std::lgamma(__x + __m + 1));
1519 __reject |= __x + __m >= __thr;
1529 double __prod = 1.0;
1533 __prod *= __aurng();
1536 while (__prod > __param._M_lm_thr);
1542 template<
typename _IntType>
1543 template<
typename _ForwardIterator,
1544 typename _UniformRandomNumberGenerator>
1548 _UniformRandomNumberGenerator& __urng,
1549 const param_type& __param)
1551 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1557 template<
typename _IntType,
1558 typename _CharT,
typename _Traits>
1561 const poisson_distribution<_IntType>& __x)
1563 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1565 const typename __ios_base::fmtflags __flags = __os.
flags();
1566 const _CharT __fill = __os.
fill();
1568 const _CharT __space = __os.
widen(
' ');
1569 __os.
flags(__ios_base::scientific | __ios_base::left);
1573 __os << __x.mean() << __space << __x._M_nd;
1575 __os.
flags(__flags);
1581 template<
typename _IntType,
1582 typename _CharT,
typename _Traits>
1583 std::basic_istream<_CharT, _Traits>&
1584 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1585 poisson_distribution<_IntType>& __x)
1587 using param_type =
typename poisson_distribution<_IntType>::param_type;
1588 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1590 const typename __ios_base::fmtflags __flags = __is.
flags();
1591 __is.
flags(__ios_base::skipws);
1594 if (__is >> __mean >> __x._M_nd)
1597 __is.
flags(__flags);
1602 template<
typename _IntType>
1607 const double __p12 = _M_p <= 0.5 ? _M_p : 1.0 - _M_p;
1611#if _GLIBCXX_USE_C99_MATH_FUNCS
1612 if (_M_t * __p12 >= 8)
1615 const double __np = std::floor(_M_t * __p12);
1616 const double __pa = __np / _M_t;
1617 const double __1p = 1 - __pa;
1619 const double __pi_4 = 0.7853981633974483096156608458198757L;
1620 const double __d1x =
1622 / (81 * __pi_4 * __1p)));
1624 const double __d2x =
1626 / (__pi_4 * __pa)));
1630 const double __spi_2 = 1.2533141373155002512078826424055226L;
1631 _M_s1 =
std::sqrt(__np * __1p) * (1 + _M_d1 / (4 * __np));
1632 _M_s2 =
std::sqrt(__np * __1p) * (1 + _M_d2 / (4 * (_M_t * __1p)));
1633 _M_c = 2 * _M_d1 / __np;
1634 _M_a1 =
std::exp(_M_c) * _M_s1 * __spi_2;
1635 const double __a12 = _M_a1 + _M_s2 * __spi_2;
1636 const double __s1s = _M_s1 * _M_s1;
1637 _M_a123 = __a12 + (
std::exp(_M_d1 / (_M_t * __1p))
1639 *
std::exp(-_M_d1 * _M_d1 / (2 * __s1s)));
1640 const double __s2s = _M_s2 * _M_s2;
1641 _M_s = (_M_a123 + 2 * __s2s / _M_d2
1642 *
std::exp(-_M_d2 * _M_d2 / (2 * __s2s)));
1643 _M_lf = (std::lgamma(__np + 1)
1644 + std::lgamma(_M_t - __np + 1));
1647 _M_q = -
std::log(1 - (__p12 - __pa) / __1p);
1654 template<
typename _IntType>
1655 template<
typename _UniformRandomNumberGenerator>
1658 _M_waiting(_UniformRandomNumberGenerator& __urng,
1659 _IntType __t,
double __q)
1663 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1670 const double __e = -
std::log(1.0 - __aurng());
1671 __sum += __e / (__t - __x);
1674 while (__sum <= __q);
1689 template<
typename _IntType>
1690 template<
typename _UniformRandomNumberGenerator>
1693 operator()(_UniformRandomNumberGenerator& __urng,
1697 const _IntType __t = __param.t();
1698 const double __p = __param.p();
1699 const double __p12 = __p <= 0.5 ? __p : 1.0 - __p;
1700 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1703#if _GLIBCXX_USE_C99_MATH_FUNCS
1704 if (!__param._M_easy)
1709 const double __naf =
1711 const double __thr =
1714 const double __np = std::floor(__t * __p12);
1717 const double __spi_2 = 1.2533141373155002512078826424055226L;
1718 const double __a1 = __param._M_a1;
1719 const double __a12 = __a1 + __param._M_s2 * __spi_2;
1720 const double __a123 = __param._M_a123;
1721 const double __s1s = __param._M_s1 * __param._M_s1;
1722 const double __s2s = __param._M_s2 * __param._M_s2;
1727 const double __u = __param._M_s * __aurng();
1733 const double __n = _M_nd(__urng);
1734 const double __y = __param._M_s1 *
std::abs(__n);
1735 __reject = __y >= __param._M_d1;
1738 const double __e = -
std::log(1.0 - __aurng());
1739 __x = std::floor(__y);
1740 __v = -__e - __n * __n / 2 + __param._M_c;
1743 else if (__u <= __a12)
1745 const double __n = _M_nd(__urng);
1746 const double __y = __param._M_s2 *
std::abs(__n);
1747 __reject = __y >= __param._M_d2;
1750 const double __e = -
std::log(1.0 - __aurng());
1751 __x = std::floor(-__y);
1752 __v = -__e - __n * __n / 2;
1755 else if (__u <= __a123)
1757 const double __e1 = -
std::log(1.0 - __aurng());
1758 const double __e2 = -
std::log(1.0 - __aurng());
1760 const double __y = __param._M_d1
1761 + 2 * __s1s * __e1 / __param._M_d1;
1762 __x = std::floor(__y);
1763 __v = (-__e2 + __param._M_d1 * (1 / (__t - __np)
1764 -__y / (2 * __s1s)));
1769 const double __e1 = -
std::log(1.0 - __aurng());
1770 const double __e2 = -
std::log(1.0 - __aurng());
1772 const double __y = __param._M_d2
1773 + 2 * __s2s * __e1 / __param._M_d2;
1774 __x = std::floor(-__y);
1775 __v = -__e2 - __param._M_d2 * __y / (2 * __s2s);
1779 __reject = __reject || __x < -__np || __x > __t - __np;
1782 const double __lfx =
1783 std::lgamma(__np + __x + 1)
1784 + std::lgamma(__t - (__np + __x) + 1);
1785 __reject = __v > __param._M_lf - __lfx
1786 + __x * __param._M_lp1p;
1789 __reject |= __x + __np >= __thr;
1793 __x += __np + __naf;
1795 const _IntType __z = _M_waiting(__urng, __t - _IntType(__x),
1797 __ret = _IntType(__x) + __z;
1801 __ret = _M_waiting(__urng, __t, __param._M_q);
1804 __ret = __t - __ret;
1808 template<
typename _IntType>
1809 template<
typename _ForwardIterator,
1810 typename _UniformRandomNumberGenerator>
1814 _UniformRandomNumberGenerator& __urng,
1815 const param_type& __param)
1817 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1823 template<
typename _IntType,
1824 typename _CharT,
typename _Traits>
1827 const binomial_distribution<_IntType>& __x)
1829 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1831 const typename __ios_base::fmtflags __flags = __os.
flags();
1832 const _CharT __fill = __os.
fill();
1834 const _CharT __space = __os.
widen(
' ');
1835 __os.
flags(__ios_base::scientific | __ios_base::left);
1839 __os << __x.t() << __space << __x.p()
1840 << __space << __x._M_nd;
1842 __os.
flags(__flags);
1848 template<
typename _IntType,
1849 typename _CharT,
typename _Traits>
1850 std::basic_istream<_CharT, _Traits>&
1851 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1852 binomial_distribution<_IntType>& __x)
1854 using param_type =
typename binomial_distribution<_IntType>::param_type;
1855 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1857 const typename __ios_base::fmtflags __flags = __is.
flags();
1858 __is.
flags(__ios_base::dec | __ios_base::skipws);
1862 if (__is >> __t >> __p >> __x._M_nd)
1865 __is.
flags(__flags);
1870 template<
typename _RealType>
1871 template<
typename _ForwardIterator,
1872 typename _UniformRandomNumberGenerator>
1876 _UniformRandomNumberGenerator& __urng,
1877 const param_type& __p)
1879 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1880 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1886 template<
typename _RealType,
typename _CharT,
typename _Traits>
1889 const exponential_distribution<_RealType>& __x)
1891 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1893 const typename __ios_base::fmtflags __flags = __os.
flags();
1894 const _CharT __fill = __os.
fill();
1896 __os.
flags(__ios_base::scientific | __ios_base::left);
1900 __os << __x.lambda();
1902 __os.
flags(__flags);
1908 template<
typename _RealType,
typename _CharT,
typename _Traits>
1909 std::basic_istream<_CharT, _Traits>&
1915 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1917 const typename __ios_base::fmtflags __flags = __is.
flags();
1918 __is.
flags(__ios_base::dec | __ios_base::skipws);
1921 if (__is >> __lambda)
1922 __x.
param(param_type(__lambda));
1924 __is.
flags(__flags);
1935 template<
typename _RealType>
1936 template<
typename _UniformRandomNumberGenerator>
1939 operator()(_UniformRandomNumberGenerator& __urng,
1943 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1946 if (_M_saved_available)
1948 _M_saved_available =
false;
1958 __r2 = __x * __x + __y * __y;
1960 while (__r2 > 1.0 || __r2 == 0.0);
1963 _M_saved = __x * __mult;
1964 _M_saved_available =
true;
1965 __ret = __y * __mult;
1968 __ret = __ret * __param.stddev() + __param.mean();
1972 template<
typename _RealType>
1973 template<
typename _ForwardIterator,
1974 typename _UniformRandomNumberGenerator>
1978 _UniformRandomNumberGenerator& __urng,
1979 const param_type& __param)
1981 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1986 if (_M_saved_available)
1988 _M_saved_available =
false;
1989 *__f++ = _M_saved * __param.stddev() + __param.mean();
1995 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1998 while (__f + 1 < __t)
2000 result_type __x, __y, __r2;
2005 __r2 = __x * __x + __y * __y;
2007 while (__r2 > 1.0 || __r2 == 0.0);
2010 *__f++ = __y * __mult * __param.stddev() + __param.mean();
2011 *__f++ = __x * __mult * __param.stddev() + __param.mean();
2021 __r2 = __x * __x + __y * __y;
2023 while (__r2 > 1.0 || __r2 == 0.0);
2026 _M_saved = __x * __mult;
2027 _M_saved_available =
true;
2028 *__f = __y * __mult * __param.stddev() + __param.mean();
2032 template<
typename _RealType>
2034 operator==(
const std::normal_distribution<_RealType>& __d1,
2035 const std::normal_distribution<_RealType>& __d2)
2037 if (__d1._M_param == __d2._M_param
2038 && __d1._M_saved_available == __d2._M_saved_available)
2039 return __d1._M_saved_available ? __d1._M_saved == __d2._M_saved :
true;
2044 template<
typename _RealType,
typename _CharT,
typename _Traits>
2045 std::basic_ostream<_CharT, _Traits>&
2046 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2047 const normal_distribution<_RealType>& __x)
2049 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2051 const typename __ios_base::fmtflags __flags = __os.
flags();
2052 const _CharT __fill = __os.
fill();
2054 const _CharT __space = __os.
widen(
' ');
2055 __os.
flags(__ios_base::scientific | __ios_base::left);
2059 __os << __x.mean() << __space << __x.stddev()
2060 << __space << __x._M_saved_available;
2061 if (__x._M_saved_available)
2062 __os << __space << __x._M_saved;
2064 __os.
flags(__flags);
2070 template<
typename _RealType,
typename _CharT,
typename _Traits>
2071 std::basic_istream<_CharT, _Traits>&
2072 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2073 normal_distribution<_RealType>& __x)
2075 using param_type =
typename normal_distribution<_RealType>::param_type;
2076 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2078 const typename __ios_base::fmtflags __flags = __is.
flags();
2079 __is.
flags(__ios_base::dec | __ios_base::skipws);
2081 double __mean, __stddev;
2083 if (__is >> __mean >> __stddev >> __saved_avail)
2085 if (!__saved_avail || (__is >> __x._M_saved))
2087 __x._M_saved_available = __saved_avail;
2092 __is.
flags(__flags);
2097 template<
typename _RealType>
2098 template<
typename _ForwardIterator,
2099 typename _UniformRandomNumberGenerator>
2101 lognormal_distribution<_RealType>::
2102 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2103 _UniformRandomNumberGenerator& __urng,
2106 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2108 *__f++ =
std::exp(__p.s() * _M_nd(__urng) + __p.m());
2111 template<
typename _RealType,
typename _CharT,
typename _Traits>
2112 std::basic_ostream<_CharT, _Traits>&
2113 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2114 const lognormal_distribution<_RealType>& __x)
2116 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2118 const typename __ios_base::fmtflags __flags = __os.
flags();
2119 const _CharT __fill = __os.
fill();
2121 const _CharT __space = __os.
widen(
' ');
2122 __os.
flags(__ios_base::scientific | __ios_base::left);
2126 __os << __x.m() << __space << __x.s()
2127 << __space << __x._M_nd;
2129 __os.
flags(__flags);
2135 template<
typename _RealType,
typename _CharT,
typename _Traits>
2136 std::basic_istream<_CharT, _Traits>&
2137 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2138 lognormal_distribution<_RealType>& __x)
2141 =
typename lognormal_distribution<_RealType>::param_type;
2142 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2144 const typename __ios_base::fmtflags __flags = __is.
flags();
2145 __is.
flags(__ios_base::dec | __ios_base::skipws);
2148 if (__is >> __m >> __s >> __x._M_nd)
2151 __is.
flags(__flags);
2155 template<
typename _RealType>
2156 template<
typename _ForwardIterator,
2157 typename _UniformRandomNumberGenerator>
2159 std::chi_squared_distribution<_RealType>::
2160 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2161 _UniformRandomNumberGenerator& __urng)
2163 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2165 *__f++ = 2 * _M_gd(__urng);
2168 template<
typename _RealType>
2169 template<
typename _ForwardIterator,
2170 typename _UniformRandomNumberGenerator>
2172 std::chi_squared_distribution<_RealType>::
2173 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2174 _UniformRandomNumberGenerator& __urng,
2176 std::gamma_distribution<result_type>::param_type& __p)
2178 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2180 *__f++ = 2 * _M_gd(__urng, __p);
2183 template<
typename _RealType,
typename _CharT,
typename _Traits>
2184 std::basic_ostream<_CharT, _Traits>&
2185 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2186 const chi_squared_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(
' ');
2194 __os.
flags(__ios_base::scientific | __ios_base::left);
2198 __os << __x.n() << __space << __x._M_gd;
2200 __os.
flags(__flags);
2206 template<
typename _RealType,
typename _CharT,
typename _Traits>
2207 std::basic_istream<_CharT, _Traits>&
2208 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2209 chi_squared_distribution<_RealType>& __x)
2212 =
typename chi_squared_distribution<_RealType>::param_type;
2213 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2215 const typename __ios_base::fmtflags __flags = __is.
flags();
2216 __is.
flags(__ios_base::dec | __ios_base::skipws);
2219 if (__is >> __n >> __x._M_gd)
2222 __is.
flags(__flags);
2227 template<
typename _RealType>
2228 template<
typename _UniformRandomNumberGenerator>
2231 operator()(_UniformRandomNumberGenerator& __urng,
2234 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2241 const _RealType __pi = 3.1415926535897932384626433832795029L;
2242 return __p.a() + __p.b() *
std::tan(__pi * __u);
2245 template<
typename _RealType>
2246 template<
typename _ForwardIterator,
2247 typename _UniformRandomNumberGenerator>
2251 _UniformRandomNumberGenerator& __urng,
2252 const param_type& __p)
2254 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2255 const _RealType __pi = 3.1415926535897932384626433832795029L;
2256 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2265 *__f++ = __p.a() + __p.b() *
std::tan(__pi * __u);
2269 template<
typename _RealType,
typename _CharT,
typename _Traits>
2272 const cauchy_distribution<_RealType>& __x)
2274 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2276 const typename __ios_base::fmtflags __flags = __os.
flags();
2277 const _CharT __fill = __os.
fill();
2279 const _CharT __space = __os.
widen(
' ');
2280 __os.
flags(__ios_base::scientific | __ios_base::left);
2284 __os << __x.a() << __space << __x.b();
2286 __os.
flags(__flags);
2292 template<
typename _RealType,
typename _CharT,
typename _Traits>
2293 std::basic_istream<_CharT, _Traits>&
2298 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2300 const typename __ios_base::fmtflags __flags = __is.
flags();
2301 __is.
flags(__ios_base::dec | __ios_base::skipws);
2304 if (__is >> __a >> __b)
2305 __x.
param(param_type(__a, __b));
2307 __is.
flags(__flags);
2312 template<
typename _RealType>
2313 template<
typename _ForwardIterator,
2314 typename _UniformRandomNumberGenerator>
2318 _UniformRandomNumberGenerator& __urng)
2320 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2322 *__f++ = ((_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()));
2325 template<
typename _RealType>
2326 template<
typename _ForwardIterator,
2327 typename _UniformRandomNumberGenerator>
2329 std::fisher_f_distribution<_RealType>::
2330 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2331 _UniformRandomNumberGenerator& __urng,
2334 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2335 typedef typename std::gamma_distribution<result_type>::param_type
2340 *__f++ = ((_M_gd_x(__urng, __p1) * n())
2341 / (_M_gd_y(__urng, __p2) * m()));
2344 template<
typename _RealType,
typename _CharT,
typename _Traits>
2345 std::basic_ostream<_CharT, _Traits>&
2346 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2347 const fisher_f_distribution<_RealType>& __x)
2349 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2351 const typename __ios_base::fmtflags __flags = __os.
flags();
2352 const _CharT __fill = __os.
fill();
2354 const _CharT __space = __os.
widen(
' ');
2355 __os.
flags(__ios_base::scientific | __ios_base::left);
2359 __os << __x.m() << __space << __x.n()
2360 << __space << __x._M_gd_x << __space << __x._M_gd_y;
2362 __os.
flags(__flags);
2368 template<
typename _RealType,
typename _CharT,
typename _Traits>
2369 std::basic_istream<_CharT, _Traits>&
2370 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2371 fisher_f_distribution<_RealType>& __x)
2374 =
typename fisher_f_distribution<_RealType>::param_type;
2375 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2377 const typename __ios_base::fmtflags __flags = __is.
flags();
2378 __is.
flags(__ios_base::dec | __ios_base::skipws);
2381 if (__is >> __m >> __n >> __x._M_gd_x >> __x._M_gd_y)
2384 __is.
flags(__flags);
2389 template<
typename _RealType>
2390 template<
typename _ForwardIterator,
2391 typename _UniformRandomNumberGenerator>
2393 std::student_t_distribution<_RealType>::
2394 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2395 _UniformRandomNumberGenerator& __urng)
2397 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2399 *__f++ = _M_nd(__urng) *
std::sqrt(n() / _M_gd(__urng));
2402 template<
typename _RealType>
2403 template<
typename _ForwardIterator,
2404 typename _UniformRandomNumberGenerator>
2406 std::student_t_distribution<_RealType>::
2407 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2408 _UniformRandomNumberGenerator& __urng,
2411 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2412 typename std::gamma_distribution<result_type>::param_type
2413 __p2(__p.n() / 2, 2);
2415 *__f++ = _M_nd(__urng) *
std::sqrt(__p.n() / _M_gd(__urng, __p2));
2418 template<
typename _RealType,
typename _CharT,
typename _Traits>
2419 std::basic_ostream<_CharT, _Traits>&
2420 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2421 const student_t_distribution<_RealType>& __x)
2423 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2425 const typename __ios_base::fmtflags __flags = __os.
flags();
2426 const _CharT __fill = __os.
fill();
2428 const _CharT __space = __os.
widen(
' ');
2429 __os.
flags(__ios_base::scientific | __ios_base::left);
2433 __os << __x.n() << __space << __x._M_nd << __space << __x._M_gd;
2435 __os.
flags(__flags);
2441 template<
typename _RealType,
typename _CharT,
typename _Traits>
2442 std::basic_istream<_CharT, _Traits>&
2443 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2444 student_t_distribution<_RealType>& __x)
2447 =
typename student_t_distribution<_RealType>::param_type;
2448 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2450 const typename __ios_base::fmtflags __flags = __is.
flags();
2451 __is.
flags(__ios_base::dec | __ios_base::skipws);
2454 if (__is >> __n >> __x._M_nd >> __x._M_gd)
2457 __is.
flags(__flags);
2462 template<
typename _RealType>
2464 gamma_distribution<_RealType>::param_type::
2467 _M_malpha = _M_alpha < 1.0 ? _M_alpha + _RealType(1.0) : _M_alpha;
2469 const _RealType __a1 = _M_malpha - _RealType(1.0) / _RealType(3.0);
2470 _M_a2 = _RealType(1.0) /
std::sqrt(_RealType(9.0) * __a1);
2478 template<
typename _RealType>
2479 template<
typename _UniformRandomNumberGenerator>
2482 operator()(_UniformRandomNumberGenerator& __urng,
2485 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2490 - _RealType(1.0) / _RealType(3.0));
2496 __n = _M_nd(__urng);
2501 __v = __v * __v * __v;
2504 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2505 && (
std::log(__u) > (0.5 * __n * __n + __a1
2508 if (__param.alpha() == __param._M_malpha)
2509 return __a1 * __v * __param.beta();
2517 * __a1 * __v * __param.beta());
2521 template<
typename _RealType>
2522 template<
typename _ForwardIterator,
2523 typename _UniformRandomNumberGenerator>
2525 gamma_distribution<_RealType>::
2526 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2527 _UniformRandomNumberGenerator& __urng,
2528 const param_type& __param)
2530 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2531 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2534 result_type __u, __v, __n;
2535 const result_type __a1 = (__param._M_malpha
2536 - _RealType(1.0) / _RealType(3.0));
2538 if (__param.alpha() == __param._M_malpha)
2545 __n = _M_nd(__urng);
2550 __v = __v * __v * __v;
2553 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2554 && (
std::log(__u) > (0.5 * __n * __n + __a1
2557 *__f++ = __a1 * __v * __param.beta();
2566 __n = _M_nd(__urng);
2571 __v = __v * __v * __v;
2574 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2575 && (
std::log(__u) > (0.5 * __n * __n + __a1
2583 * __a1 * __v * __param.beta());
2587 template<
typename _RealType,
typename _CharT,
typename _Traits>
2588 std::basic_ostream<_CharT, _Traits>&
2589 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2590 const gamma_distribution<_RealType>& __x)
2592 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2594 const typename __ios_base::fmtflags __flags = __os.
flags();
2595 const _CharT __fill = __os.
fill();
2597 const _CharT __space = __os.
widen(
' ');
2598 __os.
flags(__ios_base::scientific | __ios_base::left);
2602 __os << __x.alpha() << __space << __x.beta()
2603 << __space << __x._M_nd;
2605 __os.
flags(__flags);
2611 template<
typename _RealType,
typename _CharT,
typename _Traits>
2612 std::basic_istream<_CharT, _Traits>&
2613 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2614 gamma_distribution<_RealType>& __x)
2616 using param_type =
typename gamma_distribution<_RealType>::param_type;
2617 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2619 const typename __ios_base::fmtflags __flags = __is.
flags();
2620 __is.
flags(__ios_base::dec | __ios_base::skipws);
2622 _RealType __alpha_val, __beta_val;
2623 if (__is >> __alpha_val >> __beta_val >> __x._M_nd)
2624 __x.param(
param_type(__alpha_val, __beta_val));
2626 __is.
flags(__flags);
2631 template<
typename _RealType>
2632 template<
typename _UniformRandomNumberGenerator>
2635 operator()(_UniformRandomNumberGenerator& __urng,
2638 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2644 template<
typename _RealType>
2645 template<
typename _ForwardIterator,
2646 typename _UniformRandomNumberGenerator>
2650 _UniformRandomNumberGenerator& __urng,
2651 const param_type& __p)
2653 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2654 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2663 template<
typename _RealType,
typename _CharT,
typename _Traits>
2666 const weibull_distribution<_RealType>& __x)
2668 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2670 const typename __ios_base::fmtflags __flags = __os.
flags();
2671 const _CharT __fill = __os.
fill();
2673 const _CharT __space = __os.
widen(
' ');
2674 __os.
flags(__ios_base::scientific | __ios_base::left);
2678 __os << __x.a() << __space << __x.b();
2680 __os.
flags(__flags);
2686 template<
typename _RealType,
typename _CharT,
typename _Traits>
2687 std::basic_istream<_CharT, _Traits>&
2692 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2694 const typename __ios_base::fmtflags __flags = __is.
flags();
2695 __is.
flags(__ios_base::dec | __ios_base::skipws);
2698 if (__is >> __a >> __b)
2699 __x.
param(param_type(__a, __b));
2701 __is.
flags(__flags);
2706 template<
typename _RealType>
2707 template<
typename _UniformRandomNumberGenerator>
2710 operator()(_UniformRandomNumberGenerator& __urng,
2711 const param_type& __p)
2713 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2719 template<
typename _RealType>
2720 template<
typename _ForwardIterator,
2721 typename _UniformRandomNumberGenerator>
2725 _UniformRandomNumberGenerator& __urng,
2726 const param_type& __p)
2728 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2729 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2737 template<
typename _RealType,
typename _CharT,
typename _Traits>
2740 const extreme_value_distribution<_RealType>& __x)
2742 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2744 const typename __ios_base::fmtflags __flags = __os.
flags();
2745 const _CharT __fill = __os.
fill();
2747 const _CharT __space = __os.
widen(
' ');
2748 __os.
flags(__ios_base::scientific | __ios_base::left);
2752 __os << __x.a() << __space << __x.b();
2754 __os.
flags(__flags);
2760 template<
typename _RealType,
typename _CharT,
typename _Traits>
2761 std::basic_istream<_CharT, _Traits>&
2767 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2769 const typename __ios_base::fmtflags __flags = __is.
flags();
2770 __is.
flags(__ios_base::dec | __ios_base::skipws);
2773 if (__is >> __a >> __b)
2774 __x.
param(param_type(__a, __b));
2776 __is.
flags(__flags);
2781 template<
typename _IntType>
2783 discrete_distribution<_IntType>::param_type::
2786 if (_M_prob.size() < 2)
2793 _M_prob.end(), 0.0);
2794 __glibcxx_assert(__sum > 0);
2796 __detail::__normalize(_M_prob.begin(), _M_prob.end(), _M_prob.begin(),
2799 _M_cp.reserve(_M_prob.size());
2803 _M_cp[_M_cp.size() - 1] = 1.0;
2806 template<
typename _IntType>
2807 template<
typename _Func>
2808 discrete_distribution<_IntType>::param_type::
2809 param_type(
size_t __nw,
double __xmin,
double __xmax, _Func __fw)
2810 : _M_prob(), _M_cp()
2812 const size_t __n = __nw == 0 ? 1 : __nw;
2813 const double __delta = (__xmax - __xmin) / __n;
2815 _M_prob.reserve(__n);
2816 for (
size_t __k = 0; __k < __nw; ++__k)
2817 _M_prob.push_back(__fw(__xmin + __k * __delta + 0.5 * __delta));
2822 template<
typename _IntType>
2823 template<
typename _UniformRandomNumberGenerator>
2824 typename discrete_distribution<_IntType>::result_type
2825 discrete_distribution<_IntType>::
2826 operator()(_UniformRandomNumberGenerator& __urng,
2827 const param_type& __param)
2829 if (__param._M_cp.empty())
2830 return result_type(0);
2832 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2835 const double __p = __aurng();
2836 auto __pos = std::lower_bound(__param._M_cp.begin(),
2837 __param._M_cp.end(), __p);
2839 return __pos - __param._M_cp.begin();
2842 template<
typename _IntType>
2843 template<
typename _ForwardIterator,
2844 typename _UniformRandomNumberGenerator>
2846 discrete_distribution<_IntType>::
2847 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2848 _UniformRandomNumberGenerator& __urng,
2849 const param_type& __param)
2851 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2853 if (__param._M_cp.empty())
2856 *__f++ = result_type(0);
2860 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2865 const double __p = __aurng();
2866 auto __pos = std::lower_bound(__param._M_cp.begin(),
2867 __param._M_cp.end(), __p);
2869 *__f++ = __pos - __param._M_cp.begin();
2873 template<
typename _IntType,
typename _CharT,
typename _Traits>
2876 const discrete_distribution<_IntType>& __x)
2878 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2880 const typename __ios_base::fmtflags __flags = __os.
flags();
2881 const _CharT __fill = __os.
fill();
2883 const _CharT __space = __os.
widen(
' ');
2884 __os.
flags(__ios_base::scientific | __ios_base::left);
2889 __os << __prob.
size();
2890 for (
auto __dit = __prob.
begin(); __dit != __prob.
end(); ++__dit)
2891 __os << __space << *__dit;
2893 __os.
flags(__flags);
2901 template<
typename _ValT,
typename _CharT,
typename _Traits>
2902 basic_istream<_CharT, _Traits>&
2903 __extract_params(basic_istream<_CharT, _Traits>& __is,
2904 vector<_ValT>& __vals,
size_t __n)
2906 __vals.reserve(__n);
2911 __vals.push_back(__val);
2919 template<
typename _IntType,
typename _CharT,
typename _Traits>
2922 discrete_distribution<_IntType>& __x)
2924 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2926 const typename __ios_base::fmtflags __flags = __is.
flags();
2927 __is.
flags(__ios_base::dec | __ios_base::skipws);
2933 if (__detail::__extract_params(__is, __prob_vec, __n))
2934 __x.param({__prob_vec.
begin(), __prob_vec.
end()});
2937 __is.
flags(__flags);
2942 template<
typename _RealType>
2944 piecewise_constant_distribution<_RealType>::param_type::
2947 if (_M_int.size() < 2
2948 || (_M_int.size() == 2
2949 && _M_int[0] == _RealType(0)
2950 && _M_int[1] == _RealType(1)))
2959 __glibcxx_assert(__sum > 0);
2961 __detail::__normalize(_M_den.begin(), _M_den.end(), _M_den.begin(),
2964 _M_cp.reserve(_M_den.size());
2969 _M_cp[_M_cp.size() - 1] = 1.0;
2971 for (
size_t __k = 0; __k < _M_den.size(); ++__k)
2972 _M_den[__k] /= _M_int[__k + 1] - _M_int[__k];
2975 template<
typename _RealType>
2976 template<
typename _InputIteratorB,
typename _InputIteratorW>
2977 piecewise_constant_distribution<_RealType>::param_type::
2978 param_type(_InputIteratorB __bbegin,
2979 _InputIteratorB __bend,
2980 _InputIteratorW __wbegin)
2981 : _M_int(), _M_den(), _M_cp()
2983 if (__bbegin != __bend)
2987 _M_int.push_back(*__bbegin);
2989 if (__bbegin == __bend)
2992 _M_den.push_back(*__wbegin);
3000 template<
typename _RealType>
3001 template<
typename _Func>
3004 : _M_int(), _M_den(), _M_cp()
3006 _M_int.reserve(__bl.size());
3007 for (
auto __biter = __bl.begin(); __biter != __bl.end(); ++__biter)
3008 _M_int.push_back(*__biter);
3010 _M_den.reserve(_M_int.size() - 1);
3011 for (
size_t __k = 0; __k < _M_int.size() - 1; ++__k)
3012 _M_den.push_back(__fw(0.5 * (_M_int[__k + 1] + _M_int[__k])));
3017 template<
typename _RealType>
3018 template<
typename _Func>
3019 piecewise_constant_distribution<_RealType>::param_type::
3020 param_type(
size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
3021 : _M_int(), _M_den(), _M_cp()
3023 const size_t __n = __nw == 0 ? 1 : __nw;
3024 const _RealType __delta = (__xmax - __xmin) / __n;
3026 _M_int.reserve(__n + 1);
3027 for (
size_t __k = 0; __k <= __nw; ++__k)
3028 _M_int.push_back(__xmin + __k * __delta);
3030 _M_den.reserve(__n);
3031 for (
size_t __k = 0; __k < __nw; ++__k)
3032 _M_den.push_back(__fw(_M_int[__k] + 0.5 * __delta));
3037 template<
typename _RealType>
3038 template<
typename _UniformRandomNumberGenerator>
3041 operator()(_UniformRandomNumberGenerator& __urng,
3042 const param_type& __param)
3044 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
3047 const double __p = __aurng();
3048 if (__param._M_cp.empty())
3051 auto __pos = std::lower_bound(__param._M_cp.begin(),
3052 __param._M_cp.end(), __p);
3053 const size_t __i = __pos - __param._M_cp.begin();
3055 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
3057 return __param._M_int[__i] + (__p - __pref) / __param._M_den[__i];
3060 template<
typename _RealType>
3061 template<
typename _ForwardIterator,
3062 typename _UniformRandomNumberGenerator>
3066 _UniformRandomNumberGenerator& __urng,
3067 const param_type& __param)
3069 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3070 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
3073 if (__param._M_cp.empty())
3082 const double __p = __aurng();
3084 auto __pos = std::lower_bound(__param._M_cp.begin(),
3085 __param._M_cp.end(), __p);
3086 const size_t __i = __pos - __param._M_cp.begin();
3088 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
3090 *__f++ = (__param._M_int[__i]
3091 + (__p - __pref) / __param._M_den[__i]);
3095 template<
typename _RealType,
typename _CharT,
typename _Traits>
3096 std::basic_ostream<_CharT, _Traits>&
3097 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3100 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
3102 const typename __ios_base::fmtflags __flags = __os.
flags();
3103 const _CharT __fill = __os.
fill();
3105 const _CharT __space = __os.
widen(
' ');
3106 __os.
flags(__ios_base::scientific | __ios_base::left);
3110 std::vector<_RealType> __int = __x.intervals();
3111 __os << __int.
size() - 1;
3113 for (
auto __xit = __int.
begin(); __xit != __int.
end(); ++__xit)
3114 __os << __space << *__xit;
3116 std::vector<double> __den = __x.densities();
3117 for (
auto __dit = __den.
begin(); __dit != __den.
end(); ++__dit)
3118 __os << __space << *__dit;
3120 __os.
flags(__flags);
3126 template<
typename _RealType,
typename _CharT,
typename _Traits>
3127 std::basic_istream<_CharT, _Traits>&
3128 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3131 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
3133 const typename __ios_base::fmtflags __flags = __is.
flags();
3134 __is.
flags(__ios_base::dec | __ios_base::skipws);
3139 std::vector<_RealType> __int_vec;
3140 if (__detail::__extract_params(__is, __int_vec, __n + 1))
3142 std::vector<double> __den_vec;
3143 if (__detail::__extract_params(__is, __den_vec, __n))
3145 __x.param({ __int_vec.
begin(), __int_vec.
end(),
3146 __den_vec.
begin() });
3151 __is.
flags(__flags);
3156 template<
typename _RealType>
3161 if (_M_int.size() < 2
3162 || (_M_int.size() == 2
3163 && _M_int[0] == _RealType(0)
3164 && _M_int[1] == _RealType(1)
3165 && _M_den[0] == _M_den[1]))
3173 _M_cp.reserve(_M_int.size() - 1);
3174 _M_m.reserve(_M_int.size() - 1);
3175 for (
size_t __k = 0; __k < _M_int.size() - 1; ++__k)
3177 const _RealType __delta = _M_int[__k + 1] - _M_int[__k];
3178 __sum += 0.5 * (_M_den[__k + 1] + _M_den[__k]) * __delta;
3179 _M_cp.push_back(__sum);
3180 _M_m.push_back((_M_den[__k + 1] - _M_den[__k]) / __delta);
3182 __glibcxx_assert(__sum > 0);
3185 __detail::__normalize(_M_den.begin(), _M_den.end(), _M_den.begin(),
3188 __detail::__normalize(_M_cp.begin(), _M_cp.end(), _M_cp.begin(), __sum);
3190 __detail::__normalize(_M_m.begin(), _M_m.end(), _M_m.begin(), __sum);
3193 _M_cp[_M_cp.size() - 1] = 1.0;
3196 template<
typename _RealType>
3197 template<
typename _InputIteratorB,
typename _InputIteratorW>
3198 piecewise_linear_distribution<_RealType>::param_type::
3199 param_type(_InputIteratorB __bbegin,
3200 _InputIteratorB __bend,
3201 _InputIteratorW __wbegin)
3202 : _M_int(), _M_den(), _M_cp(), _M_m()
3204 for (; __bbegin != __bend; ++__bbegin, (void) ++__wbegin)
3206 _M_int.push_back(*__bbegin);
3207 _M_den.push_back(*__wbegin);
3213 template<
typename _RealType>
3214 template<
typename _Func>
3217 : _M_int(), _M_den(), _M_cp(), _M_m()
3219 _M_int.reserve(__bl.size());
3220 _M_den.reserve(__bl.size());
3221 for (
auto __biter = __bl.begin(); __biter != __bl.end(); ++__biter)
3223 _M_int.push_back(*__biter);
3224 _M_den.push_back(__fw(*__biter));
3230 template<
typename _RealType>
3231 template<
typename _Func>
3233 param_type(
size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
3234 : _M_int(), _M_den(), _M_cp(), _M_m()
3236 const size_t __n = __nw == 0 ? 1 : __nw;
3237 const _RealType __delta = (__xmax - __xmin) / __n;
3239 _M_int.reserve(__n + 1);
3240 _M_den.reserve(__n + 1);
3241 for (
size_t __k = 0; __k <= __nw; ++__k)
3243 _M_int.push_back(__xmin + __k * __delta);
3244 _M_den.push_back(__fw(_M_int[__k] + __delta));
3250 template<
typename _RealType>
3251 template<
typename _UniformRandomNumberGenerator>
3254 operator()(_UniformRandomNumberGenerator& __urng,
3255 const param_type& __param)
3257 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
3260 const double __p = __aurng();
3261 if (__param._M_cp.empty())
3264 auto __pos = std::lower_bound(__param._M_cp.begin(),
3265 __param._M_cp.end(), __p);
3266 const size_t __i = __pos - __param._M_cp.begin();
3268 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
3270 const double __a = 0.5 * __param._M_m[__i];
3271 const double __b = __param._M_den[__i];
3272 const double __cm = __p - __pref;
3274 _RealType __x = __param._M_int[__i];
3279 const double __d = __b * __b + 4.0 * __a * __cm;
3280 __x += 0.5 * (
std::sqrt(__d) - __b) / __a;
3286 template<
typename _RealType>
3287 template<
typename _ForwardIterator,
3288 typename _UniformRandomNumberGenerator>
3292 _UniformRandomNumberGenerator& __urng,
3293 const param_type& __param)
3295 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3298 *__f++ = this->operator()(__urng, __param);
3301 template<
typename _RealType,
typename _CharT,
typename _Traits>
3302 std::basic_ostream<_CharT, _Traits>&
3303 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3306 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
3308 const typename __ios_base::fmtflags __flags = __os.
flags();
3309 const _CharT __fill = __os.
fill();
3311 const _CharT __space = __os.
widen(
' ');
3312 __os.
flags(__ios_base::scientific | __ios_base::left);
3316 std::vector<_RealType> __int = __x.intervals();
3317 __os << __int.
size() - 1;
3319 for (
auto __xit = __int.
begin(); __xit != __int.
end(); ++__xit)
3320 __os << __space << *__xit;
3322 std::vector<double> __den = __x.densities();
3323 for (
auto __dit = __den.
begin(); __dit != __den.
end(); ++__dit)
3324 __os << __space << *__dit;
3326 __os.
flags(__flags);
3332 template<
typename _RealType,
typename _CharT,
typename _Traits>
3333 std::basic_istream<_CharT, _Traits>&
3334 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3337 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
3339 const typename __ios_base::fmtflags __flags = __is.
flags();
3340 __is.
flags(__ios_base::dec | __ios_base::skipws);
3346 if (__detail::__extract_params(__is, __int_vec, __n + 1))
3349 if (__detail::__extract_params(__is, __den_vec, __n + 1))
3351 __x.param({ __int_vec.begin(), __int_vec.end(),
3352 __den_vec.begin() });
3356 __is.
flags(__flags);
3361 template<
typename _IntType,
typename>
3364 _M_v.reserve(__il.size());
3365 for (
auto __iter = __il.begin(); __iter != __il.end(); ++__iter)
3367 __detail::_Shift<result_type, 32>::__value>(*__iter));
3370 template<
typename _InputIterator>
3373#pragma GCC diagnostic push
3374#pragma GCC diagnostic ignored "-Wc++17-extensions"
3375 if constexpr (__is_random_access_iter<_InputIterator>::value)
3377#pragma GCC diagnostic pop
3379 for (_InputIterator __iter = __begin; __iter != __end; ++__iter)
3381 __detail::_Shift<result_type, 32>::__value>(*__iter));
3384 template<
typename _RandomAccessIterator>
3386 seed_seq::generate(_RandomAccessIterator __begin,
3387 _RandomAccessIterator __end)
3389 typedef typename iterator_traits<_RandomAccessIterator>::value_type
3392 if (__begin == __end)
3395 std::fill(__begin, __end, _Type(0x8b8b8b8bu));
3397 const size_t __n = __end - __begin;
3398 const size_t __s = _M_v.size();
3399 const size_t __t = (__n >= 623) ? 11
3404 const size_t __p = (__n - __t) / 2;
3405 const size_t __q = __p + __t;
3406 const size_t __m =
std::max(
size_t(__s + 1), __n);
3408#ifndef __UINT32_TYPE__
3411 _Up(uint_least32_t v) : _M_v(v & 0xffffffffu) { }
3413 operator uint_least32_t()
const {
return _M_v; }
3415 uint_least32_t _M_v;
3417 using uint32_t = _Up;
3422 uint32_t __r1 = 1371501266u;
3423 uint32_t __r2 = __r1 + __s;
3424 __begin[__p] += __r1;
3425 __begin[__q] = (uint32_t)__begin[__q] + __r2;
3429 for (
size_t __k = 1; __k <= __s; ++__k)
3431 const size_t __kn = __k % __n;
3432 const size_t __kpn = (__k + __p) % __n;
3433 const size_t __kqn = (__k + __q) % __n;
3434 uint32_t __arg = (__begin[__kn]
3436 ^ __begin[(__k - 1) % __n]);
3437 uint32_t __r1 = 1664525u * (__arg ^ (__arg >> 27));
3438 uint32_t __r2 = __r1 + (uint32_t)__kn + _M_v[__k - 1];
3439 __begin[__kpn] = (uint32_t)__begin[__kpn] + __r1;
3440 __begin[__kqn] = (uint32_t)__begin[__kqn] + __r2;
3441 __begin[__kn] = __r2;
3444 for (
size_t __k = __s + 1; __k < __m; ++__k)
3446 const size_t __kn = __k % __n;
3447 const size_t __kpn = (__k + __p) % __n;
3448 const size_t __kqn = (__k + __q) % __n;
3449 uint32_t __arg = (__begin[__kn]
3451 ^ __begin[(__k - 1) % __n]);
3452 uint32_t __r1 = 1664525u * (__arg ^ (__arg >> 27));
3453 uint32_t __r2 = __r1 + (uint32_t)__kn;
3454 __begin[__kpn] = (uint32_t)__begin[__kpn] + __r1;
3455 __begin[__kqn] = (uint32_t)__begin[__kqn] + __r2;
3456 __begin[__kn] = __r2;
3459 for (
size_t __k = __m; __k < __m + __n; ++__k)
3461 const size_t __kn = __k % __n;
3462 const size_t __kpn = (__k + __p) % __n;
3463 const size_t __kqn = (__k + __q) % __n;
3464 uint32_t __arg = (__begin[__kn]
3466 + __begin[(__k - 1) % __n]);
3467 uint32_t __r3 = 1566083941u * (__arg ^ (__arg >> 27));
3468 uint32_t __r4 = __r3 - __kn;
3469 __begin[__kpn] ^= __r3;
3470 __begin[__kqn] ^= __r4;
3471 __begin[__kn] = __r4;
3475 template<
typename _RealType,
size_t __bits,
3476 typename _UniformRandomNumberGenerator>
3481 "template argument must be a floating point type");
3486 const long double __r =
static_cast<long double>(__urng.max())
3487 -
static_cast<long double>(__urng.min()) + 1.0L;
3490 (__b + __log2r - 1UL) / __log2r);
3492 _RealType __sum = _RealType(0);
3493 _RealType __tmp = _RealType(1);
3494 for (
size_t __k = __m; __k != 0; --__k)
3496 __sum += _RealType(__urng() - __urng.min()) * __tmp;
3499 __ret = __sum / __tmp;
3500 if (__builtin_expect(__ret >= _RealType(1), 0))
3502#if _GLIBCXX_USE_C99_MATH_FUNCS
3503 __ret = std::nextafter(_RealType(1), _RealType(0));
3505 __ret = _RealType(1)
3512_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...
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.
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.
constexpr _Tp __lg(_Tp __n)
This is a helper function for the sort routines and for random.tcc.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
Implementation details not part of the namespace std interface.
A standard container for storing a fixed size sequence of elements.
char_type widen(char __c) const
Widens characters.
char_type fill() const
Retrieves the empty character.
Template class basic_istream.
Template class basic_ostream.
static constexpr bool is_integer
static constexpr int max_digits10
static constexpr int digits
static constexpr bool is_signed
static constexpr _Tp max() noexcept
static constexpr _Tp epsilon() 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
std::mersenne_twister_engine< uint_fast32_t, 32, 624, 397, 31, 0x9908b0dfUL, 11, 0xffffffffUL, 7, 0x9d2c5680UL, 15, 0xefc60000UL, 18, 1812433253UL >::result_type uint_fast32_t result_type
The Marsaglia-Zaman generator.
void seed(result_type __sd=0u)
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 reordering random numbers from some base engine.
const _RandomNumberEngine & base() const noexcept
_RandomNumberEngine::result_type result_type
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.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
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 Bernoulli random number distribution.
double p() const
Returns the p parameter of the 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.
A negative_binomial_distribution random number distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
A discrete Poisson random number distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
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_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 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.
A piecewise_constant_distribution random number distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
A piecewise_linear_distribution random number distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
uint_least32_t result_type
A standard container which offers fixed time access to individual elements in any order.
constexpr iterator end() noexcept
constexpr iterator begin() noexcept
constexpr 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.