35 namespace std _GLIBCXX_VISIBILITY(default)
42 _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;
92 _GLIBCXX_END_NAMESPACE_VERSION
95 _GLIBCXX_BEGIN_NAMESPACE_VERSION
97 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
99 linear_congruential_engine<_UIntType, __a, __c, __m>::multiplier;
101 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
103 linear_congruential_engine<_UIntType, __a, __c, __m>::increment;
105 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
107 linear_congruential_engine<_UIntType, __a, __c, __m>::modulus;
109 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
111 linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed;
117 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
122 if ((__detail::__mod<_UIntType, __m>(__c) == 0)
123 && (__detail::__mod<_UIntType, __m>(__s) == 0))
126 _M_x = __detail::__mod<_UIntType, __m>(__s);
132 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
133 template<
typename _Sseq>
134 typename std::enable_if<std::is_class<_Sseq>::value>::type
140 const _UIntType __k = (__k0 + 31) / 32;
141 uint_least32_t __arr[__k + 3];
142 __q.generate(__arr + 0, __arr + __k + 3);
143 _UIntType __factor = 1u;
144 _UIntType __sum = 0u;
145 for (
size_t __j = 0; __j < __k; ++__j)
147 __sum += __arr[__j + 3] * __factor;
148 __factor *= __detail::_Shift<_UIntType, 32>::__value;
153 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m,
154 typename _CharT,
typename _Traits>
156 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
158 __a, __c, __m>& __lcr)
161 typedef typename __ostream_type::ios_base __ios_base;
163 const typename __ios_base::fmtflags __flags = __os.
flags();
164 const _CharT __fill = __os.fill();
166 __os.fill(__os.widen(
' '));
175 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m,
176 typename _CharT,
typename _Traits>
179 linear_congruential_engine<_UIntType, __a, __c, __m>& __lcr)
182 typedef typename __istream_type::ios_base __ios_base;
184 const typename __ios_base::fmtflags __flags = __is.
flags();
194 template<
typename _UIntType,
195 size_t __w,
size_t __n,
size_t __m,
size_t __r,
196 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
197 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
200 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
201 __s, __b, __t, __c, __l, __f>::word_size;
203 template<
typename _UIntType,
204 size_t __w,
size_t __n,
size_t __m,
size_t __r,
205 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
206 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
209 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
210 __s, __b, __t, __c, __l, __f>::state_size;
212 template<
typename _UIntType,
213 size_t __w,
size_t __n,
size_t __m,
size_t __r,
214 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
215 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
218 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
219 __s, __b, __t, __c, __l, __f>::shift_size;
221 template<
typename _UIntType,
222 size_t __w,
size_t __n,
size_t __m,
size_t __r,
223 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
224 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
227 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
228 __s, __b, __t, __c, __l, __f>::mask_bits;
230 template<
typename _UIntType,
231 size_t __w,
size_t __n,
size_t __m,
size_t __r,
232 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
233 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
236 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
237 __s, __b, __t, __c, __l, __f>::xor_mask;
239 template<
typename _UIntType,
240 size_t __w,
size_t __n,
size_t __m,
size_t __r,
241 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
242 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
245 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
246 __s, __b, __t, __c, __l, __f>::tempering_u;
248 template<
typename _UIntType,
249 size_t __w,
size_t __n,
size_t __m,
size_t __r,
250 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
251 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
254 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
255 __s, __b, __t, __c, __l, __f>::tempering_d;
257 template<
typename _UIntType,
258 size_t __w,
size_t __n,
size_t __m,
size_t __r,
259 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
260 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
263 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
264 __s, __b, __t, __c, __l, __f>::tempering_s;
266 template<
typename _UIntType,
267 size_t __w,
size_t __n,
size_t __m,
size_t __r,
268 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
269 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
272 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
273 __s, __b, __t, __c, __l, __f>::tempering_b;
275 template<
typename _UIntType,
276 size_t __w,
size_t __n,
size_t __m,
size_t __r,
277 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
278 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
281 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
282 __s, __b, __t, __c, __l, __f>::tempering_t;
284 template<
typename _UIntType,
285 size_t __w,
size_t __n,
size_t __m,
size_t __r,
286 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
287 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
290 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
291 __s, __b, __t, __c, __l, __f>::tempering_c;
293 template<
typename _UIntType,
294 size_t __w,
size_t __n,
size_t __m,
size_t __r,
295 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
296 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
299 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
300 __s, __b, __t, __c, __l, __f>::tempering_l;
302 template<
typename _UIntType,
303 size_t __w,
size_t __n,
size_t __m,
size_t __r,
304 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
305 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
308 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
309 __s, __b, __t, __c, __l, __f>::
310 initialization_multiplier;
312 template<
typename _UIntType,
313 size_t __w,
size_t __n,
size_t __m,
size_t __r,
314 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
315 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
318 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
319 __s, __b, __t, __c, __l, __f>::default_seed;
321 template<
typename _UIntType,
322 size_t __w,
size_t __n,
size_t __m,
size_t __r,
323 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
324 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
327 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
328 __s, __b, __t, __c, __l, __f>::
329 seed(result_type __sd)
331 _M_x[0] = __detail::__mod<_UIntType,
332 __detail::_Shift<_UIntType, __w>::__value>(__sd);
334 for (
size_t __i = 1; __i < state_size; ++__i)
336 _UIntType __x = _M_x[__i - 1];
337 __x ^= __x >> (__w - 2);
339 __x += __detail::__mod<_UIntType, __n>(__i);
340 _M_x[__i] = __detail::__mod<_UIntType,
341 __detail::_Shift<_UIntType, __w>::__value>(__x);
346 template<
typename _UIntType,
347 size_t __w,
size_t __n,
size_t __m,
size_t __r,
348 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
349 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
351 template<
typename _Sseq>
352 typename std::enable_if<std::is_class<_Sseq>::value>::type
353 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
354 __s, __b, __t, __c, __l, __f>::
357 const _UIntType __upper_mask = (~_UIntType()) << __r;
358 const size_t __k = (__w + 31) / 32;
359 uint_least32_t __arr[__n * __k];
360 __q.generate(__arr + 0, __arr + __n * __k);
363 for (
size_t __i = 0; __i < state_size; ++__i)
365 _UIntType __factor = 1u;
366 _UIntType __sum = 0u;
367 for (
size_t __j = 0; __j < __k; ++__j)
369 __sum += __arr[__k * __i + __j] * __factor;
370 __factor *= __detail::_Shift<_UIntType, 32>::__value;
372 _M_x[__i] = __detail::__mod<_UIntType,
373 __detail::_Shift<_UIntType, __w>::__value>(__sum);
379 if ((_M_x[0] & __upper_mask) != 0u)
382 else if (_M_x[__i] != 0u)
387 _M_x[0] = __detail::_Shift<_UIntType, __w - 1>::__value;
391 template<
typename _UIntType,
size_t __w,
392 size_t __n,
size_t __m,
size_t __r,
393 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
394 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
397 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
398 __s, __b, __t, __c, __l, __f>::
401 const _UIntType __upper_mask = (~_UIntType()) << __r;
402 const _UIntType __lower_mask = ~__upper_mask;
404 for (
size_t __k = 0; __k < (__n - __m); ++__k)
406 _UIntType __y = ((_M_x[__k] & __upper_mask)
407 | (_M_x[__k + 1] & __lower_mask));
408 _M_x[__k] = (_M_x[__k + __m] ^ (__y >> 1)
409 ^ ((__y & 0x01) ? __a : 0));
412 for (
size_t __k = (__n - __m); __k < (__n - 1); ++__k)
414 _UIntType __y = ((_M_x[__k] & __upper_mask)
415 | (_M_x[__k + 1] & __lower_mask));
416 _M_x[__k] = (_M_x[__k + (__m - __n)] ^ (__y >> 1)
417 ^ ((__y & 0x01) ? __a : 0));
420 _UIntType __y = ((_M_x[__n - 1] & __upper_mask)
421 | (_M_x[0] & __lower_mask));
422 _M_x[__n - 1] = (_M_x[__m - 1] ^ (__y >> 1)
423 ^ ((__y & 0x01) ? __a : 0));
427 template<
typename _UIntType,
size_t __w,
428 size_t __n,
size_t __m,
size_t __r,
429 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
430 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
433 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
434 __s, __b, __t, __c, __l, __f>::
435 discard(
unsigned long long __z)
437 while (__z > state_size - _M_p)
439 __z -= state_size - _M_p;
445 template<
typename _UIntType,
size_t __w,
446 size_t __n,
size_t __m,
size_t __r,
447 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
448 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
452 __s, __b, __t, __c, __l, __f>::result_type
454 __s, __b, __t, __c, __l, __f>::
458 if (_M_p >= state_size)
462 result_type __z = _M_x[_M_p++];
463 __z ^= (__z >> __u) & __d;
464 __z ^= (__z << __s) & __b;
465 __z ^= (__z << __t) & __c;
471 template<
typename _UIntType,
size_t __w,
472 size_t __n,
size_t __m,
size_t __r,
473 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
474 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
475 _UIntType __f,
typename _CharT,
typename _Traits>
477 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
478 const mersenne_twister_engine<_UIntType, __w, __n, __m,
479 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __x)
482 typedef typename __ostream_type::ios_base __ios_base;
484 const typename __ios_base::fmtflags __flags = __os.
flags();
485 const _CharT __fill = __os.fill();
486 const _CharT __space = __os.widen(
' ');
490 for (
size_t __i = 0; __i < __n; ++__i)
491 __os << __x._M_x[__i] << __space;
499 template<
typename _UIntType,
size_t __w,
500 size_t __n,
size_t __m,
size_t __r,
501 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
502 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
503 _UIntType __f,
typename _CharT,
typename _Traits>
506 mersenne_twister_engine<_UIntType, __w, __n, __m,
507 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __x)
510 typedef typename __istream_type::ios_base __ios_base;
512 const typename __ios_base::fmtflags __flags = __is.
flags();
515 for (
size_t __i = 0; __i < __n; ++__i)
516 __is >> __x._M_x[__i];
524 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
526 subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size;
528 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
530 subtract_with_carry_engine<_UIntType, __w, __s, __r>::short_lag;
532 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
534 subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag;
536 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
538 subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed;
540 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
546 __lcg(__value == 0u ? default_seed : __value);
548 const size_t __n = (__w + 31) / 32;
550 for (
size_t __i = 0; __i < long_lag; ++__i)
552 _UIntType __sum = 0u;
553 _UIntType __factor = 1u;
554 for (
size_t __j = 0; __j < __n; ++__j)
556 __sum += __detail::__mod<uint_least32_t,
557 __detail::_Shift<uint_least32_t, 32>::__value>
558 (__lcg()) * __factor;
559 __factor *= __detail::_Shift<_UIntType, 32>::__value;
561 _M_x[__i] = __detail::__mod<_UIntType,
562 __detail::_Shift<_UIntType, __w>::__value>(__sum);
564 _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
568 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
569 template<
typename _Sseq>
570 typename std::enable_if<std::is_class<_Sseq>::value>::type
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>
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;
754 typedef typename std::common_type<_Eresult_type, result_type>::type
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();
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>
935 std::basic_ostream<_CharT, _Traits>&
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();
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>
997 std::basic_ostream<_CharT, _Traits>&
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>
1022 typename geometric_distribution<_IntType>::result_type
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 =
1058 (1 - std::numeric_limits<
double>::epsilon()) / 2;
1060 const
double __thr =
1061 std::numeric_limits<_IntType>::
max() + __naf;
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>
1124 typename negative_binomial_distribution<_IntType>::result_type
1126 operator()(_UniformRandomNumberGenerator& __urng)
1128 const double __y = _M_gd(__urng);
1132 return __poisson(__urng);
1135 template<
typename _IntType>
1136 template<
typename _UniformRandomNumberGenerator>
1137 typename negative_binomial_distribution<_IntType>::result_type
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>)
1181 typename std::gamma_distribution<result_type>::param_type
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 __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;
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>
1282 typename poisson_distribution<_IntType>::result_type
1285 const param_type& __param)
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 __e178 = 1.0129030479320018583185514777512983L;
1309 const double __c5 = __c4 + __e178;
1310 const double __c = __param._M_cb + __c5;
1311 const double __2cx = 2 * (2 * __m + __param._M_d);
1313 bool __reject =
true;
1316 const double __u = __c * __aurng();
1317 const double __e = -
std::log(1.0 - __aurng());
1323 const double __n = _M_nd(__urng);
1324 const double __y = -
std::abs(__n) * __param._M_sm - 1;
1325 __x = std::floor(__y);
1326 __w = -__n * __n / 2;
1330 else if (__u <= __c2)
1332 const double __n = _M_nd(__urng);
1333 const double __y = 1 +
std::abs(__n) * __param._M_scx;
1334 __x = std::ceil(__y);
1335 __w = __y * (2 - __y) * __param._M_1cx;
1336 if (__x > __param._M_d)
1339 else if (__u <= __c3)
1343 else if (__u <= __c4)
1345 else if (__u <= __c5)
1349 const double __v = -
std::log(1.0 - __aurng());
1350 const double __y = __param._M_d
1351 + __v * __2cx / __param._M_d;
1352 __x = std::ceil(__y);
1353 __w = -__param._M_d * __param._M_1cx * (1 + __y / 2);
1356 __reject = (__w - __e - __x * __param._M_lm_thr
1357 > __param._M_lfm - std::lgamma(__x + __m + 1));
1359 __reject |= __x + __m >= __thr;
1369 double __prod = 1.0;
1373 __prod *= __aurng();
1376 while (__prod > __param._M_lm_thr);
1382 template<
typename _IntType>
1383 template<
typename _ForwardIterator,
1384 typename _UniformRandomNumberGenerator>
1388 _UniformRandomNumberGenerator& __urng,
1389 const param_type& __param)
1391 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1394 *__f++ = this->operator()(__urng, __param);
1397 template<typename _IntType,
1398 typename _CharT, typename _Traits>
1404 typedef typename __ostream_type::ios_base __ios_base;
1406 const typename __ios_base::fmtflags __flags = __os.
flags();
1407 const _CharT __fill = __os.fill();
1409 const _CharT __space = __os.widen(
' ');
1414 __os << __x.mean() << __space << __x._M_nd;
1416 __os.flags(__flags);
1418 __os.precision(__precision);
1422 template<
typename _IntType,
1423 typename _CharT,
typename _Traits>
1426 poisson_distribution<_IntType>& __x)
1429 typedef typename __istream_type::ios_base __ios_base;
1431 const typename __ios_base::fmtflags __flags = __is.
flags();
1435 __is >> __mean >> __x._M_nd;
1436 __x.param(
typename poisson_distribution<_IntType>::param_type(__mean));
1438 __is.
flags(__flags);
1443 template<
typename _IntType>
1445 binomial_distribution<_IntType>::param_type::
1448 const double __p12 = _M_p <= 0.5 ? _M_p : 1.0 - _M_p;
1452 #if _GLIBCXX_USE_C99_MATH_TR1
1453 if (_M_t * __p12 >= 8)
1456 const double __np = std::floor(_M_t * __p12);
1457 const double __pa = __np / _M_t;
1458 const double __1p = 1 - __pa;
1460 const double __pi_4 = 0.7853981633974483096156608458198757L;
1461 const double __d1x =
1463 / (81 * __pi_4 * __1p)));
1464 _M_d1 = std::round(
std::max(1.0, __d1x));
1465 const double __d2x =
1467 / (__pi_4 * __pa)));
1468 _M_d2 = std::round(
std::max(1.0, __d2x));
1471 const double __spi_2 = 1.2533141373155002512078826424055226L;
1472 _M_s1 =
std::sqrt(__np * __1p) * (1 + _M_d1 / (4 * __np));
1473 _M_s2 =
std::sqrt(__np * __1p) * (1 + _M_d2 / (4 * _M_t * __1p));
1474 _M_c = 2 * _M_d1 / __np;
1475 _M_a1 =
std::exp(_M_c) * _M_s1 * __spi_2;
1476 const double __a12 = _M_a1 + _M_s2 * __spi_2;
1477 const double __s1s = _M_s1 * _M_s1;
1478 _M_a123 = __a12 + (
std::exp(_M_d1 / (_M_t * __1p))
1480 *
std::exp(-_M_d1 * _M_d1 / (2 * __s1s)));
1481 const double __s2s = _M_s2 * _M_s2;
1482 _M_s = (_M_a123 + 2 * __s2s / _M_d2
1483 *
std::exp(-_M_d2 * _M_d2 / (2 * __s2s)));
1484 _M_lf = (std::lgamma(__np + 1)
1485 + std::lgamma(_M_t - __np + 1));
1488 _M_q = -
std::log(1 - (__p12 - __pa) / __1p);
1495 template<
typename _IntType>
1496 template<
typename _UniformRandomNumberGenerator>
1497 typename binomial_distribution<_IntType>::result_type
1498 binomial_distribution<_IntType>::
1499 _M_waiting(_UniformRandomNumberGenerator& __urng,
1500 _IntType __t,
double __q)
1504 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1511 const double __e = -
std::log(1.0 - __aurng());
1512 __sum += __e / (__t - __x);
1515 while (__sum <= __q);
1530 template<
typename _IntType>
1531 template<
typename _UniformRandomNumberGenerator>
1532 typename binomial_distribution<_IntType>::result_type
1535 const param_type& __param)
1538 const _IntType __t = __param.t();
1539 const double __p = __param.p();
1540 const double __p12 = __p <= 0.5 ? __p : 1.0 - __p;
1541 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1544 #if _GLIBCXX_USE_C99_MATH_TR1
1545 if (!__param._M_easy)
1550 const double __naf =
1552 const double __thr =
1555 const double __np = std::floor(__t * __p12);
1558 const double __spi_2 = 1.2533141373155002512078826424055226L;
1559 const double __a1 = __param._M_a1;
1560 const double __a12 = __a1 + __param._M_s2 * __spi_2;
1561 const double __a123 = __param._M_a123;
1562 const double __s1s = __param._M_s1 * __param._M_s1;
1563 const double __s2s = __param._M_s2 * __param._M_s2;
1568 const double __u = __param._M_s * __aurng();
1574 const double __n = _M_nd(__urng);
1575 const double __y = __param._M_s1 *
std::abs(__n);
1576 __reject = __y >= __param._M_d1;
1579 const double __e = -
std::log(1.0 - __aurng());
1580 __x = std::floor(__y);
1581 __v = -__e - __n * __n / 2 + __param._M_c;
1584 else if (__u <= __a12)
1586 const double __n = _M_nd(__urng);
1587 const double __y = __param._M_s2 *
std::abs(__n);
1588 __reject = __y >= __param._M_d2;
1591 const double __e = -
std::log(1.0 - __aurng());
1592 __x = std::floor(-__y);
1593 __v = -__e - __n * __n / 2;
1596 else if (__u <= __a123)
1598 const double __e1 = -
std::log(1.0 - __aurng());
1599 const double __e2 = -
std::log(1.0 - __aurng());
1601 const double __y = __param._M_d1
1602 + 2 * __s1s * __e1 / __param._M_d1;
1603 __x = std::floor(__y);
1604 __v = (-__e2 + __param._M_d1 * (1 / (__t - __np)
1605 -__y / (2 * __s1s)));
1610 const double __e1 = -
std::log(1.0 - __aurng());
1611 const double __e2 = -
std::log(1.0 - __aurng());
1613 const double __y = __param._M_d2
1614 + 2 * __s2s * __e1 / __param._M_d2;
1615 __x = std::floor(-__y);
1616 __v = -__e2 - __param._M_d2 * __y / (2 * __s2s);
1620 __reject = __reject || __x < -__np || __x > __t - __np;
1623 const double __lfx =
1624 std::lgamma(__np + __x + 1)
1625 + std::lgamma(__t - (__np + __x) + 1);
1626 __reject = __v > __param._M_lf - __lfx
1627 + __x * __param._M_lp1p;
1630 __reject |= __x + __np >= __thr;
1634 __x += __np + __naf;
1636 const _IntType __z = _M_waiting(__urng, __t - _IntType(__x),
1638 __ret = _IntType(__x) + __z;
1642 __ret = _M_waiting(__urng, __t, __param._M_q);
1645 __ret = __t - __ret;
1649 template<
typename _IntType>
1650 template<
typename _ForwardIterator,
1651 typename _UniformRandomNumberGenerator>
1655 _UniformRandomNumberGenerator& __urng,
1656 const param_type& __param)
1658 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1661 *__f++ = this->operator()(__urng, __param);
1664 template<typename _IntType,
1665 typename _CharT, typename _Traits>
1671 typedef typename __ostream_type::ios_base __ios_base;
1673 const typename __ios_base::fmtflags __flags = __os.
flags();
1674 const _CharT __fill = __os.fill();
1676 const _CharT __space = __os.widen(
' ');
1681 __os << __x.t() << __space << __x.p()
1682 << __space << __x._M_nd;
1684 __os.flags(__flags);
1686 __os.precision(__precision);
1690 template<
typename _IntType,
1691 typename _CharT,
typename _Traits>
1694 binomial_distribution<_IntType>& __x)
1697 typedef typename __istream_type::ios_base __ios_base;
1699 const typename __ios_base::fmtflags __flags = __is.
flags();
1704 __is >> __t >> __p >> __x._M_nd;
1705 __x.param(
typename binomial_distribution<_IntType>::
1706 param_type(__t, __p));
1708 __is.
flags(__flags);
1713 template<
typename _RealType>
1714 template<
typename _ForwardIterator,
1715 typename _UniformRandomNumberGenerator>
1719 _UniformRandomNumberGenerator& __urng,
1720 const param_type& __p)
1722 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1723 __detail::_Adaptor<_UniformRandomNumberGenerator,
result_type>
1729 template<typename _RealType, typename _CharT, typename _Traits>
1730 std::basic_ostream<_CharT, _Traits>&
1735 typedef typename __ostream_type::ios_base __ios_base;
1737 const typename __ios_base::fmtflags __flags = __os.
flags();
1738 const _CharT __fill = __os.fill();
1741 __os.fill(__os.widen(
' '));
1744 __os << __x.lambda();
1746 __os.flags(__flags);
1748 __os.precision(__precision);
1752 template<
typename _RealType,
typename _CharT,
typename _Traits>
1758 typedef typename __istream_type::ios_base __ios_base;
1760 const typename __ios_base::fmtflags __flags = __is.
flags();
1766 param_type(__lambda));
1768 __is.
flags(__flags);
1779 template<
typename _RealType>
1780 template<
typename _UniformRandomNumberGenerator>
1781 typename normal_distribution<_RealType>::result_type
1784 const param_type& __param)
1787 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1790 if (_M_saved_available)
1792 _M_saved_available =
false;
1802 __r2 = __x * __x + __y * __y;
1804 while (__r2 > 1.0 || __r2 == 0.0);
1807 _M_saved = __x * __mult;
1808 _M_saved_available =
true;
1809 __ret = __y * __mult;
1812 __ret = __ret * __param.stddev() + __param.mean();
1816 template<
typename _RealType>
1817 template<
typename _ForwardIterator,
1818 typename _UniformRandomNumberGenerator>
1822 _UniformRandomNumberGenerator& __urng,
1823 const param_type& __param)
1825 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1830 if (_M_saved_available)
1832 _M_saved_available =
false;
1833 *__f++ = _M_saved * __param.stddev() + __param.mean();
1839 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1842 while (__f + 1 < __t)
1849 __r2 = __x * __x + __y * __y;
1851 while (__r2 > 1.0 || __r2 == 0.0);
1854 *__f++ = __y * __mult * __param.stddev() + __param.mean();
1855 *__f++ = __x * __mult * __param.stddev() + __param.mean();
1865 __r2 = __x * __x + __y * __y;
1867 while (__r2 > 1.0 || __r2 == 0.0);
1870 _M_saved = __x * __mult;
1871 _M_saved_available =
true;
1872 *__f = __y * __mult * __param.stddev() + __param.mean();
1876 template<
typename _RealType>
1881 if (__d1._M_param == __d2._M_param
1882 && __d1._M_saved_available == __d2._M_saved_available)
1884 if (__d1._M_saved_available
1885 && __d1._M_saved == __d2._M_saved)
1887 else if(!__d1._M_saved_available)
1896 template<
typename _RealType,
typename _CharT,
typename _Traits>
1898 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1899 const normal_distribution<_RealType>& __x)
1902 typedef typename __ostream_type::ios_base __ios_base;
1904 const typename __ios_base::fmtflags __flags = __os.
flags();
1905 const _CharT __fill = __os.
fill();
1907 const _CharT __space = __os.
widen(
' ');
1912 __os << __x.mean() << __space << __x.stddev()
1913 << __space << __x._M_saved_available;
1914 if (__x._M_saved_available)
1915 __os << __space << __x._M_saved;
1917 __os.
flags(__flags);
1923 template<
typename _RealType,
typename _CharT,
typename _Traits>
1926 normal_distribution<_RealType>& __x)
1929 typedef typename __istream_type::ios_base __ios_base;
1931 const typename __ios_base::fmtflags __flags = __is.
flags();
1934 double __mean, __stddev;
1935 __is >> __mean >> __stddev
1936 >> __x._M_saved_available;
1937 if (__x._M_saved_available)
1938 __is >> __x._M_saved;
1939 __x.param(
typename normal_distribution<_RealType>::
1940 param_type(__mean, __stddev));
1942 __is.
flags(__flags);
1947 template<
typename _RealType>
1948 template<
typename _ForwardIterator,
1949 typename _UniformRandomNumberGenerator>
1951 lognormal_distribution<_RealType>::
1952 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1953 _UniformRandomNumberGenerator& __urng,
1954 const param_type& __p)
1956 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1958 *__f++ = std::
exp(__p.s() * _M_nd(__urng) + __p.m());
1961 template<typename _RealType, typename _CharT, typename _Traits>
1962 std::basic_ostream<_CharT, _Traits>&
1963 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1964 const lognormal_distribution<_RealType>& __x)
1967 typedef typename __ostream_type::ios_base __ios_base;
1969 const typename __ios_base::fmtflags __flags = __os.
flags();
1970 const _CharT __fill = __os.fill();
1972 const _CharT __space = __os.widen(
' ');
1977 __os << __x.m() << __space << __x.s()
1978 << __space << __x._M_nd;
1980 __os.flags(__flags);
1982 __os.precision(__precision);
1986 template<
typename _RealType,
typename _CharT,
typename _Traits>
1989 lognormal_distribution<_RealType>& __x)
1992 typedef typename __istream_type::ios_base __ios_base;
1994 const typename __ios_base::fmtflags __flags = __is.
flags();
1998 __is >> __m >> __s >> __x._M_nd;
1999 __x.param(
typename lognormal_distribution<_RealType>::
2000 param_type(__m, __s));
2002 __is.
flags(__flags);
2006 template<
typename _RealType>
2007 template<
typename _ForwardIterator,
2008 typename _UniformRandomNumberGenerator>
2012 _UniformRandomNumberGenerator& __urng)
2014 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2016 *__f++ = 2 * _M_gd(__urng);
2019 template<typename _RealType>
2020 template<typename _ForwardIterator,
2021 typename _UniformRandomNumberGenerator>
2023 std::chi_squared_distribution<_RealType>::
2024 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2025 _UniformRandomNumberGenerator& __urng,
2027 std::gamma_distribution<
result_type>::param_type& __p)
2029 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2031 *__f++ = 2 * _M_gd(__urng, __p);
2034 template<typename _RealType, typename _CharT, typename _Traits>
2035 std::basic_ostream<_CharT, _Traits>&
2036 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2037 const chi_squared_distribution<_RealType>& __x)
2040 typedef typename __ostream_type::ios_base __ios_base;
2042 const typename __ios_base::fmtflags __flags = __os.
flags();
2043 const _CharT __fill = __os.fill();
2045 const _CharT __space = __os.widen(
' ');
2050 __os << __x.n() << __space << __x._M_gd;
2052 __os.flags(__flags);
2054 __os.precision(__precision);
2058 template<
typename _RealType,
typename _CharT,
typename _Traits>
2061 chi_squared_distribution<_RealType>& __x)
2064 typedef typename __istream_type::ios_base __ios_base;
2066 const typename __ios_base::fmtflags __flags = __is.
flags();
2070 __is >> __n >> __x._M_gd;
2071 __x.param(
typename chi_squared_distribution<_RealType>::
2074 __is.
flags(__flags);
2079 template<
typename _RealType>
2080 template<
typename _UniformRandomNumberGenerator>
2081 typename cauchy_distribution<_RealType>::result_type
2083 operator()(_UniformRandomNumberGenerator& __urng,
2084 const param_type& __p)
2086 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2093 const _RealType __pi = 3.1415926535897932384626433832795029L;
2094 return __p.a() + __p.b() *
std::tan(__pi * __u);
2097 template<
typename _RealType>
2098 template<
typename _ForwardIterator,
2099 typename _UniformRandomNumberGenerator>
2101 cauchy_distribution<_RealType>::
2102 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2103 _UniformRandomNumberGenerator& __urng,
2104 const param_type& __p)
2106 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2107 const _RealType __pi = 3.1415926535897932384626433832795029L;
2108 __detail::_Adaptor<_UniformRandomNumberGenerator,
result_type>
2117 *__f++ = __p.a() + __p.b() *
std::tan(__pi * __u);
2121 template<
typename _RealType,
typename _CharT,
typename _Traits>
2123 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2127 typedef typename __ostream_type::ios_base __ios_base;
2129 const typename __ios_base::fmtflags __flags = __os.
flags();
2130 const _CharT __fill = __os.fill();
2132 const _CharT __space = __os.widen(
' ');
2137 __os << __x.a() << __space << __x.b();
2139 __os.flags(__flags);
2141 __os.precision(__precision);
2145 template<
typename _RealType,
typename _CharT,
typename _Traits>
2151 typedef typename __istream_type::ios_base __ios_base;
2153 const typename __ios_base::fmtflags __flags = __is.
flags();
2159 param_type(__a, __b));
2161 __is.
flags(__flags);
2166 template<
typename _RealType>
2167 template<
typename _ForwardIterator,
2168 typename _UniformRandomNumberGenerator>
2172 _UniformRandomNumberGenerator& __urng)
2174 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2176 *__f++ = ((_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()));
2179 template<typename _RealType>
2180 template<typename _ForwardIterator,
2181 typename _UniformRandomNumberGenerator>
2183 std::fisher_f_distribution<_RealType>::
2184 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2185 _UniformRandomNumberGenerator& __urng,
2186 const param_type& __p)
2188 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2189 typedef typename std::gamma_distribution<
result_type>::param_type
2191 param_type __p1(__p.m() / 2);
2192 param_type __p2(__p.n() / 2);
2194 *__f++ = ((_M_gd_x(__urng, __p1) * n())
2195 / (_M_gd_y(__urng, __p2) * m()));
2198 template<typename _RealType, typename _CharT, typename _Traits>
2199 std::basic_ostream<_CharT, _Traits>&
2200 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2201 const fisher_f_distribution<_RealType>& __x)
2204 typedef typename __ostream_type::ios_base __ios_base;
2206 const typename __ios_base::fmtflags __flags = __os.
flags();
2207 const _CharT __fill = __os.fill();
2209 const _CharT __space = __os.widen(
' ');
2214 __os << __x.m() << __space << __x.n()
2215 << __space << __x._M_gd_x << __space << __x._M_gd_y;
2217 __os.flags(__flags);
2219 __os.precision(__precision);
2223 template<
typename _RealType,
typename _CharT,
typename _Traits>
2226 fisher_f_distribution<_RealType>& __x)
2229 typedef typename __istream_type::ios_base __ios_base;
2231 const typename __ios_base::fmtflags __flags = __is.
flags();
2235 __is >> __m >> __n >> __x._M_gd_x >> __x._M_gd_y;
2236 __x.param(
typename fisher_f_distribution<_RealType>::
2237 param_type(__m, __n));
2239 __is.
flags(__flags);
2244 template<
typename _RealType>
2245 template<
typename _ForwardIterator,
2246 typename _UniformRandomNumberGenerator>
2250 _UniformRandomNumberGenerator& __urng)
2252 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2254 *__f++ = _M_nd(__urng) * std::
sqrt(n() / _M_gd(__urng));
2257 template<typename _RealType>
2258 template<typename _ForwardIterator,
2259 typename _UniformRandomNumberGenerator>
2261 std::student_t_distribution<_RealType>::
2262 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2263 _UniformRandomNumberGenerator& __urng,
2264 const param_type& __p)
2266 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2267 typename std::gamma_distribution<
result_type>::param_type
2268 __p2(__p.n() / 2, 2);
2270 *__f++ = _M_nd(__urng) * std::
sqrt(__p.n() / _M_gd(__urng, __p2));
2273 template<typename _RealType, typename _CharT, typename _Traits>
2274 std::basic_ostream<_CharT, _Traits>&
2275 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2276 const student_t_distribution<_RealType>& __x)
2279 typedef typename __ostream_type::ios_base __ios_base;
2281 const typename __ios_base::fmtflags __flags = __os.
flags();
2282 const _CharT __fill = __os.fill();
2284 const _CharT __space = __os.widen(
' ');
2289 __os << __x.n() << __space << __x._M_nd << __space << __x._M_gd;
2291 __os.flags(__flags);
2293 __os.precision(__precision);
2297 template<
typename _RealType,
typename _CharT,
typename _Traits>
2300 student_t_distribution<_RealType>& __x)
2303 typedef typename __istream_type::ios_base __ios_base;
2305 const typename __ios_base::fmtflags __flags = __is.
flags();
2309 __is >> __n >> __x._M_nd >> __x._M_gd;
2310 __x.param(
typename student_t_distribution<_RealType>::param_type(__n));
2312 __is.
flags(__flags);
2317 template<
typename _RealType>
2319 gamma_distribution<_RealType>::param_type::
2322 _M_malpha = _M_alpha < 1.0 ? _M_alpha + _RealType(1.0) : _M_alpha;
2324 const _RealType __a1 = _M_malpha - _RealType(1.0) / _RealType(3.0);
2325 _M_a2 = _RealType(1.0) /
std::sqrt(_RealType(9.0) * __a1);
2333 template<
typename _RealType>
2334 template<
typename _UniformRandomNumberGenerator>
2335 typename gamma_distribution<_RealType>::result_type
2338 const param_type& __param)
2340 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2345 - _RealType(1.0) / _RealType(3.0));
2351 __n = _M_nd(__urng);
2356 __v = __v * __v * __v;
2359 while (__u >
result_type(1.0) - 0.331 * __n * __n * __n * __n
2360 && (
std::log(__u) > (0.5 * __n * __n + __a1
2363 if (__param.alpha() == __param._M_malpha)
2364 return __a1 * __v * __param.beta();
2372 * __a1 * __v * __param.beta());
2376 template<
typename _RealType>
2377 template<
typename _ForwardIterator,
2378 typename _UniformRandomNumberGenerator>
2382 _UniformRandomNumberGenerator& __urng,
2383 const param_type& __param)
2385 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2386 __detail::_Adaptor<_UniformRandomNumberGenerator,
result_type>
2391 - _RealType(1.0) / _RealType(3.0));
2393 if (__param.alpha() == __param._M_malpha)
2400 __n = _M_nd(__urng);
2405 __v = __v * __v * __v;
2408 while (__u >
result_type(1.0) - 0.331 * __n * __n * __n * __n
2409 && (
std::log(__u) > (0.5 * __n * __n + __a1
2412 *__f++ = __a1 * __v * __param.beta();
2421 __n = _M_nd(__urng);
2426 __v = __v * __v * __v;
2429 while (__u >
result_type(1.0) - 0.331 * __n * __n * __n * __n
2430 && (
std::log(__u) > (0.5 * __n * __n + __a1
2438 * __a1 * __v * __param.beta());
2442 template<
typename _RealType,
typename _CharT,
typename _Traits>
2444 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2445 const gamma_distribution<_RealType>& __x)
2448 typedef typename __ostream_type::ios_base __ios_base;
2450 const typename __ios_base::fmtflags __flags = __os.
flags();
2451 const _CharT __fill = __os.
fill();
2453 const _CharT __space = __os.
widen(
' ');
2458 __os << __x.alpha() << __space << __x.beta()
2459 << __space << __x._M_nd;
2461 __os.
flags(__flags);
2467 template<
typename _RealType,
typename _CharT,
typename _Traits>
2470 gamma_distribution<_RealType>& __x)
2473 typedef typename __istream_type::ios_base __ios_base;
2475 const typename __ios_base::fmtflags __flags = __is.
flags();
2478 _RealType __alpha_val, __beta_val;
2479 __is >> __alpha_val >> __beta_val >> __x._M_nd;
2480 __x.param(
typename gamma_distribution<_RealType>::
2481 param_type(__alpha_val, __beta_val));
2483 __is.
flags(__flags);
2488 template<
typename _RealType>
2489 template<
typename _UniformRandomNumberGenerator>
2490 typename weibull_distribution<_RealType>::result_type
2492 operator()(_UniformRandomNumberGenerator& __urng,
2493 const param_type& __p)
2495 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2501 template<
typename _RealType>
2502 template<
typename _ForwardIterator,
2503 typename _UniformRandomNumberGenerator>
2505 weibull_distribution<_RealType>::
2506 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2507 _UniformRandomNumberGenerator& __urng,
2508 const param_type& __p)
2510 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2511 __detail::_Adaptor<_UniformRandomNumberGenerator,
result_type>
2520 template<typename _RealType, typename _CharT, typename _Traits>
2521 std::basic_ostream<_CharT, _Traits>&
2526 typedef typename __ostream_type::ios_base __ios_base;
2528 const typename __ios_base::fmtflags __flags = __os.
flags();
2529 const _CharT __fill = __os.fill();
2531 const _CharT __space = __os.widen(
' ');
2536 __os << __x.a() << __space << __x.b();
2538 __os.flags(__flags);
2540 __os.precision(__precision);
2544 template<
typename _RealType,
typename _CharT,
typename _Traits>
2550 typedef typename __istream_type::ios_base __ios_base;
2552 const typename __ios_base::fmtflags __flags = __is.
flags();
2558 param_type(__a, __b));
2560 __is.
flags(__flags);
2565 template<
typename _RealType>
2566 template<
typename _UniformRandomNumberGenerator>
2567 typename extreme_value_distribution<_RealType>::result_type
2569 operator()(_UniformRandomNumberGenerator& __urng,
2570 const param_type& __p)
2572 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2578 template<
typename _RealType>
2579 template<
typename _ForwardIterator,
2580 typename _UniformRandomNumberGenerator>
2582 extreme_value_distribution<_RealType>::
2583 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2584 _UniformRandomNumberGenerator& __urng,
2585 const param_type& __p)
2587 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2588 __detail::_Adaptor<_UniformRandomNumberGenerator,
result_type>
2596 template<typename _RealType, typename _CharT, typename _Traits>
2597 std::basic_ostream<_CharT, _Traits>&
2602 typedef typename __ostream_type::ios_base __ios_base;
2604 const typename __ios_base::fmtflags __flags = __os.
flags();
2605 const _CharT __fill = __os.fill();
2607 const _CharT __space = __os.widen(
' ');
2612 __os << __x.a() << __space << __x.b();
2614 __os.flags(__flags);
2616 __os.precision(__precision);
2620 template<
typename _RealType,
typename _CharT,
typename _Traits>
2626 typedef typename __istream_type::ios_base __ios_base;
2628 const typename __ios_base::fmtflags __flags = __is.
flags();
2634 param_type(__a, __b));
2636 __is.
flags(__flags);
2641 template<
typename _IntType>
2643 discrete_distribution<_IntType>::param_type::
2646 if (_M_prob.size() < 2)
2653 _M_prob.end(), 0.0);
2655 __detail::__normalize(_M_prob.begin(), _M_prob.end(), _M_prob.begin(),
2658 _M_cp.reserve(_M_prob.size());
2662 _M_cp[_M_cp.size() - 1] = 1.0;
2665 template<
typename _IntType>
2666 template<
typename _Func>
2667 discrete_distribution<_IntType>::param_type::
2668 param_type(
size_t __nw,
double __xmin,
double __xmax, _Func __fw)
2669 : _M_prob(), _M_cp()
2671 const size_t __n = __nw == 0 ? 1 : __nw;
2672 const double __delta = (__xmax - __xmin) / __n;
2674 _M_prob.reserve(__n);
2675 for (
size_t __k = 0; __k < __nw; ++__k)
2676 _M_prob.push_back(__fw(__xmin + __k * __delta + 0.5 * __delta));
2681 template<
typename _IntType>
2682 template<
typename _UniformRandomNumberGenerator>
2683 typename discrete_distribution<_IntType>::result_type
2684 discrete_distribution<_IntType>::
2685 operator()(_UniformRandomNumberGenerator& __urng,
2686 const param_type& __param)
2688 if (__param._M_cp.empty())
2689 return result_type(0);
2691 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2694 const double __p = __aurng();
2696 __param._M_cp.end(), __p);
2698 return __pos - __param._M_cp.begin();
2701 template<
typename _IntType>
2702 template<
typename _ForwardIterator,
2703 typename _UniformRandomNumberGenerator>
2705 discrete_distribution<_IntType>::
2706 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2707 _UniformRandomNumberGenerator& __urng,
2708 const param_type& __param)
2710 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2712 if (__param._M_cp.empty())
2715 *__f++ = result_type(0);
2719 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2724 const double __p = __aurng();
2726 __param._M_cp.end(), __p);
2728 *__f++ = __pos - __param._M_cp.begin();
2732 template<
typename _IntType,
typename _CharT,
typename _Traits>
2734 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2735 const discrete_distribution<_IntType>& __x)
2738 typedef typename __ostream_type::ios_base __ios_base;
2740 const typename __ios_base::fmtflags __flags = __os.
flags();
2741 const _CharT __fill = __os.
fill();
2743 const _CharT __space = __os.
widen(
' ');
2749 __os << __prob.
size();
2750 for (
auto __dit = __prob.
begin(); __dit != __prob.
end(); ++__dit)
2751 __os << __space << *__dit;
2753 __os.
flags(__flags);
2759 template<
typename _IntType,
typename _CharT,
typename _Traits>
2762 discrete_distribution<_IntType>& __x)
2765 typedef typename __istream_type::ios_base __ios_base;
2767 const typename __ios_base::fmtflags __flags = __is.
flags();
2775 for (; __n != 0; --__n)
2782 __x.param(
typename discrete_distribution<_IntType>::
2783 param_type(__prob_vec.
begin(), __prob_vec.
end()));
2785 __is.
flags(__flags);
2790 template<
typename _RealType>
2792 piecewise_constant_distribution<_RealType>::param_type::
2795 if (_M_int.size() < 2
2796 || (_M_int.size() == 2
2797 && _M_int[0] == _RealType(0)
2798 && _M_int[1] == _RealType(1)))
2808 __detail::__normalize(_M_den.begin(), _M_den.end(), _M_den.begin(),
2811 _M_cp.reserve(_M_den.size());
2816 _M_cp[_M_cp.size() - 1] = 1.0;
2818 for (
size_t __k = 0; __k < _M_den.size(); ++__k)
2819 _M_den[__k] /= _M_int[__k + 1] - _M_int[__k];
2822 template<
typename _RealType>
2823 template<
typename _InputIteratorB,
typename _InputIteratorW>
2824 piecewise_constant_distribution<_RealType>::param_type::
2825 param_type(_InputIteratorB __bbegin,
2826 _InputIteratorB __bend,
2827 _InputIteratorW __wbegin)
2828 : _M_int(), _M_den(), _M_cp()
2830 if (__bbegin != __bend)
2834 _M_int.push_back(*__bbegin);
2836 if (__bbegin == __bend)
2839 _M_den.push_back(*__wbegin);
2847 template<
typename _RealType>
2848 template<
typename _Func>
2849 piecewise_constant_distribution<_RealType>::param_type::
2850 param_type(initializer_list<_RealType> __bl, _Func __fw)
2851 : _M_int(), _M_den(), _M_cp()
2853 _M_int.reserve(__bl.size());
2854 for (
auto __biter = __bl.begin(); __biter != __bl.end(); ++__biter)
2855 _M_int.push_back(*__biter);
2857 _M_den.reserve(_M_int.size() - 1);
2858 for (
size_t __k = 0; __k < _M_int.size() - 1; ++__k)
2859 _M_den.push_back(__fw(0.5 * (_M_int[__k + 1] + _M_int[__k])));
2864 template<
typename _RealType>
2865 template<
typename _Func>
2866 piecewise_constant_distribution<_RealType>::param_type::
2867 param_type(
size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
2868 : _M_int(), _M_den(), _M_cp()
2870 const size_t __n = __nw == 0 ? 1 : __nw;
2871 const _RealType __delta = (__xmax - __xmin) / __n;
2873 _M_int.reserve(__n + 1);
2874 for (
size_t __k = 0; __k <= __nw; ++__k)
2875 _M_int.push_back(__xmin + __k * __delta);
2877 _M_den.reserve(__n);
2878 for (
size_t __k = 0; __k < __nw; ++__k)
2879 _M_den.push_back(__fw(_M_int[__k] + 0.5 * __delta));
2884 template<
typename _RealType>
2885 template<
typename _UniformRandomNumberGenerator>
2886 typename piecewise_constant_distribution<_RealType>::result_type
2887 piecewise_constant_distribution<_RealType>::
2888 operator()(_UniformRandomNumberGenerator& __urng,
2889 const param_type& __param)
2891 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2894 const double __p = __aurng();
2895 if (__param._M_cp.empty())
2899 __param._M_cp.end(), __p);
2900 const size_t __i = __pos - __param._M_cp.begin();
2902 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
2904 return __param._M_int[__i] + (__p - __pref) / __param._M_den[__i];
2907 template<
typename _RealType>
2908 template<
typename _ForwardIterator,
2909 typename _UniformRandomNumberGenerator>
2911 piecewise_constant_distribution<_RealType>::
2912 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2913 _UniformRandomNumberGenerator& __urng,
2914 const param_type& __param)
2916 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2917 __detail::_Adaptor<_UniformRandomNumberGenerator,
double>
2920 if (__param._M_cp.empty())
2929 const double __p = __aurng();
2932 __param._M_cp.end(), __p);
2933 const size_t __i = __pos - __param._M_cp.begin();
2935 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
2937 *__f++ = (__param._M_int[__i]
2938 + (__p - __pref) / __param._M_den[__i]);
2942 template<
typename _RealType,
typename _CharT,
typename _Traits>
2944 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2945 const piecewise_constant_distribution<_RealType>& __x)
2948 typedef typename __ostream_type::ios_base __ios_base;
2950 const typename __ios_base::fmtflags __flags = __os.
flags();
2951 const _CharT __fill = __os.
fill();
2953 const _CharT __space = __os.
widen(
' ');
2959 __os << __int.
size() - 1;
2961 for (
auto __xit = __int.
begin(); __xit != __int.
end(); ++__xit)
2962 __os << __space << *__xit;
2965 for (
auto __dit = __den.
begin(); __dit != __den.
end(); ++__dit)
2966 __os << __space << *__dit;
2968 __os.
flags(__flags);
2974 template<
typename _RealType,
typename _CharT,
typename _Traits>
2977 piecewise_constant_distribution<_RealType>& __x)
2980 typedef typename __istream_type::ios_base __ios_base;
2982 const typename __ios_base::fmtflags __flags = __is.
flags();
2990 for (
size_t __i = 0; __i <= __n; ++__i)
2999 for (
size_t __i = 0; __i < __n; ++__i)
3006 __x.param(
typename piecewise_constant_distribution<_RealType>::
3007 param_type(__int_vec.
begin(), __int_vec.
end(), __den_vec.
begin()));
3009 __is.
flags(__flags);
3014 template<
typename _RealType>
3016 piecewise_linear_distribution<_RealType>::param_type::
3019 if (_M_int.size() < 2
3020 || (_M_int.size() == 2
3021 && _M_int[0] == _RealType(0)
3022 && _M_int[1] == _RealType(1)
3023 && _M_den[0] == _M_den[1]))
3031 _M_cp.reserve(_M_int.size() - 1);
3032 _M_m.reserve(_M_int.size() - 1);
3033 for (
size_t __k = 0; __k < _M_int.size() - 1; ++__k)
3035 const _RealType __delta = _M_int[__k + 1] - _M_int[__k];
3036 __sum += 0.5 * (_M_den[__k + 1] + _M_den[__k]) * __delta;
3037 _M_cp.push_back(__sum);
3038 _M_m.push_back((_M_den[__k + 1] - _M_den[__k]) / __delta);
3042 __detail::__normalize(_M_den.begin(), _M_den.end(), _M_den.begin(),
3045 __detail::__normalize(_M_cp.begin(), _M_cp.end(), _M_cp.begin(), __sum);
3047 __detail::__normalize(_M_m.begin(), _M_m.end(), _M_m.begin(), __sum);
3050 _M_cp[_M_cp.size() - 1] = 1.0;
3053 template<
typename _RealType>
3054 template<
typename _InputIteratorB,
typename _InputIteratorW>
3055 piecewise_linear_distribution<_RealType>::param_type::
3056 param_type(_InputIteratorB __bbegin,
3057 _InputIteratorB __bend,
3058 _InputIteratorW __wbegin)
3059 : _M_int(), _M_den(), _M_cp(), _M_m()
3061 for (; __bbegin != __bend; ++__bbegin, ++__wbegin)
3063 _M_int.push_back(*__bbegin);
3064 _M_den.push_back(*__wbegin);
3070 template<
typename _RealType>
3071 template<
typename _Func>
3072 piecewise_linear_distribution<_RealType>::param_type::
3073 param_type(initializer_list<_RealType> __bl, _Func __fw)
3074 : _M_int(), _M_den(), _M_cp(), _M_m()
3076 _M_int.reserve(__bl.size());
3077 _M_den.reserve(__bl.size());
3078 for (
auto __biter = __bl.begin(); __biter != __bl.end(); ++__biter)
3080 _M_int.push_back(*__biter);
3081 _M_den.push_back(__fw(*__biter));
3087 template<
typename _RealType>
3088 template<
typename _Func>
3089 piecewise_linear_distribution<_RealType>::param_type::
3090 param_type(
size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
3091 : _M_int(), _M_den(), _M_cp(), _M_m()
3093 const size_t __n = __nw == 0 ? 1 : __nw;
3094 const _RealType __delta = (__xmax - __xmin) / __n;
3096 _M_int.reserve(__n + 1);
3097 _M_den.reserve(__n + 1);
3098 for (
size_t __k = 0; __k <= __nw; ++__k)
3100 _M_int.push_back(__xmin + __k * __delta);
3101 _M_den.push_back(__fw(_M_int[__k] + __delta));
3107 template<
typename _RealType>
3108 template<
typename _UniformRandomNumberGenerator>
3109 typename piecewise_linear_distribution<_RealType>::result_type
3110 piecewise_linear_distribution<_RealType>::
3111 operator()(_UniformRandomNumberGenerator& __urng,
3112 const param_type& __param)
3114 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
3117 const double __p = __aurng();
3118 if (__param._M_cp.empty())
3122 __param._M_cp.end(), __p);
3123 const size_t __i = __pos - __param._M_cp.begin();
3125 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
3127 const double __a = 0.5 * __param._M_m[__i];
3128 const double __b = __param._M_den[__i];
3129 const double __cm = __p - __pref;
3131 _RealType __x = __param._M_int[__i];
3136 const double __d = __b * __b + 4.0 * __a * __cm;
3137 __x += 0.5 * (
std::sqrt(__d) - __b) / __a;
3143 template<
typename _RealType>
3144 template<
typename _ForwardIterator,
3145 typename _UniformRandomNumberGenerator>
3147 piecewise_linear_distribution<_RealType>::
3148 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3149 _UniformRandomNumberGenerator& __urng,
3150 const param_type& __param)
3152 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3155 *__f++ = this->operator()(__urng, __param);
3158 template<typename _RealType, typename _CharT, typename _Traits>
3159 std::basic_ostream<_CharT, _Traits>&
3160 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3161 const piecewise_linear_distribution<_RealType>& __x)
3164 typedef typename __ostream_type::ios_base __ios_base;
3166 const typename __ios_base::fmtflags __flags = __os.
flags();
3167 const _CharT __fill = __os.fill();
3169 const _CharT __space = __os.widen(
' ');
3175 __os << __int.
size() - 1;
3177 for (
auto __xit = __int.
begin(); __xit != __int.
end(); ++__xit)
3178 __os << __space << *__xit;
3181 for (
auto __dit = __den.
begin(); __dit != __den.
end(); ++__dit)
3182 __os << __space << *__dit;
3184 __os.flags(__flags);
3186 __os.precision(__precision);
3190 template<
typename _RealType,
typename _CharT,
typename _Traits>
3193 piecewise_linear_distribution<_RealType>& __x)
3196 typedef typename __istream_type::ios_base __ios_base;
3198 const typename __ios_base::fmtflags __flags = __is.
flags();
3206 for (
size_t __i = 0; __i <= __n; ++__i)
3215 for (
size_t __i = 0; __i <= __n; ++__i)
3222 __x.param(
typename piecewise_linear_distribution<_RealType>::
3223 param_type(__int_vec.
begin(), __int_vec.
end(), __den_vec.
begin()));
3225 __is.
flags(__flags);
3230 template<
typename _IntType>
3233 for (
auto __iter = __il.begin(); __iter != __il.end(); ++__iter)
3234 _M_v.push_back(__detail::__mod<result_type,
3235 __detail::_Shift<result_type, 32>::__value>(*__iter));
3238 template<
typename _InputIterator>
3239 seed_seq::seed_seq(_InputIterator __begin, _InputIterator __end)
3241 for (_InputIterator __iter = __begin; __iter != __end; ++__iter)
3242 _M_v.push_back(__detail::__mod<result_type,
3243 __detail::_Shift<result_type, 32>::__value>(*__iter));
3246 template<
typename _RandomAccessIterator>
3248 seed_seq::generate(_RandomAccessIterator __begin,
3249 _RandomAccessIterator __end)
3251 typedef typename iterator_traits<_RandomAccessIterator>::value_type
3254 if (__begin == __end)
3257 std::fill(__begin, __end, _Type(0x8b8b8b8bu));
3259 const size_t __n = __end - __begin;
3260 const size_t __s = _M_v.size();
3261 const size_t __t = (__n >= 623) ? 11
3266 const size_t __p = (__n - __t) / 2;
3267 const size_t __q = __p + __t;
3268 const size_t __m =
std::max(
size_t(__s + 1), __n);
3270 for (
size_t __k = 0; __k < __m; ++__k)
3272 _Type __arg = (__begin[__k % __n]
3273 ^ __begin[(__k + __p) % __n]
3274 ^ __begin[(__k - 1) % __n]);
3275 _Type __r1 = __arg ^ (__arg >> 27);
3276 __r1 = __detail::__mod<_Type,
3277 __detail::_Shift<_Type, 32>::__value>(1664525u * __r1);
3281 else if (__k <= __s)
3282 __r2 += __k % __n + _M_v[__k - 1];
3285 __r2 = __detail::__mod<_Type,
3286 __detail::_Shift<_Type, 32>::__value>(__r2);
3287 __begin[(__k + __p) % __n] += __r1;
3288 __begin[(__k + __q) % __n] += __r2;
3289 __begin[__k % __n] = __r2;
3292 for (
size_t __k = __m; __k < __m + __n; ++__k)
3294 _Type __arg = (__begin[__k % __n]
3295 + __begin[(__k + __p) % __n]
3296 + __begin[(__k - 1) % __n]);
3297 _Type __r3 = __arg ^ (__arg >> 27);
3298 __r3 = __detail::__mod<_Type,
3299 __detail::_Shift<_Type, 32>::__value>(1566083941u * __r3);
3300 _Type __r4 = __r3 - __k % __n;
3301 __r4 = __detail::__mod<_Type,
3302 __detail::_Shift<_Type, 32>::__value>(__r4);
3303 __begin[(__k + __p) % __n] ^= __r3;
3304 __begin[(__k + __q) % __n] ^= __r4;
3305 __begin[__k % __n] = __r4;
3309 template<
typename _RealType,
size_t __bits,
3310 typename _UniformRandomNumberGenerator>
3315 "template argument not a floating point type");
3320 const long double __r =
static_cast<long double>(__urng.max())
3321 - static_cast<long double>(__urng.min()) + 1.0L;
3323 size_t __k = std::max<size_t>(1UL, (__b + __log2r - 1UL) / __log2r);
3324 _RealType __sum = _RealType(0);
3325 _RealType __tmp = _RealType(1);
3326 for (; __k != 0; --__k)
3328 __sum += _RealType(__urng() - __urng.min()) * __tmp;
3331 return __sum / __tmp;
3334 _GLIBCXX_END_NAMESPACE_VERSION
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
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.
char_type fill() const
Retrieves the empty character.
_RandomNumberEngine::result_type result_type
back_insert_iterator< _Container > back_inserter(_Container &__x)
ios_base & dec(ios_base &__base)
Calls base.setf(ios_base::dec, ios_base::basefield).
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
param_type param() const
Returns the parameter set of the distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
ios_base & fixed(ios_base &__base)
Calls base.setf(ios_base::fixed, ios_base::floatfield).
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Template class basic_istream.
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, std::poisson_distribution< _IntType1 > &__x)
Extracts a poisson_distribution random number distribution __x from the input stream __is...
A chi_squared_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...
complex< _Tp > tan(const complex< _Tp > &)
Return complex tangent of z.
void clear(iostate __state=goodbit)
[Re]sets the error state.
A extreme_value_distribution random number distribution.
An exponential continuous distribution for random numbers.
A gamma continuous distribution for random numbers.
_ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp &__val)
Finds the first position in which val could be inserted without changing the ordering.
fmtflags flags() const
Access to format flags.
Produces random numbers by combining random numbers from some base engine to produce random numbers w...
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
A Bernoulli random number distribution.
_RealType generate_canonical(_UniformRandomNumberGenerator &__g)
A function template for converting the output of a (integral) uniform random number generator to a fl...
result_type operator()()
Gets the next value in the generated random number sequence.
A student_t_distribution random number distribution.
ios_base & scientific(ios_base &__base)
Calls base.setf(ios_base::scientific, ios_base::floatfield).
A normal continuous distribution for random numbers.
A discrete Poisson random number distribution.
param_type param() const
Returns the parameter set of the distribution.
_GLIBCXX14_CONSTEXPR const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
_Tp abs(const complex< _Tp > &)
Return magnitude of z.
_GLIBCXX14_CONSTEXPR const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
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...
param_type param() const
Returns the parameter set of the distribution.
static constexpr _Tp min() noexcept
constexpr int __lg(int __n)
This is a helper function for the sort routines and for random.tcc.
ios_base & skipws(ios_base &__base)
Calls base.setf(ios_base::skipws).
param_type param() const
Returns the parameter set of the distribution.
complex< _Tp > log(const complex< _Tp > &)
Return complex natural logarithm of z.
streamsize precision() const
Flags access.
A model of a linear congruential random number generator.
A discrete binomial random number distribution.
param_type param() const
Returns the parameter set of the distribution.
A weibull_distribution random number distribution.
A discrete geometric random number distribution.
ios_base & left(ios_base &__base)
Calls base.setf(ios_base::left, ios_base::adjustfield).
A fisher_f_distribution random number distribution.
complex< _Tp > pow(const complex< _Tp > &, int)
Return x to the y'th power.
char_type widen(char __c) const
Widens characters.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
static constexpr _Tp max() noexcept
void reserve(size_type __n)
Attempt to preallocate enough memory for specified number of elements.
Template class basic_ostream.
Uniform continuous distribution for random numbers.
static constexpr _Tp epsilon() noexcept
Uniform discrete distribution for random numbers.
complex< _Tp > exp(const complex< _Tp > &)
Return complex base e exponential of z.
complex< _Tp > sqrt(const complex< _Tp > &)
Return complex square root of z.
void push_back(const value_type &__x)
Add data to the end of the vector.
void seed(result_type __sd=default_seed)
Seeds the initial state of the random number generator.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
A cauchy_distribution random number distribution.
result_type operator()()
Gets the next random number in the sequence.
_Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
Accumulate values in a range.
iterator begin() noexcept
param_type param() const
Returns the parameter set of the distribution.
Properties of fundamental types.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
param_type param() const
Returns the parameter set of the distribution.
size_type size() const noexcept
The Marsaglia-Zaman generator.
result_type operator()()
Gets the next value in the generated random number sequence.
_OutputIterator partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
Return list of partial sums.