35 namespace std _GLIBCXX_VISIBILITY(default)
37 _GLIBCXX_BEGIN_NAMESPACE_VERSION
50 template<
typename _Tp, _Tp __m, _Tp __a, _Tp __c>
52 _Mod<_Tp, __m, __a, __c, false, true>::
59 static const _Tp __q = __m / __a;
60 static const _Tp __r = __m % __a;
62 _Tp __t1 = __a * (__x % __q);
63 _Tp __t2 = __r * (__x / __q);
67 __x = __m - __t2 + __t1;
72 const _Tp __d = __m - __x;
81 template<
typename _InputIterator,
typename _OutputIterator,
84 __normalize(_InputIterator __first, _InputIterator __last,
85 _OutputIterator __result,
const _Tp& __factor)
87 for (; __first != __last; ++__first, ++__result)
88 *__result = *__first / __factor;
94 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
96 linear_congruential_engine<_UIntType, __a, __c, __m>::multiplier;
98 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
100 linear_congruential_engine<_UIntType, __a, __c, __m>::increment;
102 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
104 linear_congruential_engine<_UIntType, __a, __c, __m>::modulus;
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>
154 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
155 const linear_congruential_engine<_UIntType,
156 __a, __c, __m>& __lcr)
158 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
160 const typename __ios_base::fmtflags __flags = __os.
flags();
161 const _CharT __fill = __os.fill();
163 __os.fill(__os.widen(
' '));
172 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m,
173 typename _CharT,
typename _Traits>
176 linear_congruential_engine<_UIntType, __a, __c, __m>& __lcr)
178 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
180 const typename __ios_base::fmtflags __flags = __is.
flags();
190 template<
typename _UIntType,
191 size_t __w,
size_t __n,
size_t __m,
size_t __r,
192 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
193 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
196 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
197 __s, __b, __t, __c, __l, __f>::word_size;
199 template<
typename _UIntType,
200 size_t __w,
size_t __n,
size_t __m,
size_t __r,
201 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
202 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
205 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
206 __s, __b, __t, __c, __l, __f>::state_size;
208 template<
typename _UIntType,
209 size_t __w,
size_t __n,
size_t __m,
size_t __r,
210 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
211 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
214 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
215 __s, __b, __t, __c, __l, __f>::shift_size;
217 template<
typename _UIntType,
218 size_t __w,
size_t __n,
size_t __m,
size_t __r,
219 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
220 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
223 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
224 __s, __b, __t, __c, __l, __f>::mask_bits;
226 template<
typename _UIntType,
227 size_t __w,
size_t __n,
size_t __m,
size_t __r,
228 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
229 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
232 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
233 __s, __b, __t, __c, __l, __f>::xor_mask;
235 template<
typename _UIntType,
236 size_t __w,
size_t __n,
size_t __m,
size_t __r,
237 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
238 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
241 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
242 __s, __b, __t, __c, __l, __f>::tempering_u;
244 template<
typename _UIntType,
245 size_t __w,
size_t __n,
size_t __m,
size_t __r,
246 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
247 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
250 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
251 __s, __b, __t, __c, __l, __f>::tempering_d;
253 template<
typename _UIntType,
254 size_t __w,
size_t __n,
size_t __m,
size_t __r,
255 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
256 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
259 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
260 __s, __b, __t, __c, __l, __f>::tempering_s;
262 template<
typename _UIntType,
263 size_t __w,
size_t __n,
size_t __m,
size_t __r,
264 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
265 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
268 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
269 __s, __b, __t, __c, __l, __f>::tempering_b;
271 template<
typename _UIntType,
272 size_t __w,
size_t __n,
size_t __m,
size_t __r,
273 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
274 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
277 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
278 __s, __b, __t, __c, __l, __f>::tempering_t;
280 template<
typename _UIntType,
281 size_t __w,
size_t __n,
size_t __m,
size_t __r,
282 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
283 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
286 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
287 __s, __b, __t, __c, __l, __f>::tempering_c;
289 template<
typename _UIntType,
290 size_t __w,
size_t __n,
size_t __m,
size_t __r,
291 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
292 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
295 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
296 __s, __b, __t, __c, __l, __f>::tempering_l;
298 template<
typename _UIntType,
299 size_t __w,
size_t __n,
size_t __m,
size_t __r,
300 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
301 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
304 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
305 __s, __b, __t, __c, __l, __f>::
306 initialization_multiplier;
308 template<
typename _UIntType,
309 size_t __w,
size_t __n,
size_t __m,
size_t __r,
310 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
311 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
314 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
315 __s, __b, __t, __c, __l, __f>::default_seed;
317 template<
typename _UIntType,
318 size_t __w,
size_t __n,
size_t __m,
size_t __r,
319 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
320 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
323 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
324 __s, __b, __t, __c, __l, __f>::
325 seed(result_type __sd)
327 _M_x[0] = __detail::__mod<_UIntType,
328 __detail::_Shift<_UIntType, __w>::__value>(__sd);
330 for (
size_t __i = 1; __i < state_size; ++__i)
332 _UIntType __x = _M_x[__i - 1];
333 __x ^= __x >> (__w - 2);
335 __x += __detail::__mod<_UIntType, __n>(__i);
336 _M_x[__i] = __detail::__mod<_UIntType,
337 __detail::_Shift<_UIntType, __w>::__value>(__x);
342 template<
typename _UIntType,
343 size_t __w,
size_t __n,
size_t __m,
size_t __r,
344 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
345 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
347 template<
typename _Sseq>
349 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
350 __s, __b, __t, __c, __l, __f>::
352 -> _If_seed_seq<_Sseq>
354 const _UIntType __upper_mask = (~_UIntType()) << __r;
355 const size_t __k = (__w + 31) / 32;
356 uint_least32_t __arr[__n * __k];
357 __q.generate(__arr + 0, __arr + __n * __k);
360 for (
size_t __i = 0; __i < state_size; ++__i)
362 _UIntType __factor = 1u;
363 _UIntType __sum = 0u;
364 for (
size_t __j = 0; __j < __k; ++__j)
366 __sum += __arr[__k * __i + __j] * __factor;
367 __factor *= __detail::_Shift<_UIntType, 32>::__value;
369 _M_x[__i] = __detail::__mod<_UIntType,
370 __detail::_Shift<_UIntType, __w>::__value>(__sum);
376 if ((_M_x[0] & __upper_mask) != 0u)
379 else if (_M_x[__i] != 0u)
384 _M_x[0] = __detail::_Shift<_UIntType, __w - 1>::__value;
388 template<
typename _UIntType,
size_t __w,
389 size_t __n,
size_t __m,
size_t __r,
390 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
391 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
394 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
395 __s, __b, __t, __c, __l, __f>::
398 const _UIntType __upper_mask = (~_UIntType()) << __r;
399 const _UIntType __lower_mask = ~__upper_mask;
401 for (
size_t __k = 0; __k < (__n - __m); ++__k)
403 _UIntType __y = ((_M_x[__k] & __upper_mask)
404 | (_M_x[__k + 1] & __lower_mask));
405 _M_x[__k] = (_M_x[__k + __m] ^ (__y >> 1)
406 ^ ((__y & 0x01) ? __a : 0));
409 for (
size_t __k = (__n - __m); __k < (__n - 1); ++__k)
411 _UIntType __y = ((_M_x[__k] & __upper_mask)
412 | (_M_x[__k + 1] & __lower_mask));
413 _M_x[__k] = (_M_x[__k + (__m - __n)] ^ (__y >> 1)
414 ^ ((__y & 0x01) ? __a : 0));
417 _UIntType __y = ((_M_x[__n - 1] & __upper_mask)
418 | (_M_x[0] & __lower_mask));
419 _M_x[__n - 1] = (_M_x[__m - 1] ^ (__y >> 1)
420 ^ ((__y & 0x01) ? __a : 0));
424 template<
typename _UIntType,
size_t __w,
425 size_t __n,
size_t __m,
size_t __r,
426 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
427 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
430 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
431 __s, __b, __t, __c, __l, __f>::
432 discard(
unsigned long long __z)
434 while (__z > state_size - _M_p)
436 __z -= state_size - _M_p;
442 template<
typename _UIntType,
size_t __w,
443 size_t __n,
size_t __m,
size_t __r,
444 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
445 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
449 __s, __b, __t, __c, __l, __f>::result_type
451 __s, __b, __t, __c, __l, __f>::
455 if (_M_p >= state_size)
459 result_type __z = _M_x[_M_p++];
460 __z ^= (__z >> __u) & __d;
461 __z ^= (__z << __s) & __b;
462 __z ^= (__z << __t) & __c;
468 template<
typename _UIntType,
size_t __w,
469 size_t __n,
size_t __m,
size_t __r,
470 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
471 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
472 _UIntType __f,
typename _CharT,
typename _Traits>
474 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
475 const mersenne_twister_engine<_UIntType, __w, __n, __m,
476 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __x)
478 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
480 const typename __ios_base::fmtflags __flags = __os.flags();
481 const _CharT __fill = __os.fill();
482 const _CharT __space = __os.widen(
' ');
486 for (
size_t __i = 0; __i < __n; ++__i)
487 __os << __x._M_x[__i] << __space;
495 template<
typename _UIntType,
size_t __w,
496 size_t __n,
size_t __m,
size_t __r,
497 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
498 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
499 _UIntType __f,
typename _CharT,
typename _Traits>
502 mersenne_twister_engine<_UIntType, __w, __n, __m,
503 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __x)
505 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
507 const typename __ios_base::fmtflags __flags = __is.
flags();
510 for (
size_t __i = 0; __i < __n; ++__i)
511 __is >> __x._M_x[__i];
519 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
521 subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size;
523 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
525 subtract_with_carry_engine<_UIntType, __w, __s, __r>::short_lag;
527 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
529 subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag;
531 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
533 subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed;
535 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
541 __lcg(__value == 0u ? default_seed : __value);
543 const size_t __n = (__w + 31) / 32;
545 for (
size_t __i = 0; __i < long_lag; ++__i)
547 _UIntType __sum = 0u;
548 _UIntType __factor = 1u;
549 for (
size_t __j = 0; __j < __n; ++__j)
551 __sum += __detail::__mod<uint_least32_t,
552 __detail::_Shift<uint_least32_t, 32>::__value>
553 (__lcg()) * __factor;
554 __factor *= __detail::_Shift<_UIntType, 32>::__value;
556 _M_x[__i] = __detail::__mod<_UIntType,
557 __detail::_Shift<_UIntType, __w>::__value>(__sum);
559 _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
563 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
564 template<
typename _Sseq>
568 -> _If_seed_seq<_Sseq>
570 const size_t __k = (__w + 31) / 32;
571 uint_least32_t __arr[__r * __k];
572 __q.generate(__arr + 0, __arr + __r * __k);
574 for (
size_t __i = 0; __i < long_lag; ++__i)
576 _UIntType __sum = 0u;
577 _UIntType __factor = 1u;
578 for (
size_t __j = 0; __j < __k; ++__j)
580 __sum += __arr[__k * __i + __j] * __factor;
581 __factor *= __detail::_Shift<_UIntType, 32>::__value;
583 _M_x[__i] = __detail::__mod<_UIntType,
584 __detail::_Shift<_UIntType, __w>::__value>(__sum);
586 _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
590 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
591 typename subtract_with_carry_engine<_UIntType, __w, __s, __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>
628 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
634 const typename __ios_base::fmtflags __flags = __os.
flags();
635 const _CharT __fill = __os.fill();
636 const _CharT __space = __os.widen(
' ');
640 for (
size_t __i = 0; __i < __r; ++__i)
641 __os << __x._M_x[__i] << __space;
642 __os << __x._M_carry << __space << __x._M_p;
649 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r,
650 typename _CharT,
typename _Traits>
653 subtract_with_carry_engine<_UIntType, __w, __s, __r>& __x)
655 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
657 const typename __ios_base::fmtflags __flags = __is.
flags();
660 for (
size_t __i = 0; __i < __r; ++__i)
661 __is >> __x._M_x[__i];
662 __is >> __x._M_carry;
670 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
672 discard_block_engine<_RandomNumberEngine, __p, __r>::block_size;
674 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
676 discard_block_engine<_RandomNumberEngine, __p, __r>::used_block;
678 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
679 typename discard_block_engine<_RandomNumberEngine,
680 __p, __r>::result_type
684 if (_M_n >= used_block)
686 _M_b.discard(block_size - _M_n);
693 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r,
694 typename _CharT,
typename _Traits>
696 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
702 const typename __ios_base::fmtflags __flags = __os.
flags();
703 const _CharT __fill = __os.fill();
704 const _CharT __space = __os.widen(
' ');
708 __os << __x.base() << __space << __x._M_n;
715 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r,
716 typename _CharT,
typename _Traits>
719 discard_block_engine<_RandomNumberEngine, __p, __r>& __x)
721 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
723 const typename __ios_base::fmtflags __flags = __is.
flags();
726 __is >> __x._M_b >> __x._M_n;
733 template<
typename _RandomNumberEngine,
size_t __w,
typename _UIntType>
734 typename independent_bits_engine<_RandomNumberEngine, __w, _UIntType>::
739 typedef typename _RandomNumberEngine::result_type _Eresult_type;
740 const _Eresult_type __r
742 ? _M_b.max() - _M_b.min() + 1 : 0);
744 const unsigned __m = __r ?
std::__lg(__r) : __edig;
751 __ctype __s0, __s1, __y0, __y1;
753 for (
size_t __i = 0; __i < 2; ++__i)
755 __n = (__w + __m - 1) / __m + __i;
756 __n0 = __n - __w % __n;
757 const unsigned __w0 = __w / __n;
763 __s0 = __ctype(1) << __w0;
771 __y0 = __s0 * (__r / __s0);
773 __y1 = __s1 * (__r / __s1);
775 if (__r - __y0 <= __y0 / __n)
783 for (
size_t __k = 0; __k < __n0; ++__k)
787 __u = _M_b() - _M_b.
min();
788 while (__y0 && __u >= __y0);
789 __sum = __s0 * __sum + (__s0 ? __u % __s0 : __u);
791 for (
size_t __k = __n0; __k < __n; ++__k)
795 __u = _M_b() - _M_b.min();
796 while (__y1 && __u >= __y1);
797 __sum = __s1 * __sum + (__s1 ? __u % __s1 : __u);
803 template<
typename _RandomNumberEngine,
size_t __k>
807 template<
typename _RandomNumberEngine,
size_t __k>
812 size_t __j = __k * ((_M_y - _M_b.min())
813 / (_M_b.max() - _M_b.min() + 1.0L));
820 template<
typename _RandomNumberEngine,
size_t __k,
821 typename _CharT,
typename _Traits>
823 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
828 const typename __ios_base::fmtflags __flags = __os.
flags();
829 const _CharT __fill = __os.fill();
830 const _CharT __space = __os.widen(
' ');
835 for (
size_t __i = 0; __i < __k; ++__i)
836 __os << __space << __x._M_v[__i];
837 __os << __space << __x._M_y;
844 template<
typename _RandomNumberEngine,
size_t __k,
845 typename _CharT,
typename _Traits>
848 shuffle_order_engine<_RandomNumberEngine, __k>& __x)
850 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
852 const typename __ios_base::fmtflags __flags = __is.
flags();
856 for (
size_t __i = 0; __i < __k; ++__i)
857 __is >> __x._M_v[__i];
865 template<
typename _IntType,
typename _CharT,
typename _Traits>
867 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
872 const typename __ios_base::fmtflags __flags = __os.
flags();
873 const _CharT __fill = __os.fill();
874 const _CharT __space = __os.widen(
' ');
878 __os << __x.a() << __space << __x.b();
885 template<
typename _IntType,
typename _CharT,
typename _Traits>
894 const typename __ios_base::fmtflags __flags = __is.
flags();
898 if (__is >> __a >> __b)
899 __x.
param(param_type(__a, __b));
906 template<
typename _RealType>
907 template<
typename _ForwardIterator,
908 typename _UniformRandomNumberGenerator>
910 uniform_real_distribution<_RealType>::
911 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
912 _UniformRandomNumberGenerator& __urng,
913 const param_type& __p)
915 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
916 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
918 auto __range = __p.b() - __p.a();
920 *__f++ = __aurng() * __range + __p.a();
923 template<typename _RealType, typename _CharT, typename _Traits>
924 std::basic_ostream<_CharT, _Traits>&
930 const typename __ios_base::fmtflags __flags = __os.
flags();
931 const _CharT __fill = __os.fill();
933 const _CharT __space = __os.widen(
' ');
938 __os << __x.a() << __space << __x.b();
942 __os.precision(__precision);
946 template<
typename _RealType,
typename _CharT,
typename _Traits>
955 const typename __ios_base::fmtflags __flags = __is.
flags();
959 if (__is >> __a >> __b)
960 __x.
param(param_type(__a, __b));
967 template<
typename _ForwardIterator,
968 typename _UniformRandomNumberGenerator>
970 std::bernoulli_distribution::
971 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
972 _UniformRandomNumberGenerator& __urng,
973 const param_type& __p)
975 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
976 __detail::_Adaptor<_UniformRandomNumberGenerator,
double>
978 auto __limit = __p.p() * (__aurng.
max() - __aurng.
min());
981 *__f++ = (__aurng() - __aurng.min()) < __limit;
984 template<typename _CharT, typename _Traits>
985 std::basic_ostream<_CharT, _Traits>&
991 const typename __ios_base::fmtflags __flags = __os.
flags();
992 const _CharT __fill = __os.fill();
995 __os.fill(__os.widen(
' '));
1000 __os.flags(__flags);
1002 __os.precision(__precision);
1007 template<
typename _IntType>
1008 template<
typename _UniformRandomNumberGenerator>
1009 typename geometric_distribution<_IntType>::result_type
1011 operator()(_UniformRandomNumberGenerator& __urng,
1012 const param_type& __param)
1016 const double __naf =
1019 const double __thr =
1021 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1026 __cand = std::floor(
std::log(1.0 - __aurng()) / __param._M_log_1_p);
1027 while (__cand >= __thr);
1029 return result_type(__cand + __naf);
1032 template<
typename _IntType>
1033 template<
typename _ForwardIterator,
1034 typename _UniformRandomNumberGenerator>
1036 geometric_distribution<_IntType>::
1037 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1038 _UniformRandomNumberGenerator& __urng,
1039 const param_type& __param)
1041 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1044 const
double __naf =
1045 (1 - std::numeric_limits<
double>::epsilon()) / 2;
1047 const
double __thr =
1048 std::numeric_limits<_IntType>::
max() + __naf;
1049 __detail::_Adaptor<_UniformRandomNumberGenerator,
double>
1056 __cand = std::floor(
std::log(1.0 - __aurng())
1057 / __param._M_log_1_p);
1058 while (__cand >= __thr);
1060 *__f++ = __cand + __naf;
1064 template<
typename _IntType,
1065 typename _CharT,
typename _Traits>
1067 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1072 const typename __ios_base::fmtflags __flags = __os.
flags();
1073 const _CharT __fill = __os.fill();
1076 __os.fill(__os.widen(
' '));
1081 __os.flags(__flags);
1083 __os.precision(__precision);
1087 template<
typename _IntType,
1088 typename _CharT,
typename _Traits>
1096 const typename __ios_base::fmtflags __flags = __is.
flags();
1101 __x.
param(param_type(__p));
1103 __is.
flags(__flags);
1108 template<
typename _IntType>
1109 template<
typename _UniformRandomNumberGenerator>
1110 typename negative_binomial_distribution<_IntType>::result_type
1112 operator()(_UniformRandomNumberGenerator& __urng)
1114 const double __y = _M_gd(__urng);
1118 return __poisson(__urng);
1121 template<
typename _IntType>
1122 template<
typename _UniformRandomNumberGenerator>
1123 typename negative_binomial_distribution<_IntType>::result_type
1125 operator()(_UniformRandomNumberGenerator& __urng,
1126 const param_type& __p)
1132 _M_gd(__urng, param_type(__p.k(), (1.0 - __p.p()) / __p.p()));
1135 return __poisson(__urng);
1138 template<
typename _IntType>
1139 template<
typename _ForwardIterator,
1140 typename _UniformRandomNumberGenerator>
1142 negative_binomial_distribution<_IntType>::
1143 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1144 _UniformRandomNumberGenerator& __urng)
1146 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1149 const double __y = _M_gd(__urng);
1153 *__f++ = __poisson(__urng);
1157 template<
typename _IntType>
1158 template<
typename _ForwardIterator,
1159 typename _UniformRandomNumberGenerator>
1161 negative_binomial_distribution<_IntType>::
1162 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1163 _UniformRandomNumberGenerator& __urng,
1164 const param_type& __p)
1166 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1167 typename std::gamma_distribution<result_type>::param_type
1168 __p2(__p.k(), (1.0 - __p.p()) / __p.p());
1172 const double __y = _M_gd(__urng, __p2);
1175 *__f++ = __poisson(__urng);
1179 template<
typename _IntType,
typename _CharT,
typename _Traits>
1181 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1182 const negative_binomial_distribution<_IntType>& __x)
1184 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1186 const typename __ios_base::fmtflags __flags = __os.
flags();
1187 const _CharT __fill = __os.
fill();
1189 const _CharT __space = __os.
widen(
' ');
1194 __os << __x.k() << __space << __x.p()
1195 << __space << __x._M_gd;
1197 __os.
flags(__flags);
1203 template<
typename _IntType,
typename _CharT,
typename _Traits>
1206 negative_binomial_distribution<_IntType>& __x)
1209 =
typename negative_binomial_distribution<_IntType>::param_type;
1210 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1212 const typename __ios_base::fmtflags __flags = __is.
flags();
1217 if (__is >> __k >> __p >> __x._M_gd)
1218 __x.param(param_type(__k, __p));
1220 __is.
flags(__flags);
1225 template<
typename _IntType>
1227 poisson_distribution<_IntType>::param_type::
1230 #if _GLIBCXX_USE_C99_MATH_TR1
1233 const double __m = std::floor(_M_mean);
1235 _M_lfm = std::lgamma(__m + 1);
1238 const double __pi_4 = 0.7853981633974483096156608458198757L;
1241 _M_d = std::round(std::max<double>(6.0,
std::min(__m, __dx)));
1242 const double __cx = 2 * __m + _M_d;
1247 _M_cb = 2 * __cx *
std::exp(-_M_d * _M_1cx * (1 + _M_d / 2))
1265 template<
typename _IntType>
1266 template<
typename _UniformRandomNumberGenerator>
1267 typename poisson_distribution<_IntType>::result_type
1270 const param_type& __param)
1272 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1274 #if _GLIBCXX_USE_C99_MATH_TR1
1275 if (__param.mean() >= 12)
1280 const double __naf =
1282 const double __thr =
1285 const double __m = std::floor(__param.mean());
1287 const double __spi_2 = 1.2533141373155002512078826424055226L;
1288 const double __c1 = __param._M_sm * __spi_2;
1289 const double __c2 = __param._M_c2b + __c1;
1290 const double __c3 = __c2 + 1;
1291 const double __c4 = __c3 + 1;
1293 const double __178 = 0.0128205128205128205128205128205128L;
1295 const double __e178 = 1.0129030479320018583185514777512983L;
1296 const double __c5 = __c4 + __e178;
1297 const double __c = __param._M_cb + __c5;
1298 const double __2cx = 2 * (2 * __m + __param._M_d);
1300 bool __reject =
true;
1303 const double __u = __c * __aurng();
1304 const double __e = -
std::log(1.0 - __aurng());
1310 const double __n = _M_nd(__urng);
1311 const double __y = -
std::abs(__n) * __param._M_sm - 1;
1312 __x = std::floor(__y);
1313 __w = -__n * __n / 2;
1317 else if (__u <= __c2)
1319 const double __n = _M_nd(__urng);
1320 const double __y = 1 +
std::abs(__n) * __param._M_scx;
1321 __x = std::ceil(__y);
1322 __w = __y * (2 - __y) * __param._M_1cx;
1323 if (__x > __param._M_d)
1326 else if (__u <= __c3)
1330 else if (__u <= __c4)
1332 else if (__u <= __c5)
1340 const double __v = -
std::log(1.0 - __aurng());
1341 const double __y = __param._M_d
1342 + __v * __2cx / __param._M_d;
1343 __x = std::ceil(__y);
1344 __w = -__param._M_d * __param._M_1cx * (1 + __y / 2);
1347 __reject = (__w - __e - __x * __param._M_lm_thr
1348 > __param._M_lfm - std::lgamma(__x + __m + 1));
1350 __reject |= __x + __m >= __thr;
1360 double __prod = 1.0;
1364 __prod *= __aurng();
1367 while (__prod > __param._M_lm_thr);
1373 template<
typename _IntType>
1374 template<
typename _ForwardIterator,
1375 typename _UniformRandomNumberGenerator>
1379 _UniformRandomNumberGenerator& __urng,
1380 const param_type& __param)
1382 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1385 *__f++ = this->operator()(__urng, __param);
1388 template<typename _IntType,
1389 typename _CharT, typename _Traits>
1396 const typename __ios_base::fmtflags __flags = __os.
flags();
1397 const _CharT __fill = __os.fill();
1399 const _CharT __space = __os.widen(
' ');
1404 __os << __x.mean() << __space << __x._M_nd;
1406 __os.flags(__flags);
1408 __os.precision(__precision);
1412 template<
typename _IntType,
1413 typename _CharT,
typename _Traits>
1416 poisson_distribution<_IntType>& __x)
1418 using param_type =
typename poisson_distribution<_IntType>::param_type;
1419 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1421 const typename __ios_base::fmtflags __flags = __is.
flags();
1425 if (__is >> __mean >> __x._M_nd)
1426 __x.param(param_type(__mean));
1428 __is.
flags(__flags);
1433 template<
typename _IntType>
1435 binomial_distribution<_IntType>::param_type::
1438 const double __p12 = _M_p <= 0.5 ? _M_p : 1.0 - _M_p;
1442 #if _GLIBCXX_USE_C99_MATH_TR1
1443 if (_M_t * __p12 >= 8)
1446 const double __np = std::floor(_M_t * __p12);
1447 const double __pa = __np / _M_t;
1448 const double __1p = 1 - __pa;
1450 const double __pi_4 = 0.7853981633974483096156608458198757L;
1451 const double __d1x =
1453 / (81 * __pi_4 * __1p)));
1454 _M_d1 = std::round(std::max<double>(1.0, __d1x));
1455 const double __d2x =
1457 / (__pi_4 * __pa)));
1458 _M_d2 = std::round(std::max<double>(1.0, __d2x));
1461 const double __spi_2 = 1.2533141373155002512078826424055226L;
1462 _M_s1 =
std::sqrt(__np * __1p) * (1 + _M_d1 / (4 * __np));
1463 _M_s2 =
std::sqrt(__np * __1p) * (1 + _M_d2 / (4 * _M_t * __1p));
1464 _M_c = 2 * _M_d1 / __np;
1465 _M_a1 =
std::exp(_M_c) * _M_s1 * __spi_2;
1466 const double __a12 = _M_a1 + _M_s2 * __spi_2;
1467 const double __s1s = _M_s1 * _M_s1;
1468 _M_a123 = __a12 + (
std::exp(_M_d1 / (_M_t * __1p))
1470 *
std::exp(-_M_d1 * _M_d1 / (2 * __s1s)));
1471 const double __s2s = _M_s2 * _M_s2;
1472 _M_s = (_M_a123 + 2 * __s2s / _M_d2
1473 *
std::exp(-_M_d2 * _M_d2 / (2 * __s2s)));
1474 _M_lf = (std::lgamma(__np + 1)
1475 + std::lgamma(_M_t - __np + 1));
1478 _M_q = -
std::log(1 - (__p12 - __pa) / __1p);
1485 template<
typename _IntType>
1486 template<
typename _UniformRandomNumberGenerator>
1487 typename binomial_distribution<_IntType>::result_type
1488 binomial_distribution<_IntType>::
1489 _M_waiting(_UniformRandomNumberGenerator& __urng,
1490 _IntType __t,
double __q)
1494 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1501 const double __e = -
std::log(1.0 - __aurng());
1502 __sum += __e / (__t - __x);
1505 while (__sum <= __q);
1520 template<
typename _IntType>
1521 template<
typename _UniformRandomNumberGenerator>
1522 typename binomial_distribution<_IntType>::result_type
1525 const param_type& __param)
1528 const _IntType __t = __param.t();
1529 const double __p = __param.p();
1530 const double __p12 = __p <= 0.5 ? __p : 1.0 - __p;
1531 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1534 #if _GLIBCXX_USE_C99_MATH_TR1
1535 if (!__param._M_easy)
1540 const double __naf =
1542 const double __thr =
1545 const double __np = std::floor(__t * __p12);
1548 const double __spi_2 = 1.2533141373155002512078826424055226L;
1549 const double __a1 = __param._M_a1;
1550 const double __a12 = __a1 + __param._M_s2 * __spi_2;
1551 const double __a123 = __param._M_a123;
1552 const double __s1s = __param._M_s1 * __param._M_s1;
1553 const double __s2s = __param._M_s2 * __param._M_s2;
1558 const double __u = __param._M_s * __aurng();
1564 const double __n = _M_nd(__urng);
1565 const double __y = __param._M_s1 *
std::abs(__n);
1566 __reject = __y >= __param._M_d1;
1569 const double __e = -
std::log(1.0 - __aurng());
1570 __x = std::floor(__y);
1571 __v = -__e - __n * __n / 2 + __param._M_c;
1574 else if (__u <= __a12)
1576 const double __n = _M_nd(__urng);
1577 const double __y = __param._M_s2 *
std::abs(__n);
1578 __reject = __y >= __param._M_d2;
1581 const double __e = -
std::log(1.0 - __aurng());
1582 __x = std::floor(-__y);
1583 __v = -__e - __n * __n / 2;
1586 else if (__u <= __a123)
1588 const double __e1 = -
std::log(1.0 - __aurng());
1589 const double __e2 = -
std::log(1.0 - __aurng());
1591 const double __y = __param._M_d1
1592 + 2 * __s1s * __e1 / __param._M_d1;
1593 __x = std::floor(__y);
1594 __v = (-__e2 + __param._M_d1 * (1 / (__t - __np)
1595 -__y / (2 * __s1s)));
1600 const double __e1 = -
std::log(1.0 - __aurng());
1601 const double __e2 = -
std::log(1.0 - __aurng());
1603 const double __y = __param._M_d2
1604 + 2 * __s2s * __e1 / __param._M_d2;
1605 __x = std::floor(-__y);
1606 __v = -__e2 - __param._M_d2 * __y / (2 * __s2s);
1610 __reject = __reject || __x < -__np || __x > __t - __np;
1613 const double __lfx =
1614 std::lgamma(__np + __x + 1)
1615 + std::lgamma(__t - (__np + __x) + 1);
1616 __reject = __v > __param._M_lf - __lfx
1617 + __x * __param._M_lp1p;
1620 __reject |= __x + __np >= __thr;
1624 __x += __np + __naf;
1626 const _IntType __z = _M_waiting(__urng, __t - _IntType(__x),
1628 __ret = _IntType(__x) + __z;
1632 __ret = _M_waiting(__urng, __t, __param._M_q);
1635 __ret = __t - __ret;
1639 template<
typename _IntType>
1640 template<
typename _ForwardIterator,
1641 typename _UniformRandomNumberGenerator>
1645 _UniformRandomNumberGenerator& __urng,
1646 const param_type& __param)
1648 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1651 *__f++ = this->operator()(__urng, __param);
1654 template<typename _IntType,
1655 typename _CharT, typename _Traits>
1662 const typename __ios_base::fmtflags __flags = __os.
flags();
1663 const _CharT __fill = __os.fill();
1665 const _CharT __space = __os.widen(
' ');
1670 __os << __x.t() << __space << __x.p()
1671 << __space << __x._M_nd;
1673 __os.flags(__flags);
1675 __os.precision(__precision);
1679 template<
typename _IntType,
1680 typename _CharT,
typename _Traits>
1683 binomial_distribution<_IntType>& __x)
1685 using param_type =
typename binomial_distribution<_IntType>::param_type;
1686 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1688 const typename __ios_base::fmtflags __flags = __is.
flags();
1693 if (__is >> __t >> __p >> __x._M_nd)
1694 __x.param(param_type(__t, __p));
1696 __is.
flags(__flags);
1701 template<
typename _RealType>
1702 template<
typename _ForwardIterator,
1703 typename _UniformRandomNumberGenerator>
1707 _UniformRandomNumberGenerator& __urng,
1708 const param_type& __p)
1710 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1711 __detail::_Adaptor<_UniformRandomNumberGenerator,
result_type>
1717 template<typename _RealType, typename _CharT, typename _Traits>
1718 std::basic_ostream<_CharT, _Traits>&
1724 const typename __ios_base::fmtflags __flags = __os.
flags();
1725 const _CharT __fill = __os.fill();
1728 __os.fill(__os.widen(
' '));
1731 __os << __x.lambda();
1733 __os.flags(__flags);
1735 __os.precision(__precision);
1739 template<
typename _RealType,
typename _CharT,
typename _Traits>
1748 const typename __ios_base::fmtflags __flags = __is.
flags();
1752 if (__is >> __lambda)
1753 __x.
param(param_type(__lambda));
1755 __is.
flags(__flags);
1766 template<
typename _RealType>
1767 template<
typename _UniformRandomNumberGenerator>
1768 typename normal_distribution<_RealType>::result_type
1771 const param_type& __param)
1774 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1777 if (_M_saved_available)
1779 _M_saved_available =
false;
1789 __r2 = __x * __x + __y * __y;
1791 while (__r2 > 1.0 || __r2 == 0.0);
1794 _M_saved = __x * __mult;
1795 _M_saved_available =
true;
1796 __ret = __y * __mult;
1799 __ret = __ret * __param.stddev() + __param.mean();
1803 template<
typename _RealType>
1804 template<
typename _ForwardIterator,
1805 typename _UniformRandomNumberGenerator>
1809 _UniformRandomNumberGenerator& __urng,
1810 const param_type& __param)
1812 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1817 if (_M_saved_available)
1819 _M_saved_available =
false;
1820 *__f++ = _M_saved * __param.stddev() + __param.mean();
1826 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1829 while (__f + 1 < __t)
1836 __r2 = __x * __x + __y * __y;
1838 while (__r2 > 1.0 || __r2 == 0.0);
1841 *__f++ = __y * __mult * __param.stddev() + __param.mean();
1842 *__f++ = __x * __mult * __param.stddev() + __param.mean();
1852 __r2 = __x * __x + __y * __y;
1854 while (__r2 > 1.0 || __r2 == 0.0);
1857 _M_saved = __x * __mult;
1858 _M_saved_available =
true;
1859 *__f = __y * __mult * __param.stddev() + __param.mean();
1863 template<
typename _RealType>
1868 if (__d1._M_param == __d2._M_param
1869 && __d1._M_saved_available == __d2._M_saved_available)
1871 if (__d1._M_saved_available
1872 && __d1._M_saved == __d2._M_saved)
1874 else if(!__d1._M_saved_available)
1883 template<
typename _RealType,
typename _CharT,
typename _Traits>
1885 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1886 const normal_distribution<_RealType>& __x)
1888 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1890 const typename __ios_base::fmtflags __flags = __os.
flags();
1891 const _CharT __fill = __os.
fill();
1893 const _CharT __space = __os.
widen(
' ');
1898 __os << __x.mean() << __space << __x.stddev()
1899 << __space << __x._M_saved_available;
1900 if (__x._M_saved_available)
1901 __os << __space << __x._M_saved;
1903 __os.
flags(__flags);
1909 template<
typename _RealType,
typename _CharT,
typename _Traits>
1912 normal_distribution<_RealType>& __x)
1914 using param_type =
typename normal_distribution<_RealType>::param_type;
1915 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1917 const typename __ios_base::fmtflags __flags = __is.
flags();
1920 double __mean, __stddev;
1922 if (__is >> __mean >> __stddev >> __saved_avail)
1924 if (__saved_avail && (__is >> __x._M_saved))
1926 __x._M_saved_available = __saved_avail;
1927 __x.param(param_type(__mean, __stddev));
1931 __is.
flags(__flags);
1936 template<
typename _RealType>
1937 template<
typename _ForwardIterator,
1938 typename _UniformRandomNumberGenerator>
1940 lognormal_distribution<_RealType>::
1941 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1942 _UniformRandomNumberGenerator& __urng,
1943 const param_type& __p)
1945 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1947 *__f++ = std::
exp(__p.s() * _M_nd(__urng) + __p.m());
1950 template<typename _RealType, typename _CharT, typename _Traits>
1951 std::basic_ostream<_CharT, _Traits>&
1952 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1953 const lognormal_distribution<_RealType>& __x)
1955 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1957 const typename __ios_base::fmtflags __flags = __os.flags();
1958 const _CharT __fill = __os.fill();
1960 const _CharT __space = __os.widen(
' ');
1965 __os << __x.m() << __space << __x.s()
1966 << __space << __x._M_nd;
1968 __os.flags(__flags);
1970 __os.precision(__precision);
1974 template<
typename _RealType,
typename _CharT,
typename _Traits>
1977 lognormal_distribution<_RealType>& __x)
1980 =
typename lognormal_distribution<_RealType>::param_type;
1981 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1983 const typename __ios_base::fmtflags __flags = __is.
flags();
1987 if (__is >> __m >> __s >> __x._M_nd)
1988 __x.param(param_type(__m, __s));
1990 __is.
flags(__flags);
1994 template<
typename _RealType>
1995 template<
typename _ForwardIterator,
1996 typename _UniformRandomNumberGenerator>
2000 _UniformRandomNumberGenerator& __urng)
2002 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2004 *__f++ = 2 * _M_gd(__urng);
2007 template<typename _RealType>
2008 template<typename _ForwardIterator,
2009 typename _UniformRandomNumberGenerator>
2011 std::chi_squared_distribution<_RealType>::
2012 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2013 _UniformRandomNumberGenerator& __urng,
2015 std::gamma_distribution<
result_type>::param_type& __p)
2017 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2019 *__f++ = 2 * _M_gd(__urng, __p);
2022 template<typename _RealType, typename _CharT, typename _Traits>
2023 std::basic_ostream<_CharT, _Traits>&
2024 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2025 const chi_squared_distribution<_RealType>& __x)
2027 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2029 const typename __ios_base::fmtflags __flags = __os.flags();
2030 const _CharT __fill = __os.fill();
2032 const _CharT __space = __os.widen(
' ');
2037 __os << __x.n() << __space << __x._M_gd;
2039 __os.flags(__flags);
2041 __os.precision(__precision);
2045 template<
typename _RealType,
typename _CharT,
typename _Traits>
2048 chi_squared_distribution<_RealType>& __x)
2051 =
typename chi_squared_distribution<_RealType>::param_type;
2052 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2054 const typename __ios_base::fmtflags __flags = __is.
flags();
2058 if (__is >> __n >> __x._M_gd)
2059 __x.param(param_type(__n));
2061 __is.
flags(__flags);
2066 template<
typename _RealType>
2067 template<
typename _UniformRandomNumberGenerator>
2068 typename cauchy_distribution<_RealType>::result_type
2070 operator()(_UniformRandomNumberGenerator& __urng,
2071 const param_type& __p)
2073 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2080 const _RealType __pi = 3.1415926535897932384626433832795029L;
2081 return __p.a() + __p.b() *
std::tan(__pi * __u);
2084 template<
typename _RealType>
2085 template<
typename _ForwardIterator,
2086 typename _UniformRandomNumberGenerator>
2088 cauchy_distribution<_RealType>::
2089 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2090 _UniformRandomNumberGenerator& __urng,
2091 const param_type& __p)
2093 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2094 const _RealType __pi = 3.1415926535897932384626433832795029L;
2095 __detail::_Adaptor<_UniformRandomNumberGenerator,
result_type>
2104 *__f++ = __p.a() + __p.b() *
std::tan(__pi * __u);
2108 template<
typename _RealType,
typename _CharT,
typename _Traits>
2110 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2115 const typename __ios_base::fmtflags __flags = __os.
flags();
2116 const _CharT __fill = __os.fill();
2118 const _CharT __space = __os.widen(
' ');
2123 __os << __x.a() << __space << __x.b();
2125 __os.flags(__flags);
2127 __os.precision(__precision);
2131 template<
typename _RealType,
typename _CharT,
typename _Traits>
2139 const typename __ios_base::fmtflags __flags = __is.
flags();
2143 if (__is >> __a >> __b)
2144 __x.
param(param_type(__a, __b));
2146 __is.
flags(__flags);
2151 template<
typename _RealType>
2152 template<
typename _ForwardIterator,
2153 typename _UniformRandomNumberGenerator>
2157 _UniformRandomNumberGenerator& __urng)
2159 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2161 *__f++ = ((_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()));
2164 template<typename _RealType>
2165 template<typename _ForwardIterator,
2166 typename _UniformRandomNumberGenerator>
2168 std::fisher_f_distribution<_RealType>::
2169 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2170 _UniformRandomNumberGenerator& __urng,
2171 const param_type& __p)
2173 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2174 typedef typename std::gamma_distribution<
result_type>::param_type
2176 param_type __p1(__p.m() / 2);
2177 param_type __p2(__p.n() / 2);
2179 *__f++ = ((_M_gd_x(__urng, __p1) * n())
2180 / (_M_gd_y(__urng, __p2) * m()));
2183 template<typename _RealType, typename _CharT, typename _Traits>
2184 std::basic_ostream<_CharT, _Traits>&
2185 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2186 const fisher_f_distribution<_RealType>& __x)
2188 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2190 const typename __ios_base::fmtflags __flags = __os.flags();
2191 const _CharT __fill = __os.fill();
2193 const _CharT __space = __os.widen(
' ');
2198 __os << __x.m() << __space << __x.n()
2199 << __space << __x._M_gd_x << __space << __x._M_gd_y;
2201 __os.flags(__flags);
2203 __os.precision(__precision);
2207 template<
typename _RealType,
typename _CharT,
typename _Traits>
2210 fisher_f_distribution<_RealType>& __x)
2213 =
typename fisher_f_distribution<_RealType>::param_type;
2214 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2216 const typename __ios_base::fmtflags __flags = __is.
flags();
2220 if (__is >> __m >> __n >> __x._M_gd_x >> __x._M_gd_y)
2221 __x.param(param_type(__m, __n));
2223 __is.
flags(__flags);
2228 template<
typename _RealType>
2229 template<
typename _ForwardIterator,
2230 typename _UniformRandomNumberGenerator>
2234 _UniformRandomNumberGenerator& __urng)
2236 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2238 *__f++ = _M_nd(__urng) * std::
sqrt(n() / _M_gd(__urng));
2241 template<typename _RealType>
2242 template<typename _ForwardIterator,
2243 typename _UniformRandomNumberGenerator>
2245 std::student_t_distribution<_RealType>::
2246 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2247 _UniformRandomNumberGenerator& __urng,
2248 const param_type& __p)
2250 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2251 typename std::gamma_distribution<
result_type>::param_type
2252 __p2(__p.n() / 2, 2);
2254 *__f++ = _M_nd(__urng) * std::
sqrt(__p.n() / _M_gd(__urng, __p2));
2257 template<typename _RealType, typename _CharT, typename _Traits>
2258 std::basic_ostream<_CharT, _Traits>&
2259 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2260 const student_t_distribution<_RealType>& __x)
2262 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2264 const typename __ios_base::fmtflags __flags = __os.flags();
2265 const _CharT __fill = __os.fill();
2267 const _CharT __space = __os.widen(
' ');
2272 __os << __x.n() << __space << __x._M_nd << __space << __x._M_gd;
2274 __os.flags(__flags);
2276 __os.precision(__precision);
2280 template<
typename _RealType,
typename _CharT,
typename _Traits>
2283 student_t_distribution<_RealType>& __x)
2286 =
typename student_t_distribution<_RealType>::param_type;
2287 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2289 const typename __ios_base::fmtflags __flags = __is.
flags();
2293 if (__is >> __n >> __x._M_nd >> __x._M_gd)
2294 __x.param(param_type(__n));
2296 __is.
flags(__flags);
2301 template<
typename _RealType>
2303 gamma_distribution<_RealType>::param_type::
2306 _M_malpha = _M_alpha < 1.0 ? _M_alpha + _RealType(1.0) : _M_alpha;
2308 const _RealType __a1 = _M_malpha - _RealType(1.0) / _RealType(3.0);
2309 _M_a2 = _RealType(1.0) /
std::sqrt(_RealType(9.0) * __a1);
2317 template<
typename _RealType>
2318 template<
typename _UniformRandomNumberGenerator>
2319 typename gamma_distribution<_RealType>::result_type
2322 const param_type& __param)
2324 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2329 - _RealType(1.0) / _RealType(3.0));
2335 __n = _M_nd(__urng);
2340 __v = __v * __v * __v;
2343 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2344 && (
std::log(__u) > (0.5 * __n * __n + __a1
2347 if (__param.alpha() == __param._M_malpha)
2348 return __a1 * __v * __param.beta();
2356 * __a1 * __v * __param.beta());
2360 template<
typename _RealType>
2361 template<
typename _ForwardIterator,
2362 typename _UniformRandomNumberGenerator>
2366 _UniformRandomNumberGenerator& __urng,
2367 const param_type& __param)
2369 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2370 __detail::_Adaptor<_UniformRandomNumberGenerator,
result_type>
2375 - _RealType(1.0) / _RealType(3.0));
2377 if (__param.alpha() == __param._M_malpha)
2384 __n = _M_nd(__urng);
2389 __v = __v * __v * __v;
2392 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2393 && (
std::log(__u) > (0.5 * __n * __n + __a1
2396 *__f++ = __a1 * __v * __param.beta();
2405 __n = _M_nd(__urng);
2410 __v = __v * __v * __v;
2413 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2414 && (
std::log(__u) > (0.5 * __n * __n + __a1
2422 * __a1 * __v * __param.beta());
2426 template<
typename _RealType,
typename _CharT,
typename _Traits>
2428 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2429 const gamma_distribution<_RealType>& __x)
2431 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2433 const typename __ios_base::fmtflags __flags = __os.
flags();
2434 const _CharT __fill = __os.
fill();
2436 const _CharT __space = __os.
widen(
' ');
2441 __os << __x.alpha() << __space << __x.beta()
2442 << __space << __x._M_nd;
2444 __os.
flags(__flags);
2450 template<
typename _RealType,
typename _CharT,
typename _Traits>
2453 gamma_distribution<_RealType>& __x)
2455 using param_type =
typename gamma_distribution<_RealType>::param_type;
2456 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2458 const typename __ios_base::fmtflags __flags = __is.
flags();
2461 _RealType __alpha_val, __beta_val;
2462 if (__is >> __alpha_val >> __beta_val >> __x._M_nd)
2463 __x.param(param_type(__alpha_val, __beta_val));
2465 __is.
flags(__flags);
2470 template<
typename _RealType>
2471 template<
typename _UniformRandomNumberGenerator>
2472 typename weibull_distribution<_RealType>::result_type
2473 weibull_distribution<_RealType>::
2474 operator()(_UniformRandomNumberGenerator& __urng,
2475 const param_type& __p)
2477 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2483 template<
typename _RealType>
2484 template<
typename _ForwardIterator,
2485 typename _UniformRandomNumberGenerator>
2487 weibull_distribution<_RealType>::
2488 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2489 _UniformRandomNumberGenerator& __urng,
2490 const param_type& __p)
2492 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2493 __detail::_Adaptor<_UniformRandomNumberGenerator,
result_type>
2502 template<typename _RealType, typename _CharT, typename _Traits>
2503 std::basic_ostream<_CharT, _Traits>&
2509 const typename __ios_base::fmtflags __flags = __os.
flags();
2510 const _CharT __fill = __os.fill();
2512 const _CharT __space = __os.widen(
' ');
2517 __os << __x.a() << __space << __x.b();
2519 __os.flags(__flags);
2521 __os.precision(__precision);
2525 template<
typename _RealType,
typename _CharT,
typename _Traits>
2533 const typename __ios_base::fmtflags __flags = __is.
flags();
2537 if (__is >> __a >> __b)
2538 __x.param(param_type(__a, __b));
2540 __is.
flags(__flags);
2545 template<
typename _RealType>
2546 template<
typename _UniformRandomNumberGenerator>
2547 typename extreme_value_distribution<_RealType>::result_type
2548 extreme_value_distribution<_RealType>::
2549 operator()(_UniformRandomNumberGenerator& __urng,
2550 const param_type& __p)
2552 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2558 template<
typename _RealType>
2559 template<
typename _ForwardIterator,
2560 typename _UniformRandomNumberGenerator>
2562 extreme_value_distribution<_RealType>::
2563 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2564 _UniformRandomNumberGenerator& __urng,
2565 const param_type& __p)
2567 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2568 __detail::_Adaptor<_UniformRandomNumberGenerator,
result_type>
2576 template<typename _RealType, typename _CharT, typename _Traits>
2577 std::basic_ostream<_CharT, _Traits>&
2583 const typename __ios_base::fmtflags __flags = __os.
flags();
2584 const _CharT __fill = __os.fill();
2586 const _CharT __space = __os.widen(
' ');
2591 __os << __x.a() << __space << __x.b();
2593 __os.flags(__flags);
2595 __os.precision(__precision);
2599 template<
typename _RealType,
typename _CharT,
typename _Traits>
2608 const typename __ios_base::fmtflags __flags = __is.
flags();
2612 if (__is >> __a >> __b)
2613 __x.param(param_type(__a, __b));
2615 __is.
flags(__flags);
2620 template<
typename _IntType>
2622 discrete_distribution<_IntType>::param_type::
2625 if (_M_prob.size() < 2)
2632 _M_prob.end(), 0.0);
2634 __detail::__normalize(_M_prob.begin(), _M_prob.end(), _M_prob.begin(),
2637 _M_cp.reserve(_M_prob.size());
2641 _M_cp[_M_cp.size() - 1] = 1.0;
2644 template<
typename _IntType>
2645 template<
typename _Func>
2646 discrete_distribution<_IntType>::param_type::
2647 param_type(
size_t __nw,
double __xmin,
double __xmax, _Func __fw)
2648 : _M_prob(), _M_cp()
2650 const size_t __n = __nw == 0 ? 1 : __nw;
2651 const double __delta = (__xmax - __xmin) / __n;
2653 _M_prob.reserve(__n);
2654 for (
size_t __k = 0; __k < __nw; ++__k)
2655 _M_prob.push_back(__fw(__xmin + __k * __delta + 0.5 * __delta));
2660 template<
typename _IntType>
2661 template<
typename _UniformRandomNumberGenerator>
2662 typename discrete_distribution<_IntType>::result_type
2663 discrete_distribution<_IntType>::
2664 operator()(_UniformRandomNumberGenerator& __urng,
2665 const param_type& __param)
2667 if (__param._M_cp.empty())
2668 return result_type(0);
2670 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2673 const double __p = __aurng();
2675 __param._M_cp.end(), __p);
2677 return __pos - __param._M_cp.begin();
2680 template<
typename _IntType>
2681 template<
typename _ForwardIterator,
2682 typename _UniformRandomNumberGenerator>
2684 discrete_distribution<_IntType>::
2685 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2686 _UniformRandomNumberGenerator& __urng,
2687 const param_type& __param)
2689 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2691 if (__param._M_cp.empty())
2694 *__f++ = result_type(0);
2698 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2703 const double __p = __aurng();
2705 __param._M_cp.end(), __p);
2707 *__f++ = __pos - __param._M_cp.begin();
2711 template<
typename _IntType,
typename _CharT,
typename _Traits>
2713 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2714 const discrete_distribution<_IntType>& __x)
2716 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2718 const typename __ios_base::fmtflags __flags = __os.
flags();
2719 const _CharT __fill = __os.
fill();
2721 const _CharT __space = __os.
widen(
' ');
2727 __os << __prob.
size();
2728 for (
auto __dit = __prob.
begin(); __dit != __prob.
end(); ++__dit)
2729 __os << __space << *__dit;
2731 __os.
flags(__flags);
2739 template<
typename _ValT,
typename _CharT,
typename _Traits>
2740 basic_istream<_CharT, _Traits>&
2741 __extract_params(basic_istream<_CharT, _Traits>& __is,
2742 vector<_ValT>& __vals,
size_t __n)
2744 __vals.reserve(__n);
2749 __vals.push_back(__val);
2757 template<
typename _IntType,
typename _CharT,
typename _Traits>
2760 discrete_distribution<_IntType>& __x)
2762 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2764 const typename __ios_base::fmtflags __flags = __is.
flags();
2771 if (__detail::__extract_params(__is, __prob_vec, __n))
2772 __x.param({__prob_vec.
begin(), __prob_vec.
end()});
2775 __is.
flags(__flags);
2780 template<
typename _RealType>
2782 piecewise_constant_distribution<_RealType>::param_type::
2785 if (_M_int.size() < 2
2786 || (_M_int.size() == 2
2787 && _M_int[0] == _RealType(0)
2788 && _M_int[1] == _RealType(1)))
2798 __detail::__normalize(_M_den.begin(), _M_den.end(), _M_den.begin(),
2801 _M_cp.reserve(_M_den.size());
2806 _M_cp[_M_cp.size() - 1] = 1.0;
2808 for (
size_t __k = 0; __k < _M_den.size(); ++__k)
2809 _M_den[__k] /= _M_int[__k + 1] - _M_int[__k];
2812 template<
typename _RealType>
2813 template<
typename _InputIteratorB,
typename _InputIteratorW>
2814 piecewise_constant_distribution<_RealType>::param_type::
2815 param_type(_InputIteratorB __bbegin,
2816 _InputIteratorB __bend,
2817 _InputIteratorW __wbegin)
2818 : _M_int(), _M_den(), _M_cp()
2820 if (__bbegin != __bend)
2824 _M_int.push_back(*__bbegin);
2826 if (__bbegin == __bend)
2829 _M_den.push_back(*__wbegin);
2837 template<
typename _RealType>
2838 template<
typename _Func>
2839 piecewise_constant_distribution<_RealType>::param_type::
2840 param_type(initializer_list<_RealType> __bl, _Func __fw)
2841 : _M_int(), _M_den(), _M_cp()
2843 _M_int.reserve(__bl.size());
2844 for (
auto __biter = __bl.begin(); __biter != __bl.end(); ++__biter)
2845 _M_int.push_back(*__biter);
2847 _M_den.reserve(_M_int.size() - 1);
2848 for (
size_t __k = 0; __k < _M_int.size() - 1; ++__k)
2849 _M_den.push_back(__fw(0.5 * (_M_int[__k + 1] + _M_int[__k])));
2854 template<
typename _RealType>
2855 template<
typename _Func>
2856 piecewise_constant_distribution<_RealType>::param_type::
2857 param_type(
size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
2858 : _M_int(), _M_den(), _M_cp()
2860 const size_t __n = __nw == 0 ? 1 : __nw;
2861 const _RealType __delta = (__xmax - __xmin) / __n;
2863 _M_int.reserve(__n + 1);
2864 for (
size_t __k = 0; __k <= __nw; ++__k)
2865 _M_int.push_back(__xmin + __k * __delta);
2867 _M_den.reserve(__n);
2868 for (
size_t __k = 0; __k < __nw; ++__k)
2869 _M_den.push_back(__fw(_M_int[__k] + 0.5 * __delta));
2874 template<
typename _RealType>
2875 template<
typename _UniformRandomNumberGenerator>
2876 typename piecewise_constant_distribution<_RealType>::result_type
2877 piecewise_constant_distribution<_RealType>::
2878 operator()(_UniformRandomNumberGenerator& __urng,
2879 const param_type& __param)
2881 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2884 const double __p = __aurng();
2885 if (__param._M_cp.empty())
2889 __param._M_cp.end(), __p);
2890 const size_t __i = __pos - __param._M_cp.begin();
2892 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
2894 return __param._M_int[__i] + (__p - __pref) / __param._M_den[__i];
2897 template<
typename _RealType>
2898 template<
typename _ForwardIterator,
2899 typename _UniformRandomNumberGenerator>
2901 piecewise_constant_distribution<_RealType>::
2902 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2903 _UniformRandomNumberGenerator& __urng,
2904 const param_type& __param)
2906 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2907 __detail::_Adaptor<_UniformRandomNumberGenerator,
double>
2910 if (__param._M_cp.empty())
2919 const double __p = __aurng();
2922 __param._M_cp.end(), __p);
2923 const size_t __i = __pos - __param._M_cp.begin();
2925 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
2927 *__f++ = (__param._M_int[__i]
2928 + (__p - __pref) / __param._M_den[__i]);
2932 template<
typename _RealType,
typename _CharT,
typename _Traits>
2934 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2935 const piecewise_constant_distribution<_RealType>& __x)
2937 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2939 const typename __ios_base::fmtflags __flags = __os.
flags();
2940 const _CharT __fill = __os.
fill();
2942 const _CharT __space = __os.
widen(
' ');
2948 __os << __int.
size() - 1;
2950 for (
auto __xit = __int.
begin(); __xit != __int.
end(); ++__xit)
2951 __os << __space << *__xit;
2954 for (
auto __dit = __den.
begin(); __dit != __den.
end(); ++__dit)
2955 __os << __space << *__dit;
2957 __os.
flags(__flags);
2963 template<
typename _RealType,
typename _CharT,
typename _Traits>
2966 piecewise_constant_distribution<_RealType>& __x)
2968 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2970 const typename __ios_base::fmtflags __flags = __is.
flags();
2977 if (__detail::__extract_params(__is, __int_vec, __n + 1))
2980 if (__detail::__extract_params(__is, __den_vec, __n))
2982 __x.param({ __int_vec.
begin(), __int_vec.
end(),
2983 __den_vec.
begin() });
2988 __is.
flags(__flags);
2993 template<
typename _RealType>
2995 piecewise_linear_distribution<_RealType>::param_type::
2998 if (_M_int.size() < 2
2999 || (_M_int.size() == 2
3000 && _M_int[0] == _RealType(0)
3001 && _M_int[1] == _RealType(1)
3002 && _M_den[0] == _M_den[1]))
3010 _M_cp.reserve(_M_int.size() - 1);
3011 _M_m.reserve(_M_int.size() - 1);
3012 for (
size_t __k = 0; __k < _M_int.size() - 1; ++__k)
3014 const _RealType __delta = _M_int[__k + 1] - _M_int[__k];
3015 __sum += 0.5 * (_M_den[__k + 1] + _M_den[__k]) * __delta;
3016 _M_cp.push_back(__sum);
3017 _M_m.push_back((_M_den[__k + 1] - _M_den[__k]) / __delta);
3021 __detail::__normalize(_M_den.begin(), _M_den.end(), _M_den.begin(),
3024 __detail::__normalize(_M_cp.begin(), _M_cp.end(), _M_cp.begin(), __sum);
3026 __detail::__normalize(_M_m.begin(), _M_m.end(), _M_m.begin(), __sum);
3029 _M_cp[_M_cp.size() - 1] = 1.0;
3032 template<
typename _RealType>
3033 template<
typename _InputIteratorB,
typename _InputIteratorW>
3034 piecewise_linear_distribution<_RealType>::param_type::
3035 param_type(_InputIteratorB __bbegin,
3036 _InputIteratorB __bend,
3037 _InputIteratorW __wbegin)
3038 : _M_int(), _M_den(), _M_cp(), _M_m()
3040 for (; __bbegin != __bend; ++__bbegin, ++__wbegin)
3042 _M_int.push_back(*__bbegin);
3043 _M_den.push_back(*__wbegin);
3049 template<
typename _RealType>
3050 template<
typename _Func>
3051 piecewise_linear_distribution<_RealType>::param_type::
3052 param_type(initializer_list<_RealType> __bl, _Func __fw)
3053 : _M_int(), _M_den(), _M_cp(), _M_m()
3055 _M_int.reserve(__bl.size());
3056 _M_den.reserve(__bl.size());
3057 for (
auto __biter = __bl.begin(); __biter != __bl.end(); ++__biter)
3059 _M_int.push_back(*__biter);
3060 _M_den.push_back(__fw(*__biter));
3066 template<
typename _RealType>
3067 template<
typename _Func>
3068 piecewise_linear_distribution<_RealType>::param_type::
3069 param_type(
size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
3070 : _M_int(), _M_den(), _M_cp(), _M_m()
3072 const size_t __n = __nw == 0 ? 1 : __nw;
3073 const _RealType __delta = (__xmax - __xmin) / __n;
3075 _M_int.reserve(__n + 1);
3076 _M_den.reserve(__n + 1);
3077 for (
size_t __k = 0; __k <= __nw; ++__k)
3079 _M_int.push_back(__xmin + __k * __delta);
3080 _M_den.push_back(__fw(_M_int[__k] + __delta));
3086 template<
typename _RealType>
3087 template<
typename _UniformRandomNumberGenerator>
3088 typename piecewise_linear_distribution<_RealType>::result_type
3089 piecewise_linear_distribution<_RealType>::
3090 operator()(_UniformRandomNumberGenerator& __urng,
3091 const param_type& __param)
3093 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
3096 const double __p = __aurng();
3097 if (__param._M_cp.empty())
3101 __param._M_cp.end(), __p);
3102 const size_t __i = __pos - __param._M_cp.begin();
3104 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
3106 const double __a = 0.5 * __param._M_m[__i];
3107 const double __b = __param._M_den[__i];
3108 const double __cm = __p - __pref;
3110 _RealType __x = __param._M_int[__i];
3115 const double __d = __b * __b + 4.0 * __a * __cm;
3116 __x += 0.5 * (
std::sqrt(__d) - __b) / __a;
3122 template<
typename _RealType>
3123 template<
typename _ForwardIterator,
3124 typename _UniformRandomNumberGenerator>
3126 piecewise_linear_distribution<_RealType>::
3127 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3128 _UniformRandomNumberGenerator& __urng,
3129 const param_type& __param)
3131 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3134 *__f++ = this->operator()(__urng, __param);
3137 template<typename _RealType, typename _CharT, typename _Traits>
3138 std::basic_ostream<_CharT, _Traits>&
3139 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3140 const piecewise_linear_distribution<_RealType>& __x)
3142 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
3144 const typename __ios_base::fmtflags __flags = __os.flags();
3145 const _CharT __fill = __os.fill();
3147 const _CharT __space = __os.widen(
' ');
3153 __os << __int.
size() - 1;
3155 for (
auto __xit = __int.
begin(); __xit != __int.
end(); ++__xit)
3156 __os << __space << *__xit;
3159 for (
auto __dit = __den.
begin(); __dit != __den.
end(); ++__dit)
3160 __os << __space << *__dit;
3162 __os.flags(__flags);
3164 __os.precision(__precision);
3168 template<
typename _RealType,
typename _CharT,
typename _Traits>
3171 piecewise_linear_distribution<_RealType>& __x)
3173 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
3175 const typename __ios_base::fmtflags __flags = __is.
flags();
3181 vector<_RealType> __int_vec;
3182 if (__detail::__extract_params(__is, __int_vec, __n + 1))
3184 vector<double> __den_vec;
3185 if (__detail::__extract_params(__is, __den_vec, __n + 1))
3187 __x.param({ __int_vec.begin(), __int_vec.end(),
3188 __den_vec.begin() });
3192 __is.
flags(__flags);
3197 template<
typename _IntType>
3200 for (
auto __iter = __il.begin(); __iter != __il.end(); ++__iter)
3201 _M_v.push_back(__detail::__mod<result_type,
3202 __detail::_Shift<result_type, 32>::__value>(*__iter));
3205 template<
typename _InputIterator>
3206 seed_seq::seed_seq(_InputIterator __begin, _InputIterator __end)
3208 for (_InputIterator __iter = __begin; __iter != __end; ++__iter)
3209 _M_v.push_back(__detail::__mod<result_type,
3210 __detail::_Shift<result_type, 32>::__value>(*__iter));
3213 template<
typename _RandomAccessIterator>
3215 seed_seq::generate(_RandomAccessIterator __begin,
3216 _RandomAccessIterator __end)
3218 typedef typename iterator_traits<_RandomAccessIterator>::value_type
3221 if (__begin == __end)
3224 std::fill(__begin, __end, _Type(0x8b8b8b8bu));
3226 const size_t __n = __end - __begin;
3227 const size_t __s = _M_v.size();
3228 const size_t __t = (__n >= 623) ? 11
3233 const size_t __p = (__n - __t) / 2;
3234 const size_t __q = __p + __t;
3235 const size_t __m =
std::max(
size_t(__s + 1), __n);
3237 for (
size_t __k = 0; __k < __m; ++__k)
3239 _Type __arg = (__begin[__k % __n]
3240 ^ __begin[(__k + __p) % __n]
3241 ^ __begin[(__k - 1) % __n]);
3242 _Type __r1 = __arg ^ (__arg >> 27);
3243 __r1 = __detail::__mod<_Type,
3244 __detail::_Shift<_Type, 32>::__value>(1664525u * __r1);
3248 else if (__k <= __s)
3249 __r2 += __k % __n + _M_v[__k - 1];
3252 __r2 = __detail::__mod<_Type,
3253 __detail::_Shift<_Type, 32>::__value>(__r2);
3254 __begin[(__k + __p) % __n] += __r1;
3255 __begin[(__k + __q) % __n] += __r2;
3256 __begin[__k % __n] = __r2;
3259 for (
size_t __k = __m; __k < __m + __n; ++__k)
3261 _Type __arg = (__begin[__k % __n]
3262 + __begin[(__k + __p) % __n]
3263 + __begin[(__k - 1) % __n]);
3264 _Type __r3 = __arg ^ (__arg >> 27);
3265 __r3 = __detail::__mod<_Type,
3266 __detail::_Shift<_Type, 32>::__value>(1566083941u * __r3);
3267 _Type __r4 = __r3 - __k % __n;
3268 __r4 = __detail::__mod<_Type,
3269 __detail::_Shift<_Type, 32>::__value>(__r4);
3270 __begin[(__k + __p) % __n] ^= __r3;
3271 __begin[(__k + __q) % __n] ^= __r4;
3272 __begin[__k % __n] = __r4;
3276 template<
typename _RealType,
size_t __bits,
3277 typename _UniformRandomNumberGenerator>
3282 "template argument must be a floating point type");
3287 const long double __r =
static_cast<long double>(__urng.max())
3288 - static_cast<long double>(__urng.min()) + 1.0L;
3290 const size_t __m = std::max<size_t>(1UL,
3291 (__b + __log2r - 1UL) / __log2r);
3293 _RealType __sum = _RealType(0);
3294 _RealType __tmp = _RealType(1);
3295 for (
size_t __k = __m; __k != 0; --__k)
3297 __sum += _RealType(__urng() - __urng.min()) * __tmp;
3300 __ret = __sum / __tmp;
3301 if (__builtin_expect(__ret >= _RealType(1), 0))
3303 #if _GLIBCXX_USE_C99_MATH_TR1
3304 __ret = std::nextafter(_RealType(1), _RealType(0));
3306 __ret = _RealType(1)
3313 _GLIBCXX_END_NAMESPACE_VERSION
param_type param() const
Returns the parameter set of the distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
static constexpr _Tp min() noexcept
A normal continuous distribution for random numbers.
constexpr int __lg(int __n)
This is a helper function for the sort routines and for random.tcc.
An exponential continuous distribution for random numbers.
_Tp abs(const complex< _Tp > &)
Return magnitude of z.
The Marsaglia-Zaman generator.
complex< _Tp > sqrt(const complex< _Tp > &)
Return complex square root of z.
ios_base & left(ios_base &__base)
Calls base.setf(ios_base::left, ios_base::adjustfield).
streamsize precision() const
Flags access.
size_type size() const noexcept
ios_base & dec(ios_base &__base)
Calls base.setf(ios_base::dec, ios_base::basefield).
char_type fill() const
Retrieves the empty character.
complex< _Tp > exp(const complex< _Tp > &)
Return complex base e exponential of z.
complex< _Tp > tan(const complex< _Tp > &)
Return complex tangent of z.
constexpr back_insert_iterator< _Container > back_inserter(_Container &__x)
static constexpr _Tp max() noexcept
fmtflags flags() const
Access to format flags.
constexpr _OutputIterator partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
Return list of partial sums.
Template class basic_istream.
A model of a linear congruential random number generator.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
A cauchy_distribution random number distribution.
param_type param() const
Returns the parameter set of the distribution.
void clear(iostate __state=goodbit)
[Re]sets the error state.
iterator begin() noexcept
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
void seed(result_type __s=default_seed)
Reseeds the linear_congruential_engine random number generator engine sequence to the seed __s...
result_type operator()()
Gets the next random number in the sequence.
constexpr _Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
Accumulate values in a range.
char_type widen(char __c) const
Widens characters.
ios_base & skipws(ios_base &__base)
Calls base.setf(ios_base::skipws).
A fisher_f_distribution random number distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Produces random numbers by combining random numbers from some base engine to produce random numbers w...
Uniform continuous distribution for random numbers.
_RealType generate_canonical(_UniformRandomNumberGenerator &__g)
A function template for converting the output of a (integral) uniform random number generator to a fl...
constexpr _ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp &__val)
Finds the first position in which val could be inserted without changing the ordering.
param_type param() const
Returns the parameter set of the distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
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...
A extreme_value_distribution random number distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
A chi_squared_distribution random number distribution.
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...
result_type operator()()
Gets the next value in the generated random number sequence.
A weibull_distribution random number distribution.
Properties of fundamental types.
constexpr const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
A Bernoulli random number distribution.
A discrete geometric random number distribution.
complex< _Tp > pow(const complex< _Tp > &, int)
Return x to the y'th power.
void seed(result_type __sd=default_seed)
Seeds the initial state of the random number generator.
result_type operator()()
Gets the next value in the generated random number sequence.
complex< _Tp > log(const complex< _Tp > &)
Return complex natural logarithm of z.
A student_t_distribution random number distribution.
param_type param() const
Returns the parameter set of the distribution.
Uniform discrete distribution for random numbers. A discrete random distribution on the range with e...
A discrete Poisson random number distribution.
ios_base & scientific(ios_base &__base)
Calls base.setf(ios_base::scientific, ios_base::floatfield).
_RandomNumberEngine::result_type result_type
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
A discrete binomial random number distribution.
A gamma continuous distribution for random numbers.
Template class basic_ostream.
param_type param() const
Returns the parameter set of the distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
static constexpr _Tp epsilon() noexcept
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.