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 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
98 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
102 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
106 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
108 linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed;
114 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
119 if ((__detail::__mod<_UIntType, __m>(__c) == 0)
120 && (__detail::__mod<_UIntType, __m>(__s) == 0))
123 _M_x = __detail::__mod<_UIntType, __m>(__s);
129 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
130 template<
typename _Sseq>
134 -> _If_seed_seq<_Sseq>
138 const _UIntType __k = (__k0 + 31) / 32;
139 uint_least32_t __arr[__k + 3];
140 __q.generate(__arr + 0, __arr + __k + 3);
141 _UIntType __factor = 1u;
142 _UIntType __sum = 0u;
143 for (
size_t __j = 0; __j < __k; ++__j)
145 __sum += __arr[__j + 3] * __factor;
146 __factor *= __detail::_Shift<_UIntType, 32>::__value;
151 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m,
152 typename _CharT,
typename _Traits>
156 __a, __c, __m>& __lcr)
160 const typename __ios_base::fmtflags __flags = __os.
flags();
161 const _CharT __fill = __os.
fill();
162 __os.
flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
172 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m,
173 typename _CharT,
typename _Traits>
176 linear_congruential_engine<_UIntType, __a, __c, __m>& __lcr)
178 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
180 const typename __ios_base::fmtflags __flags = __is.
flags();
181 __is.
flags(__ios_base::dec);
190 template<
typename _UIntType,
191 size_t __w,
size_t __n,
size_t __m,
size_t __r,
192 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
193 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
196 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
197 __s, __b, __t, __c, __l, __f>::word_size;
199 template<
typename _UIntType,
200 size_t __w,
size_t __n,
size_t __m,
size_t __r,
201 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
202 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
205 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
206 __s, __b, __t, __c, __l, __f>::state_size;
208 template<
typename _UIntType,
209 size_t __w,
size_t __n,
size_t __m,
size_t __r,
210 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
211 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
214 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
215 __s, __b, __t, __c, __l, __f>::shift_size;
217 template<
typename _UIntType,
218 size_t __w,
size_t __n,
size_t __m,
size_t __r,
219 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
220 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
223 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
224 __s, __b, __t, __c, __l, __f>::mask_bits;
226 template<
typename _UIntType,
227 size_t __w,
size_t __n,
size_t __m,
size_t __r,
228 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
229 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
232 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
233 __s, __b, __t, __c, __l, __f>::xor_mask;
235 template<
typename _UIntType,
236 size_t __w,
size_t __n,
size_t __m,
size_t __r,
237 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
238 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
241 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
242 __s, __b, __t, __c, __l, __f>::tempering_u;
244 template<
typename _UIntType,
245 size_t __w,
size_t __n,
size_t __m,
size_t __r,
246 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
247 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
250 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
251 __s, __b, __t, __c, __l, __f>::tempering_d;
253 template<
typename _UIntType,
254 size_t __w,
size_t __n,
size_t __m,
size_t __r,
255 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
256 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
259 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
260 __s, __b, __t, __c, __l, __f>::tempering_s;
262 template<
typename _UIntType,
263 size_t __w,
size_t __n,
size_t __m,
size_t __r,
264 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
265 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
268 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
269 __s, __b, __t, __c, __l, __f>::tempering_b;
271 template<
typename _UIntType,
272 size_t __w,
size_t __n,
size_t __m,
size_t __r,
273 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
274 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
277 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
278 __s, __b, __t, __c, __l, __f>::tempering_t;
280 template<
typename _UIntType,
281 size_t __w,
size_t __n,
size_t __m,
size_t __r,
282 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
283 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
286 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
287 __s, __b, __t, __c, __l, __f>::tempering_c;
289 template<
typename _UIntType,
290 size_t __w,
size_t __n,
size_t __m,
size_t __r,
291 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
292 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
295 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
296 __s, __b, __t, __c, __l, __f>::tempering_l;
298 template<
typename _UIntType,
299 size_t __w,
size_t __n,
size_t __m,
size_t __r,
300 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
301 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
304 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
305 __s, __b, __t, __c, __l, __f>::
306 initialization_multiplier;
308 template<
typename _UIntType,
309 size_t __w,
size_t __n,
size_t __m,
size_t __r,
310 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
311 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
314 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
315 __s, __b, __t, __c, __l, __f>::default_seed;
317 template<
typename _UIntType,
318 size_t __w,
size_t __n,
size_t __m,
size_t __r,
319 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
320 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
323 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
324 __s, __b, __t, __c, __l, __f>::
325 seed(result_type __sd)
327 _M_x[0] = __detail::__mod<_UIntType,
328 __detail::_Shift<_UIntType, __w>::__value>(__sd);
330 for (
size_t __i = 1; __i < state_size; ++__i)
332 _UIntType __x = _M_x[__i - 1];
333 __x ^= __x >> (__w - 2);
335 __x += __detail::__mod<_UIntType, __n>(__i);
336 _M_x[__i] = __detail::__mod<_UIntType,
337 __detail::_Shift<_UIntType, __w>::__value>(__x);
342 template<
typename _UIntType,
343 size_t __w,
size_t __n,
size_t __m,
size_t __r,
344 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
345 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
347 template<
typename _Sseq>
349 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
350 __s, __b, __t, __c, __l, __f>::
352 -> _If_seed_seq<_Sseq>
354 const _UIntType __upper_mask = (~_UIntType()) << __r;
355 const size_t __k = (__w + 31) / 32;
356 uint_least32_t __arr[__n * __k];
357 __q.generate(__arr + 0, __arr + __n * __k);
360 for (
size_t __i = 0; __i < state_size; ++__i)
362 _UIntType __factor = 1u;
363 _UIntType __sum = 0u;
364 for (
size_t __j = 0; __j < __k; ++__j)
366 __sum += __arr[__k * __i + __j] * __factor;
367 __factor *= __detail::_Shift<_UIntType, 32>::__value;
369 _M_x[__i] = __detail::__mod<_UIntType,
370 __detail::_Shift<_UIntType, __w>::__value>(__sum);
376 if ((_M_x[0] & __upper_mask) != 0u)
379 else if (_M_x[__i] != 0u)
384 _M_x[0] = __detail::_Shift<_UIntType, __w - 1>::__value;
388 template<
typename _UIntType,
size_t __w,
389 size_t __n,
size_t __m,
size_t __r,
390 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
391 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
394 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
395 __s, __b, __t, __c, __l, __f>::
398 const _UIntType __upper_mask = (~_UIntType()) << __r;
399 const _UIntType __lower_mask = ~__upper_mask;
401 for (
size_t __k = 0; __k < (__n - __m); ++__k)
403 _UIntType __y = ((_M_x[__k] & __upper_mask)
404 | (_M_x[__k + 1] & __lower_mask));
405 _M_x[__k] = (_M_x[__k + __m] ^ (__y >> 1)
406 ^ ((__y & 0x01) ? __a : 0));
409 for (
size_t __k = (__n - __m); __k < (__n - 1); ++__k)
411 _UIntType __y = ((_M_x[__k] & __upper_mask)
412 | (_M_x[__k + 1] & __lower_mask));
413 _M_x[__k] = (_M_x[__k + (__m - __n)] ^ (__y >> 1)
414 ^ ((__y & 0x01) ? __a : 0));
417 _UIntType __y = ((_M_x[__n - 1] & __upper_mask)
418 | (_M_x[0] & __lower_mask));
419 _M_x[__n - 1] = (_M_x[__m - 1] ^ (__y >> 1)
420 ^ ((__y & 0x01) ? __a : 0));
424 template<
typename _UIntType,
size_t __w,
425 size_t __n,
size_t __m,
size_t __r,
426 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
427 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
430 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
431 __s, __b, __t, __c, __l, __f>::
432 discard(
unsigned long long __z)
434 while (__z > state_size - _M_p)
436 __z -= state_size - _M_p;
442 template<
typename _UIntType,
size_t __w,
443 size_t __n,
size_t __m,
size_t __r,
444 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
445 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
449 __s, __b, __t, __c, __l, __f>::result_type
451 __s, __b, __t, __c, __l, __f>::
455 if (_M_p >= state_size)
459 result_type __z = _M_x[_M_p++];
460 __z ^= (__z >> __u) & __d;
461 __z ^= (__z << __s) & __b;
462 __z ^= (__z << __t) & __c;
468 template<
typename _UIntType,
size_t __w,
469 size_t __n,
size_t __m,
size_t __r,
470 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
471 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
472 _UIntType __f,
typename _CharT,
typename _Traits>
475 const mersenne_twister_engine<_UIntType, __w, __n, __m,
476 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __x)
478 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
480 const typename __ios_base::fmtflags __flags = __os.
flags();
481 const _CharT __fill = __os.
fill();
482 const _CharT __space = __os.
widen(
' ');
483 __os.
flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
486 for (
size_t __i = 0; __i < __n; ++__i)
487 __os << __x._M_x[__i] << __space;
495 template<
typename _UIntType,
size_t __w,
496 size_t __n,
size_t __m,
size_t __r,
497 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
498 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
499 _UIntType __f,
typename _CharT,
typename _Traits>
502 mersenne_twister_engine<_UIntType, __w, __n, __m,
503 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __x)
505 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
507 const typename __ios_base::fmtflags __flags = __is.
flags();
508 __is.
flags(__ios_base::dec | __ios_base::skipws);
510 for (
size_t __i = 0; __i < __n; ++__i)
511 __is >> __x._M_x[__i];
519 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
521 subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size;
523 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
525 subtract_with_carry_engine<_UIntType, __w, __s, __r>::short_lag;
527 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
529 subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag;
531 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
533 subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed;
535 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
541 __lcg(__value == 0u ? default_seed : __value);
543 const size_t __n = (__w + 31) / 32;
545 for (
size_t __i = 0; __i < long_lag; ++__i)
547 _UIntType __sum = 0u;
548 _UIntType __factor = 1u;
549 for (
size_t __j = 0; __j < __n; ++__j)
551 __sum += __detail::__mod<uint_least32_t,
552 __detail::_Shift<uint_least32_t, 32>::__value>
553 (__lcg()) * __factor;
554 __factor *= __detail::_Shift<_UIntType, 32>::__value;
556 _M_x[__i] = __detail::__mod<_UIntType,
557 __detail::_Shift<_UIntType, __w>::__value>(__sum);
559 _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
563 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
564 template<
typename _Sseq>
568 -> _If_seed_seq<_Sseq>
570 const size_t __k = (__w + 31) / 32;
571 uint_least32_t __arr[__r * __k];
572 __q.generate(__arr + 0, __arr + __r * __k);
574 for (
size_t __i = 0; __i < long_lag; ++__i)
576 _UIntType __sum = 0u;
577 _UIntType __factor = 1u;
578 for (
size_t __j = 0; __j < __k; ++__j)
580 __sum += __arr[__k * __i + __j] * __factor;
581 __factor *= __detail::_Shift<_UIntType, 32>::__value;
583 _M_x[__i] = __detail::__mod<_UIntType,
584 __detail::_Shift<_UIntType, __w>::__value>(__sum);
586 _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
590 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
597 long __ps = _M_p - short_lag;
605 if (_M_x[__ps] >= _M_x[_M_p] + _M_carry)
607 __xi = _M_x[__ps] - _M_x[_M_p] - _M_carry;
612 __xi = (__detail::_Shift<_UIntType, __w>::__value
613 - _M_x[_M_p] - _M_carry + _M_x[__ps]);
619 if (++_M_p >= long_lag)
625 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r,
626 typename _CharT,
typename _Traits>
634 const typename __ios_base::fmtflags __flags = __os.
flags();
635 const _CharT __fill = __os.
fill();
636 const _CharT __space = __os.
widen(
' ');
637 __os.
flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
640 for (
size_t __i = 0; __i < __r; ++__i)
641 __os << __x._M_x[__i] << __space;
642 __os << __x._M_carry << __space << __x._M_p;
649 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r,
650 typename _CharT,
typename _Traits>
653 subtract_with_carry_engine<_UIntType, __w, __s, __r>& __x)
655 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
657 const typename __ios_base::fmtflags __flags = __is.
flags();
658 __is.
flags(__ios_base::dec | __ios_base::skipws);
660 for (
size_t __i = 0; __i < __r; ++__i)
661 __is >> __x._M_x[__i];
662 __is >> __x._M_carry;
670 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
672 discard_block_engine<_RandomNumberEngine, __p, __r>::block_size;
674 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
676 discard_block_engine<_RandomNumberEngine, __p, __r>::used_block;
678 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
679 typename discard_block_engine<_RandomNumberEngine,
680 __p, __r>::result_type
684 if (_M_n >= used_block)
686 _M_b.discard(block_size - _M_n);
693 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r,
694 typename _CharT,
typename _Traits>
702 const typename __ios_base::fmtflags __flags = __os.
flags();
703 const _CharT __fill = __os.
fill();
704 const _CharT __space = __os.
widen(
' ');
705 __os.
flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
708 __os << __x.base() << __space << __x._M_n;
715 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r,
716 typename _CharT,
typename _Traits>
719 discard_block_engine<_RandomNumberEngine, __p, __r>& __x)
721 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
723 const typename __ios_base::fmtflags __flags = __is.
flags();
724 __is.
flags(__ios_base::dec | __ios_base::skipws);
726 __is >> __x._M_b >> __x._M_n;
733 template<
typename _RandomNumberEngine,
size_t __w,
typename _UIntType>
734 typename independent_bits_engine<_RandomNumberEngine, __w, _UIntType>::
739 typedef typename _RandomNumberEngine::result_type _Eresult_type;
740 const _Eresult_type __r
742 ? _M_b.max() - _M_b.min() + 1 : 0);
744 const unsigned __m = __r ?
std::__lg(__r) : __edig;
751 __ctype __s0, __s1, __y0, __y1;
753 for (
size_t __i = 0; __i < 2; ++__i)
755 __n = (__w + __m - 1) / __m + __i;
756 __n0 = __n - __w % __n;
757 const unsigned __w0 = __w / __n;
763 __s0 = __ctype(1) << __w0;
771 __y0 = __s0 * (__r / __s0);
773 __y1 = __s1 * (__r / __s1);
775 if (__r - __y0 <= __y0 / __n)
783 for (
size_t __k = 0; __k < __n0; ++__k)
787 __u = _M_b() - _M_b.
min();
788 while (__y0 && __u >= __y0);
789 __sum = __s0 * __sum + (__s0 ? __u % __s0 : __u);
791 for (
size_t __k = __n0; __k < __n; ++__k)
795 __u = _M_b() - _M_b.min();
796 while (__y1 && __u >= __y1);
797 __sum = __s1 * __sum + (__s1 ? __u % __s1 : __u);
803 template<
typename _RandomNumberEngine,
size_t __k>
810 template<
typename _Tp>
812 __representable_as_double(_Tp __x)
noexcept
817 return (__x <= (1ull << __DBL_MANT_DIG__))
819 || (!(__x & 1) && __detail::__representable_as_double(__x >> 1));
823 template<
typename _Tp>
825 __p1_representable_as_double(_Tp __x)
noexcept
831 && __detail::__representable_as_double(__x + 1u));
835 template<
typename _RandomNumberEngine,
size_t __k>
844 if _GLIBCXX17_CONSTEXPR (__detail::__p1_representable_as_double(__range))
845 __j *= __y / (__range + 1.0);
847 __j *= __y / (__range + 1.0L);
854 template<
typename _RandomNumberEngine,
size_t __k,
855 typename _CharT,
typename _Traits>
862 const typename __ios_base::fmtflags __flags = __os.
flags();
863 const _CharT __fill = __os.
fill();
864 const _CharT __space = __os.
widen(
' ');
865 __os.
flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
869 for (
size_t __i = 0; __i < __k; ++__i)
870 __os << __space << __x._M_v[__i];
871 __os << __space << __x._M_y;
878 template<
typename _RandomNumberEngine,
size_t __k,
879 typename _CharT,
typename _Traits>
886 const typename __ios_base::fmtflags __flags = __is.
flags();
887 __is.
flags(__ios_base::dec | __ios_base::skipws);
890 for (
size_t __i = 0; __i < __k; ++__i)
891 __is >> __x._M_v[__i];
899 template<
typename _IntType,
typename _CharT,
typename _Traits>
902 const uniform_int_distribution<_IntType>& __x)
904 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
906 const typename __ios_base::fmtflags __flags = __os.
flags();
907 const _CharT __fill = __os.
fill();
908 const _CharT __space = __os.
widen(
' ');
909 __os.
flags(__ios_base::scientific | __ios_base::left);
912 __os << __x.a() << __space << __x.b();
919 template<
typename _IntType,
typename _CharT,
typename _Traits>
928 const typename __ios_base::fmtflags __flags = __is.
flags();
929 __is.
flags(__ios_base::dec | __ios_base::skipws);
932 if (__is >> __a >> __b)
933 __x.
param(param_type(__a, __b));
940 template<
typename _RealType>
941 template<
typename _ForwardIterator,
942 typename _UniformRandomNumberGenerator>
946 _UniformRandomNumberGenerator& __urng,
947 const param_type& __p)
949 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
950 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
952 auto __range = __p.b() - __p.a();
954 *__f++ = __aurng() * __range + __p.a();
957 template<
typename _RealType,
typename _CharT,
typename _Traits>
960 const uniform_real_distribution<_RealType>& __x)
962 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
964 const typename __ios_base::fmtflags __flags = __os.
flags();
965 const _CharT __fill = __os.
fill();
967 const _CharT __space = __os.
widen(
' ');
968 __os.
flags(__ios_base::scientific | __ios_base::left);
972 __os << __x.a() << __space << __x.b();
980 template<
typename _RealType,
typename _CharT,
typename _Traits>
989 const typename __ios_base::fmtflags __flags = __is.
flags();
990 __is.
flags(__ios_base::skipws);
993 if (__is >> __a >> __b)
994 __x.
param(param_type(__a, __b));
1001 template<
typename _ForwardIterator,
1002 typename _UniformRandomNumberGenerator>
1004 std::bernoulli_distribution::
1005 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1006 _UniformRandomNumberGenerator& __urng,
1007 const param_type& __p)
1009 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1010 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1012 auto __limit = __p.p() * (__aurng.max() - __aurng.min());
1015 *__f++ = (__aurng() - __aurng.min()) < __limit;
1018 template<
typename _CharT,
typename _Traits>
1021 const bernoulli_distribution& __x)
1023 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1025 const typename __ios_base::fmtflags __flags = __os.
flags();
1026 const _CharT __fill = __os.
fill();
1028 __os.
flags(__ios_base::scientific | __ios_base::left);
1034 __os.
flags(__flags);
1041 template<
typename _IntType>
1042 template<
typename _UniformRandomNumberGenerator>
1045 operator()(_UniformRandomNumberGenerator& __urng,
1046 const param_type& __param)
1050 const double __naf =
1053 const double __thr =
1055 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1060 __cand = std::floor(
std::log(1.0 - __aurng()) / __param._M_log_1_p);
1061 while (__cand >= __thr);
1063 return result_type(__cand + __naf);
1066 template<
typename _IntType>
1067 template<
typename _ForwardIterator,
1068 typename _UniformRandomNumberGenerator>
1072 _UniformRandomNumberGenerator& __urng,
1073 const param_type& __param)
1075 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1078 const double __naf =
1081 const double __thr =
1083 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1090 __cand = std::floor(
std::log(1.0 - __aurng())
1091 / __param._M_log_1_p);
1092 while (__cand >= __thr);
1094 *__f++ = __cand + __naf;
1098 template<
typename _IntType,
1099 typename _CharT,
typename _Traits>
1102 const geometric_distribution<_IntType>& __x)
1104 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1106 const typename __ios_base::fmtflags __flags = __os.
flags();
1107 const _CharT __fill = __os.
fill();
1109 __os.
flags(__ios_base::scientific | __ios_base::left);
1115 __os.
flags(__flags);
1121 template<
typename _IntType,
1122 typename _CharT,
typename _Traits>
1130 const typename __ios_base::fmtflags __flags = __is.
flags();
1131 __is.
flags(__ios_base::skipws);
1135 __x.
param(param_type(__p));
1137 __is.
flags(__flags);
1142 template<
typename _IntType>
1143 template<
typename _UniformRandomNumberGenerator>
1146 operator()(_UniformRandomNumberGenerator& __urng)
1148 const double __y = _M_gd(__urng);
1152 return __poisson(__urng);
1155 template<
typename _IntType>
1156 template<
typename _UniformRandomNumberGenerator>
1159 operator()(_UniformRandomNumberGenerator& __urng,
1160 const param_type& __p)
1166 _M_gd(__urng, param_type(__p.k(), (1.0 - __p.p()) / __p.p()));
1169 return __poisson(__urng);
1172 template<
typename _IntType>
1173 template<
typename _ForwardIterator,
1174 typename _UniformRandomNumberGenerator>
1176 negative_binomial_distribution<_IntType>::
1177 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1178 _UniformRandomNumberGenerator& __urng)
1180 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1183 const double __y = _M_gd(__urng);
1187 *__f++ = __poisson(__urng);
1191 template<
typename _IntType>
1192 template<
typename _ForwardIterator,
1193 typename _UniformRandomNumberGenerator>
1195 negative_binomial_distribution<_IntType>::
1196 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1197 _UniformRandomNumberGenerator& __urng,
1198 const param_type& __p)
1200 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1202 __p2(__p.k(), (1.0 - __p.p()) / __p.p());
1206 const double __y = _M_gd(__urng, __p2);
1209 *__f++ = __poisson(__urng);
1213 template<
typename _IntType,
typename _CharT,
typename _Traits>
1216 const negative_binomial_distribution<_IntType>& __x)
1218 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1220 const typename __ios_base::fmtflags __flags = __os.
flags();
1221 const _CharT __fill = __os.
fill();
1223 const _CharT __space = __os.
widen(
' ');
1224 __os.
flags(__ios_base::scientific | __ios_base::left);
1228 __os << __x.k() << __space << __x.p()
1229 << __space << __x._M_gd;
1231 __os.
flags(__flags);
1237 template<
typename _IntType,
typename _CharT,
typename _Traits>
1240 negative_binomial_distribution<_IntType>& __x)
1243 =
typename negative_binomial_distribution<_IntType>::param_type;
1244 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1246 const typename __ios_base::fmtflags __flags = __is.
flags();
1247 __is.
flags(__ios_base::skipws);
1251 if (__is >> __k >> __p >> __x._M_gd)
1252 __x.param(param_type(__k, __p));
1254 __is.
flags(__flags);
1259 template<
typename _IntType>
1261 poisson_distribution<_IntType>::param_type::
1264#if _GLIBCXX_USE_C99_MATH_TR1
1267 const double __m = std::floor(_M_mean);
1269 _M_lfm = std::lgamma(__m + 1);
1272 const double __pi_4 = 0.7853981633974483096156608458198757L;
1275 _M_d = std::round(std::max<double>(6.0,
std::min(__m, __dx)));
1276 const double __cx = 2 * __m + _M_d;
1281 _M_cb = 2 * __cx *
std::exp(-_M_d * _M_1cx * (1 + _M_d / 2))
1299 template<
typename _IntType>
1300 template<
typename _UniformRandomNumberGenerator>
1303 operator()(_UniformRandomNumberGenerator& __urng,
1306 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1308#if _GLIBCXX_USE_C99_MATH_TR1
1309 if (__param.mean() >= 12)
1314 const double __naf =
1316 const double __thr =
1319 const double __m = std::floor(__param.mean());
1321 const double __spi_2 = 1.2533141373155002512078826424055226L;
1322 const double __c1 = __param._M_sm * __spi_2;
1323 const double __c2 = __param._M_c2b + __c1;
1324 const double __c3 = __c2 + 1;
1325 const double __c4 = __c3 + 1;
1327 const double __178 = 0.0128205128205128205128205128205128L;
1329 const double __e178 = 1.0129030479320018583185514777512983L;
1330 const double __c5 = __c4 + __e178;
1331 const double __c = __param._M_cb + __c5;
1332 const double __2cx = 2 * (2 * __m + __param._M_d);
1334 bool __reject =
true;
1337 const double __u = __c * __aurng();
1338 const double __e = -
std::log(1.0 - __aurng());
1344 const double __n = _M_nd(__urng);
1345 const double __y = -
std::abs(__n) * __param._M_sm - 1;
1346 __x = std::floor(__y);
1347 __w = -__n * __n / 2;
1351 else if (__u <= __c2)
1353 const double __n = _M_nd(__urng);
1354 const double __y = 1 +
std::abs(__n) * __param._M_scx;
1355 __x = std::ceil(__y);
1356 __w = __y * (2 - __y) * __param._M_1cx;
1357 if (__x > __param._M_d)
1360 else if (__u <= __c3)
1364 else if (__u <= __c4)
1366 else if (__u <= __c5)
1374 const double __v = -
std::log(1.0 - __aurng());
1375 const double __y = __param._M_d
1376 + __v * __2cx / __param._M_d;
1377 __x = std::ceil(__y);
1378 __w = -__param._M_d * __param._M_1cx * (1 + __y / 2);
1381 __reject = (__w - __e - __x * __param._M_lm_thr
1382 > __param._M_lfm - std::lgamma(__x + __m + 1));
1384 __reject |= __x + __m >= __thr;
1394 double __prod = 1.0;
1398 __prod *= __aurng();
1401 while (__prod > __param._M_lm_thr);
1407 template<
typename _IntType>
1408 template<
typename _ForwardIterator,
1409 typename _UniformRandomNumberGenerator>
1413 _UniformRandomNumberGenerator& __urng,
1414 const param_type& __param)
1416 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1422 template<
typename _IntType,
1423 typename _CharT,
typename _Traits>
1426 const poisson_distribution<_IntType>& __x)
1428 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1430 const typename __ios_base::fmtflags __flags = __os.
flags();
1431 const _CharT __fill = __os.
fill();
1433 const _CharT __space = __os.
widen(
' ');
1434 __os.
flags(__ios_base::scientific | __ios_base::left);
1438 __os << __x.mean() << __space << __x._M_nd;
1440 __os.
flags(__flags);
1446 template<
typename _IntType,
1447 typename _CharT,
typename _Traits>
1450 poisson_distribution<_IntType>& __x)
1452 using param_type =
typename poisson_distribution<_IntType>::param_type;
1453 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1455 const typename __ios_base::fmtflags __flags = __is.
flags();
1456 __is.
flags(__ios_base::skipws);
1459 if (__is >> __mean >> __x._M_nd)
1460 __x.param(param_type(__mean));
1462 __is.
flags(__flags);
1467 template<
typename _IntType>
1469 binomial_distribution<_IntType>::param_type::
1472 const double __p12 = _M_p <= 0.5 ? _M_p : 1.0 - _M_p;
1476#if _GLIBCXX_USE_C99_MATH_TR1
1477 if (_M_t * __p12 >= 8)
1480 const double __np = std::floor(_M_t * __p12);
1481 const double __pa = __np / _M_t;
1482 const double __1p = 1 - __pa;
1484 const double __pi_4 = 0.7853981633974483096156608458198757L;
1485 const double __d1x =
1487 / (81 * __pi_4 * __1p)));
1488 _M_d1 = std::round(std::max<double>(1.0, __d1x));
1489 const double __d2x =
1491 / (__pi_4 * __pa)));
1492 _M_d2 = std::round(std::max<double>(1.0, __d2x));
1495 const double __spi_2 = 1.2533141373155002512078826424055226L;
1496 _M_s1 =
std::sqrt(__np * __1p) * (1 + _M_d1 / (4 * __np));
1497 _M_s2 =
std::sqrt(__np * __1p) * (1 + _M_d2 / (4 * _M_t * __1p));
1498 _M_c = 2 * _M_d1 / __np;
1499 _M_a1 =
std::exp(_M_c) * _M_s1 * __spi_2;
1500 const double __a12 = _M_a1 + _M_s2 * __spi_2;
1501 const double __s1s = _M_s1 * _M_s1;
1502 _M_a123 = __a12 + (
std::exp(_M_d1 / (_M_t * __1p))
1504 *
std::exp(-_M_d1 * _M_d1 / (2 * __s1s)));
1505 const double __s2s = _M_s2 * _M_s2;
1506 _M_s = (_M_a123 + 2 * __s2s / _M_d2
1507 *
std::exp(-_M_d2 * _M_d2 / (2 * __s2s)));
1508 _M_lf = (std::lgamma(__np + 1)
1509 + std::lgamma(_M_t - __np + 1));
1512 _M_q = -
std::log(1 - (__p12 - __pa) / __1p);
1519 template<
typename _IntType>
1520 template<
typename _UniformRandomNumberGenerator>
1522 binomial_distribution<_IntType>::
1523 _M_waiting(_UniformRandomNumberGenerator& __urng,
1524 _IntType __t,
double __q)
1528 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1535 const double __e = -
std::log(1.0 - __aurng());
1536 __sum += __e / (__t - __x);
1539 while (__sum <= __q);
1554 template<
typename _IntType>
1555 template<
typename _UniformRandomNumberGenerator>
1558 operator()(_UniformRandomNumberGenerator& __urng,
1562 const _IntType __t = __param.t();
1563 const double __p = __param.p();
1564 const double __p12 = __p <= 0.5 ? __p : 1.0 - __p;
1565 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1568#if _GLIBCXX_USE_C99_MATH_TR1
1569 if (!__param._M_easy)
1574 const double __naf =
1576 const double __thr =
1579 const double __np = std::floor(__t * __p12);
1582 const double __spi_2 = 1.2533141373155002512078826424055226L;
1583 const double __a1 = __param._M_a1;
1584 const double __a12 = __a1 + __param._M_s2 * __spi_2;
1585 const double __a123 = __param._M_a123;
1586 const double __s1s = __param._M_s1 * __param._M_s1;
1587 const double __s2s = __param._M_s2 * __param._M_s2;
1592 const double __u = __param._M_s * __aurng();
1598 const double __n = _M_nd(__urng);
1599 const double __y = __param._M_s1 *
std::abs(__n);
1600 __reject = __y >= __param._M_d1;
1603 const double __e = -
std::log(1.0 - __aurng());
1604 __x = std::floor(__y);
1605 __v = -__e - __n * __n / 2 + __param._M_c;
1608 else if (__u <= __a12)
1610 const double __n = _M_nd(__urng);
1611 const double __y = __param._M_s2 *
std::abs(__n);
1612 __reject = __y >= __param._M_d2;
1615 const double __e = -
std::log(1.0 - __aurng());
1616 __x = std::floor(-__y);
1617 __v = -__e - __n * __n / 2;
1620 else if (__u <= __a123)
1622 const double __e1 = -
std::log(1.0 - __aurng());
1623 const double __e2 = -
std::log(1.0 - __aurng());
1625 const double __y = __param._M_d1
1626 + 2 * __s1s * __e1 / __param._M_d1;
1627 __x = std::floor(__y);
1628 __v = (-__e2 + __param._M_d1 * (1 / (__t - __np)
1629 -__y / (2 * __s1s)));
1634 const double __e1 = -
std::log(1.0 - __aurng());
1635 const double __e2 = -
std::log(1.0 - __aurng());
1637 const double __y = __param._M_d2
1638 + 2 * __s2s * __e1 / __param._M_d2;
1639 __x = std::floor(-__y);
1640 __v = -__e2 - __param._M_d2 * __y / (2 * __s2s);
1644 __reject = __reject || __x < -__np || __x > __t - __np;
1647 const double __lfx =
1648 std::lgamma(__np + __x + 1)
1649 + std::lgamma(__t - (__np + __x) + 1);
1650 __reject = __v > __param._M_lf - __lfx
1651 + __x * __param._M_lp1p;
1654 __reject |= __x + __np >= __thr;
1658 __x += __np + __naf;
1660 const _IntType __z = _M_waiting(__urng, __t - _IntType(__x),
1662 __ret = _IntType(__x) + __z;
1666 __ret = _M_waiting(__urng, __t, __param._M_q);
1669 __ret = __t - __ret;
1673 template<
typename _IntType>
1674 template<
typename _ForwardIterator,
1675 typename _UniformRandomNumberGenerator>
1679 _UniformRandomNumberGenerator& __urng,
1680 const param_type& __param)
1682 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1688 template<
typename _IntType,
1689 typename _CharT,
typename _Traits>
1692 const binomial_distribution<_IntType>& __x)
1694 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1696 const typename __ios_base::fmtflags __flags = __os.
flags();
1697 const _CharT __fill = __os.
fill();
1699 const _CharT __space = __os.
widen(
' ');
1700 __os.
flags(__ios_base::scientific | __ios_base::left);
1704 __os << __x.t() << __space << __x.p()
1705 << __space << __x._M_nd;
1707 __os.
flags(__flags);
1713 template<
typename _IntType,
1714 typename _CharT,
typename _Traits>
1717 binomial_distribution<_IntType>& __x)
1719 using param_type =
typename binomial_distribution<_IntType>::param_type;
1720 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1722 const typename __ios_base::fmtflags __flags = __is.
flags();
1723 __is.
flags(__ios_base::dec | __ios_base::skipws);
1727 if (__is >> __t >> __p >> __x._M_nd)
1728 __x.param(param_type(__t, __p));
1730 __is.
flags(__flags);
1735 template<
typename _RealType>
1736 template<
typename _ForwardIterator,
1737 typename _UniformRandomNumberGenerator>
1741 _UniformRandomNumberGenerator& __urng,
1742 const param_type& __p)
1744 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1745 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1751 template<
typename _RealType,
typename _CharT,
typename _Traits>
1754 const exponential_distribution<_RealType>& __x)
1756 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1758 const typename __ios_base::fmtflags __flags = __os.
flags();
1759 const _CharT __fill = __os.
fill();
1761 __os.
flags(__ios_base::scientific | __ios_base::left);
1765 __os << __x.lambda();
1767 __os.
flags(__flags);
1773 template<
typename _RealType,
typename _CharT,
typename _Traits>
1782 const typename __ios_base::fmtflags __flags = __is.
flags();
1783 __is.
flags(__ios_base::dec | __ios_base::skipws);
1786 if (__is >> __lambda)
1787 __x.
param(param_type(__lambda));
1789 __is.
flags(__flags);
1800 template<
typename _RealType>
1801 template<
typename _UniformRandomNumberGenerator>
1804 operator()(_UniformRandomNumberGenerator& __urng,
1808 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1811 if (_M_saved_available)
1813 _M_saved_available =
false;
1823 __r2 = __x * __x + __y * __y;
1825 while (__r2 > 1.0 || __r2 == 0.0);
1828 _M_saved = __x * __mult;
1829 _M_saved_available =
true;
1830 __ret = __y * __mult;
1833 __ret = __ret * __param.stddev() + __param.mean();
1837 template<
typename _RealType>
1838 template<
typename _ForwardIterator,
1839 typename _UniformRandomNumberGenerator>
1843 _UniformRandomNumberGenerator& __urng,
1844 const param_type& __param)
1846 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1851 if (_M_saved_available)
1853 _M_saved_available =
false;
1854 *__f++ = _M_saved * __param.stddev() + __param.mean();
1860 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1863 while (__f + 1 < __t)
1870 __r2 = __x * __x + __y * __y;
1872 while (__r2 > 1.0 || __r2 == 0.0);
1875 *__f++ = __y * __mult * __param.stddev() + __param.mean();
1876 *__f++ = __x * __mult * __param.stddev() + __param.mean();
1886 __r2 = __x * __x + __y * __y;
1888 while (__r2 > 1.0 || __r2 == 0.0);
1891 _M_saved = __x * __mult;
1892 _M_saved_available =
true;
1893 *__f = __y * __mult * __param.stddev() + __param.mean();
1897 template<
typename _RealType>
1902 if (__d1._M_param == __d2._M_param
1903 && __d1._M_saved_available == __d2._M_saved_available)
1905 if (__d1._M_saved_available
1906 && __d1._M_saved == __d2._M_saved)
1908 else if(!__d1._M_saved_available)
1917 template<
typename _RealType,
typename _CharT,
typename _Traits>
1920 const normal_distribution<_RealType>& __x)
1922 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1924 const typename __ios_base::fmtflags __flags = __os.
flags();
1925 const _CharT __fill = __os.
fill();
1927 const _CharT __space = __os.
widen(
' ');
1928 __os.
flags(__ios_base::scientific | __ios_base::left);
1932 __os << __x.mean() << __space << __x.stddev()
1933 << __space << __x._M_saved_available;
1934 if (__x._M_saved_available)
1935 __os << __space << __x._M_saved;
1937 __os.
flags(__flags);
1943 template<
typename _RealType,
typename _CharT,
typename _Traits>
1946 normal_distribution<_RealType>& __x)
1948 using param_type =
typename normal_distribution<_RealType>::param_type;
1949 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1951 const typename __ios_base::fmtflags __flags = __is.
flags();
1952 __is.
flags(__ios_base::dec | __ios_base::skipws);
1954 double __mean, __stddev;
1956 if (__is >> __mean >> __stddev >> __saved_avail)
1958 if (!__saved_avail || (__is >> __x._M_saved))
1960 __x._M_saved_available = __saved_avail;
1961 __x.param(param_type(__mean, __stddev));
1965 __is.
flags(__flags);
1970 template<
typename _RealType>
1971 template<
typename _ForwardIterator,
1972 typename _UniformRandomNumberGenerator>
1974 lognormal_distribution<_RealType>::
1975 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1976 _UniformRandomNumberGenerator& __urng,
1977 const param_type& __p)
1979 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1981 *__f++ =
std::exp(__p.s() * _M_nd(__urng) + __p.m());
1984 template<
typename _RealType,
typename _CharT,
typename _Traits>
1987 const lognormal_distribution<_RealType>& __x)
1989 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1991 const typename __ios_base::fmtflags __flags = __os.
flags();
1992 const _CharT __fill = __os.
fill();
1994 const _CharT __space = __os.
widen(
' ');
1995 __os.
flags(__ios_base::scientific | __ios_base::left);
1999 __os << __x.m() << __space << __x.s()
2000 << __space << __x._M_nd;
2002 __os.
flags(__flags);
2008 template<
typename _RealType,
typename _CharT,
typename _Traits>
2011 lognormal_distribution<_RealType>& __x)
2014 =
typename lognormal_distribution<_RealType>::param_type;
2015 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2017 const typename __ios_base::fmtflags __flags = __is.
flags();
2018 __is.
flags(__ios_base::dec | __ios_base::skipws);
2021 if (__is >> __m >> __s >> __x._M_nd)
2022 __x.param(param_type(__m, __s));
2024 __is.
flags(__flags);
2028 template<
typename _RealType>
2029 template<
typename _ForwardIterator,
2030 typename _UniformRandomNumberGenerator>
2034 _UniformRandomNumberGenerator& __urng)
2036 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2038 *__f++ = 2 * _M_gd(__urng);
2041 template<
typename _RealType>
2042 template<
typename _ForwardIterator,
2043 typename _UniformRandomNumberGenerator>
2047 _UniformRandomNumberGenerator& __urng,
2051 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2053 *__f++ = 2 * _M_gd(__urng, __p);
2056 template<
typename _RealType,
typename _CharT,
typename _Traits>
2059 const chi_squared_distribution<_RealType>& __x)
2061 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2063 const typename __ios_base::fmtflags __flags = __os.
flags();
2064 const _CharT __fill = __os.
fill();
2066 const _CharT __space = __os.
widen(
' ');
2067 __os.
flags(__ios_base::scientific | __ios_base::left);
2071 __os << __x.n() << __space << __x._M_gd;
2073 __os.
flags(__flags);
2079 template<
typename _RealType,
typename _CharT,
typename _Traits>
2082 chi_squared_distribution<_RealType>& __x)
2085 =
typename chi_squared_distribution<_RealType>::param_type;
2086 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2088 const typename __ios_base::fmtflags __flags = __is.
flags();
2089 __is.
flags(__ios_base::dec | __ios_base::skipws);
2092 if (__is >> __n >> __x._M_gd)
2093 __x.param(param_type(__n));
2100 template<
typename _RealType>
2101 template<
typename _UniformRandomNumberGenerator>
2104 operator()(_UniformRandomNumberGenerator& __urng,
2105 const param_type& __p)
2107 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2114 const _RealType __pi = 3.1415926535897932384626433832795029L;
2115 return __p.a() + __p.b() *
std::tan(__pi * __u);
2118 template<
typename _RealType>
2119 template<
typename _ForwardIterator,
2120 typename _UniformRandomNumberGenerator>
2124 _UniformRandomNumberGenerator& __urng,
2125 const param_type& __p)
2127 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2128 const _RealType __pi = 3.1415926535897932384626433832795029L;
2129 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2138 *__f++ = __p.a() + __p.b() *
std::tan(__pi * __u);
2142 template<
typename _RealType,
typename _CharT,
typename _Traits>
2145 const cauchy_distribution<_RealType>& __x)
2147 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2149 const typename __ios_base::fmtflags __flags = __os.
flags();
2150 const _CharT __fill = __os.
fill();
2152 const _CharT __space = __os.
widen(
' ');
2153 __os.
flags(__ios_base::scientific | __ios_base::left);
2157 __os << __x.a() << __space << __x.b();
2159 __os.
flags(__flags);
2165 template<
typename _RealType,
typename _CharT,
typename _Traits>
2173 const typename __ios_base::fmtflags __flags = __is.
flags();
2174 __is.
flags(__ios_base::dec | __ios_base::skipws);
2177 if (__is >> __a >> __b)
2178 __x.
param(param_type(__a, __b));
2180 __is.
flags(__flags);
2185 template<
typename _RealType>
2186 template<
typename _ForwardIterator,
2187 typename _UniformRandomNumberGenerator>
2191 _UniformRandomNumberGenerator& __urng)
2193 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2195 *__f++ = ((_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()));
2198 template<
typename _RealType>
2199 template<
typename _ForwardIterator,
2200 typename _UniformRandomNumberGenerator>
2204 _UniformRandomNumberGenerator& __urng,
2205 const param_type& __p)
2207 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2210 param_type __p1(__p.m() / 2);
2211 param_type __p2(__p.n() / 2);
2213 *__f++ = ((_M_gd_x(__urng, __p1) * n())
2214 / (_M_gd_y(__urng, __p2) * m()));
2217 template<
typename _RealType,
typename _CharT,
typename _Traits>
2220 const fisher_f_distribution<_RealType>& __x)
2222 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2224 const typename __ios_base::fmtflags __flags = __os.
flags();
2225 const _CharT __fill = __os.
fill();
2227 const _CharT __space = __os.
widen(
' ');
2228 __os.
flags(__ios_base::scientific | __ios_base::left);
2232 __os << __x.m() << __space << __x.n()
2233 << __space << __x._M_gd_x << __space << __x._M_gd_y;
2235 __os.
flags(__flags);
2241 template<
typename _RealType,
typename _CharT,
typename _Traits>
2244 fisher_f_distribution<_RealType>& __x)
2247 =
typename fisher_f_distribution<_RealType>::param_type;
2248 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2250 const typename __ios_base::fmtflags __flags = __is.
flags();
2251 __is.
flags(__ios_base::dec | __ios_base::skipws);
2254 if (__is >> __m >> __n >> __x._M_gd_x >> __x._M_gd_y)
2255 __x.param(param_type(__m, __n));
2257 __is.
flags(__flags);
2262 template<
typename _RealType>
2263 template<
typename _ForwardIterator,
2264 typename _UniformRandomNumberGenerator>
2268 _UniformRandomNumberGenerator& __urng)
2270 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2272 *__f++ = _M_nd(__urng) *
std::sqrt(n() / _M_gd(__urng));
2275 template<
typename _RealType>
2276 template<
typename _ForwardIterator,
2277 typename _UniformRandomNumberGenerator>
2281 _UniformRandomNumberGenerator& __urng,
2282 const param_type& __p)
2284 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2286 __p2(__p.n() / 2, 2);
2288 *__f++ = _M_nd(__urng) *
std::sqrt(__p.n() / _M_gd(__urng, __p2));
2291 template<
typename _RealType,
typename _CharT,
typename _Traits>
2294 const student_t_distribution<_RealType>& __x)
2296 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2298 const typename __ios_base::fmtflags __flags = __os.
flags();
2299 const _CharT __fill = __os.
fill();
2301 const _CharT __space = __os.
widen(
' ');
2302 __os.
flags(__ios_base::scientific | __ios_base::left);
2306 __os << __x.n() << __space << __x._M_nd << __space << __x._M_gd;
2308 __os.
flags(__flags);
2314 template<
typename _RealType,
typename _CharT,
typename _Traits>
2317 student_t_distribution<_RealType>& __x)
2320 =
typename student_t_distribution<_RealType>::param_type;
2321 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2323 const typename __ios_base::fmtflags __flags = __is.
flags();
2324 __is.
flags(__ios_base::dec | __ios_base::skipws);
2327 if (__is >> __n >> __x._M_nd >> __x._M_gd)
2328 __x.param(param_type(__n));
2330 __is.
flags(__flags);
2335 template<
typename _RealType>
2337 gamma_distribution<_RealType>::param_type::
2340 _M_malpha = _M_alpha < 1.0 ? _M_alpha + _RealType(1.0) : _M_alpha;
2342 const _RealType __a1 = _M_malpha - _RealType(1.0) / _RealType(3.0);
2343 _M_a2 = _RealType(1.0) /
std::sqrt(_RealType(9.0) * __a1);
2351 template<
typename _RealType>
2352 template<
typename _UniformRandomNumberGenerator>
2355 operator()(_UniformRandomNumberGenerator& __urng,
2358 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2363 - _RealType(1.0) / _RealType(3.0));
2369 __n = _M_nd(__urng);
2374 __v = __v * __v * __v;
2377 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2378 && (
std::log(__u) > (0.5 * __n * __n + __a1
2381 if (__param.alpha() == __param._M_malpha)
2382 return __a1 * __v * __param.beta();
2390 * __a1 * __v * __param.beta());
2394 template<
typename _RealType>
2395 template<
typename _ForwardIterator,
2396 typename _UniformRandomNumberGenerator>
2400 _UniformRandomNumberGenerator& __urng,
2401 const param_type& __param)
2403 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2404 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2409 - _RealType(1.0) / _RealType(3.0));
2411 if (__param.alpha() == __param._M_malpha)
2418 __n = _M_nd(__urng);
2423 __v = __v * __v * __v;
2426 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2427 && (
std::log(__u) > (0.5 * __n * __n + __a1
2430 *__f++ = __a1 * __v * __param.beta();
2439 __n = _M_nd(__urng);
2444 __v = __v * __v * __v;
2447 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2448 && (
std::log(__u) > (0.5 * __n * __n + __a1
2456 * __a1 * __v * __param.beta());
2460 template<
typename _RealType,
typename _CharT,
typename _Traits>
2463 const gamma_distribution<_RealType>& __x)
2465 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2467 const typename __ios_base::fmtflags __flags = __os.
flags();
2468 const _CharT __fill = __os.
fill();
2470 const _CharT __space = __os.
widen(
' ');
2471 __os.
flags(__ios_base::scientific | __ios_base::left);
2475 __os << __x.alpha() << __space << __x.beta()
2476 << __space << __x._M_nd;
2478 __os.
flags(__flags);
2484 template<
typename _RealType,
typename _CharT,
typename _Traits>
2487 gamma_distribution<_RealType>& __x)
2489 using param_type =
typename gamma_distribution<_RealType>::param_type;
2490 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2492 const typename __ios_base::fmtflags __flags = __is.
flags();
2493 __is.
flags(__ios_base::dec | __ios_base::skipws);
2495 _RealType __alpha_val, __beta_val;
2496 if (__is >> __alpha_val >> __beta_val >> __x._M_nd)
2497 __x.param(param_type(__alpha_val, __beta_val));
2499 __is.
flags(__flags);
2504 template<
typename _RealType>
2505 template<
typename _UniformRandomNumberGenerator>
2508 operator()(_UniformRandomNumberGenerator& __urng,
2509 const param_type& __p)
2511 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2517 template<
typename _RealType>
2518 template<
typename _ForwardIterator,
2519 typename _UniformRandomNumberGenerator>
2523 _UniformRandomNumberGenerator& __urng,
2524 const param_type& __p)
2526 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2527 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2536 template<
typename _RealType,
typename _CharT,
typename _Traits>
2543 const typename __ios_base::fmtflags __flags = __os.
flags();
2544 const _CharT __fill = __os.
fill();
2546 const _CharT __space = __os.
widen(
' ');
2547 __os.
flags(__ios_base::scientific | __ios_base::left);
2551 __os << __x.
a() << __space << __x.
b();
2553 __os.
flags(__flags);
2559 template<
typename _RealType,
typename _CharT,
typename _Traits>
2567 const typename __ios_base::fmtflags __flags = __is.
flags();
2568 __is.
flags(__ios_base::dec | __ios_base::skipws);
2571 if (__is >> __a >> __b)
2572 __x.
param(param_type(__a, __b));
2574 __is.
flags(__flags);
2579 template<
typename _RealType>
2580 template<
typename _UniformRandomNumberGenerator>
2583 operator()(_UniformRandomNumberGenerator& __urng,
2584 const param_type& __p)
2586 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2592 template<
typename _RealType>
2593 template<
typename _ForwardIterator,
2594 typename _UniformRandomNumberGenerator>
2598 _UniformRandomNumberGenerator& __urng,
2599 const param_type& __p)
2601 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2602 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2610 template<
typename _RealType,
typename _CharT,
typename _Traits>
2613 const extreme_value_distribution<_RealType>& __x)
2615 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2617 const typename __ios_base::fmtflags __flags = __os.
flags();
2618 const _CharT __fill = __os.
fill();
2620 const _CharT __space = __os.
widen(
' ');
2621 __os.
flags(__ios_base::scientific | __ios_base::left);
2625 __os << __x.a() << __space << __x.b();
2627 __os.
flags(__flags);
2633 template<
typename _RealType,
typename _CharT,
typename _Traits>
2642 const typename __ios_base::fmtflags __flags = __is.
flags();
2643 __is.
flags(__ios_base::dec | __ios_base::skipws);
2646 if (__is >> __a >> __b)
2647 __x.
param(param_type(__a, __b));
2649 __is.
flags(__flags);
2654 template<
typename _IntType>
2656 discrete_distribution<_IntType>::param_type::
2659 if (_M_prob.size() < 2)
2666 _M_prob.end(), 0.0);
2667 __glibcxx_assert(__sum > 0);
2669 __detail::__normalize(_M_prob.begin(), _M_prob.end(), _M_prob.begin(),
2672 _M_cp.reserve(_M_prob.size());
2676 _M_cp[_M_cp.size() - 1] = 1.0;
2679 template<
typename _IntType>
2680 template<
typename _Func>
2681 discrete_distribution<_IntType>::param_type::
2682 param_type(
size_t __nw,
double __xmin,
double __xmax, _Func __fw)
2683 : _M_prob(), _M_cp()
2685 const size_t __n = __nw == 0 ? 1 : __nw;
2686 const double __delta = (__xmax - __xmin) / __n;
2688 _M_prob.reserve(__n);
2689 for (
size_t __k = 0; __k < __nw; ++__k)
2690 _M_prob.push_back(__fw(__xmin + __k * __delta + 0.5 * __delta));
2695 template<
typename _IntType>
2696 template<
typename _UniformRandomNumberGenerator>
2697 typename discrete_distribution<_IntType>::result_type
2698 discrete_distribution<_IntType>::
2699 operator()(_UniformRandomNumberGenerator& __urng,
2700 const param_type& __param)
2702 if (__param._M_cp.empty())
2703 return result_type(0);
2705 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2708 const double __p = __aurng();
2709 auto __pos = std::lower_bound(__param._M_cp.begin(),
2710 __param._M_cp.end(), __p);
2712 return __pos - __param._M_cp.begin();
2715 template<
typename _IntType>
2716 template<
typename _ForwardIterator,
2717 typename _UniformRandomNumberGenerator>
2719 discrete_distribution<_IntType>::
2720 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2721 _UniformRandomNumberGenerator& __urng,
2722 const param_type& __param)
2724 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2726 if (__param._M_cp.empty())
2729 *__f++ = result_type(0);
2733 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2738 const double __p = __aurng();
2739 auto __pos = std::lower_bound(__param._M_cp.begin(),
2740 __param._M_cp.end(), __p);
2742 *__f++ = __pos - __param._M_cp.begin();
2746 template<
typename _IntType,
typename _CharT,
typename _Traits>
2749 const discrete_distribution<_IntType>& __x)
2751 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2753 const typename __ios_base::fmtflags __flags = __os.
flags();
2754 const _CharT __fill = __os.
fill();
2756 const _CharT __space = __os.
widen(
' ');
2757 __os.
flags(__ios_base::scientific | __ios_base::left);
2762 __os << __prob.
size();
2763 for (
auto __dit = __prob.
begin(); __dit != __prob.
end(); ++__dit)
2764 __os << __space << *__dit;
2766 __os.
flags(__flags);
2774 template<
typename _ValT,
typename _CharT,
typename _Traits>
2775 basic_istream<_CharT, _Traits>&
2776 __extract_params(basic_istream<_CharT, _Traits>& __is,
2777 vector<_ValT>& __vals,
size_t __n)
2779 __vals.reserve(__n);
2784 __vals.push_back(__val);
2792 template<
typename _IntType,
typename _CharT,
typename _Traits>
2795 discrete_distribution<_IntType>& __x)
2797 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2799 const typename __ios_base::fmtflags __flags = __is.
flags();
2800 __is.
flags(__ios_base::dec | __ios_base::skipws);
2806 if (__detail::__extract_params(__is, __prob_vec, __n))
2807 __x.param({__prob_vec.
begin(), __prob_vec.
end()});
2810 __is.
flags(__flags);
2815 template<
typename _RealType>
2817 piecewise_constant_distribution<_RealType>::param_type::
2820 if (_M_int.size() < 2
2821 || (_M_int.size() == 2
2822 && _M_int[0] == _RealType(0)
2823 && _M_int[1] == _RealType(1)))
2832 __glibcxx_assert(__sum > 0);
2834 __detail::__normalize(_M_den.begin(), _M_den.end(), _M_den.begin(),
2837 _M_cp.reserve(_M_den.size());
2842 _M_cp[_M_cp.size() - 1] = 1.0;
2844 for (
size_t __k = 0; __k < _M_den.size(); ++__k)
2845 _M_den[__k] /= _M_int[__k + 1] - _M_int[__k];
2848 template<
typename _RealType>
2849 template<
typename _InputIteratorB,
typename _InputIteratorW>
2850 piecewise_constant_distribution<_RealType>::param_type::
2851 param_type(_InputIteratorB __bbegin,
2852 _InputIteratorB __bend,
2853 _InputIteratorW __wbegin)
2854 : _M_int(), _M_den(), _M_cp()
2856 if (__bbegin != __bend)
2860 _M_int.push_back(*__bbegin);
2862 if (__bbegin == __bend)
2865 _M_den.push_back(*__wbegin);
2873 template<
typename _RealType>
2874 template<
typename _Func>
2875 piecewise_constant_distribution<_RealType>::param_type::
2876 param_type(initializer_list<_RealType> __bl, _Func __fw)
2877 : _M_int(), _M_den(), _M_cp()
2879 _M_int.reserve(__bl.size());
2880 for (
auto __biter = __bl.begin(); __biter != __bl.end(); ++__biter)
2881 _M_int.push_back(*__biter);
2883 _M_den.reserve(_M_int.size() - 1);
2884 for (
size_t __k = 0; __k < _M_int.size() - 1; ++__k)
2885 _M_den.push_back(__fw(0.5 * (_M_int[__k + 1] + _M_int[__k])));
2890 template<
typename _RealType>
2891 template<
typename _Func>
2892 piecewise_constant_distribution<_RealType>::param_type::
2893 param_type(
size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
2894 : _M_int(), _M_den(), _M_cp()
2896 const size_t __n = __nw == 0 ? 1 : __nw;
2897 const _RealType __delta = (__xmax - __xmin) / __n;
2899 _M_int.reserve(__n + 1);
2900 for (
size_t __k = 0; __k <= __nw; ++__k)
2901 _M_int.push_back(__xmin + __k * __delta);
2903 _M_den.reserve(__n);
2904 for (
size_t __k = 0; __k < __nw; ++__k)
2905 _M_den.push_back(__fw(_M_int[__k] + 0.5 * __delta));
2910 template<
typename _RealType>
2911 template<
typename _UniformRandomNumberGenerator>
2912 typename piecewise_constant_distribution<_RealType>::result_type
2913 piecewise_constant_distribution<_RealType>::
2914 operator()(_UniformRandomNumberGenerator& __urng,
2915 const param_type& __param)
2917 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2920 const double __p = __aurng();
2921 if (__param._M_cp.empty())
2924 auto __pos = std::lower_bound(__param._M_cp.begin(),
2925 __param._M_cp.end(), __p);
2926 const size_t __i = __pos - __param._M_cp.begin();
2928 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
2930 return __param._M_int[__i] + (__p - __pref) / __param._M_den[__i];
2933 template<
typename _RealType>
2934 template<
typename _ForwardIterator,
2935 typename _UniformRandomNumberGenerator>
2937 piecewise_constant_distribution<_RealType>::
2938 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2939 _UniformRandomNumberGenerator& __urng,
2940 const param_type& __param)
2942 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2943 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2946 if (__param._M_cp.empty())
2955 const double __p = __aurng();
2957 auto __pos = std::lower_bound(__param._M_cp.begin(),
2958 __param._M_cp.end(), __p);
2959 const size_t __i = __pos - __param._M_cp.begin();
2961 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
2963 *__f++ = (__param._M_int[__i]
2964 + (__p - __pref) / __param._M_den[__i]);
2968 template<
typename _RealType,
typename _CharT,
typename _Traits>
2971 const piecewise_constant_distribution<_RealType>& __x)
2973 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2975 const typename __ios_base::fmtflags __flags = __os.
flags();
2976 const _CharT __fill = __os.
fill();
2978 const _CharT __space = __os.
widen(
' ');
2979 __os.
flags(__ios_base::scientific | __ios_base::left);
2984 __os << __int.
size() - 1;
2986 for (
auto __xit = __int.
begin(); __xit != __int.
end(); ++__xit)
2987 __os << __space << *__xit;
2990 for (
auto __dit = __den.
begin(); __dit != __den.
end(); ++__dit)
2991 __os << __space << *__dit;
2993 __os.
flags(__flags);
2999 template<
typename _RealType,
typename _CharT,
typename _Traits>
3002 piecewise_constant_distribution<_RealType>& __x)
3004 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
3006 const typename __ios_base::fmtflags __flags = __is.
flags();
3007 __is.
flags(__ios_base::dec | __ios_base::skipws);
3013 if (__detail::__extract_params(__is, __int_vec, __n + 1))
3016 if (__detail::__extract_params(__is, __den_vec, __n))
3018 __x.param({ __int_vec.
begin(), __int_vec.
end(),
3019 __den_vec.
begin() });
3024 __is.
flags(__flags);
3029 template<
typename _RealType>
3031 piecewise_linear_distribution<_RealType>::param_type::
3034 if (_M_int.size() < 2
3035 || (_M_int.size() == 2
3036 && _M_int[0] == _RealType(0)
3037 && _M_int[1] == _RealType(1)
3038 && _M_den[0] == _M_den[1]))
3046 _M_cp.reserve(_M_int.size() - 1);
3047 _M_m.reserve(_M_int.size() - 1);
3048 for (
size_t __k = 0; __k < _M_int.size() - 1; ++__k)
3050 const _RealType __delta = _M_int[__k + 1] - _M_int[__k];
3051 __sum += 0.5 * (_M_den[__k + 1] + _M_den[__k]) * __delta;
3052 _M_cp.push_back(__sum);
3053 _M_m.push_back((_M_den[__k + 1] - _M_den[__k]) / __delta);
3055 __glibcxx_assert(__sum > 0);
3058 __detail::__normalize(_M_den.begin(), _M_den.end(), _M_den.begin(),
3061 __detail::__normalize(_M_cp.begin(), _M_cp.end(), _M_cp.begin(), __sum);
3063 __detail::__normalize(_M_m.begin(), _M_m.end(), _M_m.begin(), __sum);
3066 _M_cp[_M_cp.size() - 1] = 1.0;
3069 template<
typename _RealType>
3070 template<
typename _InputIteratorB,
typename _InputIteratorW>
3071 piecewise_linear_distribution<_RealType>::param_type::
3072 param_type(_InputIteratorB __bbegin,
3073 _InputIteratorB __bend,
3074 _InputIteratorW __wbegin)
3075 : _M_int(), _M_den(), _M_cp(), _M_m()
3077 for (; __bbegin != __bend; ++__bbegin, ++__wbegin)
3079 _M_int.push_back(*__bbegin);
3080 _M_den.push_back(*__wbegin);
3086 template<
typename _RealType>
3087 template<
typename _Func>
3088 piecewise_linear_distribution<_RealType>::param_type::
3089 param_type(initializer_list<_RealType> __bl, _Func __fw)
3090 : _M_int(), _M_den(), _M_cp(), _M_m()
3092 _M_int.reserve(__bl.size());
3093 _M_den.reserve(__bl.size());
3094 for (
auto __biter = __bl.begin(); __biter != __bl.end(); ++__biter)
3096 _M_int.push_back(*__biter);
3097 _M_den.push_back(__fw(*__biter));
3103 template<
typename _RealType>
3104 template<
typename _Func>
3105 piecewise_linear_distribution<_RealType>::param_type::
3106 param_type(
size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
3107 : _M_int(), _M_den(), _M_cp(), _M_m()
3109 const size_t __n = __nw == 0 ? 1 : __nw;
3110 const _RealType __delta = (__xmax - __xmin) / __n;
3112 _M_int.reserve(__n + 1);
3113 _M_den.reserve(__n + 1);
3114 for (
size_t __k = 0; __k <= __nw; ++__k)
3116 _M_int.push_back(__xmin + __k * __delta);
3117 _M_den.push_back(__fw(_M_int[__k] + __delta));
3123 template<
typename _RealType>
3124 template<
typename _UniformRandomNumberGenerator>
3125 typename piecewise_linear_distribution<_RealType>::result_type
3126 piecewise_linear_distribution<_RealType>::
3127 operator()(_UniformRandomNumberGenerator& __urng,
3128 const param_type& __param)
3130 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
3133 const double __p = __aurng();
3134 if (__param._M_cp.empty())
3137 auto __pos = std::lower_bound(__param._M_cp.begin(),
3138 __param._M_cp.end(), __p);
3139 const size_t __i = __pos - __param._M_cp.begin();
3141 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
3143 const double __a = 0.5 * __param._M_m[__i];
3144 const double __b = __param._M_den[__i];
3145 const double __cm = __p - __pref;
3147 _RealType __x = __param._M_int[__i];
3152 const double __d = __b * __b + 4.0 * __a * __cm;
3153 __x += 0.5 * (
std::sqrt(__d) - __b) / __a;
3159 template<
typename _RealType>
3160 template<
typename _ForwardIterator,
3161 typename _UniformRandomNumberGenerator>
3163 piecewise_linear_distribution<_RealType>::
3164 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3165 _UniformRandomNumberGenerator& __urng,
3166 const param_type& __param)
3168 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3171 *__f++ = this->operator()(__urng, __param);
3174 template<
typename _RealType,
typename _CharT,
typename _Traits>
3177 const piecewise_linear_distribution<_RealType>& __x)
3179 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
3181 const typename __ios_base::fmtflags __flags = __os.
flags();
3182 const _CharT __fill = __os.
fill();
3184 const _CharT __space = __os.
widen(
' ');
3185 __os.
flags(__ios_base::scientific | __ios_base::left);
3190 __os << __int.
size() - 1;
3192 for (
auto __xit = __int.
begin(); __xit != __int.
end(); ++__xit)
3193 __os << __space << *__xit;
3196 for (
auto __dit = __den.
begin(); __dit != __den.
end(); ++__dit)
3197 __os << __space << *__dit;
3199 __os.
flags(__flags);
3205 template<
typename _RealType,
typename _CharT,
typename _Traits>
3208 piecewise_linear_distribution<_RealType>& __x)
3210 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
3212 const typename __ios_base::fmtflags __flags = __is.
flags();
3213 __is.
flags(__ios_base::dec | __ios_base::skipws);
3218 vector<_RealType> __int_vec;
3219 if (__detail::__extract_params(__is, __int_vec, __n + 1))
3221 vector<double> __den_vec;
3222 if (__detail::__extract_params(__is, __den_vec, __n + 1))
3224 __x.param({ __int_vec.begin(), __int_vec.end(),
3225 __den_vec.begin() });
3229 __is.
flags(__flags);
3234 template<
typename _IntType,
typename>
3237 _M_v.reserve(__il.size());
3238 for (
auto __iter = __il.begin(); __iter != __il.end(); ++__iter)
3239 _M_v.push_back(__detail::__mod<result_type,
3240 __detail::_Shift<result_type, 32>::__value>(*__iter));
3243 template<
typename _InputIterator>
3244 seed_seq::seed_seq(_InputIterator __begin, _InputIterator __end)
3246 if _GLIBCXX17_CONSTEXPR (__is_random_access_iter<_InputIterator>::value)
3249 for (_InputIterator __iter = __begin; __iter != __end; ++__iter)
3250 _M_v.push_back(__detail::__mod<result_type,
3251 __detail::_Shift<result_type, 32>::__value>(*__iter));
3254 template<
typename _RandomAccessIterator>
3256 seed_seq::generate(_RandomAccessIterator __begin,
3257 _RandomAccessIterator __end)
3259 typedef typename iterator_traits<_RandomAccessIterator>::value_type
3262 if (__begin == __end)
3265 std::fill(__begin, __end, _Type(0x8b8b8b8bu));
3267 const size_t __n = __end - __begin;
3268 const size_t __s = _M_v.size();
3269 const size_t __t = (__n >= 623) ? 11
3274 const size_t __p = (__n - __t) / 2;
3275 const size_t __q = __p + __t;
3276 const size_t __m =
std::max(
size_t(__s + 1), __n);
3278#ifndef __UINT32_TYPE__
3281 _Up(uint_least32_t v) : _M_v(v & 0xffffffffu) { }
3283 operator uint_least32_t()
const {
return _M_v; }
3285 uint_least32_t _M_v;
3287 using uint32_t = _Up;
3292 uint32_t __r1 = 1371501266u;
3293 uint32_t __r2 = __r1 + __s;
3294 __begin[__p] += __r1;
3295 __begin[__q] = (uint32_t)__begin[__q] + __r2;
3299 for (
size_t __k = 1; __k <= __s; ++__k)
3301 const size_t __kn = __k % __n;
3302 const size_t __kpn = (__k + __p) % __n;
3303 const size_t __kqn = (__k + __q) % __n;
3304 uint32_t __arg = (__begin[__kn]
3306 ^ __begin[(__k - 1) % __n]);
3307 uint32_t __r1 = 1664525u * (__arg ^ (__arg >> 27));
3308 uint32_t __r2 = __r1 + (uint32_t)__kn + _M_v[__k - 1];
3309 __begin[__kpn] = (uint32_t)__begin[__kpn] + __r1;
3310 __begin[__kqn] = (uint32_t)__begin[__kqn] + __r2;
3311 __begin[__kn] = __r2;
3314 for (
size_t __k = __s + 1; __k < __m; ++__k)
3316 const size_t __kn = __k % __n;
3317 const size_t __kpn = (__k + __p) % __n;
3318 const size_t __kqn = (__k + __q) % __n;
3319 uint32_t __arg = (__begin[__kn]
3321 ^ __begin[(__k - 1) % __n]);
3322 uint32_t __r1 = 1664525u * (__arg ^ (__arg >> 27));
3323 uint32_t __r2 = __r1 + (uint32_t)__kn;
3324 __begin[__kpn] = (uint32_t)__begin[__kpn] + __r1;
3325 __begin[__kqn] = (uint32_t)__begin[__kqn] + __r2;
3326 __begin[__kn] = __r2;
3329 for (
size_t __k = __m; __k < __m + __n; ++__k)
3331 const size_t __kn = __k % __n;
3332 const size_t __kpn = (__k + __p) % __n;
3333 const size_t __kqn = (__k + __q) % __n;
3334 uint32_t __arg = (__begin[__kn]
3336 + __begin[(__k - 1) % __n]);
3337 uint32_t __r3 = 1566083941u * (__arg ^ (__arg >> 27));
3338 uint32_t __r4 = __r3 - __kn;
3339 __begin[__kpn] ^= __r3;
3340 __begin[__kqn] ^= __r4;
3341 __begin[__kn] = __r4;
3345 template<
typename _RealType,
size_t __bits,
3346 typename _UniformRandomNumberGenerator>
3351 "template argument must be a floating point type");
3356 const long double __r =
static_cast<long double>(__urng.max())
3357 -
static_cast<long double>(__urng.min()) + 1.0L;
3359 const size_t __m = std::max<size_t>(1UL,
3360 (__b + __log2r - 1UL) / __log2r);
3362 _RealType __sum = _RealType(0);
3363 _RealType __tmp = _RealType(1);
3364 for (
size_t __k = __m; __k != 0; --__k)
3366 __sum += _RealType(__urng() - __urng.min()) * __tmp;
3369 __ret = __sum / __tmp;
3370 if (__builtin_expect(__ret >= _RealType(1), 0))
3372#if _GLIBCXX_USE_C99_MATH_TR1
3373 __ret = std::nextafter(_RealType(1), _RealType(0));
3375 __ret = _RealType(1)
3382_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 int __lg(int __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=default_seed)
Seeds the initial state of the random number generator.
result_type operator()()
Gets the next random number in the sequence.
result_type operator()()
Gets the next value in the generated random number sequence.
result_type operator()()
Gets the next value in the generated random number sequence.
Produces random numbers by 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.
_RealType b() const
Return the parameter of the distribution.
_RealType a() const
Return the parameter of the distribution.
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.
iterator begin() noexcept
size_type size() const noexcept
Uniform discrete distribution for random numbers. A discrete random distribution on the range with e...
param_type param() const
Returns the parameter set of the distribution.
Parallel STL function calls corresponding to stl_numeric.h. The functions defined here mainly do case...