35 namespace std _GLIBCXX_VISIBILITY(default)
37 _GLIBCXX_BEGIN_NAMESPACE_VERSION
50 template<
typename _Tp, _Tp __m, _Tp __a, _Tp __c>
52 _Mod<_Tp, __m, __a, __c, false, true>::
59 static const _Tp __q = __m / __a;
60 static const _Tp __r = __m % __a;
62 _Tp __t1 = __a * (__x % __q);
63 _Tp __t2 = __r * (__x / __q);
67 __x = __m - __t2 + __t1;
72 const _Tp __d = __m - __x;
81 template<
typename _InputIterator,
typename _OutputIterator,
84 __normalize(_InputIterator __first, _InputIterator __last,
85 _OutputIterator __result,
const _Tp& __factor)
87 for (; __first != __last; ++__first, ++__result)
88 *__result = *__first / __factor;
94 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
98 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
102 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
106 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
108 linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed;
114 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
119 if ((__detail::__mod<_UIntType, __m>(__c) == 0)
120 && (__detail::__mod<_UIntType, __m>(__s) == 0))
123 _M_x = __detail::__mod<_UIntType, __m>(__s);
129 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
130 template<
typename _Sseq>
137 const _UIntType __k = (__k0 + 31) / 32;
138 uint_least32_t __arr[__k + 3];
139 __q.generate(__arr + 0, __arr + __k + 3);
140 _UIntType __factor = 1u;
141 _UIntType __sum = 0u;
142 for (
size_t __j = 0; __j < __k; ++__j)
144 __sum += __arr[__j + 3] * __factor;
145 __factor *= __detail::_Shift<_UIntType, 32>::__value;
150 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m,
151 typename _CharT,
typename _Traits>
155 __a, __c, __m>& __lcr)
158 typedef typename __ostream_type::ios_base __ios_base;
160 const typename __ios_base::fmtflags __flags = __os.
flags();
161 const _CharT __fill = __os.
fill();
172 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m,
173 typename _CharT,
typename _Traits>
176 linear_congruential_engine<_UIntType, __a, __c, __m>& __lcr)
179 typedef typename __istream_type::ios_base __ios_base;
181 const typename __ios_base::fmtflags __flags = __is.
flags();
191 template<
typename _UIntType,
192 size_t __w,
size_t __n,
size_t __m,
size_t __r,
193 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
194 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
197 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
198 __s, __b, __t, __c, __l, __f>::word_size;
200 template<
typename _UIntType,
201 size_t __w,
size_t __n,
size_t __m,
size_t __r,
202 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
203 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
206 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
207 __s, __b, __t, __c, __l, __f>::state_size;
209 template<
typename _UIntType,
210 size_t __w,
size_t __n,
size_t __m,
size_t __r,
211 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
212 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
215 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
216 __s, __b, __t, __c, __l, __f>::shift_size;
218 template<
typename _UIntType,
219 size_t __w,
size_t __n,
size_t __m,
size_t __r,
220 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
221 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
224 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
225 __s, __b, __t, __c, __l, __f>::mask_bits;
227 template<
typename _UIntType,
228 size_t __w,
size_t __n,
size_t __m,
size_t __r,
229 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
230 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
233 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
234 __s, __b, __t, __c, __l, __f>::xor_mask;
236 template<
typename _UIntType,
237 size_t __w,
size_t __n,
size_t __m,
size_t __r,
238 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
239 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
242 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
243 __s, __b, __t, __c, __l, __f>::tempering_u;
245 template<
typename _UIntType,
246 size_t __w,
size_t __n,
size_t __m,
size_t __r,
247 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
248 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
251 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
252 __s, __b, __t, __c, __l, __f>::tempering_d;
254 template<
typename _UIntType,
255 size_t __w,
size_t __n,
size_t __m,
size_t __r,
256 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
257 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
260 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
261 __s, __b, __t, __c, __l, __f>::tempering_s;
263 template<
typename _UIntType,
264 size_t __w,
size_t __n,
size_t __m,
size_t __r,
265 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
266 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
269 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
270 __s, __b, __t, __c, __l, __f>::tempering_b;
272 template<
typename _UIntType,
273 size_t __w,
size_t __n,
size_t __m,
size_t __r,
274 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
275 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
278 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
279 __s, __b, __t, __c, __l, __f>::tempering_t;
281 template<
typename _UIntType,
282 size_t __w,
size_t __n,
size_t __m,
size_t __r,
283 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
284 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
287 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
288 __s, __b, __t, __c, __l, __f>::tempering_c;
290 template<
typename _UIntType,
291 size_t __w,
size_t __n,
size_t __m,
size_t __r,
292 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
293 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
296 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
297 __s, __b, __t, __c, __l, __f>::tempering_l;
299 template<
typename _UIntType,
300 size_t __w,
size_t __n,
size_t __m,
size_t __r,
301 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
302 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
305 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
306 __s, __b, __t, __c, __l, __f>::
307 initialization_multiplier;
309 template<
typename _UIntType,
310 size_t __w,
size_t __n,
size_t __m,
size_t __r,
311 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
312 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
315 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
316 __s, __b, __t, __c, __l, __f>::default_seed;
318 template<
typename _UIntType,
319 size_t __w,
size_t __n,
size_t __m,
size_t __r,
320 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
321 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
324 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
325 __s, __b, __t, __c, __l, __f>::
326 seed(result_type __sd)
328 _M_x[0] = __detail::__mod<_UIntType,
329 __detail::_Shift<_UIntType, __w>::__value>(__sd);
331 for (
size_t __i = 1; __i < state_size; ++__i)
333 _UIntType __x = _M_x[__i - 1];
334 __x ^= __x >> (__w - 2);
336 __x += __detail::__mod<_UIntType, __n>(__i);
337 _M_x[__i] = __detail::__mod<_UIntType,
338 __detail::_Shift<_UIntType, __w>::__value>(__x);
343 template<
typename _UIntType,
344 size_t __w,
size_t __n,
size_t __m,
size_t __r,
345 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
346 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
348 template<
typename _Sseq>
350 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
351 __s, __b, __t, __c, __l, __f>::
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)
479 typedef typename __ostream_type::ios_base __ios_base;
481 const typename __ios_base::fmtflags __flags = __os.
flags();
482 const _CharT __fill = __os.
fill();
483 const _CharT __space = __os.
widen(
' ');
487 for (
size_t __i = 0; __i < __n; ++__i)
488 __os << __x._M_x[__i] << __space;
496 template<
typename _UIntType,
size_t __w,
497 size_t __n,
size_t __m,
size_t __r,
498 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
499 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
500 _UIntType __f,
typename _CharT,
typename _Traits>
503 mersenne_twister_engine<_UIntType, __w, __n, __m,
504 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __x)
507 typedef typename __istream_type::ios_base __ios_base;
509 const typename __ios_base::fmtflags __flags = __is.
flags();
512 for (
size_t __i = 0; __i < __n; ++__i)
513 __is >> __x._M_x[__i];
521 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
523 subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size;
525 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
527 subtract_with_carry_engine<_UIntType, __w, __s, __r>::short_lag;
529 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
531 subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag;
533 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
535 subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed;
537 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
543 __lcg(__value == 0u ? default_seed : __value);
545 const size_t __n = (__w + 31) / 32;
547 for (
size_t __i = 0; __i < long_lag; ++__i)
549 _UIntType __sum = 0u;
550 _UIntType __factor = 1u;
551 for (
size_t __j = 0; __j < __n; ++__j)
553 __sum += __detail::__mod<uint_least32_t,
554 __detail::_Shift<uint_least32_t, 32>::__value>
555 (__lcg()) * __factor;
556 __factor *= __detail::_Shift<_UIntType, 32>::__value;
558 _M_x[__i] = __detail::__mod<_UIntType,
559 __detail::_Shift<_UIntType, __w>::__value>(__sum);
561 _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
565 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
566 template<
typename _Sseq>
571 const size_t __k = (__w + 31) / 32;
572 uint_least32_t __arr[__r * __k];
573 __q.generate(__arr + 0, __arr + __r * __k);
575 for (
size_t __i = 0; __i < long_lag; ++__i)
577 _UIntType __sum = 0u;
578 _UIntType __factor = 1u;
579 for (
size_t __j = 0; __j < __k; ++__j)
581 __sum += __arr[__k * __i + __j] * __factor;
582 __factor *= __detail::_Shift<_UIntType, 32>::__value;
584 _M_x[__i] = __detail::__mod<_UIntType,
585 __detail::_Shift<_UIntType, __w>::__value>(__sum);
587 _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
591 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
598 long __ps = _M_p - short_lag;
606 if (_M_x[__ps] >= _M_x[_M_p] + _M_carry)
608 __xi = _M_x[__ps] - _M_x[_M_p] - _M_carry;
613 __xi = (__detail::_Shift<_UIntType, __w>::__value
614 - _M_x[_M_p] - _M_carry + _M_x[__ps]);
620 if (++_M_p >= long_lag)
626 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r,
627 typename _CharT,
typename _Traits>
634 typedef typename __ostream_type::ios_base __ios_base;
636 const typename __ios_base::fmtflags __flags = __os.
flags();
637 const _CharT __fill = __os.
fill();
638 const _CharT __space = __os.
widen(
' ');
642 for (
size_t __i = 0; __i < __r; ++__i)
643 __os << __x._M_x[__i] << __space;
644 __os << __x._M_carry << __space << __x._M_p;
651 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r,
652 typename _CharT,
typename _Traits>
655 subtract_with_carry_engine<_UIntType, __w, __s, __r>& __x)
658 typedef typename __istream_type::ios_base __ios_base;
660 const typename __ios_base::fmtflags __flags = __is.
flags();
663 for (
size_t __i = 0; __i < __r; ++__i)
664 __is >> __x._M_x[__i];
665 __is >> __x._M_carry;
673 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
675 discard_block_engine<_RandomNumberEngine, __p, __r>::block_size;
677 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
679 discard_block_engine<_RandomNumberEngine, __p, __r>::used_block;
681 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
682 typename discard_block_engine<_RandomNumberEngine,
683 __p, __r>::result_type
687 if (_M_n >= used_block)
689 _M_b.discard(block_size - _M_n);
696 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r,
697 typename _CharT,
typename _Traits>
704 typedef typename __ostream_type::ios_base __ios_base;
706 const typename __ios_base::fmtflags __flags = __os.
flags();
707 const _CharT __fill = __os.
fill();
708 const _CharT __space = __os.
widen(
' ');
712 __os << __x.base() << __space << __x._M_n;
719 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r,
720 typename _CharT,
typename _Traits>
723 discard_block_engine<_RandomNumberEngine, __p, __r>& __x)
726 typedef typename __istream_type::ios_base __ios_base;
728 const typename __ios_base::fmtflags __flags = __is.
flags();
731 __is >> __x._M_b >> __x._M_n;
738 template<
typename _RandomNumberEngine,
size_t __w,
typename _UIntType>
739 typename independent_bits_engine<_RandomNumberEngine, __w, _UIntType>::
744 typedef typename _RandomNumberEngine::result_type _Eresult_type;
745 const _Eresult_type __r
747 ? _M_b.max() - _M_b.min() + 1 : 0);
749 const unsigned __m = __r ?
std::__lg(__r) : __edig;
756 __ctype __s0, __s1, __y0, __y1;
758 for (
size_t __i = 0; __i < 2; ++__i)
760 __n = (__w + __m - 1) / __m + __i;
761 __n0 = __n - __w % __n;
762 const unsigned __w0 = __w / __n;
768 __s0 = __ctype(1) << __w0;
776 __y0 = __s0 * (__r / __s0);
778 __y1 = __s1 * (__r / __s1);
780 if (__r - __y0 <= __y0 / __n)
788 for (
size_t __k = 0; __k < __n0; ++__k)
792 __u = _M_b() - _M_b.
min();
793 while (__y0 && __u >= __y0);
794 __sum = __s0 * __sum + (__s0 ? __u % __s0 : __u);
796 for (
size_t __k = __n0; __k < __n; ++__k)
800 __u = _M_b() - _M_b.min();
801 while (__y1 && __u >= __y1);
802 __sum = __s1 * __sum + (__s1 ? __u % __s1 : __u);
808 template<
typename _RandomNumberEngine,
size_t __k>
812 template<
typename _RandomNumberEngine,
size_t __k>
817 size_t __j = __k * ((_M_y - _M_b.min())
818 / (_M_b.max() - _M_b.min() + 1.0L));
825 template<
typename _RandomNumberEngine,
size_t __k,
826 typename _CharT,
typename _Traits>
832 typedef typename __ostream_type::ios_base __ios_base;
834 const typename __ios_base::fmtflags __flags = __os.
flags();
835 const _CharT __fill = __os.
fill();
836 const _CharT __space = __os.
widen(
' ');
841 for (
size_t __i = 0; __i < __k; ++__i)
842 __os << __space << __x._M_v[__i];
843 __os << __space << __x._M_y;
850 template<
typename _RandomNumberEngine,
size_t __k,
851 typename _CharT,
typename _Traits>
854 shuffle_order_engine<_RandomNumberEngine, __k>& __x)
857 typedef typename __istream_type::ios_base __ios_base;
859 const typename __ios_base::fmtflags __flags = __is.
flags();
863 for (
size_t __i = 0; __i < __k; ++__i)
864 __is >> __x._M_v[__i];
872 template<
typename _IntType,
typename _CharT,
typename _Traits>
878 typedef typename __ostream_type::ios_base __ios_base;
880 const typename __ios_base::fmtflags __flags = __os.
flags();
881 const _CharT __fill = __os.
fill();
882 const _CharT __space = __os.
widen(
' ');
886 __os << __x.a() << __space << __x.b();
893 template<
typename _IntType,
typename _CharT,
typename _Traits>
899 typedef typename __istream_type::ios_base __ios_base;
901 const typename __ios_base::fmtflags __flags = __is.
flags();
905 if (__is >> __a >> __b)
907 param_type(__a, __b));
914 template<
typename _RealType>
915 template<
typename _ForwardIterator,
916 typename _UniformRandomNumberGenerator>
918 uniform_real_distribution<_RealType>::
919 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
920 _UniformRandomNumberGenerator& __urng,
921 const param_type& __p)
923 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
924 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
926 auto __range = __p.b() - __p.a();
928 *__f++ = __aurng() * __range + __p.a();
931 template<
typename _RealType,
typename _CharT,
typename _Traits>
937 typedef typename __ostream_type::ios_base __ios_base;
939 const typename __ios_base::fmtflags __flags = __os.
flags();
940 const _CharT __fill = __os.
fill();
942 const _CharT __space = __os.
widen(
' ');
947 __os << __x.a() << __space << __x.b();
955 template<
typename _RealType,
typename _CharT,
typename _Traits>
961 typedef typename __istream_type::ios_base __ios_base;
963 const typename __ios_base::fmtflags __flags = __is.
flags();
967 if (__is >> __a >> __b)
969 param_type(__a, __b));
976 template<
typename _ForwardIterator,
977 typename _UniformRandomNumberGenerator>
979 std::bernoulli_distribution::
980 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
981 _UniformRandomNumberGenerator& __urng,
982 const param_type& __p)
984 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
985 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
987 auto __limit = __p.p() * (__aurng.max() - __aurng.min());
990 *__f++ = (__aurng() - __aurng.min()) < __limit;
993 template<
typename _CharT,
typename _Traits>
999 typedef typename __ostream_type::ios_base __ios_base;
1001 const typename __ios_base::fmtflags __flags = __os.
flags();
1002 const _CharT __fill = __os.
fill();
1010 __os.
flags(__flags);
1017 template<
typename _IntType>
1018 template<
typename _UniformRandomNumberGenerator>
1021 operator()(_UniformRandomNumberGenerator& __urng,
1022 const param_type& __param)
1026 const double __naf =
1029 const double __thr =
1031 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1036 __cand = std::floor(
std::log(1.0 - __aurng()) / __param._M_log_1_p);
1037 while (__cand >= __thr);
1039 return result_type(__cand + __naf);
1042 template<
typename _IntType>
1043 template<
typename _ForwardIterator,
1044 typename _UniformRandomNumberGenerator>
1046 geometric_distribution<_IntType>::
1047 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1048 _UniformRandomNumberGenerator& __urng,
1049 const param_type& __param)
1051 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1054 const double __naf =
1057 const double __thr =
1059 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1066 __cand = std::floor(
std::log(1.0 - __aurng())
1067 / __param._M_log_1_p);
1068 while (__cand >= __thr);
1070 *__f++ = __cand + __naf;
1074 template<
typename _IntType,
1075 typename _CharT,
typename _Traits>
1081 typedef typename __ostream_type::ios_base __ios_base;
1083 const typename __ios_base::fmtflags __flags = __os.
flags();
1084 const _CharT __fill = __os.
fill();
1092 __os.
flags(__flags);
1098 template<
typename _IntType,
1099 typename _CharT,
typename _Traits>
1105 typedef typename __istream_type::ios_base __ios_base;
1107 const typename __ios_base::fmtflags __flags = __is.
flags();
1114 __is.
flags(__flags);
1119 template<
typename _IntType>
1120 template<
typename _UniformRandomNumberGenerator>
1125 const double __y = _M_gd(__urng);
1129 return __poisson(__urng);
1132 template<
typename _IntType>
1133 template<
typename _UniformRandomNumberGenerator>
1136 operator()(_UniformRandomNumberGenerator& __urng,
1137 const param_type& __p)
1143 _M_gd(__urng, param_type(__p.k(), (1.0 - __p.p()) / __p.p()));
1146 return __poisson(__urng);
1149 template<
typename _IntType>
1150 template<
typename _ForwardIterator,
1151 typename _UniformRandomNumberGenerator>
1153 negative_binomial_distribution<_IntType>::
1154 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1155 _UniformRandomNumberGenerator& __urng)
1157 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1160 const double __y = _M_gd(__urng);
1164 *__f++ = __poisson(__urng);
1168 template<
typename _IntType>
1169 template<
typename _ForwardIterator,
1170 typename _UniformRandomNumberGenerator>
1172 negative_binomial_distribution<_IntType>::
1173 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1174 _UniformRandomNumberGenerator& __urng,
1175 const param_type& __p)
1177 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1179 __p2(__p.k(), (1.0 - __p.p()) / __p.p());
1183 const double __y = _M_gd(__urng, __p2);
1186 *__f++ = __poisson(__urng);
1190 template<
typename _IntType,
typename _CharT,
typename _Traits>
1193 const negative_binomial_distribution<_IntType>& __x)
1196 typedef typename __ostream_type::ios_base __ios_base;
1198 const typename __ios_base::fmtflags __flags = __os.
flags();
1199 const _CharT __fill = __os.
fill();
1201 const _CharT __space = __os.
widen(
' ');
1206 __os << __x.k() << __space << __x.p()
1207 << __space << __x._M_gd;
1209 __os.
flags(__flags);
1215 template<
typename _IntType,
typename _CharT,
typename _Traits>
1218 negative_binomial_distribution<_IntType>& __x)
1221 typedef typename __istream_type::ios_base __ios_base;
1223 const typename __ios_base::fmtflags __flags = __is.
flags();
1228 if (__is >> __k >> __p >> __x._M_gd)
1229 __x.param(
typename negative_binomial_distribution<_IntType>::
1230 param_type(__k, __p));
1232 __is.
flags(__flags);
1237 template<
typename _IntType>
1239 poisson_distribution<_IntType>::param_type::
1242 #if _GLIBCXX_USE_C99_MATH_TR1 1245 const double __m = std::floor(_M_mean);
1247 _M_lfm = std::lgamma(__m + 1);
1250 const double __pi_4 = 0.7853981633974483096156608458198757L;
1253 _M_d = std::round(std::max<double>(6.0,
std::min(__m, __dx)));
1254 const double __cx = 2 * __m + _M_d;
1259 _M_cb = 2 * __cx *
std::exp(-_M_d * _M_1cx * (1 + _M_d / 2))
1277 template<
typename _IntType>
1278 template<
typename _UniformRandomNumberGenerator>
1284 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1286 #if _GLIBCXX_USE_C99_MATH_TR1 1287 if (__param.mean() >= 12)
1292 const double __naf =
1294 const double __thr =
1297 const double __m = std::floor(__param.mean());
1299 const double __spi_2 = 1.2533141373155002512078826424055226L;
1300 const double __c1 = __param._M_sm * __spi_2;
1301 const double __c2 = __param._M_c2b + __c1;
1302 const double __c3 = __c2 + 1;
1303 const double __c4 = __c3 + 1;
1305 const double __178 = 0.0128205128205128205128205128205128L;
1307 const double __e178 = 1.0129030479320018583185514777512983L;
1308 const double __c5 = __c4 + __e178;
1309 const double __c = __param._M_cb + __c5;
1310 const double __2cx = 2 * (2 * __m + __param._M_d);
1312 bool __reject =
true;
1315 const double __u = __c * __aurng();
1316 const double __e = -
std::log(1.0 - __aurng());
1322 const double __n = _M_nd(__urng);
1323 const double __y = -
std::abs(__n) * __param._M_sm - 1;
1324 __x = std::floor(__y);
1325 __w = -__n * __n / 2;
1329 else if (__u <= __c2)
1331 const double __n = _M_nd(__urng);
1332 const double __y = 1 +
std::abs(__n) * __param._M_scx;
1333 __x = std::ceil(__y);
1334 __w = __y * (2 - __y) * __param._M_1cx;
1335 if (__x > __param._M_d)
1338 else if (__u <= __c3)
1342 else if (__u <= __c4)
1344 else if (__u <= __c5)
1352 const double __v = -
std::log(1.0 - __aurng());
1353 const double __y = __param._M_d
1354 + __v * __2cx / __param._M_d;
1355 __x = std::ceil(__y);
1356 __w = -__param._M_d * __param._M_1cx * (1 + __y / 2);
1359 __reject = (__w - __e - __x * __param._M_lm_thr
1360 > __param._M_lfm - std::lgamma(__x + __m + 1));
1362 __reject |= __x + __m >= __thr;
1372 double __prod = 1.0;
1376 __prod *= __aurng();
1379 while (__prod > __param._M_lm_thr);
1385 template<
typename _IntType>
1386 template<
typename _ForwardIterator,
1387 typename _UniformRandomNumberGenerator>
1391 _UniformRandomNumberGenerator& __urng,
1392 const param_type& __param)
1394 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1400 template<
typename _IntType,
1401 typename _CharT,
typename _Traits>
1404 const poisson_distribution<_IntType>& __x)
1407 typedef typename __ostream_type::ios_base __ios_base;
1409 const typename __ios_base::fmtflags __flags = __os.
flags();
1410 const _CharT __fill = __os.
fill();
1412 const _CharT __space = __os.
widen(
' ');
1417 __os << __x.mean() << __space << __x._M_nd;
1419 __os.
flags(__flags);
1425 template<
typename _IntType,
1426 typename _CharT,
typename _Traits>
1429 poisson_distribution<_IntType>& __x)
1432 typedef typename __istream_type::ios_base __ios_base;
1434 const typename __ios_base::fmtflags __flags = __is.
flags();
1438 if (__is >> __mean >> __x._M_nd)
1439 __x.param(
typename poisson_distribution<_IntType>::param_type(__mean));
1441 __is.
flags(__flags);
1446 template<
typename _IntType>
1448 binomial_distribution<_IntType>::param_type::
1451 const double __p12 = _M_p <= 0.5 ? _M_p : 1.0 - _M_p;
1455 #if _GLIBCXX_USE_C99_MATH_TR1 1456 if (_M_t * __p12 >= 8)
1459 const double __np = std::floor(_M_t * __p12);
1460 const double __pa = __np / _M_t;
1461 const double __1p = 1 - __pa;
1463 const double __pi_4 = 0.7853981633974483096156608458198757L;
1464 const double __d1x =
1466 / (81 * __pi_4 * __1p)));
1467 _M_d1 = std::round(std::max<double>(1.0, __d1x));
1468 const double __d2x =
1470 / (__pi_4 * __pa)));
1471 _M_d2 = std::round(std::max<double>(1.0, __d2x));
1474 const double __spi_2 = 1.2533141373155002512078826424055226L;
1475 _M_s1 =
std::sqrt(__np * __1p) * (1 + _M_d1 / (4 * __np));
1476 _M_s2 =
std::sqrt(__np * __1p) * (1 + _M_d2 / (4 * _M_t * __1p));
1477 _M_c = 2 * _M_d1 / __np;
1478 _M_a1 =
std::exp(_M_c) * _M_s1 * __spi_2;
1479 const double __a12 = _M_a1 + _M_s2 * __spi_2;
1480 const double __s1s = _M_s1 * _M_s1;
1481 _M_a123 = __a12 + (
std::exp(_M_d1 / (_M_t * __1p))
1483 *
std::exp(-_M_d1 * _M_d1 / (2 * __s1s)));
1484 const double __s2s = _M_s2 * _M_s2;
1485 _M_s = (_M_a123 + 2 * __s2s / _M_d2
1486 *
std::exp(-_M_d2 * _M_d2 / (2 * __s2s)));
1487 _M_lf = (std::lgamma(__np + 1)
1488 + std::lgamma(_M_t - __np + 1));
1491 _M_q = -
std::log(1 - (__p12 - __pa) / __1p);
1498 template<
typename _IntType>
1499 template<
typename _UniformRandomNumberGenerator>
1501 binomial_distribution<_IntType>::
1502 _M_waiting(_UniformRandomNumberGenerator& __urng,
1503 _IntType __t,
double __q)
1507 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1514 const double __e = -
std::log(1.0 - __aurng());
1515 __sum += __e / (__t - __x);
1518 while (__sum <= __q);
1533 template<
typename _IntType>
1534 template<
typename _UniformRandomNumberGenerator>
1541 const _IntType __t = __param.t();
1542 const double __p = __param.p();
1543 const double __p12 = __p <= 0.5 ? __p : 1.0 - __p;
1544 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1547 #if _GLIBCXX_USE_C99_MATH_TR1 1548 if (!__param._M_easy)
1553 const double __naf =
1555 const double __thr =
1558 const double __np = std::floor(__t * __p12);
1561 const double __spi_2 = 1.2533141373155002512078826424055226L;
1562 const double __a1 = __param._M_a1;
1563 const double __a12 = __a1 + __param._M_s2 * __spi_2;
1564 const double __a123 = __param._M_a123;
1565 const double __s1s = __param._M_s1 * __param._M_s1;
1566 const double __s2s = __param._M_s2 * __param._M_s2;
1571 const double __u = __param._M_s * __aurng();
1577 const double __n = _M_nd(__urng);
1578 const double __y = __param._M_s1 *
std::abs(__n);
1579 __reject = __y >= __param._M_d1;
1582 const double __e = -
std::log(1.0 - __aurng());
1583 __x = std::floor(__y);
1584 __v = -__e - __n * __n / 2 + __param._M_c;
1587 else if (__u <= __a12)
1589 const double __n = _M_nd(__urng);
1590 const double __y = __param._M_s2 *
std::abs(__n);
1591 __reject = __y >= __param._M_d2;
1594 const double __e = -
std::log(1.0 - __aurng());
1595 __x = std::floor(-__y);
1596 __v = -__e - __n * __n / 2;
1599 else if (__u <= __a123)
1601 const double __e1 = -
std::log(1.0 - __aurng());
1602 const double __e2 = -
std::log(1.0 - __aurng());
1604 const double __y = __param._M_d1
1605 + 2 * __s1s * __e1 / __param._M_d1;
1606 __x = std::floor(__y);
1607 __v = (-__e2 + __param._M_d1 * (1 / (__t - __np)
1608 -__y / (2 * __s1s)));
1613 const double __e1 = -
std::log(1.0 - __aurng());
1614 const double __e2 = -
std::log(1.0 - __aurng());
1616 const double __y = __param._M_d2
1617 + 2 * __s2s * __e1 / __param._M_d2;
1618 __x = std::floor(-__y);
1619 __v = -__e2 - __param._M_d2 * __y / (2 * __s2s);
1623 __reject = __reject || __x < -__np || __x > __t - __np;
1626 const double __lfx =
1627 std::lgamma(__np + __x + 1)
1628 + std::lgamma(__t - (__np + __x) + 1);
1629 __reject = __v > __param._M_lf - __lfx
1630 + __x * __param._M_lp1p;
1633 __reject |= __x + __np >= __thr;
1637 __x += __np + __naf;
1639 const _IntType __z = _M_waiting(__urng, __t - _IntType(__x),
1641 __ret = _IntType(__x) + __z;
1645 __ret = _M_waiting(__urng, __t, __param._M_q);
1648 __ret = __t - __ret;
1652 template<
typename _IntType>
1653 template<
typename _ForwardIterator,
1654 typename _UniformRandomNumberGenerator>
1658 _UniformRandomNumberGenerator& __urng,
1659 const param_type& __param)
1661 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1667 template<
typename _IntType,
1668 typename _CharT,
typename _Traits>
1671 const binomial_distribution<_IntType>& __x)
1674 typedef typename __ostream_type::ios_base __ios_base;
1676 const typename __ios_base::fmtflags __flags = __os.
flags();
1677 const _CharT __fill = __os.
fill();
1679 const _CharT __space = __os.
widen(
' ');
1684 __os << __x.t() << __space << __x.p()
1685 << __space << __x._M_nd;
1687 __os.
flags(__flags);
1693 template<
typename _IntType,
1694 typename _CharT,
typename _Traits>
1697 binomial_distribution<_IntType>& __x)
1700 typedef typename __istream_type::ios_base __ios_base;
1702 const typename __ios_base::fmtflags __flags = __is.
flags();
1707 if (__is >> __t >> __p >> __x._M_nd)
1708 __x.param(
typename binomial_distribution<_IntType>::
1709 param_type(__t, __p));
1711 __is.
flags(__flags);
1716 template<
typename _RealType>
1717 template<
typename _ForwardIterator,
1718 typename _UniformRandomNumberGenerator>
1722 _UniformRandomNumberGenerator& __urng,
1723 const param_type& __p)
1725 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1726 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1732 template<
typename _RealType,
typename _CharT,
typename _Traits>
1738 typedef typename __ostream_type::ios_base __ios_base;
1740 const typename __ios_base::fmtflags __flags = __os.
flags();
1741 const _CharT __fill = __os.
fill();
1749 __os.
flags(__flags);
1755 template<
typename _RealType,
typename _CharT,
typename _Traits>
1761 typedef typename __istream_type::ios_base __ios_base;
1763 const typename __ios_base::fmtflags __flags = __is.
flags();
1767 if (__is >> __lambda)
1769 param_type(__lambda));
1771 __is.
flags(__flags);
1782 template<
typename _RealType>
1783 template<
typename _UniformRandomNumberGenerator>
1787 const param_type& __param)
1790 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1793 if (_M_saved_available)
1795 _M_saved_available =
false;
1805 __r2 = __x * __x + __y * __y;
1807 while (__r2 > 1.0 || __r2 == 0.0);
1810 _M_saved = __x * __mult;
1811 _M_saved_available =
true;
1812 __ret = __y * __mult;
1815 __ret = __ret * __param.stddev() + __param.mean();
1819 template<
typename _RealType>
1820 template<
typename _ForwardIterator,
1821 typename _UniformRandomNumberGenerator>
1825 _UniformRandomNumberGenerator& __urng,
1826 const param_type& __param)
1828 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1833 if (_M_saved_available)
1835 _M_saved_available =
false;
1836 *__f++ = _M_saved * __param.stddev() + __param.mean();
1842 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1845 while (__f + 1 < __t)
1852 __r2 = __x * __x + __y * __y;
1854 while (__r2 > 1.0 || __r2 == 0.0);
1857 *__f++ = __y * __mult * __param.stddev() + __param.mean();
1858 *__f++ = __x * __mult * __param.stddev() + __param.mean();
1868 __r2 = __x * __x + __y * __y;
1870 while (__r2 > 1.0 || __r2 == 0.0);
1873 _M_saved = __x * __mult;
1874 _M_saved_available =
true;
1875 *__f = __y * __mult * __param.stddev() + __param.mean();
1879 template<
typename _RealType>
1884 if (__d1._M_param == __d2._M_param
1885 && __d1._M_saved_available == __d2._M_saved_available)
1887 if (__d1._M_saved_available
1888 && __d1._M_saved == __d2._M_saved)
1890 else if(!__d1._M_saved_available)
1899 template<
typename _RealType,
typename _CharT,
typename _Traits>
1902 const normal_distribution<_RealType>& __x)
1905 typedef typename __ostream_type::ios_base __ios_base;
1907 const typename __ios_base::fmtflags __flags = __os.
flags();
1908 const _CharT __fill = __os.
fill();
1910 const _CharT __space = __os.
widen(
' ');
1915 __os << __x.mean() << __space << __x.stddev()
1916 << __space << __x._M_saved_available;
1917 if (__x._M_saved_available)
1918 __os << __space << __x._M_saved;
1920 __os.
flags(__flags);
1926 template<
typename _RealType,
typename _CharT,
typename _Traits>
1929 normal_distribution<_RealType>& __x)
1932 typedef typename __istream_type::ios_base __ios_base;
1934 const typename __ios_base::fmtflags __flags = __is.
flags();
1937 double __mean, __stddev;
1939 if (__is >> __mean >> __stddev >> __saved_avail)
1941 if (__saved_avail && (__is >> __x._M_saved))
1943 __x._M_saved_available = __saved_avail;
1944 __x.param(
typename normal_distribution<_RealType>::
1945 param_type(__mean, __stddev));
1949 __is.
flags(__flags);
1954 template<
typename _RealType>
1955 template<
typename _ForwardIterator,
1956 typename _UniformRandomNumberGenerator>
1958 lognormal_distribution<_RealType>::
1959 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1960 _UniformRandomNumberGenerator& __urng,
1961 const param_type& __p)
1963 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1965 *__f++ =
std::exp(__p.s() * _M_nd(__urng) + __p.m());
1968 template<
typename _RealType,
typename _CharT,
typename _Traits>
1971 const lognormal_distribution<_RealType>& __x)
1974 typedef typename __ostream_type::ios_base __ios_base;
1976 const typename __ios_base::fmtflags __flags = __os.
flags();
1977 const _CharT __fill = __os.
fill();
1979 const _CharT __space = __os.
widen(
' ');
1984 __os << __x.m() << __space << __x.s()
1985 << __space << __x._M_nd;
1987 __os.
flags(__flags);
1993 template<
typename _RealType,
typename _CharT,
typename _Traits>
1996 lognormal_distribution<_RealType>& __x)
1999 typedef typename __istream_type::ios_base __ios_base;
2001 const typename __ios_base::fmtflags __flags = __is.
flags();
2005 if (__is >> __m >> __s >> __x._M_nd)
2006 __x.param(
typename lognormal_distribution<_RealType>::
2007 param_type(__m, __s));
2009 __is.
flags(__flags);
2013 template<
typename _RealType>
2014 template<
typename _ForwardIterator,
2015 typename _UniformRandomNumberGenerator>
2019 _UniformRandomNumberGenerator& __urng)
2021 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2023 *__f++ = 2 * _M_gd(__urng);
2026 template<
typename _RealType>
2027 template<
typename _ForwardIterator,
2028 typename _UniformRandomNumberGenerator>
2032 _UniformRandomNumberGenerator& __urng,
2036 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2038 *__f++ = 2 * _M_gd(__urng, __p);
2041 template<
typename _RealType,
typename _CharT,
typename _Traits>
2044 const chi_squared_distribution<_RealType>& __x)
2047 typedef typename __ostream_type::ios_base __ios_base;
2049 const typename __ios_base::fmtflags __flags = __os.
flags();
2050 const _CharT __fill = __os.
fill();
2052 const _CharT __space = __os.
widen(
' ');
2057 __os << __x.n() << __space << __x._M_gd;
2059 __os.
flags(__flags);
2065 template<
typename _RealType,
typename _CharT,
typename _Traits>
2068 chi_squared_distribution<_RealType>& __x)
2071 typedef typename __istream_type::ios_base __ios_base;
2073 const typename __ios_base::fmtflags __flags = __is.
flags();
2077 if (__is >> __n >> __x._M_gd)
2078 __x.param(
typename chi_squared_distribution<_RealType>::
2081 __is.
flags(__flags);
2086 template<
typename _RealType>
2087 template<
typename _UniformRandomNumberGenerator>
2090 operator()(_UniformRandomNumberGenerator& __urng,
2091 const param_type& __p)
2093 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2100 const _RealType __pi = 3.1415926535897932384626433832795029L;
2101 return __p.a() + __p.b() *
std::tan(__pi * __u);
2104 template<
typename _RealType>
2105 template<
typename _ForwardIterator,
2106 typename _UniformRandomNumberGenerator>
2108 cauchy_distribution<_RealType>::
2109 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2110 _UniformRandomNumberGenerator& __urng,
2111 const param_type& __p)
2113 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2114 const _RealType __pi = 3.1415926535897932384626433832795029L;
2115 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2124 *__f++ = __p.a() + __p.b() *
std::tan(__pi * __u);
2128 template<
typename _RealType,
typename _CharT,
typename _Traits>
2134 typedef typename __ostream_type::ios_base __ios_base;
2136 const typename __ios_base::fmtflags __flags = __os.
flags();
2137 const _CharT __fill = __os.
fill();
2139 const _CharT __space = __os.
widen(
' ');
2144 __os << __x.a() << __space << __x.b();
2146 __os.
flags(__flags);
2152 template<
typename _RealType,
typename _CharT,
typename _Traits>
2158 typedef typename __istream_type::ios_base __ios_base;
2160 const typename __ios_base::fmtflags __flags = __is.
flags();
2164 if (__is >> __a >> __b)
2166 param_type(__a, __b));
2168 __is.
flags(__flags);
2173 template<
typename _RealType>
2174 template<
typename _ForwardIterator,
2175 typename _UniformRandomNumberGenerator>
2179 _UniformRandomNumberGenerator& __urng)
2181 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2183 *__f++ = ((_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()));
2186 template<
typename _RealType>
2187 template<
typename _ForwardIterator,
2188 typename _UniformRandomNumberGenerator>
2192 _UniformRandomNumberGenerator& __urng,
2193 const param_type& __p)
2195 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2198 param_type __p1(__p.m() / 2);
2199 param_type __p2(__p.n() / 2);
2201 *__f++ = ((_M_gd_x(__urng, __p1) * n())
2202 / (_M_gd_y(__urng, __p2) * m()));
2205 template<
typename _RealType,
typename _CharT,
typename _Traits>
2208 const fisher_f_distribution<_RealType>& __x)
2211 typedef typename __ostream_type::ios_base __ios_base;
2213 const typename __ios_base::fmtflags __flags = __os.
flags();
2214 const _CharT __fill = __os.
fill();
2216 const _CharT __space = __os.
widen(
' ');
2221 __os << __x.m() << __space << __x.n()
2222 << __space << __x._M_gd_x << __space << __x._M_gd_y;
2224 __os.
flags(__flags);
2230 template<
typename _RealType,
typename _CharT,
typename _Traits>
2233 fisher_f_distribution<_RealType>& __x)
2236 typedef typename __istream_type::ios_base __ios_base;
2238 const typename __ios_base::fmtflags __flags = __is.
flags();
2242 if (__is >> __m >> __n >> __x._M_gd_x >> __x._M_gd_y)
2243 __x.param(
typename fisher_f_distribution<_RealType>::
2244 param_type(__m, __n));
2246 __is.
flags(__flags);
2251 template<
typename _RealType>
2252 template<
typename _ForwardIterator,
2253 typename _UniformRandomNumberGenerator>
2257 _UniformRandomNumberGenerator& __urng)
2259 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2261 *__f++ = _M_nd(__urng) *
std::sqrt(n() / _M_gd(__urng));
2264 template<
typename _RealType>
2265 template<
typename _ForwardIterator,
2266 typename _UniformRandomNumberGenerator>
2270 _UniformRandomNumberGenerator& __urng,
2271 const param_type& __p)
2273 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2275 __p2(__p.n() / 2, 2);
2277 *__f++ = _M_nd(__urng) *
std::sqrt(__p.n() / _M_gd(__urng, __p2));
2280 template<
typename _RealType,
typename _CharT,
typename _Traits>
2283 const student_t_distribution<_RealType>& __x)
2286 typedef typename __ostream_type::ios_base __ios_base;
2288 const typename __ios_base::fmtflags __flags = __os.
flags();
2289 const _CharT __fill = __os.
fill();
2291 const _CharT __space = __os.
widen(
' ');
2296 __os << __x.n() << __space << __x._M_nd << __space << __x._M_gd;
2298 __os.
flags(__flags);
2304 template<
typename _RealType,
typename _CharT,
typename _Traits>
2307 student_t_distribution<_RealType>& __x)
2310 typedef typename __istream_type::ios_base __ios_base;
2312 const typename __ios_base::fmtflags __flags = __is.
flags();
2316 if (__is >> __n >> __x._M_nd >> __x._M_gd)
2317 __x.param(
typename student_t_distribution<_RealType>::param_type(__n));
2319 __is.
flags(__flags);
2324 template<
typename _RealType>
2326 gamma_distribution<_RealType>::param_type::
2329 _M_malpha = _M_alpha < 1.0 ? _M_alpha + _RealType(1.0) : _M_alpha;
2331 const _RealType __a1 = _M_malpha - _RealType(1.0) / _RealType(3.0);
2332 _M_a2 = _RealType(1.0) /
std::sqrt(_RealType(9.0) * __a1);
2340 template<
typename _RealType>
2341 template<
typename _UniformRandomNumberGenerator>
2345 const param_type& __param)
2347 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2352 - _RealType(1.0) / _RealType(3.0));
2358 __n = _M_nd(__urng);
2363 __v = __v * __v * __v;
2366 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2367 && (
std::log(__u) > (0.5 * __n * __n + __a1
2370 if (__param.alpha() == __param._M_malpha)
2371 return __a1 * __v * __param.beta();
2379 * __a1 * __v * __param.beta());
2383 template<
typename _RealType>
2384 template<
typename _ForwardIterator,
2385 typename _UniformRandomNumberGenerator>
2389 _UniformRandomNumberGenerator& __urng,
2390 const param_type& __param)
2392 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2393 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2398 - _RealType(1.0) / _RealType(3.0));
2400 if (__param.alpha() == __param._M_malpha)
2407 __n = _M_nd(__urng);
2412 __v = __v * __v * __v;
2415 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2416 && (
std::log(__u) > (0.5 * __n * __n + __a1
2419 *__f++ = __a1 * __v * __param.beta();
2428 __n = _M_nd(__urng);
2433 __v = __v * __v * __v;
2436 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2437 && (
std::log(__u) > (0.5 * __n * __n + __a1
2445 * __a1 * __v * __param.beta());
2449 template<
typename _RealType,
typename _CharT,
typename _Traits>
2452 const gamma_distribution<_RealType>& __x)
2455 typedef typename __ostream_type::ios_base __ios_base;
2457 const typename __ios_base::fmtflags __flags = __os.
flags();
2458 const _CharT __fill = __os.
fill();
2460 const _CharT __space = __os.
widen(
' ');
2465 __os << __x.alpha() << __space << __x.beta()
2466 << __space << __x._M_nd;
2468 __os.
flags(__flags);
2474 template<
typename _RealType,
typename _CharT,
typename _Traits>
2477 gamma_distribution<_RealType>& __x)
2480 typedef typename __istream_type::ios_base __ios_base;
2482 const typename __ios_base::fmtflags __flags = __is.
flags();
2485 _RealType __alpha_val, __beta_val;
2486 if (__is >> __alpha_val >> __beta_val >> __x._M_nd)
2487 __x.param(
typename gamma_distribution<_RealType>::
2488 param_type(__alpha_val, __beta_val));
2490 __is.
flags(__flags);
2495 template<
typename _RealType>
2496 template<
typename _UniformRandomNumberGenerator>
2499 operator()(_UniformRandomNumberGenerator& __urng,
2500 const param_type& __p)
2502 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2508 template<
typename _RealType>
2509 template<
typename _ForwardIterator,
2510 typename _UniformRandomNumberGenerator>
2512 weibull_distribution<_RealType>::
2513 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2514 _UniformRandomNumberGenerator& __urng,
2515 const param_type& __p)
2517 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2518 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2527 template<
typename _RealType,
typename _CharT,
typename _Traits>
2533 typedef typename __ostream_type::ios_base __ios_base;
2535 const typename __ios_base::fmtflags __flags = __os.
flags();
2536 const _CharT __fill = __os.
fill();
2538 const _CharT __space = __os.
widen(
' ');
2543 __os << __x.
a() << __space << __x.
b();
2545 __os.
flags(__flags);
2551 template<
typename _RealType,
typename _CharT,
typename _Traits>
2557 typedef typename __istream_type::ios_base __ios_base;
2559 const typename __ios_base::fmtflags __flags = __is.
flags();
2563 if (__is >> __a >> __b)
2565 param_type(__a, __b));
2567 __is.
flags(__flags);
2572 template<
typename _RealType>
2573 template<
typename _UniformRandomNumberGenerator>
2576 operator()(_UniformRandomNumberGenerator& __urng,
2577 const param_type& __p)
2579 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2585 template<
typename _RealType>
2586 template<
typename _ForwardIterator,
2587 typename _UniformRandomNumberGenerator>
2589 extreme_value_distribution<_RealType>::
2590 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2591 _UniformRandomNumberGenerator& __urng,
2592 const param_type& __p)
2594 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2595 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2603 template<
typename _RealType,
typename _CharT,
typename _Traits>
2609 typedef typename __ostream_type::ios_base __ios_base;
2611 const typename __ios_base::fmtflags __flags = __os.
flags();
2612 const _CharT __fill = __os.
fill();
2614 const _CharT __space = __os.
widen(
' ');
2619 __os << __x.
a() << __space << __x.
b();
2621 __os.
flags(__flags);
2627 template<
typename _RealType,
typename _CharT,
typename _Traits>
2633 typedef typename __istream_type::ios_base __ios_base;
2635 const typename __ios_base::fmtflags __flags = __is.
flags();
2639 if (__is >> __a >> __b)
2641 param_type(__a, __b));
2643 __is.
flags(__flags);
2648 template<
typename _IntType>
2650 discrete_distribution<_IntType>::param_type::
2653 if (_M_prob.size() < 2)
2660 _M_prob.end(), 0.0);
2662 __detail::__normalize(_M_prob.begin(), _M_prob.end(), _M_prob.begin(),
2665 _M_cp.reserve(_M_prob.size());
2669 _M_cp[_M_cp.size() - 1] = 1.0;
2672 template<
typename _IntType>
2673 template<
typename _Func>
2674 discrete_distribution<_IntType>::param_type::
2675 param_type(
size_t __nw,
double __xmin,
double __xmax, _Func __fw)
2676 : _M_prob(), _M_cp()
2678 const size_t __n = __nw == 0 ? 1 : __nw;
2679 const double __delta = (__xmax - __xmin) / __n;
2681 _M_prob.reserve(__n);
2682 for (
size_t __k = 0; __k < __nw; ++__k)
2683 _M_prob.push_back(__fw(__xmin + __k * __delta + 0.5 * __delta));
2688 template<
typename _IntType>
2689 template<
typename _UniformRandomNumberGenerator>
2690 typename discrete_distribution<_IntType>::result_type
2691 discrete_distribution<_IntType>::
2692 operator()(_UniformRandomNumberGenerator& __urng,
2693 const param_type& __param)
2695 if (__param._M_cp.empty())
2696 return result_type(0);
2698 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2701 const double __p = __aurng();
2703 __param._M_cp.end(), __p);
2705 return __pos - __param._M_cp.begin();
2708 template<
typename _IntType>
2709 template<
typename _ForwardIterator,
2710 typename _UniformRandomNumberGenerator>
2712 discrete_distribution<_IntType>::
2713 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2714 _UniformRandomNumberGenerator& __urng,
2715 const param_type& __param)
2717 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2719 if (__param._M_cp.empty())
2722 *__f++ = result_type(0);
2726 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2731 const double __p = __aurng();
2733 __param._M_cp.end(), __p);
2735 *__f++ = __pos - __param._M_cp.begin();
2739 template<
typename _IntType,
typename _CharT,
typename _Traits>
2742 const discrete_distribution<_IntType>& __x)
2745 typedef typename __ostream_type::ios_base __ios_base;
2747 const typename __ios_base::fmtflags __flags = __os.
flags();
2748 const _CharT __fill = __os.
fill();
2750 const _CharT __space = __os.
widen(
' ');
2756 __os << __prob.
size();
2757 for (
auto __dit = __prob.
begin(); __dit != __prob.
end(); ++__dit)
2758 __os << __space << *__dit;
2760 __os.
flags(__flags);
2768 template<
typename _ValT,
typename _CharT,
typename _Traits>
2769 basic_istream<_CharT, _Traits>&
2770 __extract_params(basic_istream<_CharT, _Traits>& __is,
2771 vector<_ValT>& __vals,
size_t __n)
2773 __vals.reserve(__n);
2778 __vals.push_back(__val);
2786 template<
typename _IntType,
typename _CharT,
typename _Traits>
2789 discrete_distribution<_IntType>& __x)
2792 typedef typename __istream_type::ios_base __ios_base;
2794 const typename __ios_base::fmtflags __flags = __is.
flags();
2801 if (__detail::__extract_params(__is, __prob_vec, __n))
2802 __x.param({__prob_vec.
begin(), __prob_vec.
end()});
2805 __is.
flags(__flags);
2810 template<
typename _RealType>
2812 piecewise_constant_distribution<_RealType>::param_type::
2815 if (_M_int.size() < 2
2816 || (_M_int.size() == 2
2817 && _M_int[0] == _RealType(0)
2818 && _M_int[1] == _RealType(1)))
2828 __detail::__normalize(_M_den.begin(), _M_den.end(), _M_den.begin(),
2831 _M_cp.reserve(_M_den.size());
2836 _M_cp[_M_cp.size() - 1] = 1.0;
2838 for (
size_t __k = 0; __k < _M_den.size(); ++__k)
2839 _M_den[__k] /= _M_int[__k + 1] - _M_int[__k];
2842 template<
typename _RealType>
2843 template<
typename _InputIteratorB,
typename _InputIteratorW>
2844 piecewise_constant_distribution<_RealType>::param_type::
2845 param_type(_InputIteratorB __bbegin,
2846 _InputIteratorB __bend,
2847 _InputIteratorW __wbegin)
2848 : _M_int(), _M_den(), _M_cp()
2850 if (__bbegin != __bend)
2854 _M_int.push_back(*__bbegin);
2856 if (__bbegin == __bend)
2859 _M_den.push_back(*__wbegin);
2867 template<
typename _RealType>
2868 template<
typename _Func>
2869 piecewise_constant_distribution<_RealType>::param_type::
2870 param_type(initializer_list<_RealType> __bl, _Func __fw)
2871 : _M_int(), _M_den(), _M_cp()
2873 _M_int.reserve(__bl.size());
2874 for (
auto __biter = __bl.begin(); __biter != __bl.end(); ++__biter)
2875 _M_int.push_back(*__biter);
2877 _M_den.reserve(_M_int.size() - 1);
2878 for (
size_t __k = 0; __k < _M_int.size() - 1; ++__k)
2879 _M_den.push_back(__fw(0.5 * (_M_int[__k + 1] + _M_int[__k])));
2884 template<
typename _RealType>
2885 template<
typename _Func>
2886 piecewise_constant_distribution<_RealType>::param_type::
2887 param_type(
size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
2888 : _M_int(), _M_den(), _M_cp()
2890 const size_t __n = __nw == 0 ? 1 : __nw;
2891 const _RealType __delta = (__xmax - __xmin) / __n;
2893 _M_int.reserve(__n + 1);
2894 for (
size_t __k = 0; __k <= __nw; ++__k)
2895 _M_int.push_back(__xmin + __k * __delta);
2897 _M_den.reserve(__n);
2898 for (
size_t __k = 0; __k < __nw; ++__k)
2899 _M_den.push_back(__fw(_M_int[__k] + 0.5 * __delta));
2904 template<
typename _RealType>
2905 template<
typename _UniformRandomNumberGenerator>
2906 typename piecewise_constant_distribution<_RealType>::result_type
2907 piecewise_constant_distribution<_RealType>::
2908 operator()(_UniformRandomNumberGenerator& __urng,
2909 const param_type& __param)
2911 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2914 const double __p = __aurng();
2915 if (__param._M_cp.empty())
2919 __param._M_cp.end(), __p);
2920 const size_t __i = __pos - __param._M_cp.begin();
2922 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
2924 return __param._M_int[__i] + (__p - __pref) / __param._M_den[__i];
2927 template<
typename _RealType>
2928 template<
typename _ForwardIterator,
2929 typename _UniformRandomNumberGenerator>
2931 piecewise_constant_distribution<_RealType>::
2932 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2933 _UniformRandomNumberGenerator& __urng,
2934 const param_type& __param)
2936 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2937 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2940 if (__param._M_cp.empty())
2949 const double __p = __aurng();
2952 __param._M_cp.end(), __p);
2953 const size_t __i = __pos - __param._M_cp.begin();
2955 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
2957 *__f++ = (__param._M_int[__i]
2958 + (__p - __pref) / __param._M_den[__i]);
2962 template<
typename _RealType,
typename _CharT,
typename _Traits>
2965 const piecewise_constant_distribution<_RealType>& __x)
2968 typedef typename __ostream_type::ios_base __ios_base;
2970 const typename __ios_base::fmtflags __flags = __os.
flags();
2971 const _CharT __fill = __os.
fill();
2973 const _CharT __space = __os.
widen(
' ');
2979 __os << __int.
size() - 1;
2981 for (
auto __xit = __int.
begin(); __xit != __int.
end(); ++__xit)
2982 __os << __space << *__xit;
2985 for (
auto __dit = __den.
begin(); __dit != __den.
end(); ++__dit)
2986 __os << __space << *__dit;
2988 __os.
flags(__flags);
2994 template<
typename _RealType,
typename _CharT,
typename _Traits>
2997 piecewise_constant_distribution<_RealType>& __x)
3000 typedef typename __istream_type::ios_base __ios_base;
3002 const typename __ios_base::fmtflags __flags = __is.
flags();
3009 if (__detail::__extract_params(__is, __int_vec, __n + 1))
3012 if (__detail::__extract_params(__is, __den_vec, __n))
3014 __x.param({ __int_vec.
begin(), __int_vec.
end(),
3015 __den_vec.
begin() });
3020 __is.
flags(__flags);
3025 template<
typename _RealType>
3027 piecewise_linear_distribution<_RealType>::param_type::
3030 if (_M_int.size() < 2
3031 || (_M_int.size() == 2
3032 && _M_int[0] == _RealType(0)
3033 && _M_int[1] == _RealType(1)
3034 && _M_den[0] == _M_den[1]))
3042 _M_cp.reserve(_M_int.size() - 1);
3043 _M_m.reserve(_M_int.size() - 1);
3044 for (
size_t __k = 0; __k < _M_int.size() - 1; ++__k)
3046 const _RealType __delta = _M_int[__k + 1] - _M_int[__k];
3047 __sum += 0.5 * (_M_den[__k + 1] + _M_den[__k]) * __delta;
3048 _M_cp.push_back(__sum);
3049 _M_m.push_back((_M_den[__k + 1] - _M_den[__k]) / __delta);
3053 __detail::__normalize(_M_den.begin(), _M_den.end(), _M_den.begin(),
3056 __detail::__normalize(_M_cp.begin(), _M_cp.end(), _M_cp.begin(), __sum);
3058 __detail::__normalize(_M_m.begin(), _M_m.end(), _M_m.begin(), __sum);
3061 _M_cp[_M_cp.size() - 1] = 1.0;
3064 template<
typename _RealType>
3065 template<
typename _InputIteratorB,
typename _InputIteratorW>
3066 piecewise_linear_distribution<_RealType>::param_type::
3067 param_type(_InputIteratorB __bbegin,
3068 _InputIteratorB __bend,
3069 _InputIteratorW __wbegin)
3070 : _M_int(), _M_den(), _M_cp(), _M_m()
3072 for (; __bbegin != __bend; ++__bbegin, ++__wbegin)
3074 _M_int.push_back(*__bbegin);
3075 _M_den.push_back(*__wbegin);
3081 template<
typename _RealType>
3082 template<
typename _Func>
3083 piecewise_linear_distribution<_RealType>::param_type::
3084 param_type(initializer_list<_RealType> __bl, _Func __fw)
3085 : _M_int(), _M_den(), _M_cp(), _M_m()
3087 _M_int.reserve(__bl.size());
3088 _M_den.reserve(__bl.size());
3089 for (
auto __biter = __bl.begin(); __biter != __bl.end(); ++__biter)
3091 _M_int.push_back(*__biter);
3092 _M_den.push_back(__fw(*__biter));
3098 template<
typename _RealType>
3099 template<
typename _Func>
3100 piecewise_linear_distribution<_RealType>::param_type::
3101 param_type(
size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
3102 : _M_int(), _M_den(), _M_cp(), _M_m()
3104 const size_t __n = __nw == 0 ? 1 : __nw;
3105 const _RealType __delta = (__xmax - __xmin) / __n;
3107 _M_int.reserve(__n + 1);
3108 _M_den.reserve(__n + 1);
3109 for (
size_t __k = 0; __k <= __nw; ++__k)
3111 _M_int.push_back(__xmin + __k * __delta);
3112 _M_den.push_back(__fw(_M_int[__k] + __delta));
3118 template<
typename _RealType>
3119 template<
typename _UniformRandomNumberGenerator>
3120 typename piecewise_linear_distribution<_RealType>::result_type
3121 piecewise_linear_distribution<_RealType>::
3122 operator()(_UniformRandomNumberGenerator& __urng,
3123 const param_type& __param)
3125 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
3128 const double __p = __aurng();
3129 if (__param._M_cp.empty())
3133 __param._M_cp.end(), __p);
3134 const size_t __i = __pos - __param._M_cp.begin();
3136 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
3138 const double __a = 0.5 * __param._M_m[__i];
3139 const double __b = __param._M_den[__i];
3140 const double __cm = __p - __pref;
3142 _RealType __x = __param._M_int[__i];
3147 const double __d = __b * __b + 4.0 * __a * __cm;
3148 __x += 0.5 * (
std::sqrt(__d) - __b) / __a;
3154 template<
typename _RealType>
3155 template<
typename _ForwardIterator,
3156 typename _UniformRandomNumberGenerator>
3158 piecewise_linear_distribution<_RealType>::
3159 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3160 _UniformRandomNumberGenerator& __urng,
3161 const param_type& __param)
3163 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3166 *__f++ = this->operator()(__urng, __param);
3169 template<
typename _RealType,
typename _CharT,
typename _Traits>
3172 const piecewise_linear_distribution<_RealType>& __x)
3175 typedef typename __ostream_type::ios_base __ios_base;
3177 const typename __ios_base::fmtflags __flags = __os.
flags();
3178 const _CharT __fill = __os.
fill();
3180 const _CharT __space = __os.
widen(
' ');
3186 __os << __int.
size() - 1;
3188 for (
auto __xit = __int.
begin(); __xit != __int.
end(); ++__xit)
3189 __os << __space << *__xit;
3192 for (
auto __dit = __den.
begin(); __dit != __den.
end(); ++__dit)
3193 __os << __space << *__dit;
3195 __os.
flags(__flags);
3201 template<
typename _RealType,
typename _CharT,
typename _Traits>
3204 piecewise_linear_distribution<_RealType>& __x)
3207 typedef typename __istream_type::ios_base __ios_base;
3209 const typename __ios_base::fmtflags __flags = __is.
flags();
3215 vector<_RealType> __int_vec;
3216 if (__detail::__extract_params(__is, __int_vec, __n + 1))
3218 vector<double> __den_vec;
3219 if (__detail::__extract_params(__is, __den_vec, __n + 1))
3221 __x.param({ __int_vec.begin(), __int_vec.end(),
3222 __den_vec.begin() });
3226 __is.
flags(__flags);
3231 template<
typename _IntType>
3234 for (
auto __iter = __il.begin(); __iter != __il.end(); ++__iter)
3235 _M_v.push_back(__detail::__mod<result_type,
3236 __detail::_Shift<result_type, 32>::__value>(*__iter));
3239 template<
typename _InputIterator>
3240 seed_seq::seed_seq(_InputIterator __begin, _InputIterator __end)
3242 for (_InputIterator __iter = __begin; __iter != __end; ++__iter)
3243 _M_v.push_back(__detail::__mod<result_type,
3244 __detail::_Shift<result_type, 32>::__value>(*__iter));
3247 template<
typename _RandomAccessIterator>
3249 seed_seq::generate(_RandomAccessIterator __begin,
3250 _RandomAccessIterator __end)
3252 typedef typename iterator_traits<_RandomAccessIterator>::value_type
3255 if (__begin == __end)
3258 std::fill(__begin, __end, _Type(0x8b8b8b8bu));
3260 const size_t __n = __end - __begin;
3261 const size_t __s = _M_v.size();
3262 const size_t __t = (__n >= 623) ? 11
3267 const size_t __p = (__n - __t) / 2;
3268 const size_t __q = __p + __t;
3269 const size_t __m =
std::max(
size_t(__s + 1), __n);
3271 for (
size_t __k = 0; __k < __m; ++__k)
3273 _Type __arg = (__begin[__k % __n]
3274 ^ __begin[(__k + __p) % __n]
3275 ^ __begin[(__k - 1) % __n]);
3276 _Type __r1 = __arg ^ (__arg >> 27);
3277 __r1 = __detail::__mod<_Type,
3278 __detail::_Shift<_Type, 32>::__value>(1664525u * __r1);
3282 else if (__k <= __s)
3283 __r2 += __k % __n + _M_v[__k - 1];
3286 __r2 = __detail::__mod<_Type,
3287 __detail::_Shift<_Type, 32>::__value>(__r2);
3288 __begin[(__k + __p) % __n] += __r1;
3289 __begin[(__k + __q) % __n] += __r2;
3290 __begin[__k % __n] = __r2;
3293 for (
size_t __k = __m; __k < __m + __n; ++__k)
3295 _Type __arg = (__begin[__k % __n]
3296 + __begin[(__k + __p) % __n]
3297 + __begin[(__k - 1) % __n]);
3298 _Type __r3 = __arg ^ (__arg >> 27);
3299 __r3 = __detail::__mod<_Type,
3300 __detail::_Shift<_Type, 32>::__value>(1566083941u * __r3);
3301 _Type __r4 = __r3 - __k % __n;
3302 __r4 = __detail::__mod<_Type,
3303 __detail::_Shift<_Type, 32>::__value>(__r4);
3304 __begin[(__k + __p) % __n] ^= __r3;
3305 __begin[(__k + __q) % __n] ^= __r4;
3306 __begin[__k % __n] = __r4;
3310 template<
typename _RealType,
size_t __bits,
3311 typename _UniformRandomNumberGenerator>
3316 "template argument must be a floating point type");
3321 const long double __r = static_cast<long double>(__urng.max())
3322 - static_cast<long double>(__urng.min()) + 1.0L;
3324 const size_t __m = std::max<size_t>(1UL,
3325 (__b + __log2r - 1UL) / __log2r);
3327 _RealType __sum = _RealType(0);
3328 _RealType __tmp = _RealType(1);
3329 for (
size_t __k = __m; __k != 0; --__k)
3331 __sum += _RealType(__urng() - __urng.min()) * __tmp;
3334 __ret = __sum / __tmp;
3335 if (__builtin_expect(__ret >= _RealType(1), 0))
3337 #if _GLIBCXX_USE_C99_MATH_TR1 3338 __ret = std::nextafter(_RealType(1), _RealType(0));
3340 __ret = _RealType(1)
3347 _GLIBCXX_END_NAMESPACE_VERSION
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
A student_t_distribution random number distribution.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
param_type param() const
Returns the parameter set of the distribution.
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...
A extreme_value_distribution random number distribution.
static constexpr _Tp max() noexcept
complex< _Tp > sqrt(const complex< _Tp > &)
Return complex square root of z.
The Marsaglia-Zaman generator.
param_type param() const
Returns the parameter set of the distribution.
A Bernoulli random number distribution.
static constexpr result_type increment
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
complex< _Tp > log(const complex< _Tp > &)
Return complex natural logarithm of z.
complex< _Tp > pow(const complex< _Tp > &, int)
Return x to the y'th power.
fmtflags flags() const
Access to format flags.
A cauchy_distribution random number distribution.
Define a member typedef type only if a boolean constant is true.
void clear(iostate __state=goodbit)
[Re]sets the error state.
A discrete Poisson random number distribution.
A discrete binomial random number distribution.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
param_type param() const
Returns the parameter set of the distribution.
char_type fill() const
Retrieves the empty character.
double p() const
Returns the distribution parameter p.
char_type widen(char __c) const
Widens characters.
result_type operator()()
Gets the next value in the generated random number sequence.
Template class basic_istream.
_RealType generate_canonical(_UniformRandomNumberGenerator &__g)
A function template for converting the output of a (integral) uniform random number generator to a fl...
A discrete geometric random number distribution.
ios_base & scientific(ios_base &__base)
Calls base.setf(ios_base::scientific, ios_base::floatfield).
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Properties of fundamental types.
double p() const
Returns the p parameter of the distribution.
static constexpr result_type multiplier
_RealType b() const
Return the parameter of the distribution.
param_type param() const
Returns the parameter set of the distribution.
_RealType b() const
Return the parameter of the distribution.
_Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
Accumulate values in a range.
_RandomNumberEngine::result_type result_type
ISO C++ entities toplevel namespace is std.
_GLIBCXX14_CONSTEXPR const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
_RealType lambda() const
Returns the inverse scale parameter of the distribution.
static constexpr _Tp min() noexcept
A normal continuous distribution for random numbers.
iterator begin() noexcept
param_type param() const
Returns the parameter set of the distribution.
static constexpr result_type modulus
static constexpr _Tp epsilon() noexcept
ios_base & skipws(ios_base &__base)
Calls base.setf(ios_base::skipws).
Template class basic_ostream.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
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()(_UniformRandomNumberGenerator &__urng)
Generating functions.
result_type operator()()
Gets the next random number in the sequence.
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.
_RealType a() const
Return the parameter of the distribution.
back_insert_iterator< _Container > back_inserter(_Container &__x)
ios_base & left(ios_base &__base)
Calls base.setf(ios_base::left, ios_base::adjustfield).
constexpr int __lg(int __n)
This is a helper function for the sort routines and for random.tcc.
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.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
_OutputIterator partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
Return list of partial sums.
A fisher_f_distribution random number distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
_Tp abs(const complex< _Tp > &)
Return magnitude of z.
void seed(result_type __sd=default_seed)
Seeds the initial state of the random number generator.
A model of a linear congruential random number generator.
An exponential continuous distribution for random numbers.
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...
ios_base & fixed(ios_base &__base)
Calls base.setf(ios_base::fixed, ios_base::floatfield).
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
const _RandomNumberEngine & base() const noexcept
complex< _Tp > tan(const complex< _Tp > &)
Return complex tangent of z.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
ios_base & dec(ios_base &__base)
Calls base.setf(ios_base::dec, ios_base::basefield).
size_type size() const noexcept
complex< _Tp > exp(const complex< _Tp > &)
Return complex base e exponential of z.
Produces random numbers by combining random numbers from some base engine to produce random numbers w...
result_type operator()()
Gets the next value in the generated random number sequence.
A gamma continuous distribution for random numbers.
_ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp &__val)
Finds the first position in which val could be inserted without changing the ordering.
A weibull_distribution random number distribution.
_GLIBCXX14_CONSTEXPR const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
Uniform continuous distribution for random numbers.
param_type param() const
Returns the parameter set of the distribution.
_RealType a() const
Return the parameter of the distribution.
streamsize precision() const
Flags access.