35 namespace std _GLIBCXX_VISIBILITY(default)
42 _GLIBCXX_BEGIN_NAMESPACE_VERSION
54 template<
typename _Tp, _Tp __m, _Tp __a, _Tp __c,
bool>
64 static const _Tp __q = __m / __a;
65 static const _Tp __r = __m % __a;
67 _Tp __t1 = __a * (__x % __q);
68 _Tp __t2 = __r * (__x / __q);
72 __x = __m - __t2 + __t1;
77 const _Tp __d = __m - __x;
89 template<
typename _Tp, _Tp __m, _Tp __a, _Tp __c>
90 struct _Mod<_Tp, __m, __a, __c, true>
94 {
return __a * __x + __c; }
97 template<
typename _InputIterator,
typename _OutputIterator,
98 typename _UnaryOperation>
100 __transform(_InputIterator __first, _InputIterator __last,
101 _OutputIterator __result, _UnaryOperation __unary_op)
103 for (; __first != __last; ++__first, ++__result)
104 *__result = __unary_op(*__first);
108 _GLIBCXX_END_NAMESPACE_VERSION
111 _GLIBCXX_BEGIN_NAMESPACE_VERSION
113 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
115 linear_congruential_engine<_UIntType, __a, __c, __m>::multiplier;
117 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
119 linear_congruential_engine<_UIntType, __a, __c, __m>::increment;
121 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
123 linear_congruential_engine<_UIntType, __a, __c, __m>::modulus;
125 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
127 linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed;
133 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
138 if ((__detail::__mod<_UIntType, __m>(__c) == 0)
139 && (__detail::__mod<_UIntType, __m>(__s) == 0))
142 _M_x = __detail::__mod<_UIntType, __m>(__s);
148 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
149 template<
typename _Sseq>
156 const _UIntType __k = (__k0 + 31) / 32;
157 uint_least32_t __arr[__k + 3];
158 __q.generate(__arr + 0, __arr + __k + 3);
159 _UIntType __factor = 1u;
160 _UIntType __sum = 0u;
161 for (
size_t __j = 0; __j < __k; ++__j)
163 __sum += __arr[__j + 3] * __factor;
164 __factor *= __detail::_Shift<_UIntType, 32>::__value;
169 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m,
170 typename _CharT,
typename _Traits>
172 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
174 __a, __c, __m>& __lcr)
177 typedef typename __ostream_type::ios_base __ios_base;
179 const typename __ios_base::fmtflags __flags = __os.
flags();
180 const _CharT __fill = __os.fill();
182 __os.fill(__os.widen(
' '));
191 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m,
192 typename _CharT,
typename _Traits>
195 linear_congruential_engine<_UIntType, __a, __c, __m>& __lcr)
198 typedef typename __istream_type::ios_base __ios_base;
200 const typename __ios_base::fmtflags __flags = __is.
flags();
210 template<
typename _UIntType,
211 size_t __w,
size_t __n,
size_t __m,
size_t __r,
212 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
213 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
216 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
217 __s, __b, __t, __c, __l, __f>::word_size;
219 template<
typename _UIntType,
220 size_t __w,
size_t __n,
size_t __m,
size_t __r,
221 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
222 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
225 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
226 __s, __b, __t, __c, __l, __f>::state_size;
228 template<
typename _UIntType,
229 size_t __w,
size_t __n,
size_t __m,
size_t __r,
230 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
231 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
234 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
235 __s, __b, __t, __c, __l, __f>::shift_size;
237 template<
typename _UIntType,
238 size_t __w,
size_t __n,
size_t __m,
size_t __r,
239 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
240 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
243 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
244 __s, __b, __t, __c, __l, __f>::mask_bits;
246 template<
typename _UIntType,
247 size_t __w,
size_t __n,
size_t __m,
size_t __r,
248 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
249 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
252 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
253 __s, __b, __t, __c, __l, __f>::xor_mask;
255 template<
typename _UIntType,
256 size_t __w,
size_t __n,
size_t __m,
size_t __r,
257 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
258 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
261 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
262 __s, __b, __t, __c, __l, __f>::tempering_u;
264 template<
typename _UIntType,
265 size_t __w,
size_t __n,
size_t __m,
size_t __r,
266 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
267 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
270 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
271 __s, __b, __t, __c, __l, __f>::tempering_d;
273 template<
typename _UIntType,
274 size_t __w,
size_t __n,
size_t __m,
size_t __r,
275 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
276 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
279 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
280 __s, __b, __t, __c, __l, __f>::tempering_s;
282 template<
typename _UIntType,
283 size_t __w,
size_t __n,
size_t __m,
size_t __r,
284 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
285 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
288 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
289 __s, __b, __t, __c, __l, __f>::tempering_b;
291 template<
typename _UIntType,
292 size_t __w,
size_t __n,
size_t __m,
size_t __r,
293 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
294 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
297 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
298 __s, __b, __t, __c, __l, __f>::tempering_t;
300 template<
typename _UIntType,
301 size_t __w,
size_t __n,
size_t __m,
size_t __r,
302 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
303 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
306 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
307 __s, __b, __t, __c, __l, __f>::tempering_c;
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>::tempering_l;
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 initialization_multiplier;
328 template<
typename _UIntType,
329 size_t __w,
size_t __n,
size_t __m,
size_t __r,
330 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
331 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
334 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
335 __s, __b, __t, __c, __l, __f>::default_seed;
337 template<
typename _UIntType,
338 size_t __w,
size_t __n,
size_t __m,
size_t __r,
339 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
340 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
343 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
344 __s, __b, __t, __c, __l, __f>::
345 seed(result_type __sd)
347 _M_x[0] = __detail::__mod<_UIntType,
348 __detail::_Shift<_UIntType, __w>::__value>(__sd);
350 for (
size_t __i = 1; __i < state_size; ++__i)
352 _UIntType __x = _M_x[__i - 1];
353 __x ^= __x >> (__w - 2);
355 __x += __detail::__mod<_UIntType, __n>(__i);
356 _M_x[__i] = __detail::__mod<_UIntType,
357 __detail::_Shift<_UIntType, __w>::__value>(__x);
362 template<
typename _UIntType,
363 size_t __w,
size_t __n,
size_t __m,
size_t __r,
364 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
365 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
367 template<
typename _Sseq>
369 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
370 __s, __b, __t, __c, __l, __f>::
373 const _UIntType __upper_mask = (~_UIntType()) << __r;
374 const size_t __k = (__w + 31) / 32;
375 uint_least32_t __arr[__n * __k];
376 __q.generate(__arr + 0, __arr + __n * __k);
379 for (
size_t __i = 0; __i < state_size; ++__i)
381 _UIntType __factor = 1u;
382 _UIntType __sum = 0u;
383 for (
size_t __j = 0; __j < __k; ++__j)
385 __sum += __arr[__k * __i + __j] * __factor;
386 __factor *= __detail::_Shift<_UIntType, 32>::__value;
388 _M_x[__i] = __detail::__mod<_UIntType,
389 __detail::_Shift<_UIntType, __w>::__value>(__sum);
395 if ((_M_x[0] & __upper_mask) != 0u)
398 else if (_M_x[__i] != 0u)
403 _M_x[0] = __detail::_Shift<_UIntType, __w - 1>::__value;
406 template<
typename _UIntType,
size_t __w,
407 size_t __n,
size_t __m,
size_t __r,
408 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
409 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
412 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
413 __s, __b, __t, __c, __l, __f>::result_type
414 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
415 __s, __b, __t, __c, __l, __f>::
419 if (_M_p >= state_size)
421 const _UIntType __upper_mask = (~_UIntType()) << __r;
422 const _UIntType __lower_mask = ~__upper_mask;
424 for (
size_t __k = 0; __k < (__n - __m); ++__k)
426 _UIntType __y = ((_M_x[__k] & __upper_mask)
427 | (_M_x[__k + 1] & __lower_mask));
428 _M_x[__k] = (_M_x[__k + __m] ^ (__y >> 1)
429 ^ ((__y & 0x01) ? __a : 0));
432 for (
size_t __k = (__n - __m); __k < (__n - 1); ++__k)
434 _UIntType __y = ((_M_x[__k] & __upper_mask)
435 | (_M_x[__k + 1] & __lower_mask));
436 _M_x[__k] = (_M_x[__k + (__m - __n)] ^ (__y >> 1)
437 ^ ((__y & 0x01) ? __a : 0));
440 _UIntType __y = ((_M_x[__n - 1] & __upper_mask)
441 | (_M_x[0] & __lower_mask));
442 _M_x[__n - 1] = (_M_x[__m - 1] ^ (__y >> 1)
443 ^ ((__y & 0x01) ? __a : 0));
448 result_type __z = _M_x[_M_p++];
449 __z ^= (__z >> __u) & __d;
450 __z ^= (__z << __s) & __b;
451 __z ^= (__z << __t) & __c;
457 template<
typename _UIntType,
size_t __w,
458 size_t __n,
size_t __m,
size_t __r,
459 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
460 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
461 _UIntType __f,
typename _CharT,
typename _Traits>
463 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
464 const mersenne_twister_engine<_UIntType, __w, __n, __m,
465 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __x)
468 typedef typename __ostream_type::ios_base __ios_base;
470 const typename __ios_base::fmtflags __flags = __os.
flags();
471 const _CharT __fill = __os.fill();
472 const _CharT __space = __os.widen(
' ');
476 for (
size_t __i = 0; __i < __n - 1; ++__i)
477 __os << __x._M_x[__i] << __space;
478 __os << __x._M_x[__n - 1];
485 template<
typename _UIntType,
size_t __w,
486 size_t __n,
size_t __m,
size_t __r,
487 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
488 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
489 _UIntType __f,
typename _CharT,
typename _Traits>
492 mersenne_twister_engine<_UIntType, __w, __n, __m,
493 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __x)
496 typedef typename __istream_type::ios_base __ios_base;
498 const typename __ios_base::fmtflags __flags = __is.
flags();
501 for (
size_t __i = 0; __i < __n; ++__i)
502 __is >> __x._M_x[__i];
509 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
511 subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size;
513 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
515 subtract_with_carry_engine<_UIntType, __w, __s, __r>::short_lag;
517 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
519 subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag;
521 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
523 subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed;
525 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
527 subtract_with_carry_engine<_UIntType, __w, __s, __r>::
528 seed(result_type __value)
531 __lcg(__value == 0u ? default_seed : __value);
533 const size_t __n = (__w + 31) / 32;
535 for (
size_t __i = 0; __i < long_lag; ++__i)
537 _UIntType __sum = 0u;
538 _UIntType __factor = 1u;
539 for (
size_t __j = 0; __j < __n; ++__j)
541 __sum += __detail::__mod<uint_least32_t,
542 __detail::_Shift<uint_least32_t, 32>::__value>
543 (__lcg()) * __factor;
544 __factor *= __detail::_Shift<_UIntType, 32>::__value;
546 _M_x[__i] = __detail::__mod<_UIntType,
547 __detail::_Shift<_UIntType, __w>::__value>(__sum);
549 _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
553 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
554 template<
typename _Sseq>
556 subtract_with_carry_engine<_UIntType, __w, __s, __r>::
559 const size_t __k = (__w + 31) / 32;
560 uint_least32_t __arr[__r * __k];
561 __q.generate(__arr + 0, __arr + __r * __k);
563 for (
size_t __i = 0; __i < long_lag; ++__i)
565 _UIntType __sum = 0u;
566 _UIntType __factor = 1u;
567 for (
size_t __j = 0; __j < __k; ++__j)
569 __sum += __arr[__k * __i + __j] * __factor;
570 __factor *= __detail::_Shift<_UIntType, 32>::__value;
572 _M_x[__i] = __detail::__mod<_UIntType,
573 __detail::_Shift<_UIntType, __w>::__value>(__sum);
575 _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
579 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
580 typename subtract_with_carry_engine<_UIntType, __w, __s, __r>::
582 subtract_with_carry_engine<_UIntType, __w, __s, __r>::
586 long __ps = _M_p - short_lag;
594 if (_M_x[__ps] >= _M_x[_M_p] + _M_carry)
596 __xi = _M_x[__ps] - _M_x[_M_p] - _M_carry;
601 __xi = (__detail::_Shift<_UIntType, __w>::__value
602 - _M_x[_M_p] - _M_carry + _M_x[__ps]);
608 if (++_M_p >= long_lag)
614 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r,
615 typename _CharT,
typename _Traits>
617 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
618 const subtract_with_carry_engine<_UIntType,
622 typedef typename __ostream_type::ios_base __ios_base;
624 const typename __ios_base::fmtflags __flags = __os.
flags();
625 const _CharT __fill = __os.fill();
626 const _CharT __space = __os.widen(
' ');
630 for (
size_t __i = 0; __i < __r; ++__i)
631 __os << __x._M_x[__i] << __space;
632 __os << __x._M_carry;
639 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r,
640 typename _CharT,
typename _Traits>
643 subtract_with_carry_engine<_UIntType, __w, __s, __r>& __x)
646 typedef typename __istream_type::ios_base __ios_base;
648 const typename __ios_base::fmtflags __flags = __is.
flags();
651 for (
size_t __i = 0; __i < __r; ++__i)
652 __is >> __x._M_x[__i];
653 __is >> __x._M_carry;
660 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
662 discard_block_engine<_RandomNumberEngine, __p, __r>::block_size;
664 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
666 discard_block_engine<_RandomNumberEngine, __p, __r>::used_block;
668 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
669 typename discard_block_engine<_RandomNumberEngine,
670 __p, __r>::result_type
674 if (_M_n >= used_block)
676 _M_b.discard(block_size - _M_n);
683 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r,
684 typename _CharT,
typename _Traits>
686 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
691 typedef typename __ostream_type::ios_base __ios_base;
693 const typename __ios_base::fmtflags __flags = __os.
flags();
694 const _CharT __fill = __os.fill();
695 const _CharT __space = __os.widen(
' ');
699 __os << __x.base() << __space << __x._M_n;
706 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r,
707 typename _CharT,
typename _Traits>
710 discard_block_engine<_RandomNumberEngine, __p, __r>& __x)
713 typedef typename __istream_type::ios_base __ios_base;
715 const typename __ios_base::fmtflags __flags = __is.
flags();
718 __is >> __x._M_b >> __x._M_n;
725 template<
typename _RandomNumberEngine,
size_t __w,
typename _UIntType>
726 typename independent_bits_engine<_RandomNumberEngine, __w, _UIntType>::
731 const long double __r =
static_cast<long double>(_M_b.max())
732 - static_cast<long double>(_M_b.min()) + 1.0L;
735 for (
size_t __i = 0; __i < 2; ++__i)
737 __n = (__w + __m - 1) / __m + __i;
738 __n0 = __n - __w % __n;
743 __y0 = __s0 * (__r / __s0);
744 __y1 = __s1 * (__r / __s1);
745 if (__r - __y0 <= __y0 / __n)
750 for (
size_t __k = 0; __k < __n0; ++__k)
754 __u = _M_b() - _M_b.min();
756 __sum = __s0 * __sum + __u % __s0;
758 for (
size_t __k = __n0; __k < __n; ++__k)
762 __u = _M_b() - _M_b.min();
764 __sum = __s1 * __sum + __u % __s1;
770 template<
typename _RandomNumberEngine,
size_t __k>
774 template<
typename _RandomNumberEngine,
size_t __k>
779 size_t __j = __k * ((_M_y - _M_b.min())
780 / (_M_b.max() - _M_b.min() + 1.0L));
787 template<
typename _RandomNumberEngine,
size_t __k,
788 typename _CharT,
typename _Traits>
790 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
794 typedef typename __ostream_type::ios_base __ios_base;
796 const typename __ios_base::fmtflags __flags = __os.
flags();
797 const _CharT __fill = __os.fill();
798 const _CharT __space = __os.widen(
' ');
803 for (
size_t __i = 0; __i < __k; ++__i)
804 __os << __space << __x._M_v[__i];
805 __os << __space << __x._M_y;
812 template<
typename _RandomNumberEngine,
size_t __k,
813 typename _CharT,
typename _Traits>
816 shuffle_order_engine<_RandomNumberEngine, __k>& __x)
819 typedef typename __istream_type::ios_base __ios_base;
821 const typename __ios_base::fmtflags __flags = __is.
flags();
825 for (
size_t __i = 0; __i < __k; ++__i)
826 __is >> __x._M_v[__i];
834 template<
typename _IntType>
835 template<
typename _UniformRandomNumberGenerator>
836 typename uniform_int_distribution<_IntType>::result_type
838 operator()(_UniformRandomNumberGenerator& __urng,
839 const param_type& __param)
842 _UniformRandomNumberGenerator::result_type>::type __urngtype;
843 typedef typename std::make_unsigned<result_type>::type __utype;
846 __urngtype, __utype>::type __uctype;
848 const __uctype __urngmin = __urng.min();
849 const __uctype __urngmax = __urng.max();
850 const __uctype __urngrange = __urngmax - __urngmin;
851 const __uctype __urange
852 = __uctype(__param.b()) - __uctype(__param.a());
856 if (__urngrange > __urange)
859 const __uctype __uerange = __urange + 1;
860 const __uctype __scaling = __urngrange / __uerange;
861 const __uctype __past = __uerange * __scaling;
863 __ret = __uctype(__urng()) - __urngmin;
864 while (__ret >= __past);
867 else if (__urngrange < __urange)
887 const __uctype __uerngrange = __urngrange + 1;
888 __tmp = (__uerngrange * operator()
889 (__urng, param_type(0, __urange / __uerngrange)));
890 __ret = __tmp + (__uctype(__urng()) - __urngmin);
892 while (__ret > __urange || __ret < __tmp);
895 __ret = __uctype(__urng()) - __urngmin;
897 return __ret + __param.a();
900 template<
typename _IntType,
typename _CharT,
typename _Traits>
902 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
906 typedef typename __ostream_type::ios_base __ios_base;
908 const typename __ios_base::fmtflags __flags = __os.
flags();
909 const _CharT __fill = __os.fill();
910 const _CharT __space = __os.widen(
' ');
914 __os << __x.a() << __space << __x.b();
921 template<
typename _IntType,
typename _CharT,
typename _Traits>
927 typedef typename __istream_type::ios_base __ios_base;
929 const typename __ios_base::fmtflags __flags = __is.
flags();
935 param_type(__a, __b));
942 template<
typename _RealType,
typename _CharT,
typename _Traits>
944 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
948 typedef typename __ostream_type::ios_base __ios_base;
950 const typename __ios_base::fmtflags __flags = __os.
flags();
951 const _CharT __fill = __os.fill();
953 const _CharT __space = __os.widen(
' ');
958 __os << __x.a() << __space << __x.b();
962 __os.precision(__precision);
966 template<
typename _RealType,
typename _CharT,
typename _Traits>
972 typedef typename __istream_type::ios_base __ios_base;
974 const typename __ios_base::fmtflags __flags = __is.
flags();
980 param_type(__a, __b));
987 template<
typename _CharT,
typename _Traits>
989 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
993 typedef typename __ostream_type::ios_base __ios_base;
995 const typename __ios_base::fmtflags __flags = __os.
flags();
996 const _CharT __fill = __os.fill();
999 __os.fill(__os.widen(
' '));
1004 __os.flags(__flags);
1006 __os.precision(__precision);
1011 template<
typename _IntType>
1012 template<
typename _UniformRandomNumberGenerator>
1013 typename geometric_distribution<_IntType>::result_type
1015 operator()(_UniformRandomNumberGenerator& __urng,
1016 const param_type& __param)
1020 const double __naf =
1023 const double __thr =
1025 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1030 __cand = std::floor(
std::log(__aurng()) / __param._M_log_1_p);
1031 while (__cand >= __thr);
1033 return result_type(__cand + __naf);
1036 template<
typename _IntType,
1037 typename _CharT,
typename _Traits>
1039 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1043 typedef typename __ostream_type::ios_base __ios_base;
1045 const typename __ios_base::fmtflags __flags = __os.
flags();
1046 const _CharT __fill = __os.fill();
1049 __os.fill(__os.widen(
' '));
1054 __os.flags(__flags);
1056 __os.precision(__precision);
1060 template<
typename _IntType,
1061 typename _CharT,
typename _Traits>
1067 typedef typename __istream_type::ios_base __ios_base;
1069 const typename __ios_base::fmtflags __flags = __is.
flags();
1076 __is.
flags(__flags);
1081 template<
typename _IntType>
1082 template<
typename _UniformRandomNumberGenerator>
1083 typename negative_binomial_distribution<_IntType>::result_type
1085 operator()(_UniformRandomNumberGenerator& __urng)
1087 const double __y = _M_gd(__urng);
1091 return __poisson(__urng);
1094 template<
typename _IntType>
1095 template<
typename _UniformRandomNumberGenerator>
1096 typename negative_binomial_distribution<_IntType>::result_type
1098 operator()(_UniformRandomNumberGenerator& __urng,
1099 const param_type& __p)
1105 _M_gd(__urng, param_type(__p.k(), (1.0 - __p.p()) / __p.p()));
1108 return __poisson(__urng);
1111 template<
typename _IntType,
typename _CharT,
typename _Traits>
1113 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1114 const negative_binomial_distribution<_IntType>& __x)
1117 typedef typename __ostream_type::ios_base __ios_base;
1119 const typename __ios_base::fmtflags __flags = __os.
flags();
1120 const _CharT __fill = __os.fill();
1122 const _CharT __space = __os.widen(
' ');
1124 __os.fill(__os.widen(
' '));
1127 __os << __x.k() << __space << __x.p()
1128 << __space << __x._M_gd;
1130 __os.flags(__flags);
1132 __os.precision(__precision);
1136 template<
typename _IntType,
typename _CharT,
typename _Traits>
1139 negative_binomial_distribution<_IntType>& __x)
1142 typedef typename __istream_type::ios_base __ios_base;
1144 const typename __ios_base::fmtflags __flags = __is.
flags();
1149 __is >> __k >> __p >> __x._M_gd;
1150 __x.param(
typename negative_binomial_distribution<_IntType>::
1151 param_type(__k, __p));
1153 __is.
flags(__flags);
1158 template<
typename _IntType>
1160 poisson_distribution<_IntType>::param_type::
1163 #if _GLIBCXX_USE_C99_MATH_TR1
1166 const double __m = std::floor(_M_mean);
1168 _M_lfm = std::lgamma(__m + 1);
1171 const double __pi_4 = 0.7853981633974483096156608458198757L;
1175 const double __cx = 2 * __m + _M_d;
1180 _M_cb = 2 * __cx *
std::exp(-_M_d * _M_1cx * (1 + _M_d / 2))
1198 template<
typename _IntType>
1199 template<
typename _UniformRandomNumberGenerator>
1200 typename poisson_distribution<_IntType>::result_type
1203 const param_type& __param)
1205 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1207 #if _GLIBCXX_USE_C99_MATH_TR1
1208 if (__param.mean() >= 12)
1213 const double __naf =
1215 const double __thr =
1218 const double __m = std::floor(__param.mean());
1220 const double __spi_2 = 1.2533141373155002512078826424055226L;
1221 const double __c1 = __param._M_sm * __spi_2;
1222 const double __c2 = __param._M_c2b + __c1;
1223 const double __c3 = __c2 + 1;
1224 const double __c4 = __c3 + 1;
1226 const double __e178 = 1.0129030479320018583185514777512983L;
1227 const double __c5 = __c4 + __e178;
1228 const double __c = __param._M_cb + __c5;
1229 const double __2cx = 2 * (2 * __m + __param._M_d);
1231 bool __reject =
true;
1234 const double __u = __c * __aurng();
1235 const double __e = -
std::log(__aurng());
1241 const double __n = _M_nd(__urng);
1242 const double __y = -
std::abs(__n) * __param._M_sm - 1;
1243 __x = std::floor(__y);
1244 __w = -__n * __n / 2;
1248 else if (__u <= __c2)
1250 const double __n = _M_nd(__urng);
1251 const double __y = 1 +
std::abs(__n) * __param._M_scx;
1252 __x = std::ceil(__y);
1253 __w = __y * (2 - __y) * __param._M_1cx;
1254 if (__x > __param._M_d)
1257 else if (__u <= __c3)
1261 else if (__u <= __c4)
1263 else if (__u <= __c5)
1267 const double __v = -
std::log(__aurng());
1268 const double __y = __param._M_d
1269 + __v * __2cx / __param._M_d;
1270 __x = std::ceil(__y);
1271 __w = -__param._M_d * __param._M_1cx * (1 + __y / 2);
1274 __reject = (__w - __e - __x * __param._M_lm_thr
1275 > __param._M_lfm - std::lgamma(__x + __m + 1));
1277 __reject |= __x + __m >= __thr;
1287 double __prod = 1.0;
1291 __prod *= __aurng();
1294 while (__prod > __param._M_lm_thr);
1300 template<
typename _IntType,
1301 typename _CharT,
typename _Traits>
1303 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1307 typedef typename __ostream_type::ios_base __ios_base;
1309 const typename __ios_base::fmtflags __flags = __os.
flags();
1310 const _CharT __fill = __os.fill();
1312 const _CharT __space = __os.widen(
' ');
1317 __os << __x.mean() << __space << __x._M_nd;
1319 __os.flags(__flags);
1321 __os.precision(__precision);
1325 template<
typename _IntType,
1326 typename _CharT,
typename _Traits>
1329 poisson_distribution<_IntType>& __x)
1332 typedef typename __istream_type::ios_base __ios_base;
1334 const typename __ios_base::fmtflags __flags = __is.
flags();
1338 __is >> __mean >> __x._M_nd;
1339 __x.param(
typename poisson_distribution<_IntType>::param_type(__mean));
1341 __is.
flags(__flags);
1346 template<
typename _IntType>
1348 binomial_distribution<_IntType>::param_type::
1351 const double __p12 = _M_p <= 0.5 ? _M_p : 1.0 - _M_p;
1355 #if _GLIBCXX_USE_C99_MATH_TR1
1356 if (_M_t * __p12 >= 8)
1359 const double __np = std::floor(_M_t * __p12);
1360 const double __pa = __np / _M_t;
1361 const double __1p = 1 - __pa;
1363 const double __pi_4 = 0.7853981633974483096156608458198757L;
1364 const double __d1x =
1366 / (81 * __pi_4 * __1p)));
1367 _M_d1 = std::round(
std::max(1.0, __d1x));
1368 const double __d2x =
1370 / (__pi_4 * __pa)));
1371 _M_d2 = std::round(
std::max(1.0, __d2x));
1374 const double __spi_2 = 1.2533141373155002512078826424055226L;
1375 _M_s1 =
std::sqrt(__np * __1p) * (1 + _M_d1 / (4 * __np));
1376 _M_s2 =
std::sqrt(__np * __1p) * (1 + _M_d2 / (4 * _M_t * __1p));
1377 _M_c = 2 * _M_d1 / __np;
1378 _M_a1 =
std::exp(_M_c) * _M_s1 * __spi_2;
1379 const double __a12 = _M_a1 + _M_s2 * __spi_2;
1380 const double __s1s = _M_s1 * _M_s1;
1381 _M_a123 = __a12 + (
std::exp(_M_d1 / (_M_t * __1p))
1383 *
std::exp(-_M_d1 * _M_d1 / (2 * __s1s)));
1384 const double __s2s = _M_s2 * _M_s2;
1385 _M_s = (_M_a123 + 2 * __s2s / _M_d2
1386 *
std::exp(-_M_d2 * _M_d2 / (2 * __s2s)));
1387 _M_lf = (std::lgamma(__np + 1)
1388 + std::lgamma(_M_t - __np + 1));
1391 _M_q = -
std::log(1 - (__p12 - __pa) / __1p);
1398 template<
typename _IntType>
1399 template<
typename _UniformRandomNumberGenerator>
1400 typename binomial_distribution<_IntType>::result_type
1401 binomial_distribution<_IntType>::
1402 _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t)
1406 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1411 const double __e = -
std::log(__aurng());
1412 __sum += __e / (__t - __x);
1415 while (__sum <= _M_param._M_q);
1430 template<
typename _IntType>
1431 template<
typename _UniformRandomNumberGenerator>
1432 typename binomial_distribution<_IntType>::result_type
1435 const param_type& __param)
1438 const _IntType __t = __param.t();
1439 const double __p = __param.p();
1440 const double __p12 = __p <= 0.5 ? __p : 1.0 - __p;
1441 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1444 #if _GLIBCXX_USE_C99_MATH_TR1
1445 if (!__param._M_easy)
1450 const double __naf =
1452 const double __thr =
1455 const double __np = std::floor(__t * __p12);
1458 const double __spi_2 = 1.2533141373155002512078826424055226L;
1459 const double __a1 = __param._M_a1;
1460 const double __a12 = __a1 + __param._M_s2 * __spi_2;
1461 const double __a123 = __param._M_a123;
1462 const double __s1s = __param._M_s1 * __param._M_s1;
1463 const double __s2s = __param._M_s2 * __param._M_s2;
1468 const double __u = __param._M_s * __aurng();
1474 const double __n = _M_nd(__urng);
1475 const double __y = __param._M_s1 *
std::abs(__n);
1476 __reject = __y >= __param._M_d1;
1479 const double __e = -
std::log(__aurng());
1480 __x = std::floor(__y);
1481 __v = -__e - __n * __n / 2 + __param._M_c;
1484 else if (__u <= __a12)
1486 const double __n = _M_nd(__urng);
1487 const double __y = __param._M_s2 *
std::abs(__n);
1488 __reject = __y >= __param._M_d2;
1491 const double __e = -
std::log(__aurng());
1492 __x = std::floor(-__y);
1493 __v = -__e - __n * __n / 2;
1496 else if (__u <= __a123)
1498 const double __e1 = -
std::log(__aurng());
1499 const double __e2 = -
std::log(__aurng());
1501 const double __y = __param._M_d1
1502 + 2 * __s1s * __e1 / __param._M_d1;
1503 __x = std::floor(__y);
1504 __v = (-__e2 + __param._M_d1 * (1 / (__t - __np)
1505 -__y / (2 * __s1s)));
1510 const double __e1 = -
std::log(__aurng());
1511 const double __e2 = -
std::log(__aurng());
1513 const double __y = __param._M_d2
1514 + 2 * __s2s * __e1 / __param._M_d2;
1515 __x = std::floor(-__y);
1516 __v = -__e2 - __param._M_d2 * __y / (2 * __s2s);
1520 __reject = __reject || __x < -__np || __x > __t - __np;
1523 const double __lfx =
1524 std::lgamma(__np + __x + 1)
1525 + std::lgamma(__t - (__np + __x) + 1);
1526 __reject = __v > __param._M_lf - __lfx
1527 + __x * __param._M_lp1p;
1530 __reject |= __x + __np >= __thr;
1534 __x += __np + __naf;
1536 const _IntType __z = _M_waiting(__urng, __t - _IntType(__x));
1537 __ret = _IntType(__x) + __z;
1541 __ret = _M_waiting(__urng, __t);
1544 __ret = __t - __ret;
1548 template<
typename _IntType,
1549 typename _CharT,
typename _Traits>
1551 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1555 typedef typename __ostream_type::ios_base __ios_base;
1557 const typename __ios_base::fmtflags __flags = __os.
flags();
1558 const _CharT __fill = __os.fill();
1560 const _CharT __space = __os.widen(
' ');
1565 __os << __x.t() << __space << __x.p()
1566 << __space << __x._M_nd;
1568 __os.flags(__flags);
1570 __os.precision(__precision);
1574 template<
typename _IntType,
1575 typename _CharT,
typename _Traits>
1578 binomial_distribution<_IntType>& __x)
1581 typedef typename __istream_type::ios_base __ios_base;
1583 const typename __ios_base::fmtflags __flags = __is.
flags();
1588 __is >> __t >> __p >> __x._M_nd;
1589 __x.param(
typename binomial_distribution<_IntType>::
1590 param_type(__t, __p));
1592 __is.
flags(__flags);
1597 template<
typename _RealType,
typename _CharT,
typename _Traits>
1599 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1603 typedef typename __ostream_type::ios_base __ios_base;
1605 const typename __ios_base::fmtflags __flags = __os.
flags();
1606 const _CharT __fill = __os.fill();
1609 __os.fill(__os.widen(
' '));
1612 __os << __x.lambda();
1614 __os.flags(__flags);
1616 __os.precision(__precision);
1620 template<
typename _RealType,
typename _CharT,
typename _Traits>
1626 typedef typename __istream_type::ios_base __ios_base;
1628 const typename __ios_base::fmtflags __flags = __is.
flags();
1634 param_type(__lambda));
1636 __is.
flags(__flags);
1647 template<
typename _RealType>
1648 template<
typename _UniformRandomNumberGenerator>
1649 typename normal_distribution<_RealType>::result_type
1652 const param_type& __param)
1655 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1658 if (_M_saved_available)
1660 _M_saved_available =
false;
1670 __r2 = __x * __x + __y * __y;
1672 while (__r2 > 1.0 || __r2 == 0.0);
1675 _M_saved = __x * __mult;
1676 _M_saved_available =
true;
1677 __ret = __y * __mult;
1680 __ret = __ret * __param.stddev() + __param.mean();
1684 template<
typename _RealType>
1689 if (__d1._M_param == __d2._M_param
1690 && __d1._M_saved_available == __d2._M_saved_available)
1692 if (__d1._M_saved_available
1693 && __d1._M_saved == __d2._M_saved)
1695 else if(!__d1._M_saved_available)
1704 template<
typename _RealType,
typename _CharT,
typename _Traits>
1706 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1707 const normal_distribution<_RealType>& __x)
1710 typedef typename __ostream_type::ios_base __ios_base;
1712 const typename __ios_base::fmtflags __flags = __os.
flags();
1713 const _CharT __fill = __os.fill();
1715 const _CharT __space = __os.widen(
' ');
1720 __os << __x.mean() << __space << __x.stddev()
1721 << __space << __x._M_saved_available;
1722 if (__x._M_saved_available)
1723 __os << __space << __x._M_saved;
1725 __os.flags(__flags);
1727 __os.precision(__precision);
1731 template<
typename _RealType,
typename _CharT,
typename _Traits>
1734 normal_distribution<_RealType>& __x)
1737 typedef typename __istream_type::ios_base __ios_base;
1739 const typename __ios_base::fmtflags __flags = __is.
flags();
1742 double __mean, __stddev;
1743 __is >> __mean >> __stddev
1744 >> __x._M_saved_available;
1745 if (__x._M_saved_available)
1746 __is >> __x._M_saved;
1747 __x.param(
typename normal_distribution<_RealType>::
1748 param_type(__mean, __stddev));
1750 __is.
flags(__flags);
1755 template<
typename _RealType,
typename _CharT,
typename _Traits>
1757 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1758 const lognormal_distribution<_RealType>& __x)
1761 typedef typename __ostream_type::ios_base __ios_base;
1763 const typename __ios_base::fmtflags __flags = __os.
flags();
1764 const _CharT __fill = __os.fill();
1766 const _CharT __space = __os.widen(
' ');
1771 __os << __x.m() << __space << __x.s()
1772 << __space << __x._M_nd;
1774 __os.flags(__flags);
1776 __os.precision(__precision);
1780 template<
typename _RealType,
typename _CharT,
typename _Traits>
1783 lognormal_distribution<_RealType>& __x)
1786 typedef typename __istream_type::ios_base __ios_base;
1788 const typename __ios_base::fmtflags __flags = __is.
flags();
1792 __is >> __m >> __s >> __x._M_nd;
1793 __x.param(
typename lognormal_distribution<_RealType>::
1794 param_type(__m, __s));
1796 __is.
flags(__flags);
1801 template<
typename _RealType,
typename _CharT,
typename _Traits>
1803 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1804 const chi_squared_distribution<_RealType>& __x)
1807 typedef typename __ostream_type::ios_base __ios_base;
1809 const typename __ios_base::fmtflags __flags = __os.
flags();
1810 const _CharT __fill = __os.fill();
1812 const _CharT __space = __os.widen(
' ');
1817 __os << __x.n() << __space << __x._M_gd;
1819 __os.flags(__flags);
1821 __os.precision(__precision);
1825 template<
typename _RealType,
typename _CharT,
typename _Traits>
1828 chi_squared_distribution<_RealType>& __x)
1831 typedef typename __istream_type::ios_base __ios_base;
1833 const typename __ios_base::fmtflags __flags = __is.
flags();
1837 __is >> __n >> __x._M_gd;
1838 __x.param(
typename chi_squared_distribution<_RealType>::
1841 __is.
flags(__flags);
1846 template<
typename _RealType>
1847 template<
typename _UniformRandomNumberGenerator>
1848 typename cauchy_distribution<_RealType>::result_type
1850 operator()(_UniformRandomNumberGenerator& __urng,
1851 const param_type& __p)
1853 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1860 const _RealType __pi = 3.1415926535897932384626433832795029L;
1861 return __p.a() + __p.b() *
std::tan(__pi * __u);
1864 template<
typename _RealType,
typename _CharT,
typename _Traits>
1866 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1870 typedef typename __ostream_type::ios_base __ios_base;
1872 const typename __ios_base::fmtflags __flags = __os.
flags();
1873 const _CharT __fill = __os.fill();
1875 const _CharT __space = __os.widen(
' ');
1880 __os << __x.a() << __space << __x.b();
1882 __os.flags(__flags);
1884 __os.precision(__precision);
1888 template<
typename _RealType,
typename _CharT,
typename _Traits>
1894 typedef typename __istream_type::ios_base __ios_base;
1896 const typename __ios_base::fmtflags __flags = __is.
flags();
1902 param_type(__a, __b));
1904 __is.
flags(__flags);
1909 template<
typename _RealType,
typename _CharT,
typename _Traits>
1911 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1912 const fisher_f_distribution<_RealType>& __x)
1915 typedef typename __ostream_type::ios_base __ios_base;
1917 const typename __ios_base::fmtflags __flags = __os.
flags();
1918 const _CharT __fill = __os.fill();
1920 const _CharT __space = __os.widen(
' ');
1925 __os << __x.m() << __space << __x.n()
1926 << __space << __x._M_gd_x << __space << __x._M_gd_y;
1928 __os.flags(__flags);
1930 __os.precision(__precision);
1934 template<
typename _RealType,
typename _CharT,
typename _Traits>
1937 fisher_f_distribution<_RealType>& __x)
1940 typedef typename __istream_type::ios_base __ios_base;
1942 const typename __ios_base::fmtflags __flags = __is.
flags();
1946 __is >> __m >> __n >> __x._M_gd_x >> __x._M_gd_y;
1947 __x.param(
typename fisher_f_distribution<_RealType>::
1948 param_type(__m, __n));
1950 __is.
flags(__flags);
1955 template<
typename _RealType,
typename _CharT,
typename _Traits>
1957 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1958 const student_t_distribution<_RealType>& __x)
1961 typedef typename __ostream_type::ios_base __ios_base;
1963 const typename __ios_base::fmtflags __flags = __os.
flags();
1964 const _CharT __fill = __os.fill();
1966 const _CharT __space = __os.widen(
' ');
1971 __os << __x.n() << __space << __x._M_nd << __space << __x._M_gd;
1973 __os.flags(__flags);
1975 __os.precision(__precision);
1979 template<
typename _RealType,
typename _CharT,
typename _Traits>
1982 student_t_distribution<_RealType>& __x)
1985 typedef typename __istream_type::ios_base __ios_base;
1987 const typename __ios_base::fmtflags __flags = __is.
flags();
1991 __is >> __n >> __x._M_nd >> __x._M_gd;
1992 __x.param(
typename student_t_distribution<_RealType>::param_type(__n));
1994 __is.
flags(__flags);
1999 template<
typename _RealType>
2001 gamma_distribution<_RealType>::param_type::
2004 _M_malpha = _M_alpha < 1.0 ? _M_alpha + _RealType(1.0) : _M_alpha;
2006 const _RealType __a1 = _M_malpha - _RealType(1.0) / _RealType(3.0);
2007 _M_a2 = _RealType(1.0) /
std::sqrt(_RealType(9.0) * __a1);
2015 template<
typename _RealType>
2016 template<
typename _UniformRandomNumberGenerator>
2017 typename gamma_distribution<_RealType>::result_type
2020 const param_type& __param)
2022 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2027 - _RealType(1.0) / _RealType(3.0));
2033 __n = _M_nd(__urng);
2038 __v = __v * __v * __v;
2041 while (__u >
result_type(1.0) - 0.331 * __n * __n * __n * __n
2042 && (
std::log(__u) > (0.5 * __n * __n + __a1
2045 if (__param.alpha() == __param._M_malpha)
2046 return __a1 * __v * __param.beta();
2054 * __a1 * __v * __param.beta());
2058 template<
typename _RealType,
typename _CharT,
typename _Traits>
2060 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2064 typedef typename __ostream_type::ios_base __ios_base;
2066 const typename __ios_base::fmtflags __flags = __os.
flags();
2067 const _CharT __fill = __os.fill();
2069 const _CharT __space = __os.widen(
' ');
2074 __os << __x.alpha() << __space << __x.beta()
2075 << __space << __x._M_nd;
2077 __os.flags(__flags);
2079 __os.precision(__precision);
2083 template<
typename _RealType,
typename _CharT,
typename _Traits>
2086 gamma_distribution<_RealType>& __x)
2089 typedef typename __istream_type::ios_base __ios_base;
2091 const typename __ios_base::fmtflags __flags = __is.
flags();
2094 _RealType __alpha_val, __beta_val;
2095 __is >> __alpha_val >> __beta_val >> __x._M_nd;
2096 __x.param(
typename gamma_distribution<_RealType>::
2097 param_type(__alpha_val, __beta_val));
2099 __is.
flags(__flags);
2104 template<
typename _RealType>
2105 template<
typename _UniformRandomNumberGenerator>
2106 typename weibull_distribution<_RealType>::result_type
2108 operator()(_UniformRandomNumberGenerator& __urng,
2109 const param_type& __p)
2111 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2117 template<
typename _RealType,
typename _CharT,
typename _Traits>
2119 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2123 typedef typename __ostream_type::ios_base __ios_base;
2125 const typename __ios_base::fmtflags __flags = __os.
flags();
2126 const _CharT __fill = __os.fill();
2128 const _CharT __space = __os.widen(
' ');
2133 __os << __x.a() << __space << __x.b();
2135 __os.flags(__flags);
2137 __os.precision(__precision);
2141 template<
typename _RealType,
typename _CharT,
typename _Traits>
2147 typedef typename __istream_type::ios_base __ios_base;
2149 const typename __ios_base::fmtflags __flags = __is.
flags();
2155 param_type(__a, __b));
2157 __is.
flags(__flags);
2162 template<
typename _RealType>
2163 template<
typename _UniformRandomNumberGenerator>
2164 typename extreme_value_distribution<_RealType>::result_type
2166 operator()(_UniformRandomNumberGenerator& __urng,
2167 const param_type& __p)
2169 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2174 template<
typename _RealType,
typename _CharT,
typename _Traits>
2176 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2180 typedef typename __ostream_type::ios_base __ios_base;
2182 const typename __ios_base::fmtflags __flags = __os.
flags();
2183 const _CharT __fill = __os.fill();
2185 const _CharT __space = __os.widen(
' ');
2190 __os << __x.a() << __space << __x.b();
2192 __os.flags(__flags);
2194 __os.precision(__precision);
2198 template<
typename _RealType,
typename _CharT,
typename _Traits>
2204 typedef typename __istream_type::ios_base __ios_base;
2206 const typename __ios_base::fmtflags __flags = __is.
flags();
2212 param_type(__a, __b));
2214 __is.
flags(__flags);
2219 template<
typename _IntType>
2221 discrete_distribution<_IntType>::param_type::
2224 if (_M_prob.size() < 2)
2231 _M_prob.end(), 0.0);
2233 __detail::__transform(_M_prob.begin(), _M_prob.end(), _M_prob.begin(),
2236 _M_cp.reserve(_M_prob.size());
2240 _M_cp[_M_cp.size() - 1] = 1.0;
2243 template<
typename _IntType>
2244 template<
typename _Func>
2245 discrete_distribution<_IntType>::param_type::
2246 param_type(
size_t __nw,
double __xmin,
double __xmax, _Func __fw)
2247 : _M_prob(), _M_cp()
2249 const size_t __n = __nw == 0 ? 1 : __nw;
2250 const double __delta = (__xmax - __xmin) / __n;
2252 _M_prob.reserve(__n);
2253 for (
size_t __k = 0; __k < __nw; ++__k)
2254 _M_prob.push_back(__fw(__xmin + __k * __delta + 0.5 * __delta));
2259 template<
typename _IntType>
2260 template<
typename _UniformRandomNumberGenerator>
2261 typename discrete_distribution<_IntType>::result_type
2262 discrete_distribution<_IntType>::
2263 operator()(_UniformRandomNumberGenerator& __urng,
2264 const param_type& __param)
2266 if (__param._M_cp.empty())
2267 return result_type(0);
2269 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2272 const double __p = __aurng();
2274 __param._M_cp.end(), __p);
2276 return __pos - __param._M_cp.begin();
2279 template<
typename _IntType,
typename _CharT,
typename _Traits>
2281 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2282 const discrete_distribution<_IntType>& __x)
2285 typedef typename __ostream_type::ios_base __ios_base;
2287 const typename __ios_base::fmtflags __flags = __os.
flags();
2288 const _CharT __fill = __os.fill();
2290 const _CharT __space = __os.widen(
' ');
2296 __os << __prob.
size();
2297 for (
auto __dit = __prob.
begin(); __dit != __prob.
end(); ++__dit)
2298 __os << __space << *__dit;
2300 __os.flags(__flags);
2302 __os.precision(__precision);
2306 template<
typename _IntType,
typename _CharT,
typename _Traits>
2309 discrete_distribution<_IntType>& __x)
2312 typedef typename __istream_type::ios_base __ios_base;
2314 const typename __ios_base::fmtflags __flags = __is.
flags();
2322 for (; __n != 0; --__n)
2329 __x.param(
typename discrete_distribution<_IntType>::
2330 param_type(__prob_vec.
begin(), __prob_vec.
end()));
2332 __is.
flags(__flags);
2337 template<
typename _RealType>
2339 piecewise_constant_distribution<_RealType>::param_type::
2342 if (_M_int.size() < 2
2343 || (_M_int.size() == 2
2344 && _M_int[0] == _RealType(0)
2345 && _M_int[1] == _RealType(1)))
2355 __detail::__transform(_M_den.begin(), _M_den.end(), _M_den.begin(),
2358 _M_cp.reserve(_M_den.size());
2363 _M_cp[_M_cp.size() - 1] = 1.0;
2365 for (
size_t __k = 0; __k < _M_den.size(); ++__k)
2366 _M_den[__k] /= _M_int[__k + 1] - _M_int[__k];
2369 template<
typename _RealType>
2370 template<
typename _InputIteratorB,
typename _InputIteratorW>
2371 piecewise_constant_distribution<_RealType>::param_type::
2372 param_type(_InputIteratorB __bbegin,
2373 _InputIteratorB __bend,
2374 _InputIteratorW __wbegin)
2375 : _M_int(), _M_den(), _M_cp()
2377 if (__bbegin != __bend)
2381 _M_int.push_back(*__bbegin);
2383 if (__bbegin == __bend)
2386 _M_den.push_back(*__wbegin);
2394 template<
typename _RealType>
2395 template<
typename _Func>
2396 piecewise_constant_distribution<_RealType>::param_type::
2397 param_type(initializer_list<_RealType> __bl, _Func __fw)
2398 : _M_int(), _M_den(), _M_cp()
2400 _M_int.reserve(__bl.size());
2401 for (
auto __biter = __bl.begin(); __biter != __bl.end(); ++__biter)
2402 _M_int.push_back(*__biter);
2404 _M_den.reserve(_M_int.size() - 1);
2405 for (
size_t __k = 0; __k < _M_int.size() - 1; ++__k)
2406 _M_den.push_back(__fw(0.5 * (_M_int[__k + 1] + _M_int[__k])));
2411 template<
typename _RealType>
2412 template<
typename _Func>
2413 piecewise_constant_distribution<_RealType>::param_type::
2414 param_type(
size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
2415 : _M_int(), _M_den(), _M_cp()
2417 const size_t __n = __nw == 0 ? 1 : __nw;
2418 const _RealType __delta = (__xmax - __xmin) / __n;
2420 _M_int.reserve(__n + 1);
2421 for (
size_t __k = 0; __k <= __nw; ++__k)
2422 _M_int.push_back(__xmin + __k * __delta);
2424 _M_den.reserve(__n);
2425 for (
size_t __k = 0; __k < __nw; ++__k)
2426 _M_den.push_back(__fw(_M_int[__k] + 0.5 * __delta));
2431 template<
typename _RealType>
2432 template<
typename _UniformRandomNumberGenerator>
2433 typename piecewise_constant_distribution<_RealType>::result_type
2434 piecewise_constant_distribution<_RealType>::
2435 operator()(_UniformRandomNumberGenerator& __urng,
2436 const param_type& __param)
2438 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2441 const double __p = __aurng();
2442 if (__param._M_cp.empty())
2446 __param._M_cp.end(), __p);
2447 const size_t __i = __pos - __param._M_cp.begin();
2449 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
2451 return __param._M_int[__i] + (__p - __pref) / __param._M_den[__i];
2454 template<
typename _RealType,
typename _CharT,
typename _Traits>
2456 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2457 const piecewise_constant_distribution<_RealType>& __x)
2460 typedef typename __ostream_type::ios_base __ios_base;
2462 const typename __ios_base::fmtflags __flags = __os.
flags();
2463 const _CharT __fill = __os.fill();
2465 const _CharT __space = __os.widen(
' ');
2471 __os << __int.
size() - 1;
2473 for (
auto __xit = __int.
begin(); __xit != __int.
end(); ++__xit)
2474 __os << __space << *__xit;
2477 for (
auto __dit = __den.
begin(); __dit != __den.
end(); ++__dit)
2478 __os << __space << *__dit;
2480 __os.flags(__flags);
2482 __os.precision(__precision);
2486 template<
typename _RealType,
typename _CharT,
typename _Traits>
2489 piecewise_constant_distribution<_RealType>& __x)
2492 typedef typename __istream_type::ios_base __ios_base;
2494 const typename __ios_base::fmtflags __flags = __is.
flags();
2502 for (
size_t __i = 0; __i <= __n; ++__i)
2511 for (
size_t __i = 0; __i < __n; ++__i)
2518 __x.param(
typename piecewise_constant_distribution<_RealType>::
2519 param_type(__int_vec.
begin(), __int_vec.
end(), __den_vec.
begin()));
2521 __is.
flags(__flags);
2526 template<
typename _RealType>
2528 piecewise_linear_distribution<_RealType>::param_type::
2531 if (_M_int.size() < 2
2532 || (_M_int.size() == 2
2533 && _M_int[0] == _RealType(0)
2534 && _M_int[1] == _RealType(1)
2535 && _M_den[0] == _M_den[1]))
2543 _M_cp.reserve(_M_int.size() - 1);
2544 _M_m.reserve(_M_int.size() - 1);
2545 for (
size_t __k = 0; __k < _M_int.size() - 1; ++__k)
2547 const _RealType __delta = _M_int[__k + 1] - _M_int[__k];
2548 __sum += 0.5 * (_M_den[__k + 1] + _M_den[__k]) * __delta;
2549 _M_cp.push_back(__sum);
2550 _M_m.push_back((_M_den[__k + 1] - _M_den[__k]) / __delta);
2554 __detail::__transform(_M_den.begin(), _M_den.end(), _M_den.begin(),
2557 __detail::__transform(_M_cp.begin(), _M_cp.end(), _M_cp.begin(),
2560 __detail::__transform(_M_m.begin(), _M_m.end(), _M_m.begin(),
2563 _M_cp[_M_cp.size() - 1] = 1.0;
2566 template<
typename _RealType>
2567 template<
typename _InputIteratorB,
typename _InputIteratorW>
2568 piecewise_linear_distribution<_RealType>::param_type::
2569 param_type(_InputIteratorB __bbegin,
2570 _InputIteratorB __bend,
2571 _InputIteratorW __wbegin)
2572 : _M_int(), _M_den(), _M_cp(), _M_m()
2574 for (; __bbegin != __bend; ++__bbegin, ++__wbegin)
2576 _M_int.push_back(*__bbegin);
2577 _M_den.push_back(*__wbegin);
2583 template<
typename _RealType>
2584 template<
typename _Func>
2585 piecewise_linear_distribution<_RealType>::param_type::
2586 param_type(initializer_list<_RealType> __bl, _Func __fw)
2587 : _M_int(), _M_den(), _M_cp(), _M_m()
2589 _M_int.reserve(__bl.size());
2590 _M_den.reserve(__bl.size());
2591 for (
auto __biter = __bl.begin(); __biter != __bl.end(); ++__biter)
2593 _M_int.push_back(*__biter);
2594 _M_den.push_back(__fw(*__biter));
2600 template<
typename _RealType>
2601 template<
typename _Func>
2602 piecewise_linear_distribution<_RealType>::param_type::
2603 param_type(
size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
2604 : _M_int(), _M_den(), _M_cp(), _M_m()
2606 const size_t __n = __nw == 0 ? 1 : __nw;
2607 const _RealType __delta = (__xmax - __xmin) / __n;
2609 _M_int.reserve(__n + 1);
2610 _M_den.reserve(__n + 1);
2611 for (
size_t __k = 0; __k <= __nw; ++__k)
2613 _M_int.push_back(__xmin + __k * __delta);
2614 _M_den.push_back(__fw(_M_int[__k] + __delta));
2620 template<
typename _RealType>
2621 template<
typename _UniformRandomNumberGenerator>
2622 typename piecewise_linear_distribution<_RealType>::result_type
2623 piecewise_linear_distribution<_RealType>::
2624 operator()(_UniformRandomNumberGenerator& __urng,
2625 const param_type& __param)
2627 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2630 const double __p = __aurng();
2631 if (__param._M_cp.empty())
2635 __param._M_cp.end(), __p);
2636 const size_t __i = __pos - __param._M_cp.begin();
2638 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
2640 const double __a = 0.5 * __param._M_m[__i];
2641 const double __b = __param._M_den[__i];
2642 const double __cm = __p - __pref;
2644 _RealType __x = __param._M_int[__i];
2649 const double __d = __b * __b + 4.0 * __a * __cm;
2650 __x += 0.5 * (
std::sqrt(__d) - __b) / __a;
2656 template<
typename _RealType,
typename _CharT,
typename _Traits>
2658 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2659 const piecewise_linear_distribution<_RealType>& __x)
2662 typedef typename __ostream_type::ios_base __ios_base;
2664 const typename __ios_base::fmtflags __flags = __os.
flags();
2665 const _CharT __fill = __os.fill();
2667 const _CharT __space = __os.widen(
' ');
2673 __os << __int.
size() - 1;
2675 for (
auto __xit = __int.
begin(); __xit != __int.
end(); ++__xit)
2676 __os << __space << *__xit;
2679 for (
auto __dit = __den.
begin(); __dit != __den.
end(); ++__dit)
2680 __os << __space << *__dit;
2682 __os.flags(__flags);
2684 __os.precision(__precision);
2688 template<
typename _RealType,
typename _CharT,
typename _Traits>
2691 piecewise_linear_distribution<_RealType>& __x)
2694 typedef typename __istream_type::ios_base __ios_base;
2696 const typename __ios_base::fmtflags __flags = __is.
flags();
2704 for (
size_t __i = 0; __i <= __n; ++__i)
2713 for (
size_t __i = 0; __i <= __n; ++__i)
2720 __x.param(
typename piecewise_linear_distribution<_RealType>::
2721 param_type(__int_vec.
begin(), __int_vec.
end(), __den_vec.
begin()));
2723 __is.
flags(__flags);
2728 template<
typename _IntType>
2731 for (
auto __iter = __il.begin(); __iter != __il.end(); ++__iter)
2732 _M_v.push_back(__detail::__mod<result_type,
2733 __detail::_Shift<result_type, 32>::__value>(*__iter));
2736 template<
typename _InputIterator>
2737 seed_seq::seed_seq(_InputIterator __begin, _InputIterator __end)
2739 for (_InputIterator __iter = __begin; __iter != __end; ++__iter)
2740 _M_v.push_back(__detail::__mod<result_type,
2741 __detail::_Shift<result_type, 32>::__value>(*__iter));
2744 template<
typename _RandomAccessIterator>
2746 seed_seq::generate(_RandomAccessIterator __begin,
2747 _RandomAccessIterator __end)
2749 typedef typename iterator_traits<_RandomAccessIterator>::value_type
2752 if (__begin == __end)
2755 std::fill(__begin, __end, _Type(0x8b8b8b8bu));
2757 const size_t __n = __end - __begin;
2758 const size_t __s = _M_v.size();
2759 const size_t __t = (__n >= 623) ? 11
2764 const size_t __p = (__n - __t) / 2;
2765 const size_t __q = __p + __t;
2766 const size_t __m =
std::max(__s + 1, __n);
2768 for (
size_t __k = 0; __k < __m; ++__k)
2770 _Type __arg = (__begin[__k % __n]
2771 ^ __begin[(__k + __p) % __n]
2772 ^ __begin[(__k - 1) % __n]);
2773 _Type __r1 = __arg ^ (__arg >> 27);
2774 __r1 = __detail::__mod<_Type,
2775 __detail::_Shift<_Type, 32>::__value>(1664525u * __r1);
2779 else if (__k <= __s)
2780 __r2 += __k % __n + _M_v[__k - 1];
2783 __r2 = __detail::__mod<_Type,
2784 __detail::_Shift<_Type, 32>::__value>(__r2);
2785 __begin[(__k + __p) % __n] += __r1;
2786 __begin[(__k + __q) % __n] += __r2;
2787 __begin[__k % __n] = __r2;
2790 for (
size_t __k = __m; __k < __m + __n; ++__k)
2792 _Type __arg = (__begin[__k % __n]
2793 + __begin[(__k + __p) % __n]
2794 + __begin[(__k - 1) % __n]);
2795 _Type __r3 = __arg ^ (__arg >> 27);
2796 __r3 = __detail::__mod<_Type,
2797 __detail::_Shift<_Type, 32>::__value>(1566083941u * __r3);
2798 _Type __r4 = __r3 - __k % __n;
2799 __r4 = __detail::__mod<_Type,
2800 __detail::_Shift<_Type, 32>::__value>(__r4);
2801 __begin[(__k + __p) % __n] ^= __r3;
2802 __begin[(__k + __q) % __n] ^= __r4;
2803 __begin[__k % __n] = __r4;
2807 template<
typename _RealType,
size_t __bits,
2808 typename _UniformRandomNumberGenerator>
2815 const long double __r =
static_cast<long double>(__urng.max())
2816 - static_cast<long double>(__urng.min()) + 1.0L;
2818 size_t __k = std::max<size_t>(1UL, (__b + __log2r - 1UL) / __log2r);
2819 _RealType __sum = _RealType(0);
2820 _RealType __tmp = _RealType(1);
2821 for (; __k != 0; --__k)
2823 __sum += _RealType(__urng() - __urng.min()) * __tmp;
2826 return __sum / __tmp;
2829 _GLIBCXX_END_NAMESPACE_VERSION
result_type operator()()
Gets the next value in the generated random number sequence.
Produces random numbers by combining random numbers from some base engine to produce random numbers w...
Uniform discrete distribution for random numbers. A discrete random distribution on the range with e...
Controlling output.This is the base class for all output streams. It provides text formatting of all ...
static constexpr _Tp epsilon()
complex< _Tp > tan(const complex< _Tp > &)
Return complex tangent of z.
result_type operator()()
Gets the next value in the generated random number sequence.
ios_base & fixed(ios_base &__base)
Calls base.setf(ios_base::fixed, ios_base::floatfield).
void push_back(const value_type &__x)
Add data to the end of the vector.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
A model of a linear congruential random number generator.
back_insert_iterator< _Container > back_inserter(_Container &__x)
_RealType generate_canonical(_UniformRandomNumberGenerator &__g)
A function template for converting the output of a (integral) uniform random number generator to a fl...
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
complex< _Tp > sqrt(const complex< _Tp > &)
Return complex square root of z.
binder2nd< _Operation > bind2nd(const _Operation &__fn, const _Tp &__x)
One of the binder functors.
const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
complex< _Tp > pow(const complex< _Tp > &, const _Tp &)
Return x to the y'th power.
bitset< _Nb > operator>>(size_t __position) const
Self-explanatory.
One of the math functors.
A normal continuous distribution for random numbers.
void clear(iostate __state=goodbit)
[Re]sets the error state.
Controlling input.This is the base class for all input streams. It provides text formatting of all bu...
A weibull_distribution random number distribution.
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.
A discrete binomial random number distribution.
param_type param() const
Returns the parameter set of the distribution.
A discrete Poisson random number distribution.
Uniform 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.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
_RandomNumberEngine::result_type result_type
ios_base & scientific(ios_base &__base)
Calls base.setf(ios_base::scientific, ios_base::floatfield).
param_type param() const
Returns the parameter set of the distribution.
An exponential continuous distribution for random numbers.
static constexpr _Tp max()
param_type param() const
Returns the parameter set of the distribution.
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &, std::poisson_distribution< _IntType1 > &)
Extracts a poisson_distribution random number distribution __x from the input stream __is...
A gamma continuous distribution for random numbers.
ios_base & skipws(ios_base &__base)
Calls base.setf(ios_base::skipws).
param_type param() const
Returns the parameter set of the distribution.
A Bernoulli random number distribution.
ios_base & left(ios_base &__base)
Calls base.setf(ios_base::left, ios_base::adjustfield).
void reserve(size_type __n)
Attempt to preallocate enough memory for specified number of elements.
A cauchy_distribution random number distribution.
_Tp abs(const complex< _Tp > &)
Return magnitude of z.
A extreme_value_distribution random number distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
_Size __lg(_Size __n)
This is a helper function for the sort routines and for random.tcc.
_Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
Accumulate values in a range.
fmtflags flags() const
Access to format flags.
param_type param() const
Returns the parameter set of the distribution.
const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Properties of fundamental types.
friend bool operator==(const std::poisson_distribution< _IntType1 > &__d1, const std::poisson_distribution< _IntType1 > &__d2)
Return true if two Poisson distributions have the same parameters and the sequences that would be gen...
param_type param() const
Returns the parameter set of the distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
ios_base & dec(ios_base &__base)
Calls base.setf(ios_base::dec, ios_base::basefield).
A discrete geometric random number distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
complex< _Tp > exp(const complex< _Tp > &)
Return complex base e exponential of z.
complex< _Tp > log(const complex< _Tp > &)
Return complex natural logarithm of z.
param_type param() const
Returns the parameter set of the distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
_OutputIterator partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
Return list of partial sums.