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>
134 -> _If_seed_seq<_Sseq>
138 const _UIntType __k = (__k0 + 31) / 32;
139 uint_least32_t __arr[__k + 3];
140 __q.generate(__arr + 0, __arr + __k + 3);
141 _UIntType __factor = 1u;
142 _UIntType __sum = 0u;
143 for (
size_t __j = 0; __j < __k; ++__j)
145 __sum += __arr[__j + 3] * __factor;
146 __factor *= __detail::_Shift<_UIntType, 32>::__value;
151 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m,
152 typename _CharT,
typename _Traits>
154 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
156 __a, __c, __m>& __lcr)
159 typedef typename __ostream_type::ios_base __ios_base;
161 const typename __ios_base::fmtflags __flags = __os.
flags();
162 const _CharT __fill = __os.fill();
164 __os.fill(__os.widen(
' '));
173 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m,
174 typename _CharT,
typename _Traits>
177 linear_congruential_engine<_UIntType, __a, __c, __m>& __lcr)
180 typedef typename __istream_type::ios_base __ios_base;
182 const typename __ios_base::fmtflags __flags = __is.
flags();
192 template<
typename _UIntType,
193 size_t __w,
size_t __n,
size_t __m,
size_t __r,
194 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
195 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
198 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
199 __s, __b, __t, __c, __l, __f>::word_size;
201 template<
typename _UIntType,
202 size_t __w,
size_t __n,
size_t __m,
size_t __r,
203 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
204 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
207 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
208 __s, __b, __t, __c, __l, __f>::state_size;
210 template<
typename _UIntType,
211 size_t __w,
size_t __n,
size_t __m,
size_t __r,
212 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
213 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
216 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
217 __s, __b, __t, __c, __l, __f>::shift_size;
219 template<
typename _UIntType,
220 size_t __w,
size_t __n,
size_t __m,
size_t __r,
221 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
222 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
225 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
226 __s, __b, __t, __c, __l, __f>::mask_bits;
228 template<
typename _UIntType,
229 size_t __w,
size_t __n,
size_t __m,
size_t __r,
230 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
231 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
234 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
235 __s, __b, __t, __c, __l, __f>::xor_mask;
237 template<
typename _UIntType,
238 size_t __w,
size_t __n,
size_t __m,
size_t __r,
239 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
240 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
243 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
244 __s, __b, __t, __c, __l, __f>::tempering_u;
246 template<
typename _UIntType,
247 size_t __w,
size_t __n,
size_t __m,
size_t __r,
248 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
249 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
252 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
253 __s, __b, __t, __c, __l, __f>::tempering_d;
255 template<
typename _UIntType,
256 size_t __w,
size_t __n,
size_t __m,
size_t __r,
257 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
258 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
261 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
262 __s, __b, __t, __c, __l, __f>::tempering_s;
264 template<
typename _UIntType,
265 size_t __w,
size_t __n,
size_t __m,
size_t __r,
266 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
267 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
270 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
271 __s, __b, __t, __c, __l, __f>::tempering_b;
273 template<
typename _UIntType,
274 size_t __w,
size_t __n,
size_t __m,
size_t __r,
275 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
276 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
279 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
280 __s, __b, __t, __c, __l, __f>::tempering_t;
282 template<
typename _UIntType,
283 size_t __w,
size_t __n,
size_t __m,
size_t __r,
284 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
285 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
288 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
289 __s, __b, __t, __c, __l, __f>::tempering_c;
291 template<
typename _UIntType,
292 size_t __w,
size_t __n,
size_t __m,
size_t __r,
293 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
294 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
297 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
298 __s, __b, __t, __c, __l, __f>::tempering_l;
300 template<
typename _UIntType,
301 size_t __w,
size_t __n,
size_t __m,
size_t __r,
302 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
303 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
306 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
307 __s, __b, __t, __c, __l, __f>::
308 initialization_multiplier;
310 template<
typename _UIntType,
311 size_t __w,
size_t __n,
size_t __m,
size_t __r,
312 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
313 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
316 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
317 __s, __b, __t, __c, __l, __f>::default_seed;
319 template<
typename _UIntType,
320 size_t __w,
size_t __n,
size_t __m,
size_t __r,
321 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
322 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
325 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
326 __s, __b, __t, __c, __l, __f>::
327 seed(result_type __sd)
329 _M_x[0] = __detail::__mod<_UIntType,
330 __detail::_Shift<_UIntType, __w>::__value>(__sd);
332 for (
size_t __i = 1; __i < state_size; ++__i)
334 _UIntType __x = _M_x[__i - 1];
335 __x ^= __x >> (__w - 2);
337 __x += __detail::__mod<_UIntType, __n>(__i);
338 _M_x[__i] = __detail::__mod<_UIntType,
339 __detail::_Shift<_UIntType, __w>::__value>(__x);
344 template<
typename _UIntType,
345 size_t __w,
size_t __n,
size_t __m,
size_t __r,
346 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
347 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
349 template<
typename _Sseq>
351 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
352 __s, __b, __t, __c, __l, __f>::
354 -> _If_seed_seq<_Sseq>
356 const _UIntType __upper_mask = (~_UIntType()) << __r;
357 const size_t __k = (__w + 31) / 32;
358 uint_least32_t __arr[__n * __k];
359 __q.generate(__arr + 0, __arr + __n * __k);
362 for (
size_t __i = 0; __i < state_size; ++__i)
364 _UIntType __factor = 1u;
365 _UIntType __sum = 0u;
366 for (
size_t __j = 0; __j < __k; ++__j)
368 __sum += __arr[__k * __i + __j] * __factor;
369 __factor *= __detail::_Shift<_UIntType, 32>::__value;
371 _M_x[__i] = __detail::__mod<_UIntType,
372 __detail::_Shift<_UIntType, __w>::__value>(__sum);
378 if ((_M_x[0] & __upper_mask) != 0u)
381 else if (_M_x[__i] != 0u)
386 _M_x[0] = __detail::_Shift<_UIntType, __w - 1>::__value;
390 template<
typename _UIntType,
size_t __w,
391 size_t __n,
size_t __m,
size_t __r,
392 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
393 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
396 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
397 __s, __b, __t, __c, __l, __f>::
400 const _UIntType __upper_mask = (~_UIntType()) << __r;
401 const _UIntType __lower_mask = ~__upper_mask;
403 for (
size_t __k = 0; __k < (__n - __m); ++__k)
405 _UIntType __y = ((_M_x[__k] & __upper_mask)
406 | (_M_x[__k + 1] & __lower_mask));
407 _M_x[__k] = (_M_x[__k + __m] ^ (__y >> 1)
408 ^ ((__y & 0x01) ? __a : 0));
411 for (
size_t __k = (__n - __m); __k < (__n - 1); ++__k)
413 _UIntType __y = ((_M_x[__k] & __upper_mask)
414 | (_M_x[__k + 1] & __lower_mask));
415 _M_x[__k] = (_M_x[__k + (__m - __n)] ^ (__y >> 1)
416 ^ ((__y & 0x01) ? __a : 0));
419 _UIntType __y = ((_M_x[__n - 1] & __upper_mask)
420 | (_M_x[0] & __lower_mask));
421 _M_x[__n - 1] = (_M_x[__m - 1] ^ (__y >> 1)
422 ^ ((__y & 0x01) ? __a : 0));
426 template<
typename _UIntType,
size_t __w,
427 size_t __n,
size_t __m,
size_t __r,
428 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
429 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
432 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
433 __s, __b, __t, __c, __l, __f>::
434 discard(
unsigned long long __z)
436 while (__z > state_size - _M_p)
438 __z -= state_size - _M_p;
444 template<
typename _UIntType,
size_t __w,
445 size_t __n,
size_t __m,
size_t __r,
446 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
447 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
451 __s, __b, __t, __c, __l, __f>::result_type
453 __s, __b, __t, __c, __l, __f>::
457 if (_M_p >= state_size)
461 result_type __z = _M_x[_M_p++];
462 __z ^= (__z >> __u) & __d;
463 __z ^= (__z << __s) & __b;
464 __z ^= (__z << __t) & __c;
470 template<
typename _UIntType,
size_t __w,
471 size_t __n,
size_t __m,
size_t __r,
472 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
473 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
474 _UIntType __f,
typename _CharT,
typename _Traits>
476 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
477 const mersenne_twister_engine<_UIntType, __w, __n, __m,
478 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __x)
481 typedef typename __ostream_type::ios_base __ios_base;
483 const typename __ios_base::fmtflags __flags = __os.
flags();
484 const _CharT __fill = __os.fill();
485 const _CharT __space = __os.widen(
' ');
489 for (
size_t __i = 0; __i < __n; ++__i)
490 __os << __x._M_x[__i] << __space;
498 template<
typename _UIntType,
size_t __w,
499 size_t __n,
size_t __m,
size_t __r,
500 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
501 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
502 _UIntType __f,
typename _CharT,
typename _Traits>
505 mersenne_twister_engine<_UIntType, __w, __n, __m,
506 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __x)
509 typedef typename __istream_type::ios_base __ios_base;
511 const typename __ios_base::fmtflags __flags = __is.
flags();
514 for (
size_t __i = 0; __i < __n; ++__i)
515 __is >> __x._M_x[__i];
523 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
525 subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size;
527 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
529 subtract_with_carry_engine<_UIntType, __w, __s, __r>::short_lag;
531 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
533 subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag;
535 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
537 subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed;
539 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
545 __lcg(__value == 0u ? default_seed : __value);
547 const size_t __n = (__w + 31) / 32;
549 for (
size_t __i = 0; __i < long_lag; ++__i)
551 _UIntType __sum = 0u;
552 _UIntType __factor = 1u;
553 for (
size_t __j = 0; __j < __n; ++__j)
555 __sum += __detail::__mod<uint_least32_t,
556 __detail::_Shift<uint_least32_t, 32>::__value>
557 (__lcg()) * __factor;
558 __factor *= __detail::_Shift<_UIntType, 32>::__value;
560 _M_x[__i] = __detail::__mod<_UIntType,
561 __detail::_Shift<_UIntType, __w>::__value>(__sum);
563 _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
567 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
568 template<
typename _Sseq>
572 -> _If_seed_seq<_Sseq>
574 const size_t __k = (__w + 31) / 32;
575 uint_least32_t __arr[__r * __k];
576 __q.generate(__arr + 0, __arr + __r * __k);
578 for (
size_t __i = 0; __i < long_lag; ++__i)
580 _UIntType __sum = 0u;
581 _UIntType __factor = 1u;
582 for (
size_t __j = 0; __j < __k; ++__j)
584 __sum += __arr[__k * __i + __j] * __factor;
585 __factor *= __detail::_Shift<_UIntType, 32>::__value;
587 _M_x[__i] = __detail::__mod<_UIntType,
588 __detail::_Shift<_UIntType, __w>::__value>(__sum);
590 _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
594 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
595 typename subtract_with_carry_engine<_UIntType, __w, __s, __r>::
601 long __ps = _M_p - short_lag;
609 if (_M_x[__ps] >= _M_x[_M_p] + _M_carry)
611 __xi = _M_x[__ps] - _M_x[_M_p] - _M_carry;
616 __xi = (__detail::_Shift<_UIntType, __w>::__value
617 - _M_x[_M_p] - _M_carry + _M_x[__ps]);
623 if (++_M_p >= long_lag)
629 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r,
630 typename _CharT,
typename _Traits>
632 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
637 typedef typename __ostream_type::ios_base __ios_base;
639 const typename __ios_base::fmtflags __flags = __os.
flags();
640 const _CharT __fill = __os.fill();
641 const _CharT __space = __os.widen(
' ');
645 for (
size_t __i = 0; __i < __r; ++__i)
646 __os << __x._M_x[__i] << __space;
647 __os << __x._M_carry << __space << __x._M_p;
654 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r,
655 typename _CharT,
typename _Traits>
658 subtract_with_carry_engine<_UIntType, __w, __s, __r>& __x)
661 typedef typename __istream_type::ios_base __ios_base;
663 const typename __ios_base::fmtflags __flags = __is.
flags();
666 for (
size_t __i = 0; __i < __r; ++__i)
667 __is >> __x._M_x[__i];
668 __is >> __x._M_carry;
676 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
678 discard_block_engine<_RandomNumberEngine, __p, __r>::block_size;
680 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
682 discard_block_engine<_RandomNumberEngine, __p, __r>::used_block;
684 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
685 typename discard_block_engine<_RandomNumberEngine,
686 __p, __r>::result_type
690 if (_M_n >= used_block)
692 _M_b.discard(block_size - _M_n);
699 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r,
700 typename _CharT,
typename _Traits>
702 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
707 typedef typename __ostream_type::ios_base __ios_base;
709 const typename __ios_base::fmtflags __flags = __os.
flags();
710 const _CharT __fill = __os.fill();
711 const _CharT __space = __os.widen(
' ');
715 __os << __x.base() << __space << __x._M_n;
722 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r,
723 typename _CharT,
typename _Traits>
726 discard_block_engine<_RandomNumberEngine, __p, __r>& __x)
729 typedef typename __istream_type::ios_base __ios_base;
731 const typename __ios_base::fmtflags __flags = __is.
flags();
734 __is >> __x._M_b >> __x._M_n;
741 template<
typename _RandomNumberEngine,
size_t __w,
typename _UIntType>
742 typename independent_bits_engine<_RandomNumberEngine, __w, _UIntType>::
747 typedef typename _RandomNumberEngine::result_type _Eresult_type;
748 const _Eresult_type __r
750 ? _M_b.max() - _M_b.min() + 1 : 0);
752 const unsigned __m = __r ?
std::__lg(__r) : __edig;
759 __ctype __s0, __s1, __y0, __y1;
761 for (
size_t __i = 0; __i < 2; ++__i)
763 __n = (__w + __m - 1) / __m + __i;
764 __n0 = __n - __w % __n;
765 const unsigned __w0 = __w / __n;
771 __s0 = __ctype(1) << __w0;
779 __y0 = __s0 * (__r / __s0);
781 __y1 = __s1 * (__r / __s1);
783 if (__r - __y0 <= __y0 / __n)
791 for (
size_t __k = 0; __k < __n0; ++__k)
795 __u = _M_b() - _M_b.
min();
796 while (__y0 && __u >= __y0);
797 __sum = __s0 * __sum + (__s0 ? __u % __s0 : __u);
799 for (
size_t __k = __n0; __k < __n; ++__k)
803 __u = _M_b() - _M_b.min();
804 while (__y1 && __u >= __y1);
805 __sum = __s1 * __sum + (__s1 ? __u % __s1 : __u);
811 template<
typename _RandomNumberEngine,
size_t __k>
815 template<
typename _RandomNumberEngine,
size_t __k>
820 size_t __j = __k * ((_M_y - _M_b.min())
821 / (_M_b.max() - _M_b.min() + 1.0L));
828 template<
typename _RandomNumberEngine,
size_t __k,
829 typename _CharT,
typename _Traits>
831 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
835 typedef typename __ostream_type::ios_base __ios_base;
837 const typename __ios_base::fmtflags __flags = __os.
flags();
838 const _CharT __fill = __os.fill();
839 const _CharT __space = __os.widen(
' ');
844 for (
size_t __i = 0; __i < __k; ++__i)
845 __os << __space << __x._M_v[__i];
846 __os << __space << __x._M_y;
853 template<
typename _RandomNumberEngine,
size_t __k,
854 typename _CharT,
typename _Traits>
857 shuffle_order_engine<_RandomNumberEngine, __k>& __x)
860 typedef typename __istream_type::ios_base __ios_base;
862 const typename __ios_base::fmtflags __flags = __is.
flags();
866 for (
size_t __i = 0; __i < __k; ++__i)
867 __is >> __x._M_v[__i];
875 template<
typename _IntType,
typename _CharT,
typename _Traits>
877 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
881 typedef typename __ostream_type::ios_base __ios_base;
883 const typename __ios_base::fmtflags __flags = __os.
flags();
884 const _CharT __fill = __os.fill();
885 const _CharT __space = __os.widen(
' ');
889 __os << __x.a() << __space << __x.b();
896 template<
typename _IntType,
typename _CharT,
typename _Traits>
902 typedef typename __istream_type::ios_base __ios_base;
904 const typename __ios_base::fmtflags __flags = __is.
flags();
908 if (__is >> __a >> __b)
910 param_type(__a, __b));
917 template<
typename _RealType>
918 template<
typename _ForwardIterator,
919 typename _UniformRandomNumberGenerator>
921 uniform_real_distribution<_RealType>::
922 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
923 _UniformRandomNumberGenerator& __urng,
924 const param_type& __p)
926 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
927 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
929 auto __range = __p.b() - __p.a();
931 *__f++ = __aurng() * __range + __p.a();
934 template<
typename _RealType,
typename _CharT,
typename _Traits>
936 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
940 typedef typename __ostream_type::ios_base __ios_base;
942 const typename __ios_base::fmtflags __flags = __os.
flags();
943 const _CharT __fill = __os.fill();
945 const _CharT __space = __os.widen(
' ');
950 __os << __x.a() << __space << __x.b();
954 __os.precision(__precision);
958 template<
typename _RealType,
typename _CharT,
typename _Traits>
964 typedef typename __istream_type::ios_base __ios_base;
966 const typename __ios_base::fmtflags __flags = __is.
flags();
970 if (__is >> __a >> __b)
972 param_type(__a, __b));
979 template<
typename _ForwardIterator,
980 typename _UniformRandomNumberGenerator>
982 std::bernoulli_distribution::
983 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
984 _UniformRandomNumberGenerator& __urng,
985 const param_type& __p)
987 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
988 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
990 auto __limit = __p.p() * (__aurng.max() - __aurng.min());
993 *__f++ = (__aurng() - __aurng.min()) < __limit;
996 template<
typename _CharT,
typename _Traits>
998 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1002 typedef typename __ostream_type::ios_base __ios_base;
1004 const typename __ios_base::fmtflags __flags = __os.
flags();
1005 const _CharT __fill = __os.fill();
1008 __os.fill(__os.widen(
' '));
1013 __os.flags(__flags);
1015 __os.precision(__precision);
1020 template<
typename _IntType>
1021 template<
typename _UniformRandomNumberGenerator>
1024 operator()(_UniformRandomNumberGenerator& __urng,
1025 const param_type& __param)
1029 const double __naf =
1032 const double __thr =
1034 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1039 __cand = std::floor(
std::log(1.0 - __aurng()) / __param._M_log_1_p);
1040 while (__cand >= __thr);
1042 return result_type(__cand + __naf);
1045 template<
typename _IntType>
1046 template<
typename _ForwardIterator,
1047 typename _UniformRandomNumberGenerator>
1049 geometric_distribution<_IntType>::
1050 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1051 _UniformRandomNumberGenerator& __urng,
1052 const param_type& __param)
1054 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1057 const double __naf =
1060 const double __thr =
1062 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1069 __cand = std::floor(
std::log(1.0 - __aurng())
1070 / __param._M_log_1_p);
1071 while (__cand >= __thr);
1073 *__f++ = __cand + __naf;
1077 template<
typename _IntType,
1078 typename _CharT,
typename _Traits>
1080 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1084 typedef typename __ostream_type::ios_base __ios_base;
1086 const typename __ios_base::fmtflags __flags = __os.
flags();
1087 const _CharT __fill = __os.fill();
1090 __os.fill(__os.widen(
' '));
1095 __os.flags(__flags);
1097 __os.precision(__precision);
1101 template<
typename _IntType,
1102 typename _CharT,
typename _Traits>
1108 typedef typename __istream_type::ios_base __ios_base;
1110 const typename __ios_base::fmtflags __flags = __is.
flags();
1117 __is.
flags(__flags);
1122 template<
typename _IntType>
1123 template<
typename _UniformRandomNumberGenerator>
1128 const double __y = _M_gd(__urng);
1132 return __poisson(__urng);
1135 template<
typename _IntType>
1136 template<
typename _UniformRandomNumberGenerator>
1139 operator()(_UniformRandomNumberGenerator& __urng,
1140 const param_type& __p)
1146 _M_gd(__urng, param_type(__p.k(), (1.0 - __p.p()) / __p.p()));
1149 return __poisson(__urng);
1152 template<
typename _IntType>
1153 template<
typename _ForwardIterator,
1154 typename _UniformRandomNumberGenerator>
1156 negative_binomial_distribution<_IntType>::
1157 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1158 _UniformRandomNumberGenerator& __urng)
1160 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1163 const double __y = _M_gd(__urng);
1167 *__f++ = __poisson(__urng);
1171 template<
typename _IntType>
1172 template<
typename _ForwardIterator,
1173 typename _UniformRandomNumberGenerator>
1175 negative_binomial_distribution<_IntType>::
1176 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1177 _UniformRandomNumberGenerator& __urng,
1178 const param_type& __p)
1180 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1182 __p2(__p.k(), (1.0 - __p.p()) / __p.p());
1186 const double __y = _M_gd(__urng, __p2);
1189 *__f++ = __poisson(__urng);
1193 template<
typename _IntType,
typename _CharT,
typename _Traits>
1195 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1196 const negative_binomial_distribution<_IntType>& __x)
1199 typedef typename __ostream_type::ios_base __ios_base;
1201 const typename __ios_base::fmtflags __flags = __os.
flags();
1202 const _CharT __fill = __os.
fill();
1204 const _CharT __space = __os.
widen(
' ');
1209 __os << __x.k() << __space << __x.p()
1210 << __space << __x._M_gd;
1212 __os.
flags(__flags);
1218 template<
typename _IntType,
typename _CharT,
typename _Traits>
1221 negative_binomial_distribution<_IntType>& __x)
1224 typedef typename __istream_type::ios_base __ios_base;
1226 const typename __ios_base::fmtflags __flags = __is.
flags();
1231 if (__is >> __k >> __p >> __x._M_gd)
1232 __x.param(
typename negative_binomial_distribution<_IntType>::
1233 param_type(__k, __p));
1235 __is.
flags(__flags);
1240 template<
typename _IntType>
1242 poisson_distribution<_IntType>::param_type::
1245 #if _GLIBCXX_USE_C99_MATH_TR1 1248 const double __m = std::floor(_M_mean);
1250 _M_lfm = std::lgamma(__m + 1);
1253 const double __pi_4 = 0.7853981633974483096156608458198757L;
1256 _M_d = std::round(std::max<double>(6.0,
std::min(__m, __dx)));
1257 const double __cx = 2 * __m + _M_d;
1262 _M_cb = 2 * __cx *
std::exp(-_M_d * _M_1cx * (1 + _M_d / 2))
1280 template<
typename _IntType>
1281 template<
typename _UniformRandomNumberGenerator>
1287 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1289 #if _GLIBCXX_USE_C99_MATH_TR1 1290 if (__param.mean() >= 12)
1295 const double __naf =
1297 const double __thr =
1300 const double __m = std::floor(__param.mean());
1302 const double __spi_2 = 1.2533141373155002512078826424055226L;
1303 const double __c1 = __param._M_sm * __spi_2;
1304 const double __c2 = __param._M_c2b + __c1;
1305 const double __c3 = __c2 + 1;
1306 const double __c4 = __c3 + 1;
1308 const double __178 = 0.0128205128205128205128205128205128L;
1310 const double __e178 = 1.0129030479320018583185514777512983L;
1311 const double __c5 = __c4 + __e178;
1312 const double __c = __param._M_cb + __c5;
1313 const double __2cx = 2 * (2 * __m + __param._M_d);
1315 bool __reject =
true;
1318 const double __u = __c * __aurng();
1319 const double __e = -
std::log(1.0 - __aurng());
1325 const double __n = _M_nd(__urng);
1326 const double __y = -
std::abs(__n) * __param._M_sm - 1;
1327 __x = std::floor(__y);
1328 __w = -__n * __n / 2;
1332 else if (__u <= __c2)
1334 const double __n = _M_nd(__urng);
1335 const double __y = 1 +
std::abs(__n) * __param._M_scx;
1336 __x = std::ceil(__y);
1337 __w = __y * (2 - __y) * __param._M_1cx;
1338 if (__x > __param._M_d)
1341 else if (__u <= __c3)
1345 else if (__u <= __c4)
1347 else if (__u <= __c5)
1355 const double __v = -
std::log(1.0 - __aurng());
1356 const double __y = __param._M_d
1357 + __v * __2cx / __param._M_d;
1358 __x = std::ceil(__y);
1359 __w = -__param._M_d * __param._M_1cx * (1 + __y / 2);
1362 __reject = (__w - __e - __x * __param._M_lm_thr
1363 > __param._M_lfm - std::lgamma(__x + __m + 1));
1365 __reject |= __x + __m >= __thr;
1375 double __prod = 1.0;
1379 __prod *= __aurng();
1382 while (__prod > __param._M_lm_thr);
1388 template<
typename _IntType>
1389 template<
typename _ForwardIterator,
1390 typename _UniformRandomNumberGenerator>
1394 _UniformRandomNumberGenerator& __urng,
1395 const param_type& __param)
1397 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1403 template<
typename _IntType,
1404 typename _CharT,
typename _Traits>
1406 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1407 const poisson_distribution<_IntType>& __x)
1410 typedef typename __ostream_type::ios_base __ios_base;
1412 const typename __ios_base::fmtflags __flags = __os.
flags();
1413 const _CharT __fill = __os.fill();
1415 const _CharT __space = __os.widen(
' ');
1420 __os << __x.mean() << __space << __x._M_nd;
1422 __os.flags(__flags);
1424 __os.precision(__precision);
1428 template<
typename _IntType,
1429 typename _CharT,
typename _Traits>
1432 poisson_distribution<_IntType>& __x)
1435 typedef typename __istream_type::ios_base __ios_base;
1437 const typename __ios_base::fmtflags __flags = __is.
flags();
1441 if (__is >> __mean >> __x._M_nd)
1442 __x.param(
typename poisson_distribution<_IntType>::param_type(__mean));
1444 __is.
flags(__flags);
1449 template<
typename _IntType>
1451 binomial_distribution<_IntType>::param_type::
1454 const double __p12 = _M_p <= 0.5 ? _M_p : 1.0 - _M_p;
1458 #if _GLIBCXX_USE_C99_MATH_TR1 1459 if (_M_t * __p12 >= 8)
1462 const double __np = std::floor(_M_t * __p12);
1463 const double __pa = __np / _M_t;
1464 const double __1p = 1 - __pa;
1466 const double __pi_4 = 0.7853981633974483096156608458198757L;
1467 const double __d1x =
1469 / (81 * __pi_4 * __1p)));
1470 _M_d1 = std::round(std::max<double>(1.0, __d1x));
1471 const double __d2x =
1473 / (__pi_4 * __pa)));
1474 _M_d2 = std::round(std::max<double>(1.0, __d2x));
1477 const double __spi_2 = 1.2533141373155002512078826424055226L;
1478 _M_s1 =
std::sqrt(__np * __1p) * (1 + _M_d1 / (4 * __np));
1479 _M_s2 =
std::sqrt(__np * __1p) * (1 + _M_d2 / (4 * _M_t * __1p));
1480 _M_c = 2 * _M_d1 / __np;
1481 _M_a1 =
std::exp(_M_c) * _M_s1 * __spi_2;
1482 const double __a12 = _M_a1 + _M_s2 * __spi_2;
1483 const double __s1s = _M_s1 * _M_s1;
1484 _M_a123 = __a12 + (
std::exp(_M_d1 / (_M_t * __1p))
1486 *
std::exp(-_M_d1 * _M_d1 / (2 * __s1s)));
1487 const double __s2s = _M_s2 * _M_s2;
1488 _M_s = (_M_a123 + 2 * __s2s / _M_d2
1489 *
std::exp(-_M_d2 * _M_d2 / (2 * __s2s)));
1490 _M_lf = (std::lgamma(__np + 1)
1491 + std::lgamma(_M_t - __np + 1));
1494 _M_q = -
std::log(1 - (__p12 - __pa) / __1p);
1501 template<
typename _IntType>
1502 template<
typename _UniformRandomNumberGenerator>
1504 binomial_distribution<_IntType>::
1505 _M_waiting(_UniformRandomNumberGenerator& __urng,
1506 _IntType __t,
double __q)
1510 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1517 const double __e = -
std::log(1.0 - __aurng());
1518 __sum += __e / (__t - __x);
1521 while (__sum <= __q);
1536 template<
typename _IntType>
1537 template<
typename _UniformRandomNumberGenerator>
1544 const _IntType __t = __param.t();
1545 const double __p = __param.p();
1546 const double __p12 = __p <= 0.5 ? __p : 1.0 - __p;
1547 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1550 #if _GLIBCXX_USE_C99_MATH_TR1 1551 if (!__param._M_easy)
1556 const double __naf =
1558 const double __thr =
1561 const double __np = std::floor(__t * __p12);
1564 const double __spi_2 = 1.2533141373155002512078826424055226L;
1565 const double __a1 = __param._M_a1;
1566 const double __a12 = __a1 + __param._M_s2 * __spi_2;
1567 const double __a123 = __param._M_a123;
1568 const double __s1s = __param._M_s1 * __param._M_s1;
1569 const double __s2s = __param._M_s2 * __param._M_s2;
1574 const double __u = __param._M_s * __aurng();
1580 const double __n = _M_nd(__urng);
1581 const double __y = __param._M_s1 *
std::abs(__n);
1582 __reject = __y >= __param._M_d1;
1585 const double __e = -
std::log(1.0 - __aurng());
1586 __x = std::floor(__y);
1587 __v = -__e - __n * __n / 2 + __param._M_c;
1590 else if (__u <= __a12)
1592 const double __n = _M_nd(__urng);
1593 const double __y = __param._M_s2 *
std::abs(__n);
1594 __reject = __y >= __param._M_d2;
1597 const double __e = -
std::log(1.0 - __aurng());
1598 __x = std::floor(-__y);
1599 __v = -__e - __n * __n / 2;
1602 else if (__u <= __a123)
1604 const double __e1 = -
std::log(1.0 - __aurng());
1605 const double __e2 = -
std::log(1.0 - __aurng());
1607 const double __y = __param._M_d1
1608 + 2 * __s1s * __e1 / __param._M_d1;
1609 __x = std::floor(__y);
1610 __v = (-__e2 + __param._M_d1 * (1 / (__t - __np)
1611 -__y / (2 * __s1s)));
1616 const double __e1 = -
std::log(1.0 - __aurng());
1617 const double __e2 = -
std::log(1.0 - __aurng());
1619 const double __y = __param._M_d2
1620 + 2 * __s2s * __e1 / __param._M_d2;
1621 __x = std::floor(-__y);
1622 __v = -__e2 - __param._M_d2 * __y / (2 * __s2s);
1626 __reject = __reject || __x < -__np || __x > __t - __np;
1629 const double __lfx =
1630 std::lgamma(__np + __x + 1)
1631 + std::lgamma(__t - (__np + __x) + 1);
1632 __reject = __v > __param._M_lf - __lfx
1633 + __x * __param._M_lp1p;
1636 __reject |= __x + __np >= __thr;
1640 __x += __np + __naf;
1642 const _IntType __z = _M_waiting(__urng, __t - _IntType(__x),
1644 __ret = _IntType(__x) + __z;
1648 __ret = _M_waiting(__urng, __t, __param._M_q);
1651 __ret = __t - __ret;
1655 template<
typename _IntType>
1656 template<
typename _ForwardIterator,
1657 typename _UniformRandomNumberGenerator>
1661 _UniformRandomNumberGenerator& __urng,
1662 const param_type& __param)
1664 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1670 template<
typename _IntType,
1671 typename _CharT,
typename _Traits>
1673 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1674 const binomial_distribution<_IntType>& __x)
1677 typedef typename __ostream_type::ios_base __ios_base;
1679 const typename __ios_base::fmtflags __flags = __os.
flags();
1680 const _CharT __fill = __os.fill();
1682 const _CharT __space = __os.widen(
' ');
1687 __os << __x.t() << __space << __x.p()
1688 << __space << __x._M_nd;
1690 __os.flags(__flags);
1692 __os.precision(__precision);
1696 template<
typename _IntType,
1697 typename _CharT,
typename _Traits>
1700 binomial_distribution<_IntType>& __x)
1703 typedef typename __istream_type::ios_base __ios_base;
1705 const typename __ios_base::fmtflags __flags = __is.
flags();
1710 if (__is >> __t >> __p >> __x._M_nd)
1711 __x.param(
typename binomial_distribution<_IntType>::
1712 param_type(__t, __p));
1714 __is.
flags(__flags);
1719 template<
typename _RealType>
1720 template<
typename _ForwardIterator,
1721 typename _UniformRandomNumberGenerator>
1725 _UniformRandomNumberGenerator& __urng,
1726 const param_type& __p)
1728 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1729 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1735 template<
typename _RealType,
typename _CharT,
typename _Traits>
1737 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1741 typedef typename __ostream_type::ios_base __ios_base;
1743 const typename __ios_base::fmtflags __flags = __os.
flags();
1744 const _CharT __fill = __os.fill();
1747 __os.fill(__os.widen(
' '));
1750 __os << __x.lambda();
1752 __os.flags(__flags);
1754 __os.precision(__precision);
1758 template<
typename _RealType,
typename _CharT,
typename _Traits>
1764 typedef typename __istream_type::ios_base __ios_base;
1766 const typename __ios_base::fmtflags __flags = __is.
flags();
1770 if (__is >> __lambda)
1772 param_type(__lambda));
1774 __is.
flags(__flags);
1785 template<
typename _RealType>
1786 template<
typename _UniformRandomNumberGenerator>
1790 const param_type& __param)
1793 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1796 if (_M_saved_available)
1798 _M_saved_available =
false;
1808 __r2 = __x * __x + __y * __y;
1810 while (__r2 > 1.0 || __r2 == 0.0);
1813 _M_saved = __x * __mult;
1814 _M_saved_available =
true;
1815 __ret = __y * __mult;
1818 __ret = __ret * __param.stddev() + __param.mean();
1822 template<
typename _RealType>
1823 template<
typename _ForwardIterator,
1824 typename _UniformRandomNumberGenerator>
1828 _UniformRandomNumberGenerator& __urng,
1829 const param_type& __param)
1831 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1836 if (_M_saved_available)
1838 _M_saved_available =
false;
1839 *__f++ = _M_saved * __param.stddev() + __param.mean();
1845 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1848 while (__f + 1 < __t)
1855 __r2 = __x * __x + __y * __y;
1857 while (__r2 > 1.0 || __r2 == 0.0);
1860 *__f++ = __y * __mult * __param.stddev() + __param.mean();
1861 *__f++ = __x * __mult * __param.stddev() + __param.mean();
1871 __r2 = __x * __x + __y * __y;
1873 while (__r2 > 1.0 || __r2 == 0.0);
1876 _M_saved = __x * __mult;
1877 _M_saved_available =
true;
1878 *__f = __y * __mult * __param.stddev() + __param.mean();
1882 template<
typename _RealType>
1887 if (__d1._M_param == __d2._M_param
1888 && __d1._M_saved_available == __d2._M_saved_available)
1890 if (__d1._M_saved_available
1891 && __d1._M_saved == __d2._M_saved)
1893 else if(!__d1._M_saved_available)
1902 template<
typename _RealType,
typename _CharT,
typename _Traits>
1904 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1905 const normal_distribution<_RealType>& __x)
1908 typedef typename __ostream_type::ios_base __ios_base;
1910 const typename __ios_base::fmtflags __flags = __os.
flags();
1911 const _CharT __fill = __os.
fill();
1913 const _CharT __space = __os.
widen(
' ');
1918 __os << __x.mean() << __space << __x.stddev()
1919 << __space << __x._M_saved_available;
1920 if (__x._M_saved_available)
1921 __os << __space << __x._M_saved;
1923 __os.
flags(__flags);
1929 template<
typename _RealType,
typename _CharT,
typename _Traits>
1932 normal_distribution<_RealType>& __x)
1935 typedef typename __istream_type::ios_base __ios_base;
1937 const typename __ios_base::fmtflags __flags = __is.
flags();
1940 double __mean, __stddev;
1942 if (__is >> __mean >> __stddev >> __saved_avail)
1944 if (__saved_avail && (__is >> __x._M_saved))
1946 __x._M_saved_available = __saved_avail;
1947 __x.param(
typename normal_distribution<_RealType>::
1948 param_type(__mean, __stddev));
1952 __is.
flags(__flags);
1957 template<
typename _RealType>
1958 template<
typename _ForwardIterator,
1959 typename _UniformRandomNumberGenerator>
1961 lognormal_distribution<_RealType>::
1962 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1963 _UniformRandomNumberGenerator& __urng,
1964 const param_type& __p)
1966 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1968 *__f++ =
std::exp(__p.s() * _M_nd(__urng) + __p.m());
1971 template<
typename _RealType,
typename _CharT,
typename _Traits>
1973 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1974 const lognormal_distribution<_RealType>& __x)
1977 typedef typename __ostream_type::ios_base __ios_base;
1979 const typename __ios_base::fmtflags __flags = __os.
flags();
1980 const _CharT __fill = __os.
fill();
1982 const _CharT __space = __os.
widen(
' ');
1987 __os << __x.m() << __space << __x.s()
1988 << __space << __x._M_nd;
1990 __os.
flags(__flags);
1996 template<
typename _RealType,
typename _CharT,
typename _Traits>
1999 lognormal_distribution<_RealType>& __x)
2002 typedef typename __istream_type::ios_base __ios_base;
2004 const typename __ios_base::fmtflags __flags = __is.
flags();
2008 if (__is >> __m >> __s >> __x._M_nd)
2009 __x.param(
typename lognormal_distribution<_RealType>::
2010 param_type(__m, __s));
2012 __is.
flags(__flags);
2016 template<
typename _RealType>
2017 template<
typename _ForwardIterator,
2018 typename _UniformRandomNumberGenerator>
2022 _UniformRandomNumberGenerator& __urng)
2024 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2026 *__f++ = 2 * _M_gd(__urng);
2029 template<
typename _RealType>
2030 template<
typename _ForwardIterator,
2031 typename _UniformRandomNumberGenerator>
2035 _UniformRandomNumberGenerator& __urng,
2039 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2041 *__f++ = 2 * _M_gd(__urng, __p);
2044 template<
typename _RealType,
typename _CharT,
typename _Traits>
2046 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2047 const chi_squared_distribution<_RealType>& __x)
2050 typedef typename __ostream_type::ios_base __ios_base;
2052 const typename __ios_base::fmtflags __flags = __os.
flags();
2053 const _CharT __fill = __os.
fill();
2055 const _CharT __space = __os.
widen(
' ');
2060 __os << __x.n() << __space << __x._M_gd;
2062 __os.
flags(__flags);
2068 template<
typename _RealType,
typename _CharT,
typename _Traits>
2071 chi_squared_distribution<_RealType>& __x)
2074 typedef typename __istream_type::ios_base __ios_base;
2076 const typename __ios_base::fmtflags __flags = __is.
flags();
2080 if (__is >> __n >> __x._M_gd)
2081 __x.param(
typename chi_squared_distribution<_RealType>::
2084 __is.
flags(__flags);
2089 template<
typename _RealType>
2090 template<
typename _UniformRandomNumberGenerator>
2093 operator()(_UniformRandomNumberGenerator& __urng,
2094 const param_type& __p)
2096 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2103 const _RealType __pi = 3.1415926535897932384626433832795029L;
2104 return __p.a() + __p.b() *
std::tan(__pi * __u);
2107 template<
typename _RealType>
2108 template<
typename _ForwardIterator,
2109 typename _UniformRandomNumberGenerator>
2111 cauchy_distribution<_RealType>::
2112 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2113 _UniformRandomNumberGenerator& __urng,
2114 const param_type& __p)
2116 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2117 const _RealType __pi = 3.1415926535897932384626433832795029L;
2118 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2127 *__f++ = __p.a() + __p.b() *
std::tan(__pi * __u);
2131 template<
typename _RealType,
typename _CharT,
typename _Traits>
2133 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2137 typedef typename __ostream_type::ios_base __ios_base;
2139 const typename __ios_base::fmtflags __flags = __os.
flags();
2140 const _CharT __fill = __os.fill();
2142 const _CharT __space = __os.widen(
' ');
2147 __os << __x.a() << __space << __x.b();
2149 __os.flags(__flags);
2151 __os.precision(__precision);
2155 template<
typename _RealType,
typename _CharT,
typename _Traits>
2161 typedef typename __istream_type::ios_base __ios_base;
2163 const typename __ios_base::fmtflags __flags = __is.
flags();
2167 if (__is >> __a >> __b)
2169 param_type(__a, __b));
2171 __is.
flags(__flags);
2176 template<
typename _RealType>
2177 template<
typename _ForwardIterator,
2178 typename _UniformRandomNumberGenerator>
2182 _UniformRandomNumberGenerator& __urng)
2184 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2186 *__f++ = ((_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()));
2189 template<
typename _RealType>
2190 template<
typename _ForwardIterator,
2191 typename _UniformRandomNumberGenerator>
2195 _UniformRandomNumberGenerator& __urng,
2196 const param_type& __p)
2198 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2201 param_type __p1(__p.m() / 2);
2202 param_type __p2(__p.n() / 2);
2204 *__f++ = ((_M_gd_x(__urng, __p1) * n())
2205 / (_M_gd_y(__urng, __p2) * m()));
2208 template<
typename _RealType,
typename _CharT,
typename _Traits>
2210 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2211 const fisher_f_distribution<_RealType>& __x)
2214 typedef typename __ostream_type::ios_base __ios_base;
2216 const typename __ios_base::fmtflags __flags = __os.
flags();
2217 const _CharT __fill = __os.
fill();
2219 const _CharT __space = __os.
widen(
' ');
2224 __os << __x.m() << __space << __x.n()
2225 << __space << __x._M_gd_x << __space << __x._M_gd_y;
2227 __os.
flags(__flags);
2233 template<
typename _RealType,
typename _CharT,
typename _Traits>
2236 fisher_f_distribution<_RealType>& __x)
2239 typedef typename __istream_type::ios_base __ios_base;
2241 const typename __ios_base::fmtflags __flags = __is.
flags();
2245 if (__is >> __m >> __n >> __x._M_gd_x >> __x._M_gd_y)
2246 __x.param(
typename fisher_f_distribution<_RealType>::
2247 param_type(__m, __n));
2249 __is.
flags(__flags);
2254 template<
typename _RealType>
2255 template<
typename _ForwardIterator,
2256 typename _UniformRandomNumberGenerator>
2260 _UniformRandomNumberGenerator& __urng)
2262 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2264 *__f++ = _M_nd(__urng) *
std::sqrt(n() / _M_gd(__urng));
2267 template<
typename _RealType>
2268 template<
typename _ForwardIterator,
2269 typename _UniformRandomNumberGenerator>
2273 _UniformRandomNumberGenerator& __urng,
2274 const param_type& __p)
2276 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2278 __p2(__p.n() / 2, 2);
2280 *__f++ = _M_nd(__urng) *
std::sqrt(__p.n() / _M_gd(__urng, __p2));
2283 template<
typename _RealType,
typename _CharT,
typename _Traits>
2285 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2286 const student_t_distribution<_RealType>& __x)
2289 typedef typename __ostream_type::ios_base __ios_base;
2291 const typename __ios_base::fmtflags __flags = __os.
flags();
2292 const _CharT __fill = __os.
fill();
2294 const _CharT __space = __os.
widen(
' ');
2299 __os << __x.n() << __space << __x._M_nd << __space << __x._M_gd;
2301 __os.
flags(__flags);
2307 template<
typename _RealType,
typename _CharT,
typename _Traits>
2310 student_t_distribution<_RealType>& __x)
2313 typedef typename __istream_type::ios_base __ios_base;
2315 const typename __ios_base::fmtflags __flags = __is.
flags();
2319 if (__is >> __n >> __x._M_nd >> __x._M_gd)
2320 __x.param(
typename student_t_distribution<_RealType>::param_type(__n));
2322 __is.
flags(__flags);
2327 template<
typename _RealType>
2329 gamma_distribution<_RealType>::param_type::
2332 _M_malpha = _M_alpha < 1.0 ? _M_alpha + _RealType(1.0) : _M_alpha;
2334 const _RealType __a1 = _M_malpha - _RealType(1.0) / _RealType(3.0);
2335 _M_a2 = _RealType(1.0) /
std::sqrt(_RealType(9.0) * __a1);
2343 template<
typename _RealType>
2344 template<
typename _UniformRandomNumberGenerator>
2348 const param_type& __param)
2350 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2355 - _RealType(1.0) / _RealType(3.0));
2361 __n = _M_nd(__urng);
2366 __v = __v * __v * __v;
2369 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2370 && (
std::log(__u) > (0.5 * __n * __n + __a1
2373 if (__param.alpha() == __param._M_malpha)
2374 return __a1 * __v * __param.beta();
2382 * __a1 * __v * __param.beta());
2386 template<
typename _RealType>
2387 template<
typename _ForwardIterator,
2388 typename _UniformRandomNumberGenerator>
2392 _UniformRandomNumberGenerator& __urng,
2393 const param_type& __param)
2395 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2396 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2401 - _RealType(1.0) / _RealType(3.0));
2403 if (__param.alpha() == __param._M_malpha)
2410 __n = _M_nd(__urng);
2415 __v = __v * __v * __v;
2418 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2419 && (
std::log(__u) > (0.5 * __n * __n + __a1
2422 *__f++ = __a1 * __v * __param.beta();
2431 __n = _M_nd(__urng);
2436 __v = __v * __v * __v;
2439 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2440 && (
std::log(__u) > (0.5 * __n * __n + __a1
2448 * __a1 * __v * __param.beta());
2452 template<
typename _RealType,
typename _CharT,
typename _Traits>
2454 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2455 const gamma_distribution<_RealType>& __x)
2458 typedef typename __ostream_type::ios_base __ios_base;
2460 const typename __ios_base::fmtflags __flags = __os.
flags();
2461 const _CharT __fill = __os.
fill();
2463 const _CharT __space = __os.
widen(
' ');
2468 __os << __x.alpha() << __space << __x.beta()
2469 << __space << __x._M_nd;
2471 __os.
flags(__flags);
2477 template<
typename _RealType,
typename _CharT,
typename _Traits>
2480 gamma_distribution<_RealType>& __x)
2483 typedef typename __istream_type::ios_base __ios_base;
2485 const typename __ios_base::fmtflags __flags = __is.
flags();
2488 _RealType __alpha_val, __beta_val;
2489 if (__is >> __alpha_val >> __beta_val >> __x._M_nd)
2490 __x.param(
typename gamma_distribution<_RealType>::
2491 param_type(__alpha_val, __beta_val));
2493 __is.
flags(__flags);
2498 template<
typename _RealType>
2499 template<
typename _UniformRandomNumberGenerator>
2502 operator()(_UniformRandomNumberGenerator& __urng,
2503 const param_type& __p)
2505 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2511 template<
typename _RealType>
2512 template<
typename _ForwardIterator,
2513 typename _UniformRandomNumberGenerator>
2515 weibull_distribution<_RealType>::
2516 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2517 _UniformRandomNumberGenerator& __urng,
2518 const param_type& __p)
2520 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2521 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2530 template<
typename _RealType,
typename _CharT,
typename _Traits>
2532 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2536 typedef typename __ostream_type::ios_base __ios_base;
2538 const typename __ios_base::fmtflags __flags = __os.
flags();
2539 const _CharT __fill = __os.fill();
2541 const _CharT __space = __os.widen(
' ');
2546 __os << __x.a() << __space << __x.b();
2548 __os.flags(__flags);
2550 __os.precision(__precision);
2554 template<
typename _RealType,
typename _CharT,
typename _Traits>
2560 typedef typename __istream_type::ios_base __ios_base;
2562 const typename __ios_base::fmtflags __flags = __is.
flags();
2566 if (__is >> __a >> __b)
2568 param_type(__a, __b));
2570 __is.
flags(__flags);
2575 template<
typename _RealType>
2576 template<
typename _UniformRandomNumberGenerator>
2579 operator()(_UniformRandomNumberGenerator& __urng,
2580 const param_type& __p)
2582 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2588 template<
typename _RealType>
2589 template<
typename _ForwardIterator,
2590 typename _UniformRandomNumberGenerator>
2592 extreme_value_distribution<_RealType>::
2593 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2594 _UniformRandomNumberGenerator& __urng,
2595 const param_type& __p)
2597 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2598 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2606 template<
typename _RealType,
typename _CharT,
typename _Traits>
2608 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2612 typedef typename __ostream_type::ios_base __ios_base;
2614 const typename __ios_base::fmtflags __flags = __os.
flags();
2615 const _CharT __fill = __os.fill();
2617 const _CharT __space = __os.widen(
' ');
2622 __os << __x.a() << __space << __x.b();
2624 __os.flags(__flags);
2626 __os.precision(__precision);
2630 template<
typename _RealType,
typename _CharT,
typename _Traits>
2636 typedef typename __istream_type::ios_base __ios_base;
2638 const typename __ios_base::fmtflags __flags = __is.
flags();
2642 if (__is >> __a >> __b)
2644 param_type(__a, __b));
2646 __is.
flags(__flags);
2651 template<
typename _IntType>
2653 discrete_distribution<_IntType>::param_type::
2656 if (_M_prob.size() < 2)
2663 _M_prob.end(), 0.0);
2665 __detail::__normalize(_M_prob.begin(), _M_prob.end(), _M_prob.begin(),
2668 _M_cp.reserve(_M_prob.size());
2672 _M_cp[_M_cp.size() - 1] = 1.0;
2675 template<
typename _IntType>
2676 template<
typename _Func>
2677 discrete_distribution<_IntType>::param_type::
2678 param_type(
size_t __nw,
double __xmin,
double __xmax, _Func __fw)
2679 : _M_prob(), _M_cp()
2681 const size_t __n = __nw == 0 ? 1 : __nw;
2682 const double __delta = (__xmax - __xmin) / __n;
2684 _M_prob.reserve(__n);
2685 for (
size_t __k = 0; __k < __nw; ++__k)
2686 _M_prob.push_back(__fw(__xmin + __k * __delta + 0.5 * __delta));
2691 template<
typename _IntType>
2692 template<
typename _UniformRandomNumberGenerator>
2693 typename discrete_distribution<_IntType>::result_type
2694 discrete_distribution<_IntType>::
2695 operator()(_UniformRandomNumberGenerator& __urng,
2696 const param_type& __param)
2698 if (__param._M_cp.empty())
2699 return result_type(0);
2701 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2704 const double __p = __aurng();
2706 __param._M_cp.end(), __p);
2708 return __pos - __param._M_cp.begin();
2711 template<
typename _IntType>
2712 template<
typename _ForwardIterator,
2713 typename _UniformRandomNumberGenerator>
2715 discrete_distribution<_IntType>::
2716 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2717 _UniformRandomNumberGenerator& __urng,
2718 const param_type& __param)
2720 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2722 if (__param._M_cp.empty())
2725 *__f++ = result_type(0);
2729 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2734 const double __p = __aurng();
2736 __param._M_cp.end(), __p);
2738 *__f++ = __pos - __param._M_cp.begin();
2742 template<
typename _IntType,
typename _CharT,
typename _Traits>
2744 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2745 const discrete_distribution<_IntType>& __x)
2748 typedef typename __ostream_type::ios_base __ios_base;
2750 const typename __ios_base::fmtflags __flags = __os.
flags();
2751 const _CharT __fill = __os.
fill();
2753 const _CharT __space = __os.
widen(
' ');
2759 __os << __prob.
size();
2760 for (
auto __dit = __prob.
begin(); __dit != __prob.
end(); ++__dit)
2761 __os << __space << *__dit;
2763 __os.
flags(__flags);
2771 template<
typename _ValT,
typename _CharT,
typename _Traits>
2772 basic_istream<_CharT, _Traits>&
2773 __extract_params(basic_istream<_CharT, _Traits>& __is,
2774 vector<_ValT>& __vals,
size_t __n)
2776 __vals.reserve(__n);
2781 __vals.push_back(__val);
2789 template<
typename _IntType,
typename _CharT,
typename _Traits>
2792 discrete_distribution<_IntType>& __x)
2795 typedef typename __istream_type::ios_base __ios_base;
2797 const typename __ios_base::fmtflags __flags = __is.
flags();
2804 if (__detail::__extract_params(__is, __prob_vec, __n))
2805 __x.param({__prob_vec.
begin(), __prob_vec.
end()});
2808 __is.
flags(__flags);
2813 template<
typename _RealType>
2815 piecewise_constant_distribution<_RealType>::param_type::
2818 if (_M_int.size() < 2
2819 || (_M_int.size() == 2
2820 && _M_int[0] == _RealType(0)
2821 && _M_int[1] == _RealType(1)))
2831 __detail::__normalize(_M_den.begin(), _M_den.end(), _M_den.begin(),
2834 _M_cp.reserve(_M_den.size());
2839 _M_cp[_M_cp.size() - 1] = 1.0;
2841 for (
size_t __k = 0; __k < _M_den.size(); ++__k)
2842 _M_den[__k] /= _M_int[__k + 1] - _M_int[__k];
2845 template<
typename _RealType>
2846 template<
typename _InputIteratorB,
typename _InputIteratorW>
2847 piecewise_constant_distribution<_RealType>::param_type::
2848 param_type(_InputIteratorB __bbegin,
2849 _InputIteratorB __bend,
2850 _InputIteratorW __wbegin)
2851 : _M_int(), _M_den(), _M_cp()
2853 if (__bbegin != __bend)
2857 _M_int.push_back(*__bbegin);
2859 if (__bbegin == __bend)
2862 _M_den.push_back(*__wbegin);
2870 template<
typename _RealType>
2871 template<
typename _Func>
2872 piecewise_constant_distribution<_RealType>::param_type::
2873 param_type(initializer_list<_RealType> __bl, _Func __fw)
2874 : _M_int(), _M_den(), _M_cp()
2876 _M_int.reserve(__bl.size());
2877 for (
auto __biter = __bl.begin(); __biter != __bl.end(); ++__biter)
2878 _M_int.push_back(*__biter);
2880 _M_den.reserve(_M_int.size() - 1);
2881 for (
size_t __k = 0; __k < _M_int.size() - 1; ++__k)
2882 _M_den.push_back(__fw(0.5 * (_M_int[__k + 1] + _M_int[__k])));
2887 template<
typename _RealType>
2888 template<
typename _Func>
2889 piecewise_constant_distribution<_RealType>::param_type::
2890 param_type(
size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
2891 : _M_int(), _M_den(), _M_cp()
2893 const size_t __n = __nw == 0 ? 1 : __nw;
2894 const _RealType __delta = (__xmax - __xmin) / __n;
2896 _M_int.reserve(__n + 1);
2897 for (
size_t __k = 0; __k <= __nw; ++__k)
2898 _M_int.push_back(__xmin + __k * __delta);
2900 _M_den.reserve(__n);
2901 for (
size_t __k = 0; __k < __nw; ++__k)
2902 _M_den.push_back(__fw(_M_int[__k] + 0.5 * __delta));
2907 template<
typename _RealType>
2908 template<
typename _UniformRandomNumberGenerator>
2909 typename piecewise_constant_distribution<_RealType>::result_type
2910 piecewise_constant_distribution<_RealType>::
2911 operator()(_UniformRandomNumberGenerator& __urng,
2912 const param_type& __param)
2914 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2917 const double __p = __aurng();
2918 if (__param._M_cp.empty())
2922 __param._M_cp.end(), __p);
2923 const size_t __i = __pos - __param._M_cp.begin();
2925 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
2927 return __param._M_int[__i] + (__p - __pref) / __param._M_den[__i];
2930 template<
typename _RealType>
2931 template<
typename _ForwardIterator,
2932 typename _UniformRandomNumberGenerator>
2934 piecewise_constant_distribution<_RealType>::
2935 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2936 _UniformRandomNumberGenerator& __urng,
2937 const param_type& __param)
2939 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2940 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2943 if (__param._M_cp.empty())
2952 const double __p = __aurng();
2955 __param._M_cp.end(), __p);
2956 const size_t __i = __pos - __param._M_cp.begin();
2958 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
2960 *__f++ = (__param._M_int[__i]
2961 + (__p - __pref) / __param._M_den[__i]);
2965 template<
typename _RealType,
typename _CharT,
typename _Traits>
2967 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2968 const piecewise_constant_distribution<_RealType>& __x)
2971 typedef typename __ostream_type::ios_base __ios_base;
2973 const typename __ios_base::fmtflags __flags = __os.
flags();
2974 const _CharT __fill = __os.
fill();
2976 const _CharT __space = __os.
widen(
' ');
2982 __os << __int.
size() - 1;
2984 for (
auto __xit = __int.
begin(); __xit != __int.
end(); ++__xit)
2985 __os << __space << *__xit;
2988 for (
auto __dit = __den.
begin(); __dit != __den.
end(); ++__dit)
2989 __os << __space << *__dit;
2991 __os.
flags(__flags);
2997 template<
typename _RealType,
typename _CharT,
typename _Traits>
3000 piecewise_constant_distribution<_RealType>& __x)
3003 typedef typename __istream_type::ios_base __ios_base;
3005 const typename __ios_base::fmtflags __flags = __is.
flags();
3012 if (__detail::__extract_params(__is, __int_vec, __n + 1))
3015 if (__detail::__extract_params(__is, __den_vec, __n))
3017 __x.param({ __int_vec.
begin(), __int_vec.
end(),
3018 __den_vec.
begin() });
3023 __is.
flags(__flags);
3028 template<
typename _RealType>
3030 piecewise_linear_distribution<_RealType>::param_type::
3033 if (_M_int.size() < 2
3034 || (_M_int.size() == 2
3035 && _M_int[0] == _RealType(0)
3036 && _M_int[1] == _RealType(1)
3037 && _M_den[0] == _M_den[1]))
3045 _M_cp.reserve(_M_int.size() - 1);
3046 _M_m.reserve(_M_int.size() - 1);
3047 for (
size_t __k = 0; __k < _M_int.size() - 1; ++__k)
3049 const _RealType __delta = _M_int[__k + 1] - _M_int[__k];
3050 __sum += 0.5 * (_M_den[__k + 1] + _M_den[__k]) * __delta;
3051 _M_cp.push_back(__sum);
3052 _M_m.push_back((_M_den[__k + 1] - _M_den[__k]) / __delta);
3056 __detail::__normalize(_M_den.begin(), _M_den.end(), _M_den.begin(),
3059 __detail::__normalize(_M_cp.begin(), _M_cp.end(), _M_cp.begin(), __sum);
3061 __detail::__normalize(_M_m.begin(), _M_m.end(), _M_m.begin(), __sum);
3064 _M_cp[_M_cp.size() - 1] = 1.0;
3067 template<
typename _RealType>
3068 template<
typename _InputIteratorB,
typename _InputIteratorW>
3069 piecewise_linear_distribution<_RealType>::param_type::
3070 param_type(_InputIteratorB __bbegin,
3071 _InputIteratorB __bend,
3072 _InputIteratorW __wbegin)
3073 : _M_int(), _M_den(), _M_cp(), _M_m()
3075 for (; __bbegin != __bend; ++__bbegin, ++__wbegin)
3077 _M_int.push_back(*__bbegin);
3078 _M_den.push_back(*__wbegin);
3084 template<
typename _RealType>
3085 template<
typename _Func>
3086 piecewise_linear_distribution<_RealType>::param_type::
3087 param_type(initializer_list<_RealType> __bl, _Func __fw)
3088 : _M_int(), _M_den(), _M_cp(), _M_m()
3090 _M_int.reserve(__bl.size());
3091 _M_den.reserve(__bl.size());
3092 for (
auto __biter = __bl.begin(); __biter != __bl.end(); ++__biter)
3094 _M_int.push_back(*__biter);
3095 _M_den.push_back(__fw(*__biter));
3101 template<
typename _RealType>
3102 template<
typename _Func>
3103 piecewise_linear_distribution<_RealType>::param_type::
3104 param_type(
size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
3105 : _M_int(), _M_den(), _M_cp(), _M_m()
3107 const size_t __n = __nw == 0 ? 1 : __nw;
3108 const _RealType __delta = (__xmax - __xmin) / __n;
3110 _M_int.reserve(__n + 1);
3111 _M_den.reserve(__n + 1);
3112 for (
size_t __k = 0; __k <= __nw; ++__k)
3114 _M_int.push_back(__xmin + __k * __delta);
3115 _M_den.push_back(__fw(_M_int[__k] + __delta));
3121 template<
typename _RealType>
3122 template<
typename _UniformRandomNumberGenerator>
3123 typename piecewise_linear_distribution<_RealType>::result_type
3124 piecewise_linear_distribution<_RealType>::
3125 operator()(_UniformRandomNumberGenerator& __urng,
3126 const param_type& __param)
3128 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
3131 const double __p = __aurng();
3132 if (__param._M_cp.empty())
3136 __param._M_cp.end(), __p);
3137 const size_t __i = __pos - __param._M_cp.begin();
3139 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
3141 const double __a = 0.5 * __param._M_m[__i];
3142 const double __b = __param._M_den[__i];
3143 const double __cm = __p - __pref;
3145 _RealType __x = __param._M_int[__i];
3150 const double __d = __b * __b + 4.0 * __a * __cm;
3151 __x += 0.5 * (
std::sqrt(__d) - __b) / __a;
3157 template<
typename _RealType>
3158 template<
typename _ForwardIterator,
3159 typename _UniformRandomNumberGenerator>
3161 piecewise_linear_distribution<_RealType>::
3162 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3163 _UniformRandomNumberGenerator& __urng,
3164 const param_type& __param)
3166 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3169 *__f++ = this->operator()(__urng, __param);
3172 template<
typename _RealType,
typename _CharT,
typename _Traits>
3174 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3175 const piecewise_linear_distribution<_RealType>& __x)
3178 typedef typename __ostream_type::ios_base __ios_base;
3180 const typename __ios_base::fmtflags __flags = __os.
flags();
3181 const _CharT __fill = __os.
fill();
3183 const _CharT __space = __os.
widen(
' ');
3189 __os << __int.
size() - 1;
3191 for (
auto __xit = __int.
begin(); __xit != __int.
end(); ++__xit)
3192 __os << __space << *__xit;
3195 for (
auto __dit = __den.
begin(); __dit != __den.
end(); ++__dit)
3196 __os << __space << *__dit;
3198 __os.
flags(__flags);
3204 template<
typename _RealType,
typename _CharT,
typename _Traits>
3207 piecewise_linear_distribution<_RealType>& __x)
3210 typedef typename __istream_type::ios_base __ios_base;
3212 const typename __ios_base::fmtflags __flags = __is.
flags();
3218 vector<_RealType> __int_vec;
3219 if (__detail::__extract_params(__is, __int_vec, __n + 1))
3221 vector<double> __den_vec;
3222 if (__detail::__extract_params(__is, __den_vec, __n + 1))
3224 __x.param({ __int_vec.begin(), __int_vec.end(),
3225 __den_vec.begin() });
3229 __is.
flags(__flags);
3234 template<
typename _IntType>
3237 for (
auto __iter = __il.begin(); __iter != __il.end(); ++__iter)
3238 _M_v.push_back(__detail::__mod<result_type,
3239 __detail::_Shift<result_type, 32>::__value>(*__iter));
3242 template<
typename _InputIterator>
3243 seed_seq::seed_seq(_InputIterator __begin, _InputIterator __end)
3245 for (_InputIterator __iter = __begin; __iter != __end; ++__iter)
3246 _M_v.push_back(__detail::__mod<result_type,
3247 __detail::_Shift<result_type, 32>::__value>(*__iter));
3250 template<
typename _RandomAccessIterator>
3252 seed_seq::generate(_RandomAccessIterator __begin,
3253 _RandomAccessIterator __end)
3255 typedef typename iterator_traits<_RandomAccessIterator>::value_type
3258 if (__begin == __end)
3261 std::fill(__begin, __end, _Type(0x8b8b8b8bu));
3263 const size_t __n = __end - __begin;
3264 const size_t __s = _M_v.size();
3265 const size_t __t = (__n >= 623) ? 11
3270 const size_t __p = (__n - __t) / 2;
3271 const size_t __q = __p + __t;
3272 const size_t __m =
std::max(
size_t(__s + 1), __n);
3274 for (
size_t __k = 0; __k < __m; ++__k)
3276 _Type __arg = (__begin[__k % __n]
3277 ^ __begin[(__k + __p) % __n]
3278 ^ __begin[(__k - 1) % __n]);
3279 _Type __r1 = __arg ^ (__arg >> 27);
3280 __r1 = __detail::__mod<_Type,
3281 __detail::_Shift<_Type, 32>::__value>(1664525u * __r1);
3285 else if (__k <= __s)
3286 __r2 += __k % __n + _M_v[__k - 1];
3289 __r2 = __detail::__mod<_Type,
3290 __detail::_Shift<_Type, 32>::__value>(__r2);
3291 __begin[(__k + __p) % __n] += __r1;
3292 __begin[(__k + __q) % __n] += __r2;
3293 __begin[__k % __n] = __r2;
3296 for (
size_t __k = __m; __k < __m + __n; ++__k)
3298 _Type __arg = (__begin[__k % __n]
3299 + __begin[(__k + __p) % __n]
3300 + __begin[(__k - 1) % __n]);
3301 _Type __r3 = __arg ^ (__arg >> 27);
3302 __r3 = __detail::__mod<_Type,
3303 __detail::_Shift<_Type, 32>::__value>(1566083941u * __r3);
3304 _Type __r4 = __r3 - __k % __n;
3305 __r4 = __detail::__mod<_Type,
3306 __detail::_Shift<_Type, 32>::__value>(__r4);
3307 __begin[(__k + __p) % __n] ^= __r3;
3308 __begin[(__k + __q) % __n] ^= __r4;
3309 __begin[__k % __n] = __r4;
3313 template<
typename _RealType,
size_t __bits,
3314 typename _UniformRandomNumberGenerator>
3319 "template argument must be a floating point type");
3324 const long double __r =
static_cast<long double>(__urng.max())
3325 - static_cast<long double>(__urng.min()) + 1.0L;
3327 const size_t __m = std::max<size_t>(1UL,
3328 (__b + __log2r - 1UL) / __log2r);
3330 _RealType __sum = _RealType(0);
3331 _RealType __tmp = _RealType(1);
3332 for (
size_t __k = __m; __k != 0; --__k)
3334 __sum += _RealType(__urng() - __urng.min()) * __tmp;
3337 __ret = __sum / __tmp;
3338 if (__builtin_expect(__ret >= _RealType(1), 0))
3340 #if _GLIBCXX_USE_C99_MATH_TR1 3341 __ret = std::nextafter(_RealType(1), _RealType(0));
3343 __ret = _RealType(1)
3350 _GLIBCXX_END_NAMESPACE_VERSION
A discrete Poisson random number distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
A discrete binomial random number distribution.
ISO C++ entities toplevel namespace is std.
static constexpr result_type increment
An exponential continuous distribution for random numbers.
Properties of fundamental types.
ios_base & left(ios_base &__base)
Calls base.setf(ios_base::left, ios_base::adjustfield).
static constexpr result_type modulus
A discrete geometric random number distribution.
constexpr int __lg(int __n)
This is a helper function for the sort routines and for random.tcc.
void seed(result_type __s=default_seed)
Reseeds the linear_congruential_engine random number generator engine sequence to the seed __s...
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
char_type fill() const
Retrieves the empty character.
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 gamma continuous distribution for random numbers.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
A weibull_distribution random number distribution.
param_type param() const
Returns the parameter set of the distribution.
Uniform continuous distribution for random numbers.
result_type operator()()
Gets the next value in the generated random number sequence.
Uniform discrete distribution for random numbers. A discrete random distribution on the range with e...
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Template class basic_ostream.
A chi_squared_distribution random number distribution.
ios_base & skipws(ios_base &__base)
Calls base.setf(ios_base::skipws).
result_type operator()()
Gets the next value in the generated random number sequence.
size_type size() const noexcept
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
A extreme_value_distribution random number distribution.
_ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp &__val)
Finds the first position in which val could be inserted without changing the ordering.
complex< _Tp > sqrt(const complex< _Tp > &)
Return complex square root of z.
streamsize precision() const
Flags access.
complex< _Tp > exp(const complex< _Tp > &)
Return complex base e exponential of z.
static constexpr result_type multiplier
Template class basic_istream.
static constexpr _Tp epsilon() noexcept
_Tp abs(const complex< _Tp > &)
Return magnitude of z.
_RandomNumberEngine::result_type result_type
char_type widen(char __c) const
Widens characters.
_Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
Accumulate values in a range.
iterator begin() noexcept
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
back_insert_iterator< _Container > back_inserter(_Container &__x)
A fisher_f_distribution random number distribution.
param_type param() const
Returns the parameter set of the distribution.
ios_base & dec(ios_base &__base)
Calls base.setf(ios_base::dec, ios_base::basefield).
complex< _Tp > tan(const complex< _Tp > &)
Return complex tangent of z.
void clear(iostate __state=goodbit)
[Re]sets the error state.
param_type param() const
Returns the parameter set of the distribution.
param_type param() const
Returns the parameter set of the distribution.
A model of a linear congruential random number generator.
complex< _Tp > log(const complex< _Tp > &)
Return complex natural logarithm of z.
result_type operator()()
Gets the next random number in the sequence.
complex< _Tp > pow(const complex< _Tp > &, int)
Return x to the y'th power.
static constexpr _Tp min() noexcept
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, std::poisson_distribution< _IntType1 > &__x)
Extracts a poisson_distribution random number distribution __x from the input stream __is...
fmtflags flags() const
Access to format flags.
_GLIBCXX14_CONSTEXPR const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
Produces random numbers by combining random numbers from some base engine to produce random numbers w...
static constexpr _Tp max() noexcept
A student_t_distribution random number distribution.
A normal continuous distribution for random numbers.
void seed(result_type __sd=default_seed)
Seeds the initial state of the random number generator.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
ios_base & scientific(ios_base &__base)
Calls base.setf(ios_base::scientific, ios_base::floatfield).
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
ios_base & fixed(ios_base &__base)
Calls base.setf(ios_base::fixed, ios_base::floatfield).
_RealType generate_canonical(_UniformRandomNumberGenerator &__g)
A function template for converting the output of a (integral) uniform random number generator to a fl...
The Marsaglia-Zaman generator.
_GLIBCXX14_CONSTEXPR const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
param_type param() const
Returns the parameter set of the distribution.
param_type param() const
Returns the parameter set of the distribution.
A Bernoulli random number distribution.
param_type param() const
Returns the parameter set of the distribution.
A cauchy_distribution random number distribution.
_OutputIterator partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
Return list of partial sums.