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, ++__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)
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,
198 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
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,
207 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
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,
216 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
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,
225 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
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,
234 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
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,
243 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
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,
252 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
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,
261 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
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,
270 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
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,
279 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
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,
288 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
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,
297 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
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,
306 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
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,
316 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
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,
326 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
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>
352 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
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,
397 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
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,
433 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
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>
505 mersenne_twister_engine<_UIntType, __w, __n, __m,
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>
545 __lcg(__value == 0u ? default_seed : __value);
547 const size_t __n = (__w + 31) / 32;
549 for (
size_t __i = 0; __i < long_lag; ++__i)
551 _UIntType __sum = 0u;
552 _UIntType __factor = 1u;
553 for (
size_t __j = 0; __j < __n; ++__j)
555 __sum += __detail::__mod<uint_least32_t,
556 __detail::_Shift<uint_least32_t, 32>::__value>
557 (__lcg()) * __factor;
558 __factor *= __detail::_Shift<_UIntType, 32>::__value;
560 _M_x[__i] = __detail::__mod<_UIntType,
561 __detail::_Shift<_UIntType, __w>::__value>(__sum);
563 _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
567 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
568 template<
typename _Sseq>
572 -> _If_seed_seq<_Sseq>
574 const size_t __k = (__w + 31) / 32;
575 uint_least32_t __arr[__r * __k];
576 __q.generate(__arr + 0, __arr + __r * __k);
578 for (
size_t __i = 0; __i < long_lag; ++__i)
580 _UIntType __sum = 0u;
581 _UIntType __factor = 1u;
582 for (
size_t __j = 0; __j < __k; ++__j)
584 __sum += __arr[__k * __i + __j] * __factor;
585 __factor *= __detail::_Shift<_UIntType, 32>::__value;
587 _M_x[__i] = __detail::__mod<_UIntType,
588 __detail::_Shift<_UIntType, __w>::__value>(__sum);
590 _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
594 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
595 typename subtract_with_carry_engine<_UIntType, __w, __s, __r>::
601 long __ps = _M_p - short_lag;
609 if (_M_x[__ps] >= _M_x[_M_p] + _M_carry)
611 __xi = _M_x[__ps] - _M_x[_M_p] - _M_carry;
616 __xi = (__detail::_Shift<_UIntType, __w>::__value
617 - _M_x[_M_p] - _M_carry + _M_x[__ps]);
623 if (++_M_p >= long_lag)
629 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r,
630 typename _CharT,
typename _Traits>
638 const typename __ios_base::fmtflags __flags = __os.
flags();
639 const _CharT __fill = __os.
fill();
640 const _CharT __space = __os.
widen(
' ');
641 __os.
flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
644 for (
size_t __i = 0; __i < __r; ++__i)
645 __os << __x._M_x[__i] << __space;
646 __os << __x._M_carry << __space << __x._M_p;
653 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r,
654 typename _CharT,
typename _Traits>
657 subtract_with_carry_engine<_UIntType, __w, __s, __r>& __x)
659 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
661 const typename __ios_base::fmtflags __flags = __is.
flags();
662 __is.
flags(__ios_base::dec | __ios_base::skipws);
664 for (
size_t __i = 0; __i < __r; ++__i)
665 __is >> __x._M_x[__i];
666 __is >> __x._M_carry;
673#if ! __cpp_inline_variables
674 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
676 discard_block_engine<_RandomNumberEngine, __p, __r>::block_size;
678 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
680 discard_block_engine<_RandomNumberEngine, __p, __r>::used_block;
683 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
684 typename discard_block_engine<_RandomNumberEngine,
685 __p, __r>::result_type
689 if (_M_n >= used_block)
691 _M_b.discard(block_size - _M_n);
698 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r,
699 typename _CharT,
typename _Traits>
707 const typename __ios_base::fmtflags __flags = __os.
flags();
708 const _CharT __fill = __os.
fill();
709 const _CharT __space = __os.
widen(
' ');
710 __os.
flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
713 __os << __x.base() << __space << __x._M_n;
720 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r,
721 typename _CharT,
typename _Traits>
724 discard_block_engine<_RandomNumberEngine, __p, __r>& __x)
726 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
728 const typename __ios_base::fmtflags __flags = __is.
flags();
729 __is.
flags(__ios_base::dec | __ios_base::skipws);
731 __is >> __x._M_b >> __x._M_n;
738 template<
typename _RandomNumberEngine,
size_t __w,
typename _UIntType>
739 typename independent_bits_engine<_RandomNumberEngine, __w, _UIntType>::
744 typedef typename _RandomNumberEngine::result_type _Eresult_type;
745 const _Eresult_type __r
747 ? _M_b.max() - _M_b.min() + 1 : 0);
749 const unsigned __m = __r ?
std::__lg(__r) : __edig;
756 __ctype __s0, __s1, __y0, __y1;
758 for (
size_t __i = 0; __i < 2; ++__i)
760 __n = (__w + __m - 1) / __m + __i;
761 __n0 = __n - __w % __n;
762 const unsigned __w0 = __w / __n;
768 __s0 = __ctype(1) << __w0;
776 __y0 = __s0 * (__r / __s0);
778 __y1 = __s1 * (__r / __s1);
780 if (__r - __y0 <= __y0 / __n)
788 for (
size_t __k = 0; __k < __n0; ++__k)
792 __u = _M_b() - _M_b.
min();
793 while (__y0 && __u >= __y0);
794 __sum = __s0 * __sum + (__s0 ? __u % __s0 : __u);
796 for (
size_t __k = __n0; __k < __n; ++__k)
800 __u = _M_b() - _M_b.min();
801 while (__y1 && __u >= __y1);
802 __sum = __s1 * __sum + (__s1 ? __u % __s1 : __u);
807#if ! __cpp_inline_variables
808 template<
typename _RandomNumberEngine,
size_t __k>
816 template<
typename _Tp>
818 __representable_as_double(_Tp __x)
noexcept
823 return (__x <= (1ull << __DBL_MANT_DIG__))
825 || (!(__x & 1) && __detail::__representable_as_double(__x >> 1));
829 template<
typename _Tp>
831 __p1_representable_as_double(_Tp __x)
noexcept
837 && __detail::__representable_as_double(__x + 1u));
841 template<
typename _RandomNumberEngine,
size_t __k>
850 if _GLIBCXX17_CONSTEXPR (__detail::__p1_representable_as_double(__range))
851 __j *= __y / (__range + 1.0);
853 __j *= __y / (__range + 1.0L);
860 template<
typename _RandomNumberEngine,
size_t __k,
861 typename _CharT,
typename _Traits>
868 const typename __ios_base::fmtflags __flags = __os.
flags();
869 const _CharT __fill = __os.
fill();
870 const _CharT __space = __os.
widen(
' ');
871 __os.
flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
875 for (
size_t __i = 0; __i < __k; ++__i)
876 __os << __space << __x._M_v[__i];
877 __os << __space << __x._M_y;
884 template<
typename _RandomNumberEngine,
size_t __k,
885 typename _CharT,
typename _Traits>
892 const typename __ios_base::fmtflags __flags = __is.
flags();
893 __is.
flags(__ios_base::dec | __ios_base::skipws);
896 for (
size_t __i = 0; __i < __k; ++__i)
897 __is >> __x._M_v[__i];
905 template<
typename _IntType,
typename _CharT,
typename _Traits>
908 const uniform_int_distribution<_IntType>& __x)
910 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
912 const typename __ios_base::fmtflags __flags = __os.
flags();
913 const _CharT __fill = __os.
fill();
914 const _CharT __space = __os.
widen(
' ');
915 __os.
flags(__ios_base::scientific | __ios_base::left);
918 __os << __x.a() << __space << __x.b();
925 template<
typename _IntType,
typename _CharT,
typename _Traits>
934 const typename __ios_base::fmtflags __flags = __is.
flags();
935 __is.
flags(__ios_base::dec | __ios_base::skipws);
938 if (__is >> __a >> __b)
939 __x.
param(param_type(__a, __b));
946 template<
typename _RealType>
947 template<
typename _ForwardIterator,
948 typename _UniformRandomNumberGenerator>
952 _UniformRandomNumberGenerator& __urng,
953 const param_type& __p)
955 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
956 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
958 auto __range = __p.b() - __p.a();
960 *__f++ = __aurng() * __range + __p.a();
963 template<
typename _RealType,
typename _CharT,
typename _Traits>
966 const uniform_real_distribution<_RealType>& __x)
968 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
970 const typename __ios_base::fmtflags __flags = __os.
flags();
971 const _CharT __fill = __os.
fill();
973 const _CharT __space = __os.
widen(
' ');
974 __os.
flags(__ios_base::scientific | __ios_base::left);
978 __os << __x.a() << __space << __x.b();
986 template<
typename _RealType,
typename _CharT,
typename _Traits>
995 const typename __ios_base::fmtflags __flags = __is.
flags();
996 __is.
flags(__ios_base::skipws);
999 if (__is >> __a >> __b)
1000 __x.
param(param_type(__a, __b));
1002 __is.
flags(__flags);
1007 template<
typename _ForwardIterator,
1008 typename _UniformRandomNumberGenerator>
1010 std::bernoulli_distribution::
1011 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1012 _UniformRandomNumberGenerator& __urng,
1013 const param_type& __p)
1015 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1016 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1018 auto __limit = __p.p() * (__aurng.max() - __aurng.min());
1021 *__f++ = (__aurng() - __aurng.min()) < __limit;
1024 template<
typename _CharT,
typename _Traits>
1027 const bernoulli_distribution& __x)
1029 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1031 const typename __ios_base::fmtflags __flags = __os.
flags();
1032 const _CharT __fill = __os.
fill();
1034 __os.
flags(__ios_base::scientific | __ios_base::left);
1040 __os.
flags(__flags);
1047 template<
typename _IntType>
1048 template<
typename _UniformRandomNumberGenerator>
1051 operator()(_UniformRandomNumberGenerator& __urng,
1052 const param_type& __param)
1056 const double __naf =
1059 const double __thr =
1061 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1066 __cand = std::floor(
std::log(1.0 - __aurng()) / __param._M_log_1_p);
1067 while (__cand >= __thr);
1069 return result_type(__cand + __naf);
1072 template<
typename _IntType>
1073 template<
typename _ForwardIterator,
1074 typename _UniformRandomNumberGenerator>
1078 _UniformRandomNumberGenerator& __urng,
1079 const param_type& __param)
1081 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1084 const double __naf =
1087 const double __thr =
1089 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1096 __cand = std::floor(
std::log(1.0 - __aurng())
1097 / __param._M_log_1_p);
1098 while (__cand >= __thr);
1100 *__f++ = __cand + __naf;
1104 template<
typename _IntType,
1105 typename _CharT,
typename _Traits>
1108 const geometric_distribution<_IntType>& __x)
1110 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1112 const typename __ios_base::fmtflags __flags = __os.
flags();
1113 const _CharT __fill = __os.
fill();
1115 __os.
flags(__ios_base::scientific | __ios_base::left);
1121 __os.
flags(__flags);
1127 template<
typename _IntType,
1128 typename _CharT,
typename _Traits>
1136 const typename __ios_base::fmtflags __flags = __is.
flags();
1137 __is.
flags(__ios_base::skipws);
1141 __x.
param(param_type(__p));
1143 __is.
flags(__flags);
1148 template<
typename _IntType>
1149 template<
typename _UniformRandomNumberGenerator>
1152 operator()(_UniformRandomNumberGenerator& __urng)
1154 const double __y = _M_gd(__urng);
1158 return __poisson(__urng);
1161 template<
typename _IntType>
1162 template<
typename _UniformRandomNumberGenerator>
1165 operator()(_UniformRandomNumberGenerator& __urng,
1166 const param_type& __p)
1172 _M_gd(__urng, param_type(__p.k(), (1.0 - __p.p()) / __p.p()));
1175 return __poisson(__urng);
1178 template<
typename _IntType>
1179 template<
typename _ForwardIterator,
1180 typename _UniformRandomNumberGenerator>
1182 negative_binomial_distribution<_IntType>::
1183 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1184 _UniformRandomNumberGenerator& __urng)
1186 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1189 const double __y = _M_gd(__urng);
1193 *__f++ = __poisson(__urng);
1197 template<
typename _IntType>
1198 template<
typename _ForwardIterator,
1199 typename _UniformRandomNumberGenerator>
1201 negative_binomial_distribution<_IntType>::
1202 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1203 _UniformRandomNumberGenerator& __urng,
1204 const param_type& __p)
1206 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1208 __p2(__p.k(), (1.0 - __p.p()) / __p.p());
1212 const double __y = _M_gd(__urng, __p2);
1215 *__f++ = __poisson(__urng);
1219 template<
typename _IntType,
typename _CharT,
typename _Traits>
1222 const negative_binomial_distribution<_IntType>& __x)
1224 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1226 const typename __ios_base::fmtflags __flags = __os.
flags();
1227 const _CharT __fill = __os.
fill();
1229 const _CharT __space = __os.
widen(
' ');
1230 __os.
flags(__ios_base::scientific | __ios_base::left);
1234 __os << __x.k() << __space << __x.p()
1235 << __space << __x._M_gd;
1237 __os.
flags(__flags);
1243 template<
typename _IntType,
typename _CharT,
typename _Traits>
1246 negative_binomial_distribution<_IntType>& __x)
1249 =
typename negative_binomial_distribution<_IntType>::param_type;
1250 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1252 const typename __ios_base::fmtflags __flags = __is.
flags();
1253 __is.
flags(__ios_base::skipws);
1257 if (__is >> __k >> __p >> __x._M_gd)
1258 __x.param(param_type(__k, __p));
1260 __is.
flags(__flags);
1265 template<
typename _IntType>
1267 poisson_distribution<_IntType>::param_type::
1270#if _GLIBCXX_USE_C99_MATH_TR1
1273 const double __m = std::floor(_M_mean);
1275 _M_lfm = std::lgamma(__m + 1);
1278 const double __pi_4 = 0.7853981633974483096156608458198757L;
1281 _M_d = std::round(std::max<double>(6.0,
std::min(__m, __dx)));
1282 const double __cx = 2 * __m + _M_d;
1287 _M_cb = 2 * __cx *
std::exp(-_M_d * _M_1cx * (1 + _M_d / 2))
1305 template<
typename _IntType>
1306 template<
typename _UniformRandomNumberGenerator>
1309 operator()(_UniformRandomNumberGenerator& __urng,
1312 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1314#if _GLIBCXX_USE_C99_MATH_TR1
1315 if (__param.mean() >= 12)
1320 const double __naf =
1322 const double __thr =
1325 const double __m = std::floor(__param.mean());
1327 const double __spi_2 = 1.2533141373155002512078826424055226L;
1328 const double __c1 = __param._M_sm * __spi_2;
1329 const double __c2 = __param._M_c2b + __c1;
1330 const double __c3 = __c2 + 1;
1331 const double __c4 = __c3 + 1;
1333 const double __178 = 0.0128205128205128205128205128205128L;
1335 const double __e178 = 1.0129030479320018583185514777512983L;
1336 const double __c5 = __c4 + __e178;
1337 const double __c = __param._M_cb + __c5;
1338 const double __2cx = 2 * (2 * __m + __param._M_d);
1340 bool __reject =
true;
1343 const double __u = __c * __aurng();
1344 const double __e = -
std::log(1.0 - __aurng());
1350 const double __n = _M_nd(__urng);
1351 const double __y = -
std::abs(__n) * __param._M_sm - 1;
1352 __x = std::floor(__y);
1353 __w = -__n * __n / 2;
1357 else if (__u <= __c2)
1359 const double __n = _M_nd(__urng);
1360 const double __y = 1 +
std::abs(__n) * __param._M_scx;
1361 __x = std::ceil(__y);
1362 __w = __y * (2 - __y) * __param._M_1cx;
1363 if (__x > __param._M_d)
1366 else if (__u <= __c3)
1370 else if (__u <= __c4)
1372 else if (__u <= __c5)
1380 const double __v = -
std::log(1.0 - __aurng());
1381 const double __y = __param._M_d
1382 + __v * __2cx / __param._M_d;
1383 __x = std::ceil(__y);
1384 __w = -__param._M_d * __param._M_1cx * (1 + __y / 2);
1387 __reject = (__w - __e - __x * __param._M_lm_thr
1388 > __param._M_lfm - std::lgamma(__x + __m + 1));
1390 __reject |= __x + __m >= __thr;
1400 double __prod = 1.0;
1404 __prod *= __aurng();
1407 while (__prod > __param._M_lm_thr);
1413 template<
typename _IntType>
1414 template<
typename _ForwardIterator,
1415 typename _UniformRandomNumberGenerator>
1419 _UniformRandomNumberGenerator& __urng,
1420 const param_type& __param)
1422 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1428 template<
typename _IntType,
1429 typename _CharT,
typename _Traits>
1432 const poisson_distribution<_IntType>& __x)
1434 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1436 const typename __ios_base::fmtflags __flags = __os.
flags();
1437 const _CharT __fill = __os.
fill();
1439 const _CharT __space = __os.
widen(
' ');
1440 __os.
flags(__ios_base::scientific | __ios_base::left);
1444 __os << __x.mean() << __space << __x._M_nd;
1446 __os.
flags(__flags);
1452 template<
typename _IntType,
1453 typename _CharT,
typename _Traits>
1456 poisson_distribution<_IntType>& __x)
1458 using param_type =
typename poisson_distribution<_IntType>::param_type;
1459 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1461 const typename __ios_base::fmtflags __flags = __is.
flags();
1462 __is.
flags(__ios_base::skipws);
1465 if (__is >> __mean >> __x._M_nd)
1466 __x.param(param_type(__mean));
1468 __is.
flags(__flags);
1473 template<
typename _IntType>
1475 binomial_distribution<_IntType>::param_type::
1478 const double __p12 = _M_p <= 0.5 ? _M_p : 1.0 - _M_p;
1482#if _GLIBCXX_USE_C99_MATH_TR1
1483 if (_M_t * __p12 >= 8)
1486 const double __np = std::floor(_M_t * __p12);
1487 const double __pa = __np / _M_t;
1488 const double __1p = 1 - __pa;
1490 const double __pi_4 = 0.7853981633974483096156608458198757L;
1491 const double __d1x =
1493 / (81 * __pi_4 * __1p)));
1494 _M_d1 = std::round(std::max<double>(1.0, __d1x));
1495 const double __d2x =
1497 / (__pi_4 * __pa)));
1498 _M_d2 = std::round(std::max<double>(1.0, __d2x));
1501 const double __spi_2 = 1.2533141373155002512078826424055226L;
1502 _M_s1 =
std::sqrt(__np * __1p) * (1 + _M_d1 / (4 * __np));
1503 _M_s2 =
std::sqrt(__np * __1p) * (1 + _M_d2 / (4 * _M_t * __1p));
1504 _M_c = 2 * _M_d1 / __np;
1505 _M_a1 =
std::exp(_M_c) * _M_s1 * __spi_2;
1506 const double __a12 = _M_a1 + _M_s2 * __spi_2;
1507 const double __s1s = _M_s1 * _M_s1;
1508 _M_a123 = __a12 + (
std::exp(_M_d1 / (_M_t * __1p))
1510 *
std::exp(-_M_d1 * _M_d1 / (2 * __s1s)));
1511 const double __s2s = _M_s2 * _M_s2;
1512 _M_s = (_M_a123 + 2 * __s2s / _M_d2
1513 *
std::exp(-_M_d2 * _M_d2 / (2 * __s2s)));
1514 _M_lf = (std::lgamma(__np + 1)
1515 + std::lgamma(_M_t - __np + 1));
1518 _M_q = -
std::log(1 - (__p12 - __pa) / __1p);
1525 template<
typename _IntType>
1526 template<
typename _UniformRandomNumberGenerator>
1528 binomial_distribution<_IntType>::
1529 _M_waiting(_UniformRandomNumberGenerator& __urng,
1530 _IntType __t,
double __q)
1534 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1541 const double __e = -
std::log(1.0 - __aurng());
1542 __sum += __e / (__t - __x);
1545 while (__sum <= __q);
1560 template<
typename _IntType>
1561 template<
typename _UniformRandomNumberGenerator>
1564 operator()(_UniformRandomNumberGenerator& __urng,
1568 const _IntType __t = __param.t();
1569 const double __p = __param.p();
1570 const double __p12 = __p <= 0.5 ? __p : 1.0 - __p;
1571 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1574#if _GLIBCXX_USE_C99_MATH_TR1
1575 if (!__param._M_easy)
1580 const double __naf =
1582 const double __thr =
1585 const double __np = std::floor(__t * __p12);
1588 const double __spi_2 = 1.2533141373155002512078826424055226L;
1589 const double __a1 = __param._M_a1;
1590 const double __a12 = __a1 + __param._M_s2 * __spi_2;
1591 const double __a123 = __param._M_a123;
1592 const double __s1s = __param._M_s1 * __param._M_s1;
1593 const double __s2s = __param._M_s2 * __param._M_s2;
1598 const double __u = __param._M_s * __aurng();
1604 const double __n = _M_nd(__urng);
1605 const double __y = __param._M_s1 *
std::abs(__n);
1606 __reject = __y >= __param._M_d1;
1609 const double __e = -
std::log(1.0 - __aurng());
1610 __x = std::floor(__y);
1611 __v = -__e - __n * __n / 2 + __param._M_c;
1614 else if (__u <= __a12)
1616 const double __n = _M_nd(__urng);
1617 const double __y = __param._M_s2 *
std::abs(__n);
1618 __reject = __y >= __param._M_d2;
1621 const double __e = -
std::log(1.0 - __aurng());
1622 __x = std::floor(-__y);
1623 __v = -__e - __n * __n / 2;
1626 else if (__u <= __a123)
1628 const double __e1 = -
std::log(1.0 - __aurng());
1629 const double __e2 = -
std::log(1.0 - __aurng());
1631 const double __y = __param._M_d1
1632 + 2 * __s1s * __e1 / __param._M_d1;
1633 __x = std::floor(__y);
1634 __v = (-__e2 + __param._M_d1 * (1 / (__t - __np)
1635 -__y / (2 * __s1s)));
1640 const double __e1 = -
std::log(1.0 - __aurng());
1641 const double __e2 = -
std::log(1.0 - __aurng());
1643 const double __y = __param._M_d2
1644 + 2 * __s2s * __e1 / __param._M_d2;
1645 __x = std::floor(-__y);
1646 __v = -__e2 - __param._M_d2 * __y / (2 * __s2s);
1650 __reject = __reject || __x < -__np || __x > __t - __np;
1653 const double __lfx =
1654 std::lgamma(__np + __x + 1)
1655 + std::lgamma(__t - (__np + __x) + 1);
1656 __reject = __v > __param._M_lf - __lfx
1657 + __x * __param._M_lp1p;
1660 __reject |= __x + __np >= __thr;
1664 __x += __np + __naf;
1666 const _IntType __z = _M_waiting(__urng, __t - _IntType(__x),
1668 __ret = _IntType(__x) + __z;
1672 __ret = _M_waiting(__urng, __t, __param._M_q);
1675 __ret = __t - __ret;
1679 template<
typename _IntType>
1680 template<
typename _ForwardIterator,
1681 typename _UniformRandomNumberGenerator>
1685 _UniformRandomNumberGenerator& __urng,
1686 const param_type& __param)
1688 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1694 template<
typename _IntType,
1695 typename _CharT,
typename _Traits>
1698 const binomial_distribution<_IntType>& __x)
1700 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1702 const typename __ios_base::fmtflags __flags = __os.
flags();
1703 const _CharT __fill = __os.
fill();
1705 const _CharT __space = __os.
widen(
' ');
1706 __os.
flags(__ios_base::scientific | __ios_base::left);
1710 __os << __x.t() << __space << __x.p()
1711 << __space << __x._M_nd;
1713 __os.
flags(__flags);
1719 template<
typename _IntType,
1720 typename _CharT,
typename _Traits>
1723 binomial_distribution<_IntType>& __x)
1725 using param_type =
typename binomial_distribution<_IntType>::param_type;
1726 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1728 const typename __ios_base::fmtflags __flags = __is.
flags();
1729 __is.
flags(__ios_base::dec | __ios_base::skipws);
1733 if (__is >> __t >> __p >> __x._M_nd)
1734 __x.param(param_type(__t, __p));
1736 __is.
flags(__flags);
1741 template<
typename _RealType>
1742 template<
typename _ForwardIterator,
1743 typename _UniformRandomNumberGenerator>
1747 _UniformRandomNumberGenerator& __urng,
1748 const param_type& __p)
1750 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1751 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1757 template<
typename _RealType,
typename _CharT,
typename _Traits>
1760 const exponential_distribution<_RealType>& __x)
1762 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1764 const typename __ios_base::fmtflags __flags = __os.
flags();
1765 const _CharT __fill = __os.
fill();
1767 __os.
flags(__ios_base::scientific | __ios_base::left);
1771 __os << __x.lambda();
1773 __os.
flags(__flags);
1779 template<
typename _RealType,
typename _CharT,
typename _Traits>
1788 const typename __ios_base::fmtflags __flags = __is.
flags();
1789 __is.
flags(__ios_base::dec | __ios_base::skipws);
1792 if (__is >> __lambda)
1793 __x.
param(param_type(__lambda));
1795 __is.
flags(__flags);
1806 template<
typename _RealType>
1807 template<
typename _UniformRandomNumberGenerator>
1810 operator()(_UniformRandomNumberGenerator& __urng,
1814 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1817 if (_M_saved_available)
1819 _M_saved_available =
false;
1829 __r2 = __x * __x + __y * __y;
1831 while (__r2 > 1.0 || __r2 == 0.0);
1834 _M_saved = __x * __mult;
1835 _M_saved_available =
true;
1836 __ret = __y * __mult;
1839 __ret = __ret * __param.stddev() + __param.mean();
1843 template<
typename _RealType>
1844 template<
typename _ForwardIterator,
1845 typename _UniformRandomNumberGenerator>
1849 _UniformRandomNumberGenerator& __urng,
1850 const param_type& __param)
1852 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1857 if (_M_saved_available)
1859 _M_saved_available =
false;
1860 *__f++ = _M_saved * __param.stddev() + __param.mean();
1866 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1869 while (__f + 1 < __t)
1876 __r2 = __x * __x + __y * __y;
1878 while (__r2 > 1.0 || __r2 == 0.0);
1881 *__f++ = __y * __mult * __param.stddev() + __param.mean();
1882 *__f++ = __x * __mult * __param.stddev() + __param.mean();
1892 __r2 = __x * __x + __y * __y;
1894 while (__r2 > 1.0 || __r2 == 0.0);
1897 _M_saved = __x * __mult;
1898 _M_saved_available =
true;
1899 *__f = __y * __mult * __param.stddev() + __param.mean();
1903 template<
typename _RealType>
1908 if (__d1._M_param == __d2._M_param
1909 && __d1._M_saved_available == __d2._M_saved_available)
1910 return __d1._M_saved_available ? __d1._M_saved == __d2._M_saved :
true;
1915 template<
typename _RealType,
typename _CharT,
typename _Traits>
1918 const normal_distribution<_RealType>& __x)
1920 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1922 const typename __ios_base::fmtflags __flags = __os.
flags();
1923 const _CharT __fill = __os.
fill();
1925 const _CharT __space = __os.
widen(
' ');
1926 __os.
flags(__ios_base::scientific | __ios_base::left);
1930 __os << __x.mean() << __space << __x.stddev()
1931 << __space << __x._M_saved_available;
1932 if (__x._M_saved_available)
1933 __os << __space << __x._M_saved;
1935 __os.
flags(__flags);
1941 template<
typename _RealType,
typename _CharT,
typename _Traits>
1944 normal_distribution<_RealType>& __x)
1946 using param_type =
typename normal_distribution<_RealType>::param_type;
1947 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1949 const typename __ios_base::fmtflags __flags = __is.
flags();
1950 __is.
flags(__ios_base::dec | __ios_base::skipws);
1952 double __mean, __stddev;
1954 if (__is >> __mean >> __stddev >> __saved_avail)
1956 if (!__saved_avail || (__is >> __x._M_saved))
1958 __x._M_saved_available = __saved_avail;
1959 __x.param(param_type(__mean, __stddev));
1963 __is.
flags(__flags);
1968 template<
typename _RealType>
1969 template<
typename _ForwardIterator,
1970 typename _UniformRandomNumberGenerator>
1972 lognormal_distribution<_RealType>::
1973 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1974 _UniformRandomNumberGenerator& __urng,
1975 const param_type& __p)
1977 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1979 *__f++ =
std::exp(__p.s() * _M_nd(__urng) + __p.m());
1982 template<
typename _RealType,
typename _CharT,
typename _Traits>
1985 const lognormal_distribution<_RealType>& __x)
1987 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1989 const typename __ios_base::fmtflags __flags = __os.
flags();
1990 const _CharT __fill = __os.
fill();
1992 const _CharT __space = __os.
widen(
' ');
1993 __os.
flags(__ios_base::scientific | __ios_base::left);
1997 __os << __x.m() << __space << __x.s()
1998 << __space << __x._M_nd;
2000 __os.
flags(__flags);
2006 template<
typename _RealType,
typename _CharT,
typename _Traits>
2009 lognormal_distribution<_RealType>& __x)
2012 =
typename lognormal_distribution<_RealType>::param_type;
2013 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2015 const typename __ios_base::fmtflags __flags = __is.
flags();
2016 __is.
flags(__ios_base::dec | __ios_base::skipws);
2019 if (__is >> __m >> __s >> __x._M_nd)
2020 __x.param(param_type(__m, __s));
2022 __is.
flags(__flags);
2026 template<
typename _RealType>
2027 template<
typename _ForwardIterator,
2028 typename _UniformRandomNumberGenerator>
2032 _UniformRandomNumberGenerator& __urng)
2034 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2036 *__f++ = 2 * _M_gd(__urng);
2039 template<
typename _RealType>
2040 template<
typename _ForwardIterator,
2041 typename _UniformRandomNumberGenerator>
2045 _UniformRandomNumberGenerator& __urng,
2049 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2051 *__f++ = 2 * _M_gd(__urng, __p);
2054 template<
typename _RealType,
typename _CharT,
typename _Traits>
2057 const chi_squared_distribution<_RealType>& __x)
2059 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2061 const typename __ios_base::fmtflags __flags = __os.
flags();
2062 const _CharT __fill = __os.
fill();
2064 const _CharT __space = __os.
widen(
' ');
2065 __os.
flags(__ios_base::scientific | __ios_base::left);
2069 __os << __x.n() << __space << __x._M_gd;
2071 __os.
flags(__flags);
2077 template<
typename _RealType,
typename _CharT,
typename _Traits>
2080 chi_squared_distribution<_RealType>& __x)
2083 =
typename chi_squared_distribution<_RealType>::param_type;
2084 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2086 const typename __ios_base::fmtflags __flags = __is.
flags();
2087 __is.
flags(__ios_base::dec | __ios_base::skipws);
2090 if (__is >> __n >> __x._M_gd)
2091 __x.param(param_type(__n));
2093 __is.
flags(__flags);
2098 template<
typename _RealType>
2099 template<
typename _UniformRandomNumberGenerator>
2102 operator()(_UniformRandomNumberGenerator& __urng,
2103 const param_type& __p)
2105 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2112 const _RealType __pi = 3.1415926535897932384626433832795029L;
2113 return __p.a() + __p.b() *
std::tan(__pi * __u);
2116 template<
typename _RealType>
2117 template<
typename _ForwardIterator,
2118 typename _UniformRandomNumberGenerator>
2122 _UniformRandomNumberGenerator& __urng,
2123 const param_type& __p)
2125 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2126 const _RealType __pi = 3.1415926535897932384626433832795029L;
2127 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2136 *__f++ = __p.a() + __p.b() *
std::tan(__pi * __u);
2140 template<
typename _RealType,
typename _CharT,
typename _Traits>
2143 const cauchy_distribution<_RealType>& __x)
2145 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2147 const typename __ios_base::fmtflags __flags = __os.
flags();
2148 const _CharT __fill = __os.
fill();
2150 const _CharT __space = __os.
widen(
' ');
2151 __os.
flags(__ios_base::scientific | __ios_base::left);
2155 __os << __x.a() << __space << __x.b();
2157 __os.
flags(__flags);
2163 template<
typename _RealType,
typename _CharT,
typename _Traits>
2171 const typename __ios_base::fmtflags __flags = __is.
flags();
2172 __is.
flags(__ios_base::dec | __ios_base::skipws);
2175 if (__is >> __a >> __b)
2176 __x.
param(param_type(__a, __b));
2178 __is.
flags(__flags);
2183 template<
typename _RealType>
2184 template<
typename _ForwardIterator,
2185 typename _UniformRandomNumberGenerator>
2189 _UniformRandomNumberGenerator& __urng)
2191 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2193 *__f++ = ((_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()));
2196 template<
typename _RealType>
2197 template<
typename _ForwardIterator,
2198 typename _UniformRandomNumberGenerator>
2202 _UniformRandomNumberGenerator& __urng,
2203 const param_type& __p)
2205 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2208 param_type __p1(__p.m() / 2);
2209 param_type __p2(__p.n() / 2);
2211 *__f++ = ((_M_gd_x(__urng, __p1) * n())
2212 / (_M_gd_y(__urng, __p2) * m()));
2215 template<
typename _RealType,
typename _CharT,
typename _Traits>
2218 const fisher_f_distribution<_RealType>& __x)
2220 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2222 const typename __ios_base::fmtflags __flags = __os.
flags();
2223 const _CharT __fill = __os.
fill();
2225 const _CharT __space = __os.
widen(
' ');
2226 __os.
flags(__ios_base::scientific | __ios_base::left);
2230 __os << __x.m() << __space << __x.n()
2231 << __space << __x._M_gd_x << __space << __x._M_gd_y;
2233 __os.
flags(__flags);
2239 template<
typename _RealType,
typename _CharT,
typename _Traits>
2242 fisher_f_distribution<_RealType>& __x)
2245 =
typename fisher_f_distribution<_RealType>::param_type;
2246 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2248 const typename __ios_base::fmtflags __flags = __is.
flags();
2249 __is.
flags(__ios_base::dec | __ios_base::skipws);
2252 if (__is >> __m >> __n >> __x._M_gd_x >> __x._M_gd_y)
2253 __x.param(param_type(__m, __n));
2255 __is.
flags(__flags);
2260 template<
typename _RealType>
2261 template<
typename _ForwardIterator,
2262 typename _UniformRandomNumberGenerator>
2266 _UniformRandomNumberGenerator& __urng)
2268 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2270 *__f++ = _M_nd(__urng) *
std::sqrt(n() / _M_gd(__urng));
2273 template<
typename _RealType>
2274 template<
typename _ForwardIterator,
2275 typename _UniformRandomNumberGenerator>
2279 _UniformRandomNumberGenerator& __urng,
2280 const param_type& __p)
2282 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2284 __p2(__p.n() / 2, 2);
2286 *__f++ = _M_nd(__urng) *
std::sqrt(__p.n() / _M_gd(__urng, __p2));
2289 template<
typename _RealType,
typename _CharT,
typename _Traits>
2292 const student_t_distribution<_RealType>& __x)
2294 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2296 const typename __ios_base::fmtflags __flags = __os.
flags();
2297 const _CharT __fill = __os.
fill();
2299 const _CharT __space = __os.
widen(
' ');
2300 __os.
flags(__ios_base::scientific | __ios_base::left);
2304 __os << __x.n() << __space << __x._M_nd << __space << __x._M_gd;
2306 __os.
flags(__flags);
2312 template<
typename _RealType,
typename _CharT,
typename _Traits>
2315 student_t_distribution<_RealType>& __x)
2318 =
typename student_t_distribution<_RealType>::param_type;
2319 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2321 const typename __ios_base::fmtflags __flags = __is.
flags();
2322 __is.
flags(__ios_base::dec | __ios_base::skipws);
2325 if (__is >> __n >> __x._M_nd >> __x._M_gd)
2326 __x.param(param_type(__n));
2328 __is.
flags(__flags);
2333 template<
typename _RealType>
2335 gamma_distribution<_RealType>::param_type::
2338 _M_malpha = _M_alpha < 1.0 ? _M_alpha + _RealType(1.0) : _M_alpha;
2340 const _RealType __a1 = _M_malpha - _RealType(1.0) / _RealType(3.0);
2341 _M_a2 = _RealType(1.0) /
std::sqrt(_RealType(9.0) * __a1);
2349 template<
typename _RealType>
2350 template<
typename _UniformRandomNumberGenerator>
2353 operator()(_UniformRandomNumberGenerator& __urng,
2356 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2361 - _RealType(1.0) / _RealType(3.0));
2367 __n = _M_nd(__urng);
2372 __v = __v * __v * __v;
2375 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2376 && (
std::log(__u) > (0.5 * __n * __n + __a1
2379 if (__param.alpha() == __param._M_malpha)
2380 return __a1 * __v * __param.beta();
2388 * __a1 * __v * __param.beta());
2392 template<
typename _RealType>
2393 template<
typename _ForwardIterator,
2394 typename _UniformRandomNumberGenerator>
2398 _UniformRandomNumberGenerator& __urng,
2399 const param_type& __param)
2401 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2402 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2407 - _RealType(1.0) / _RealType(3.0));
2409 if (__param.alpha() == __param._M_malpha)
2416 __n = _M_nd(__urng);
2421 __v = __v * __v * __v;
2424 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2425 && (
std::log(__u) > (0.5 * __n * __n + __a1
2428 *__f++ = __a1 * __v * __param.beta();
2437 __n = _M_nd(__urng);
2442 __v = __v * __v * __v;
2445 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2446 && (
std::log(__u) > (0.5 * __n * __n + __a1
2454 * __a1 * __v * __param.beta());
2458 template<
typename _RealType,
typename _CharT,
typename _Traits>
2461 const gamma_distribution<_RealType>& __x)
2463 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2465 const typename __ios_base::fmtflags __flags = __os.
flags();
2466 const _CharT __fill = __os.
fill();
2468 const _CharT __space = __os.
widen(
' ');
2469 __os.
flags(__ios_base::scientific | __ios_base::left);
2473 __os << __x.alpha() << __space << __x.beta()
2474 << __space << __x._M_nd;
2476 __os.
flags(__flags);
2482 template<
typename _RealType,
typename _CharT,
typename _Traits>
2485 gamma_distribution<_RealType>& __x)
2487 using param_type =
typename gamma_distribution<_RealType>::param_type;
2488 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2490 const typename __ios_base::fmtflags __flags = __is.
flags();
2491 __is.
flags(__ios_base::dec | __ios_base::skipws);
2493 _RealType __alpha_val, __beta_val;
2494 if (__is >> __alpha_val >> __beta_val >> __x._M_nd)
2495 __x.param(param_type(__alpha_val, __beta_val));
2497 __is.
flags(__flags);
2502 template<
typename _RealType>
2503 template<
typename _UniformRandomNumberGenerator>
2506 operator()(_UniformRandomNumberGenerator& __urng,
2507 const param_type& __p)
2509 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2515 template<
typename _RealType>
2516 template<
typename _ForwardIterator,
2517 typename _UniformRandomNumberGenerator>
2521 _UniformRandomNumberGenerator& __urng,
2522 const param_type& __p)
2524 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2525 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2534 template<
typename _RealType,
typename _CharT,
typename _Traits>
2537 const weibull_distribution<_RealType>& __x)
2539 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2541 const typename __ios_base::fmtflags __flags = __os.
flags();
2542 const _CharT __fill = __os.
fill();
2544 const _CharT __space = __os.
widen(
' ');
2545 __os.
flags(__ios_base::scientific | __ios_base::left);
2549 __os << __x.a() << __space << __x.b();
2551 __os.
flags(__flags);
2557 template<
typename _RealType,
typename _CharT,
typename _Traits>
2565 const typename __ios_base::fmtflags __flags = __is.
flags();
2566 __is.
flags(__ios_base::dec | __ios_base::skipws);
2569 if (__is >> __a >> __b)
2570 __x.
param(param_type(__a, __b));
2572 __is.
flags(__flags);
2577 template<
typename _RealType>
2578 template<
typename _UniformRandomNumberGenerator>
2581 operator()(_UniformRandomNumberGenerator& __urng,
2582 const param_type& __p)
2584 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2590 template<
typename _RealType>
2591 template<
typename _ForwardIterator,
2592 typename _UniformRandomNumberGenerator>
2596 _UniformRandomNumberGenerator& __urng,
2597 const param_type& __p)
2599 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2600 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2608 template<
typename _RealType,
typename _CharT,
typename _Traits>
2611 const extreme_value_distribution<_RealType>& __x)
2613 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2615 const typename __ios_base::fmtflags __flags = __os.
flags();
2616 const _CharT __fill = __os.
fill();
2618 const _CharT __space = __os.
widen(
' ');
2619 __os.
flags(__ios_base::scientific | __ios_base::left);
2623 __os << __x.a() << __space << __x.b();
2625 __os.
flags(__flags);
2631 template<
typename _RealType,
typename _CharT,
typename _Traits>
2640 const typename __ios_base::fmtflags __flags = __is.
flags();
2641 __is.
flags(__ios_base::dec | __ios_base::skipws);
2644 if (__is >> __a >> __b)
2645 __x.
param(param_type(__a, __b));
2647 __is.
flags(__flags);
2652 template<
typename _IntType>
2654 discrete_distribution<_IntType>::param_type::
2657 if (_M_prob.size() < 2)
2664 _M_prob.end(), 0.0);
2665 __glibcxx_assert(__sum > 0);
2667 __detail::__normalize(_M_prob.begin(), _M_prob.end(), _M_prob.begin(),
2670 _M_cp.reserve(_M_prob.size());
2674 _M_cp[_M_cp.size() - 1] = 1.0;
2677 template<
typename _IntType>
2678 template<
typename _Func>
2679 discrete_distribution<_IntType>::param_type::
2680 param_type(
size_t __nw,
double __xmin,
double __xmax, _Func __fw)
2681 : _M_prob(), _M_cp()
2683 const size_t __n = __nw == 0 ? 1 : __nw;
2684 const double __delta = (__xmax - __xmin) / __n;
2686 _M_prob.reserve(__n);
2687 for (
size_t __k = 0; __k < __nw; ++__k)
2688 _M_prob.push_back(__fw(__xmin + __k * __delta + 0.5 * __delta));
2693 template<
typename _IntType>
2694 template<
typename _UniformRandomNumberGenerator>
2695 typename discrete_distribution<_IntType>::result_type
2696 discrete_distribution<_IntType>::
2697 operator()(_UniformRandomNumberGenerator& __urng,
2698 const param_type& __param)
2700 if (__param._M_cp.empty())
2701 return result_type(0);
2703 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2706 const double __p = __aurng();
2707 auto __pos = std::lower_bound(__param._M_cp.begin(),
2708 __param._M_cp.end(), __p);
2710 return __pos - __param._M_cp.begin();
2713 template<
typename _IntType>
2714 template<
typename _ForwardIterator,
2715 typename _UniformRandomNumberGenerator>
2717 discrete_distribution<_IntType>::
2718 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2719 _UniformRandomNumberGenerator& __urng,
2720 const param_type& __param)
2722 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2724 if (__param._M_cp.empty())
2727 *__f++ = result_type(0);
2731 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2736 const double __p = __aurng();
2737 auto __pos = std::lower_bound(__param._M_cp.begin(),
2738 __param._M_cp.end(), __p);
2740 *__f++ = __pos - __param._M_cp.begin();
2744 template<
typename _IntType,
typename _CharT,
typename _Traits>
2747 const discrete_distribution<_IntType>& __x)
2749 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2751 const typename __ios_base::fmtflags __flags = __os.
flags();
2752 const _CharT __fill = __os.
fill();
2754 const _CharT __space = __os.
widen(
' ');
2755 __os.
flags(__ios_base::scientific | __ios_base::left);
2760 __os << __prob.
size();
2761 for (
auto __dit = __prob.
begin(); __dit != __prob.
end(); ++__dit)
2762 __os << __space << *__dit;
2764 __os.
flags(__flags);
2772 template<
typename _ValT,
typename _CharT,
typename _Traits>
2773 basic_istream<_CharT, _Traits>&
2774 __extract_params(basic_istream<_CharT, _Traits>& __is,
2775 vector<_ValT>& __vals,
size_t __n)
2777 __vals.reserve(__n);
2782 __vals.push_back(__val);
2790 template<
typename _IntType,
typename _CharT,
typename _Traits>
2793 discrete_distribution<_IntType>& __x)
2795 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2797 const typename __ios_base::fmtflags __flags = __is.
flags();
2798 __is.
flags(__ios_base::dec | __ios_base::skipws);
2804 if (__detail::__extract_params(__is, __prob_vec, __n))
2805 __x.param({__prob_vec.
begin(), __prob_vec.
end()});
2808 __is.
flags(__flags);
2813 template<
typename _RealType>
2815 piecewise_constant_distribution<_RealType>::param_type::
2818 if (_M_int.size() < 2
2819 || (_M_int.size() == 2
2820 && _M_int[0] == _RealType(0)
2821 && _M_int[1] == _RealType(1)))
2830 __glibcxx_assert(__sum > 0);
2832 __detail::__normalize(_M_den.begin(), _M_den.end(), _M_den.begin(),
2835 _M_cp.reserve(_M_den.size());
2840 _M_cp[_M_cp.size() - 1] = 1.0;
2842 for (
size_t __k = 0; __k < _M_den.size(); ++__k)
2843 _M_den[__k] /= _M_int[__k + 1] - _M_int[__k];
2846 template<
typename _RealType>
2847 template<
typename _InputIteratorB,
typename _InputIteratorW>
2848 piecewise_constant_distribution<_RealType>::param_type::
2849 param_type(_InputIteratorB __bbegin,
2850 _InputIteratorB __bend,
2851 _InputIteratorW __wbegin)
2852 : _M_int(), _M_den(), _M_cp()
2854 if (__bbegin != __bend)
2858 _M_int.push_back(*__bbegin);
2860 if (__bbegin == __bend)
2863 _M_den.push_back(*__wbegin);
2871 template<
typename _RealType>
2872 template<
typename _Func>
2873 piecewise_constant_distribution<_RealType>::param_type::
2874 param_type(initializer_list<_RealType> __bl, _Func __fw)
2875 : _M_int(), _M_den(), _M_cp()
2877 _M_int.reserve(__bl.size());
2878 for (
auto __biter = __bl.begin(); __biter != __bl.end(); ++__biter)
2879 _M_int.push_back(*__biter);
2881 _M_den.reserve(_M_int.size() - 1);
2882 for (
size_t __k = 0; __k < _M_int.size() - 1; ++__k)
2883 _M_den.push_back(__fw(0.5 * (_M_int[__k + 1] + _M_int[__k])));
2888 template<
typename _RealType>
2889 template<
typename _Func>
2890 piecewise_constant_distribution<_RealType>::param_type::
2891 param_type(
size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
2892 : _M_int(), _M_den(), _M_cp()
2894 const size_t __n = __nw == 0 ? 1 : __nw;
2895 const _RealType __delta = (__xmax - __xmin) / __n;
2897 _M_int.reserve(__n + 1);
2898 for (
size_t __k = 0; __k <= __nw; ++__k)
2899 _M_int.push_back(__xmin + __k * __delta);
2901 _M_den.reserve(__n);
2902 for (
size_t __k = 0; __k < __nw; ++__k)
2903 _M_den.push_back(__fw(_M_int[__k] + 0.5 * __delta));
2908 template<
typename _RealType>
2909 template<
typename _UniformRandomNumberGenerator>
2910 typename piecewise_constant_distribution<_RealType>::result_type
2911 piecewise_constant_distribution<_RealType>::
2912 operator()(_UniformRandomNumberGenerator& __urng,
2913 const param_type& __param)
2915 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2918 const double __p = __aurng();
2919 if (__param._M_cp.empty())
2922 auto __pos = std::lower_bound(__param._M_cp.begin(),
2923 __param._M_cp.end(), __p);
2924 const size_t __i = __pos - __param._M_cp.begin();
2926 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
2928 return __param._M_int[__i] + (__p - __pref) / __param._M_den[__i];
2931 template<
typename _RealType>
2932 template<
typename _ForwardIterator,
2933 typename _UniformRandomNumberGenerator>
2935 piecewise_constant_distribution<_RealType>::
2936 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2937 _UniformRandomNumberGenerator& __urng,
2938 const param_type& __param)
2940 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2941 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2944 if (__param._M_cp.empty())
2953 const double __p = __aurng();
2955 auto __pos = std::lower_bound(__param._M_cp.begin(),
2956 __param._M_cp.end(), __p);
2957 const size_t __i = __pos - __param._M_cp.begin();
2959 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
2961 *__f++ = (__param._M_int[__i]
2962 + (__p - __pref) / __param._M_den[__i]);
2966 template<
typename _RealType,
typename _CharT,
typename _Traits>
2969 const piecewise_constant_distribution<_RealType>& __x)
2971 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2973 const typename __ios_base::fmtflags __flags = __os.
flags();
2974 const _CharT __fill = __os.
fill();
2976 const _CharT __space = __os.
widen(
' ');
2977 __os.
flags(__ios_base::scientific | __ios_base::left);
2982 __os << __int.
size() - 1;
2984 for (
auto __xit = __int.
begin(); __xit != __int.
end(); ++__xit)
2985 __os << __space << *__xit;
2988 for (
auto __dit = __den.
begin(); __dit != __den.
end(); ++__dit)
2989 __os << __space << *__dit;
2991 __os.
flags(__flags);
2997 template<
typename _RealType,
typename _CharT,
typename _Traits>
3000 piecewise_constant_distribution<_RealType>& __x)
3002 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
3004 const typename __ios_base::fmtflags __flags = __is.
flags();
3005 __is.
flags(__ios_base::dec | __ios_base::skipws);
3011 if (__detail::__extract_params(__is, __int_vec, __n + 1))
3014 if (__detail::__extract_params(__is, __den_vec, __n))
3016 __x.param({ __int_vec.
begin(), __int_vec.
end(),
3017 __den_vec.
begin() });
3022 __is.
flags(__flags);
3027 template<
typename _RealType>
3029 piecewise_linear_distribution<_RealType>::param_type::
3032 if (_M_int.size() < 2
3033 || (_M_int.size() == 2
3034 && _M_int[0] == _RealType(0)
3035 && _M_int[1] == _RealType(1)
3036 && _M_den[0] == _M_den[1]))
3044 _M_cp.reserve(_M_int.size() - 1);
3045 _M_m.reserve(_M_int.size() - 1);
3046 for (
size_t __k = 0; __k < _M_int.size() - 1; ++__k)
3048 const _RealType __delta = _M_int[__k + 1] - _M_int[__k];
3049 __sum += 0.5 * (_M_den[__k + 1] + _M_den[__k]) * __delta;
3050 _M_cp.push_back(__sum);
3051 _M_m.push_back((_M_den[__k + 1] - _M_den[__k]) / __delta);
3053 __glibcxx_assert(__sum > 0);
3056 __detail::__normalize(_M_den.begin(), _M_den.end(), _M_den.begin(),
3059 __detail::__normalize(_M_cp.begin(), _M_cp.end(), _M_cp.begin(), __sum);
3061 __detail::__normalize(_M_m.begin(), _M_m.end(), _M_m.begin(), __sum);
3064 _M_cp[_M_cp.size() - 1] = 1.0;
3067 template<
typename _RealType>
3068 template<
typename _InputIteratorB,
typename _InputIteratorW>
3069 piecewise_linear_distribution<_RealType>::param_type::
3070 param_type(_InputIteratorB __bbegin,
3071 _InputIteratorB __bend,
3072 _InputIteratorW __wbegin)
3073 : _M_int(), _M_den(), _M_cp(), _M_m()
3075 for (; __bbegin != __bend; ++__bbegin, ++__wbegin)
3077 _M_int.push_back(*__bbegin);
3078 _M_den.push_back(*__wbegin);
3084 template<
typename _RealType>
3085 template<
typename _Func>
3086 piecewise_linear_distribution<_RealType>::param_type::
3087 param_type(initializer_list<_RealType> __bl, _Func __fw)
3088 : _M_int(), _M_den(), _M_cp(), _M_m()
3090 _M_int.reserve(__bl.size());
3091 _M_den.reserve(__bl.size());
3092 for (
auto __biter = __bl.begin(); __biter != __bl.end(); ++__biter)
3094 _M_int.push_back(*__biter);
3095 _M_den.push_back(__fw(*__biter));
3101 template<
typename _RealType>
3102 template<
typename _Func>
3103 piecewise_linear_distribution<_RealType>::param_type::
3104 param_type(
size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
3105 : _M_int(), _M_den(), _M_cp(), _M_m()
3107 const size_t __n = __nw == 0 ? 1 : __nw;
3108 const _RealType __delta = (__xmax - __xmin) / __n;
3110 _M_int.reserve(__n + 1);
3111 _M_den.reserve(__n + 1);
3112 for (
size_t __k = 0; __k <= __nw; ++__k)
3114 _M_int.push_back(__xmin + __k * __delta);
3115 _M_den.push_back(__fw(_M_int[__k] + __delta));
3121 template<
typename _RealType>
3122 template<
typename _UniformRandomNumberGenerator>
3123 typename piecewise_linear_distribution<_RealType>::result_type
3124 piecewise_linear_distribution<_RealType>::
3125 operator()(_UniformRandomNumberGenerator& __urng,
3126 const param_type& __param)
3128 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
3131 const double __p = __aurng();
3132 if (__param._M_cp.empty())
3135 auto __pos = std::lower_bound(__param._M_cp.begin(),
3136 __param._M_cp.end(), __p);
3137 const size_t __i = __pos - __param._M_cp.begin();
3139 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
3141 const double __a = 0.5 * __param._M_m[__i];
3142 const double __b = __param._M_den[__i];
3143 const double __cm = __p - __pref;
3145 _RealType __x = __param._M_int[__i];
3150 const double __d = __b * __b + 4.0 * __a * __cm;
3151 __x += 0.5 * (
std::sqrt(__d) - __b) / __a;
3157 template<
typename _RealType>
3158 template<
typename _ForwardIterator,
3159 typename _UniformRandomNumberGenerator>
3161 piecewise_linear_distribution<_RealType>::
3162 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3163 _UniformRandomNumberGenerator& __urng,
3164 const param_type& __param)
3166 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3169 *__f++ = this->operator()(__urng, __param);
3172 template<
typename _RealType,
typename _CharT,
typename _Traits>
3175 const piecewise_linear_distribution<_RealType>& __x)
3177 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
3179 const typename __ios_base::fmtflags __flags = __os.
flags();
3180 const _CharT __fill = __os.
fill();
3182 const _CharT __space = __os.
widen(
' ');
3183 __os.
flags(__ios_base::scientific | __ios_base::left);
3188 __os << __int.
size() - 1;
3190 for (
auto __xit = __int.
begin(); __xit != __int.
end(); ++__xit)
3191 __os << __space << *__xit;
3194 for (
auto __dit = __den.
begin(); __dit != __den.
end(); ++__dit)
3195 __os << __space << *__dit;
3197 __os.
flags(__flags);
3203 template<
typename _RealType,
typename _CharT,
typename _Traits>
3206 piecewise_linear_distribution<_RealType>& __x)
3208 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
3210 const typename __ios_base::fmtflags __flags = __is.
flags();
3211 __is.
flags(__ios_base::dec | __ios_base::skipws);
3216 vector<_RealType> __int_vec;
3217 if (__detail::__extract_params(__is, __int_vec, __n + 1))
3219 vector<double> __den_vec;
3220 if (__detail::__extract_params(__is, __den_vec, __n + 1))
3222 __x.param({ __int_vec.begin(), __int_vec.end(),
3223 __den_vec.begin() });
3227 __is.
flags(__flags);
3232 template<
typename _IntType,
typename>
3235 _M_v.reserve(__il.size());
3236 for (
auto __iter = __il.begin(); __iter != __il.end(); ++__iter)
3237 _M_v.push_back(__detail::__mod<result_type,
3238 __detail::_Shift<result_type, 32>::__value>(*__iter));
3241 template<
typename _InputIterator>
3242 seed_seq::seed_seq(_InputIterator __begin, _InputIterator __end)
3244 if _GLIBCXX17_CONSTEXPR (__is_random_access_iter<_InputIterator>::value)
3247 for (_InputIterator __iter = __begin; __iter != __end; ++__iter)
3248 _M_v.push_back(__detail::__mod<result_type,
3249 __detail::_Shift<result_type, 32>::__value>(*__iter));
3252 template<
typename _RandomAccessIterator>
3254 seed_seq::generate(_RandomAccessIterator __begin,
3255 _RandomAccessIterator __end)
3257 typedef typename iterator_traits<_RandomAccessIterator>::value_type
3260 if (__begin == __end)
3263 std::fill(__begin, __end, _Type(0x8b8b8b8bu));
3265 const size_t __n = __end - __begin;
3266 const size_t __s = _M_v.size();
3267 const size_t __t = (__n >= 623) ? 11
3272 const size_t __p = (__n - __t) / 2;
3273 const size_t __q = __p + __t;
3274 const size_t __m =
std::max(
size_t(__s + 1), __n);
3276#ifndef __UINT32_TYPE__
3279 _Up(uint_least32_t v) : _M_v(v & 0xffffffffu) { }
3281 operator uint_least32_t()
const {
return _M_v; }
3283 uint_least32_t _M_v;
3285 using uint32_t = _Up;
3290 uint32_t __r1 = 1371501266u;
3291 uint32_t __r2 = __r1 + __s;
3292 __begin[__p] += __r1;
3293 __begin[__q] = (uint32_t)__begin[__q] + __r2;
3297 for (
size_t __k = 1; __k <= __s; ++__k)
3299 const size_t __kn = __k % __n;
3300 const size_t __kpn = (__k + __p) % __n;
3301 const size_t __kqn = (__k + __q) % __n;
3302 uint32_t __arg = (__begin[__kn]
3304 ^ __begin[(__k - 1) % __n]);
3305 uint32_t __r1 = 1664525u * (__arg ^ (__arg >> 27));
3306 uint32_t __r2 = __r1 + (uint32_t)__kn + _M_v[__k - 1];
3307 __begin[__kpn] = (uint32_t)__begin[__kpn] + __r1;
3308 __begin[__kqn] = (uint32_t)__begin[__kqn] + __r2;
3309 __begin[__kn] = __r2;
3312 for (
size_t __k = __s + 1; __k < __m; ++__k)
3314 const size_t __kn = __k % __n;
3315 const size_t __kpn = (__k + __p) % __n;
3316 const size_t __kqn = (__k + __q) % __n;
3317 uint32_t __arg = (__begin[__kn]
3319 ^ __begin[(__k - 1) % __n]);
3320 uint32_t __r1 = 1664525u * (__arg ^ (__arg >> 27));
3321 uint32_t __r2 = __r1 + (uint32_t)__kn;
3322 __begin[__kpn] = (uint32_t)__begin[__kpn] + __r1;
3323 __begin[__kqn] = (uint32_t)__begin[__kqn] + __r2;
3324 __begin[__kn] = __r2;
3327 for (
size_t __k = __m; __k < __m + __n; ++__k)
3329 const size_t __kn = __k % __n;
3330 const size_t __kpn = (__k + __p) % __n;
3331 const size_t __kqn = (__k + __q) % __n;
3332 uint32_t __arg = (__begin[__kn]
3334 + __begin[(__k - 1) % __n]);
3335 uint32_t __r3 = 1566083941u * (__arg ^ (__arg >> 27));
3336 uint32_t __r4 = __r3 - __kn;
3337 __begin[__kpn] ^= __r3;
3338 __begin[__kqn] ^= __r4;
3339 __begin[__kn] = __r4;
3343 template<
typename _RealType,
size_t __bits,
3344 typename _UniformRandomNumberGenerator>
3349 "template argument must be a floating point type");
3354 const long double __r =
static_cast<long double>(__urng.max())
3355 -
static_cast<long double>(__urng.min()) + 1.0L;
3357 const size_t __m = std::max<size_t>(1UL,
3358 (__b + __log2r - 1UL) / __log2r);
3360 _RealType __sum = _RealType(0);
3361 _RealType __tmp = _RealType(1);
3362 for (
size_t __k = __m; __k != 0; --__k)
3364 __sum += _RealType(__urng() - __urng.min()) * __tmp;
3367 __ret = __sum / __tmp;
3368 if (__builtin_expect(__ret >= _RealType(1), 0))
3370#if _GLIBCXX_USE_C99_MATH_TR1
3371 __ret = std::nextafter(_RealType(1), _RealType(0));
3373 __ret = _RealType(1)
3380_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.
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.
static constexpr bool is_integer
static constexpr int digits
static constexpr bool is_signed
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=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.
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 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 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.
Parallel STL function calls corresponding to stl_numeric.h. The functions defined here mainly do case...