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>
542 subtract_with_carry_engine<_UIntType, __w, __s, __r>::
543 seed(result_type __value)
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
571 subtract_with_carry_engine<_UIntType, __w, __s, __r>::
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>::
597 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,
633 const subtract_with_carry_engine<_UIntType,
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>
876 template<
typename _UniformRandomNumberGenerator>
877 typename uniform_int_distribution<_IntType>::result_type
879 operator()(_UniformRandomNumberGenerator& __urng,
880 const param_type& __param)
882 typedef typename _UniformRandomNumberGenerator::result_type
884 typedef typename std::make_unsigned<result_type>::type __utype;
885 typedef typename std::common_type<_Gresult_type, __utype>::type
888 const __uctype __urngmin = __urng.min();
889 const __uctype __urngmax = __urng.max();
890 const __uctype __urngrange = __urngmax - __urngmin;
891 const __uctype __urange
892 = __uctype(__param.b()) - __uctype(__param.a());
896 if (__urngrange > __urange)
899 const __uctype __uerange = __urange + 1;
900 const __uctype __scaling = __urngrange / __uerange;
901 const __uctype __past = __uerange * __scaling;
903 __ret = __uctype(__urng()) - __urngmin;
904 while (__ret >= __past);
907 else if (__urngrange < __urange)
927 const __uctype __uerngrange = __urngrange + 1;
928 __tmp = (__uerngrange * operator()
929 (__urng, param_type(0, __urange / __uerngrange)));
930 __ret = __tmp + (__uctype(__urng()) - __urngmin);
932 while (__ret > __urange || __ret < __tmp);
935 __ret = __uctype(__urng()) - __urngmin;
937 return __ret + __param.a();
941 template<
typename _IntType>
942 template<
typename _ForwardIterator,
943 typename _UniformRandomNumberGenerator>
945 uniform_int_distribution<_IntType>::
946 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
947 _UniformRandomNumberGenerator& __urng,
948 const param_type& __param)
950 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
951 typedef typename _UniformRandomNumberGenerator::result_type
953 typedef typename std::make_unsigned<result_type>::type __utype;
954 typedef typename std::common_type<_Gresult_type, __utype>::type
957 const __uctype __urngmin = __urng.
min();
958 const __uctype __urngmax = __urng.
max();
959 const __uctype __urngrange = __urngmax - __urngmin;
960 const __uctype __urange
961 = __uctype(__param.b()) - __uctype(__param.a());
965 if (__urngrange > __urange)
967 if (__detail::_Power_of_2(__urngrange + 1)
968 && __detail::_Power_of_2(__urange + 1))
972 __ret = __uctype(__urng()) - __urngmin;
973 *__f++ = (__ret & __urange) + __param.a();
979 const __uctype __uerange = __urange + 1;
980 const __uctype __scaling = __urngrange / __uerange;
981 const __uctype __past = __uerange * __scaling;
985 __ret = __uctype(__urng()) - __urngmin;
986 while (__ret >= __past);
987 *__f++ = __ret / __scaling + __param.a();
991 else if (__urngrange < __urange)
1013 const __uctype __uerngrange = __urngrange + 1;
1014 __tmp = (__uerngrange * operator()
1015 (__urng, param_type(0, __urange / __uerngrange)));
1016 __ret = __tmp + (__uctype(__urng()) - __urngmin);
1018 while (__ret > __urange || __ret < __tmp);
1024 *__f++ = __uctype(__urng()) - __urngmin + __param.a();
1027 template<
typename _IntType,
typename _CharT,
typename _Traits>
1029 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1033 typedef typename __ostream_type::ios_base __ios_base;
1035 const typename __ios_base::fmtflags __flags = __os.
flags();
1036 const _CharT __fill = __os.fill();
1037 const _CharT __space = __os.widen(
' ');
1041 __os << __x.a() << __space << __x.b();
1043 __os.flags(__flags);
1048 template<
typename _IntType,
typename _CharT,
typename _Traits>
1054 typedef typename __istream_type::ios_base __ios_base;
1056 const typename __ios_base::fmtflags __flags = __is.
flags();
1062 param_type(__a, __b));
1064 __is.
flags(__flags);
1069 template<
typename _RealType>
1070 template<
typename _ForwardIterator,
1071 typename _UniformRandomNumberGenerator>
1073 uniform_real_distribution<_RealType>::
1074 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1075 _UniformRandomNumberGenerator& __urng,
1076 const param_type& __p)
1078 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1079 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1081 auto __range = __p.b() - __p.a();
1083 *__f++ = __aurng() * __range + __p.a();
1086 template<typename _RealType, typename _CharT, typename _Traits>
1087 std::basic_ostream<_CharT, _Traits>&
1092 typedef typename __ostream_type::ios_base __ios_base;
1094 const typename __ios_base::fmtflags __flags = __os.
flags();
1095 const _CharT __fill = __os.fill();
1097 const _CharT __space = __os.widen(
' ');
1102 __os << __x.a() << __space << __x.b();
1104 __os.flags(__flags);
1106 __os.precision(__precision);
1110 template<
typename _RealType,
typename _CharT,
typename _Traits>
1116 typedef typename __istream_type::ios_base __ios_base;
1118 const typename __ios_base::fmtflags __flags = __is.
flags();
1124 param_type(__a, __b));
1126 __is.
flags(__flags);
1131 template<
typename _ForwardIterator,
1132 typename _UniformRandomNumberGenerator>
1134 std::bernoulli_distribution::
1135 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1136 _UniformRandomNumberGenerator& __urng,
1137 const param_type& __p)
1139 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1140 __detail::_Adaptor<_UniformRandomNumberGenerator,
double>
1142 auto __limit = __p.p() * (__aurng.max() - __aurng.min());
1145 *__f++ = (__aurng() - __aurng.min()) < __limit;
1148 template<typename _CharT, typename _Traits>
1149 std::basic_ostream<_CharT, _Traits>&
1154 typedef typename __ostream_type::ios_base __ios_base;
1156 const typename __ios_base::fmtflags __flags = __os.
flags();
1157 const _CharT __fill = __os.fill();
1160 __os.fill(__os.widen(
' '));
1165 __os.flags(__flags);
1167 __os.precision(__precision);
1172 template<
typename _IntType>
1173 template<
typename _UniformRandomNumberGenerator>
1174 typename geometric_distribution<_IntType>::result_type
1176 operator()(_UniformRandomNumberGenerator& __urng,
1177 const param_type& __param)
1181 const double __naf =
1184 const double __thr =
1186 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1191 __cand = std::floor(
std::log(1.0 - __aurng()) / __param._M_log_1_p);
1192 while (__cand >= __thr);
1194 return result_type(__cand + __naf);
1197 template<
typename _IntType>
1198 template<
typename _ForwardIterator,
1199 typename _UniformRandomNumberGenerator>
1201 geometric_distribution<_IntType>::
1202 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1203 _UniformRandomNumberGenerator& __urng,
1204 const param_type& __param)
1206 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1209 const
double __naf =
1210 (1 - std::numeric_limits<
double>::epsilon()) / 2;
1212 const
double __thr =
1213 std::numeric_limits<_IntType>::max() + __naf;
1214 __detail::_Adaptor<_UniformRandomNumberGenerator,
double>
1221 __cand = std::floor(
std::log(1.0 - __aurng())
1222 / __param._M_log_1_p);
1223 while (__cand >= __thr);
1225 *__f++ = __cand + __naf;
1229 template<
typename _IntType,
1230 typename _CharT,
typename _Traits>
1232 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1236 typedef typename __ostream_type::ios_base __ios_base;
1238 const typename __ios_base::fmtflags __flags = __os.
flags();
1239 const _CharT __fill = __os.fill();
1242 __os.fill(__os.widen(
' '));
1247 __os.flags(__flags);
1249 __os.precision(__precision);
1253 template<
typename _IntType,
1254 typename _CharT,
typename _Traits>
1260 typedef typename __istream_type::ios_base __ios_base;
1262 const typename __ios_base::fmtflags __flags = __is.
flags();
1269 __is.
flags(__flags);
1274 template<
typename _IntType>
1275 template<
typename _UniformRandomNumberGenerator>
1276 typename negative_binomial_distribution<_IntType>::result_type
1278 operator()(_UniformRandomNumberGenerator& __urng)
1280 const double __y = _M_gd(__urng);
1284 return __poisson(__urng);
1287 template<
typename _IntType>
1288 template<
typename _UniformRandomNumberGenerator>
1289 typename negative_binomial_distribution<_IntType>::result_type
1291 operator()(_UniformRandomNumberGenerator& __urng,
1292 const param_type& __p)
1298 _M_gd(__urng, param_type(__p.k(), (1.0 - __p.p()) / __p.p()));
1301 return __poisson(__urng);
1304 template<
typename _IntType>
1305 template<
typename _ForwardIterator,
1306 typename _UniformRandomNumberGenerator>
1308 negative_binomial_distribution<_IntType>::
1309 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1310 _UniformRandomNumberGenerator& __urng)
1312 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1315 const double __y = _M_gd(__urng);
1319 *__f++ = __poisson(__urng);
1323 template<
typename _IntType>
1324 template<
typename _ForwardIterator,
1325 typename _UniformRandomNumberGenerator>
1327 negative_binomial_distribution<_IntType>::
1328 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1329 _UniformRandomNumberGenerator& __urng,
1330 const param_type& __p)
1332 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1333 typename std::gamma_distribution<result_type>::param_type
1334 __p2(__p.k(), (1.0 - __p.p()) / __p.p());
1338 const double __y = _M_gd(__urng, __p2);
1341 *__f++ = __poisson(__urng);
1345 template<
typename _IntType,
typename _CharT,
typename _Traits>
1347 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1348 const negative_binomial_distribution<_IntType>& __x)
1351 typedef typename __ostream_type::ios_base __ios_base;
1353 const typename __ios_base::fmtflags __flags = __os.
flags();
1354 const _CharT __fill = __os.
fill();
1356 const _CharT __space = __os.
widen(
' ');
1361 __os << __x.k() << __space << __x.p()
1362 << __space << __x._M_gd;
1364 __os.
flags(__flags);
1370 template<
typename _IntType,
typename _CharT,
typename _Traits>
1373 negative_binomial_distribution<_IntType>& __x)
1376 typedef typename __istream_type::ios_base __ios_base;
1378 const typename __ios_base::fmtflags __flags = __is.
flags();
1383 __is >> __k >> __p >> __x._M_gd;
1384 __x.param(
typename negative_binomial_distribution<_IntType>::
1385 param_type(__k, __p));
1387 __is.
flags(__flags);
1392 template<
typename _IntType>
1394 poisson_distribution<_IntType>::param_type::
1397 #if _GLIBCXX_USE_C99_MATH_TR1
1400 const double __m = std::floor(_M_mean);
1402 _M_lfm = std::lgamma(__m + 1);
1405 const double __pi_4 = 0.7853981633974483096156608458198757L;
1409 const double __cx = 2 * __m + _M_d;
1414 _M_cb = 2 * __cx *
std::exp(-_M_d * _M_1cx * (1 + _M_d / 2))
1432 template<
typename _IntType>
1433 template<
typename _UniformRandomNumberGenerator>
1434 typename poisson_distribution<_IntType>::result_type
1437 const param_type& __param)
1439 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1441 #if _GLIBCXX_USE_C99_MATH_TR1
1442 if (__param.mean() >= 12)
1447 const double __naf =
1449 const double __thr =
1452 const double __m = std::floor(__param.mean());
1454 const double __spi_2 = 1.2533141373155002512078826424055226L;
1455 const double __c1 = __param._M_sm * __spi_2;
1456 const double __c2 = __param._M_c2b + __c1;
1457 const double __c3 = __c2 + 1;
1458 const double __c4 = __c3 + 1;
1460 const double __e178 = 1.0129030479320018583185514777512983L;
1461 const double __c5 = __c4 + __e178;
1462 const double __c = __param._M_cb + __c5;
1463 const double __2cx = 2 * (2 * __m + __param._M_d);
1465 bool __reject =
true;
1468 const double __u = __c * __aurng();
1469 const double __e = -
std::log(1.0 - __aurng());
1475 const double __n = _M_nd(__urng);
1476 const double __y = -
std::abs(__n) * __param._M_sm - 1;
1477 __x = std::floor(__y);
1478 __w = -__n * __n / 2;
1482 else if (__u <= __c2)
1484 const double __n = _M_nd(__urng);
1485 const double __y = 1 +
std::abs(__n) * __param._M_scx;
1486 __x = std::ceil(__y);
1487 __w = __y * (2 - __y) * __param._M_1cx;
1488 if (__x > __param._M_d)
1491 else if (__u <= __c3)
1495 else if (__u <= __c4)
1497 else if (__u <= __c5)
1501 const double __v = -
std::log(1.0 - __aurng());
1502 const double __y = __param._M_d
1503 + __v * __2cx / __param._M_d;
1504 __x = std::ceil(__y);
1505 __w = -__param._M_d * __param._M_1cx * (1 + __y / 2);
1508 __reject = (__w - __e - __x * __param._M_lm_thr
1509 > __param._M_lfm - std::lgamma(__x + __m + 1));
1511 __reject |= __x + __m >= __thr;
1521 double __prod = 1.0;
1525 __prod *= __aurng();
1528 while (__prod > __param._M_lm_thr);
1534 template<
typename _IntType>
1535 template<
typename _ForwardIterator,
1536 typename _UniformRandomNumberGenerator>
1540 _UniformRandomNumberGenerator& __urng,
1541 const param_type& __param)
1543 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1546 *__f++ = this->operator()(__urng, __param);
1549 template<typename _IntType,
1550 typename _CharT, typename _Traits>
1556 typedef typename __ostream_type::ios_base __ios_base;
1558 const typename __ios_base::fmtflags __flags = __os.
flags();
1559 const _CharT __fill = __os.fill();
1561 const _CharT __space = __os.widen(
' ');
1566 __os << __x.mean() << __space << __x._M_nd;
1568 __os.flags(__flags);
1570 __os.precision(__precision);
1574 template<
typename _IntType,
1575 typename _CharT,
typename _Traits>
1578 poisson_distribution<_IntType>& __x)
1581 typedef typename __istream_type::ios_base __ios_base;
1583 const typename __ios_base::fmtflags __flags = __is.
flags();
1587 __is >> __mean >> __x._M_nd;
1588 __x.param(
typename poisson_distribution<_IntType>::param_type(__mean));
1590 __is.
flags(__flags);
1595 template<
typename _IntType>
1597 binomial_distribution<_IntType>::param_type::
1600 const double __p12 = _M_p <= 0.5 ? _M_p : 1.0 - _M_p;
1604 #if _GLIBCXX_USE_C99_MATH_TR1
1605 if (_M_t * __p12 >= 8)
1608 const double __np = std::floor(_M_t * __p12);
1609 const double __pa = __np / _M_t;
1610 const double __1p = 1 - __pa;
1612 const double __pi_4 = 0.7853981633974483096156608458198757L;
1613 const double __d1x =
1615 / (81 * __pi_4 * __1p)));
1616 _M_d1 = std::round(
std::max(1.0, __d1x));
1617 const double __d2x =
1619 / (__pi_4 * __pa)));
1620 _M_d2 = std::round(
std::max(1.0, __d2x));
1623 const double __spi_2 = 1.2533141373155002512078826424055226L;
1624 _M_s1 =
std::sqrt(__np * __1p) * (1 + _M_d1 / (4 * __np));
1625 _M_s2 =
std::sqrt(__np * __1p) * (1 + _M_d2 / (4 * _M_t * __1p));
1626 _M_c = 2 * _M_d1 / __np;
1627 _M_a1 =
std::exp(_M_c) * _M_s1 * __spi_2;
1628 const double __a12 = _M_a1 + _M_s2 * __spi_2;
1629 const double __s1s = _M_s1 * _M_s1;
1630 _M_a123 = __a12 + (
std::exp(_M_d1 / (_M_t * __1p))
1632 *
std::exp(-_M_d1 * _M_d1 / (2 * __s1s)));
1633 const double __s2s = _M_s2 * _M_s2;
1634 _M_s = (_M_a123 + 2 * __s2s / _M_d2
1635 *
std::exp(-_M_d2 * _M_d2 / (2 * __s2s)));
1636 _M_lf = (std::lgamma(__np + 1)
1637 + std::lgamma(_M_t - __np + 1));
1640 _M_q = -
std::log(1 - (__p12 - __pa) / __1p);
1647 template<
typename _IntType>
1648 template<
typename _UniformRandomNumberGenerator>
1649 typename binomial_distribution<_IntType>::result_type
1650 binomial_distribution<_IntType>::
1651 _M_waiting(_UniformRandomNumberGenerator& __urng,
1652 _IntType __t,
double __q)
1656 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1663 const double __e = -
std::log(1.0 - __aurng());
1664 __sum += __e / (__t - __x);
1667 while (__sum <= __q);
1682 template<
typename _IntType>
1683 template<
typename _UniformRandomNumberGenerator>
1684 typename binomial_distribution<_IntType>::result_type
1687 const param_type& __param)
1690 const _IntType __t = __param.t();
1691 const double __p = __param.p();
1692 const double __p12 = __p <= 0.5 ? __p : 1.0 - __p;
1693 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1696 #if _GLIBCXX_USE_C99_MATH_TR1
1697 if (!__param._M_easy)
1702 const double __naf =
1704 const double __thr =
1707 const double __np = std::floor(__t * __p12);
1710 const double __spi_2 = 1.2533141373155002512078826424055226L;
1711 const double __a1 = __param._M_a1;
1712 const double __a12 = __a1 + __param._M_s2 * __spi_2;
1713 const double __a123 = __param._M_a123;
1714 const double __s1s = __param._M_s1 * __param._M_s1;
1715 const double __s2s = __param._M_s2 * __param._M_s2;
1720 const double __u = __param._M_s * __aurng();
1726 const double __n = _M_nd(__urng);
1727 const double __y = __param._M_s1 *
std::abs(__n);
1728 __reject = __y >= __param._M_d1;
1731 const double __e = -
std::log(1.0 - __aurng());
1732 __x = std::floor(__y);
1733 __v = -__e - __n * __n / 2 + __param._M_c;
1736 else if (__u <= __a12)
1738 const double __n = _M_nd(__urng);
1739 const double __y = __param._M_s2 *
std::abs(__n);
1740 __reject = __y >= __param._M_d2;
1743 const double __e = -
std::log(1.0 - __aurng());
1744 __x = std::floor(-__y);
1745 __v = -__e - __n * __n / 2;
1748 else if (__u <= __a123)
1750 const double __e1 = -
std::log(1.0 - __aurng());
1751 const double __e2 = -
std::log(1.0 - __aurng());
1753 const double __y = __param._M_d1
1754 + 2 * __s1s * __e1 / __param._M_d1;
1755 __x = std::floor(__y);
1756 __v = (-__e2 + __param._M_d1 * (1 / (__t - __np)
1757 -__y / (2 * __s1s)));
1762 const double __e1 = -
std::log(1.0 - __aurng());
1763 const double __e2 = -
std::log(1.0 - __aurng());
1765 const double __y = __param._M_d2
1766 + 2 * __s2s * __e1 / __param._M_d2;
1767 __x = std::floor(-__y);
1768 __v = -__e2 - __param._M_d2 * __y / (2 * __s2s);
1772 __reject = __reject || __x < -__np || __x > __t - __np;
1775 const double __lfx =
1776 std::lgamma(__np + __x + 1)
1777 + std::lgamma(__t - (__np + __x) + 1);
1778 __reject = __v > __param._M_lf - __lfx
1779 + __x * __param._M_lp1p;
1782 __reject |= __x + __np >= __thr;
1786 __x += __np + __naf;
1788 const _IntType __z = _M_waiting(__urng, __t - _IntType(__x),
1790 __ret = _IntType(__x) + __z;
1794 __ret = _M_waiting(__urng, __t, __param._M_q);
1797 __ret = __t - __ret;
1801 template<
typename _IntType>
1802 template<
typename _ForwardIterator,
1803 typename _UniformRandomNumberGenerator>
1807 _UniformRandomNumberGenerator& __urng,
1808 const param_type& __param)
1810 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1813 *__f++ = this->operator()(__urng, __param);
1816 template<typename _IntType,
1817 typename _CharT, typename _Traits>
1823 typedef typename __ostream_type::ios_base __ios_base;
1825 const typename __ios_base::fmtflags __flags = __os.
flags();
1826 const _CharT __fill = __os.fill();
1828 const _CharT __space = __os.widen(
' ');
1833 __os << __x.t() << __space << __x.p()
1834 << __space << __x._M_nd;
1836 __os.flags(__flags);
1838 __os.precision(__precision);
1842 template<
typename _IntType,
1843 typename _CharT,
typename _Traits>
1846 binomial_distribution<_IntType>& __x)
1849 typedef typename __istream_type::ios_base __ios_base;
1851 const typename __ios_base::fmtflags __flags = __is.
flags();
1856 __is >> __t >> __p >> __x._M_nd;
1857 __x.param(
typename binomial_distribution<_IntType>::
1858 param_type(__t, __p));
1860 __is.
flags(__flags);
1865 template<
typename _RealType>
1866 template<
typename _ForwardIterator,
1867 typename _UniformRandomNumberGenerator>
1871 _UniformRandomNumberGenerator& __urng,
1872 const param_type& __p)
1874 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1875 __detail::_Adaptor<_UniformRandomNumberGenerator,
result_type>
1881 template<typename _RealType, typename _CharT, typename _Traits>
1882 std::basic_ostream<_CharT, _Traits>&
1887 typedef typename __ostream_type::ios_base __ios_base;
1889 const typename __ios_base::fmtflags __flags = __os.
flags();
1890 const _CharT __fill = __os.fill();
1893 __os.fill(__os.widen(
' '));
1896 __os << __x.lambda();
1898 __os.flags(__flags);
1900 __os.precision(__precision);
1904 template<
typename _RealType,
typename _CharT,
typename _Traits>
1910 typedef typename __istream_type::ios_base __ios_base;
1912 const typename __ios_base::fmtflags __flags = __is.
flags();
1918 param_type(__lambda));
1920 __is.
flags(__flags);
1931 template<
typename _RealType>
1932 template<
typename _UniformRandomNumberGenerator>
1933 typename normal_distribution<_RealType>::result_type
1936 const param_type& __param)
1939 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1942 if (_M_saved_available)
1944 _M_saved_available =
false;
1954 __r2 = __x * __x + __y * __y;
1956 while (__r2 > 1.0 || __r2 == 0.0);
1959 _M_saved = __x * __mult;
1960 _M_saved_available =
true;
1961 __ret = __y * __mult;
1964 __ret = __ret * __param.stddev() + __param.mean();
1968 template<
typename _RealType>
1969 template<
typename _ForwardIterator,
1970 typename _UniformRandomNumberGenerator>
1974 _UniformRandomNumberGenerator& __urng,
1975 const param_type& __param)
1977 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1982 if (_M_saved_available)
1984 _M_saved_available =
false;
1985 *__f++ = _M_saved * __param.stddev() + __param.mean();
1991 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1994 while (__f + 1 < __t)
2001 __r2 = __x * __x + __y * __y;
2003 while (__r2 > 1.0 || __r2 == 0.0);
2006 *__f++ = __y * __mult * __param.stddev() + __param.mean();
2007 *__f++ = __x * __mult * __param.stddev() + __param.mean();
2017 __r2 = __x * __x + __y * __y;
2019 while (__r2 > 1.0 || __r2 == 0.0);
2022 _M_saved = __x * __mult;
2023 _M_saved_available =
true;
2024 *__f = __y * __mult * __param.stddev() + __param.mean();
2028 template<
typename _RealType>
2033 if (__d1._M_param == __d2._M_param
2034 && __d1._M_saved_available == __d2._M_saved_available)
2036 if (__d1._M_saved_available
2037 && __d1._M_saved == __d2._M_saved)
2039 else if(!__d1._M_saved_available)
2048 template<
typename _RealType,
typename _CharT,
typename _Traits>
2050 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2051 const normal_distribution<_RealType>& __x)
2054 typedef typename __ostream_type::ios_base __ios_base;
2056 const typename __ios_base::fmtflags __flags = __os.
flags();
2057 const _CharT __fill = __os.
fill();
2059 const _CharT __space = __os.
widen(
' ');
2064 __os << __x.mean() << __space << __x.stddev()
2065 << __space << __x._M_saved_available;
2066 if (__x._M_saved_available)
2067 __os << __space << __x._M_saved;
2069 __os.
flags(__flags);
2075 template<
typename _RealType,
typename _CharT,
typename _Traits>
2078 normal_distribution<_RealType>& __x)
2081 typedef typename __istream_type::ios_base __ios_base;
2083 const typename __ios_base::fmtflags __flags = __is.
flags();
2086 double __mean, __stddev;
2087 __is >> __mean >> __stddev
2088 >> __x._M_saved_available;
2089 if (__x._M_saved_available)
2090 __is >> __x._M_saved;
2091 __x.param(
typename normal_distribution<_RealType>::
2092 param_type(__mean, __stddev));
2094 __is.
flags(__flags);
2099 template<
typename _RealType>
2100 template<
typename _ForwardIterator,
2101 typename _UniformRandomNumberGenerator>
2103 lognormal_distribution<_RealType>::
2104 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2105 _UniformRandomNumberGenerator& __urng,
2106 const param_type& __p)
2108 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2110 *__f++ = std::
exp(__p.s() * _M_nd(__urng) + __p.m());
2113 template<typename _RealType, typename _CharT, typename _Traits>
2114 std::basic_ostream<_CharT, _Traits>&
2115 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2116 const lognormal_distribution<_RealType>& __x)
2119 typedef typename __ostream_type::ios_base __ios_base;
2121 const typename __ios_base::fmtflags __flags = __os.
flags();
2122 const _CharT __fill = __os.fill();
2124 const _CharT __space = __os.widen(
' ');
2129 __os << __x.m() << __space << __x.s()
2130 << __space << __x._M_nd;
2132 __os.flags(__flags);
2134 __os.precision(__precision);
2138 template<
typename _RealType,
typename _CharT,
typename _Traits>
2141 lognormal_distribution<_RealType>& __x)
2144 typedef typename __istream_type::ios_base __ios_base;
2146 const typename __ios_base::fmtflags __flags = __is.
flags();
2150 __is >> __m >> __s >> __x._M_nd;
2151 __x.param(
typename lognormal_distribution<_RealType>::
2152 param_type(__m, __s));
2154 __is.
flags(__flags);
2158 template<
typename _RealType>
2159 template<
typename _ForwardIterator,
2160 typename _UniformRandomNumberGenerator>
2164 _UniformRandomNumberGenerator& __urng)
2166 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2168 *__f++ = 2 * _M_gd(__urng);
2171 template<typename _RealType>
2172 template<typename _ForwardIterator,
2173 typename _UniformRandomNumberGenerator>
2175 std::chi_squared_distribution<_RealType>::
2176 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2177 _UniformRandomNumberGenerator& __urng,
2179 std::gamma_distribution<
result_type>::param_type& __p)
2181 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2183 *__f++ = 2 * _M_gd(__urng, __p);
2186 template<typename _RealType, typename _CharT, typename _Traits>
2187 std::basic_ostream<_CharT, _Traits>&
2188 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2189 const chi_squared_distribution<_RealType>& __x)
2192 typedef typename __ostream_type::ios_base __ios_base;
2194 const typename __ios_base::fmtflags __flags = __os.
flags();
2195 const _CharT __fill = __os.fill();
2197 const _CharT __space = __os.widen(
' ');
2202 __os << __x.n() << __space << __x._M_gd;
2204 __os.flags(__flags);
2206 __os.precision(__precision);
2210 template<
typename _RealType,
typename _CharT,
typename _Traits>
2213 chi_squared_distribution<_RealType>& __x)
2216 typedef typename __istream_type::ios_base __ios_base;
2218 const typename __ios_base::fmtflags __flags = __is.
flags();
2222 __is >> __n >> __x._M_gd;
2223 __x.param(
typename chi_squared_distribution<_RealType>::
2226 __is.
flags(__flags);
2231 template<
typename _RealType>
2232 template<
typename _UniformRandomNumberGenerator>
2233 typename cauchy_distribution<_RealType>::result_type
2235 operator()(_UniformRandomNumberGenerator& __urng,
2236 const param_type& __p)
2238 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2245 const _RealType __pi = 3.1415926535897932384626433832795029L;
2246 return __p.a() + __p.b() *
std::tan(__pi * __u);
2249 template<
typename _RealType>
2250 template<
typename _ForwardIterator,
2251 typename _UniformRandomNumberGenerator>
2253 cauchy_distribution<_RealType>::
2254 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2255 _UniformRandomNumberGenerator& __urng,
2256 const param_type& __p)
2258 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2259 const _RealType __pi = 3.1415926535897932384626433832795029L;
2260 __detail::_Adaptor<_UniformRandomNumberGenerator,
result_type>
2269 *__f++ = __p.a() + __p.b() *
std::tan(__pi * __u);
2273 template<
typename _RealType,
typename _CharT,
typename _Traits>
2275 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
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.a() << __space << __x.b();
2291 __os.flags(__flags);
2293 __os.precision(__precision);
2297 template<
typename _RealType,
typename _CharT,
typename _Traits>
2303 typedef typename __istream_type::ios_base __ios_base;
2305 const typename __ios_base::fmtflags __flags = __is.
flags();
2311 param_type(__a, __b));
2313 __is.
flags(__flags);
2318 template<
typename _RealType>
2319 template<
typename _ForwardIterator,
2320 typename _UniformRandomNumberGenerator>
2324 _UniformRandomNumberGenerator& __urng)
2326 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2328 *__f++ = ((_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()));
2331 template<typename _RealType>
2332 template<typename _ForwardIterator,
2333 typename _UniformRandomNumberGenerator>
2335 std::fisher_f_distribution<_RealType>::
2336 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2337 _UniformRandomNumberGenerator& __urng,
2338 const param_type& __p)
2340 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2341 typedef typename std::gamma_distribution<
result_type>::param_type
2343 param_type __p1(__p.m() / 2);
2344 param_type __p2(__p.n() / 2);
2346 *__f++ = ((_M_gd_x(__urng, __p1) * n())
2347 / (_M_gd_y(__urng, __p2) * m()));
2350 template<typename _RealType, typename _CharT, typename _Traits>
2351 std::basic_ostream<_CharT, _Traits>&
2352 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2353 const fisher_f_distribution<_RealType>& __x)
2356 typedef typename __ostream_type::ios_base __ios_base;
2358 const typename __ios_base::fmtflags __flags = __os.
flags();
2359 const _CharT __fill = __os.fill();
2361 const _CharT __space = __os.widen(
' ');
2366 __os << __x.m() << __space << __x.n()
2367 << __space << __x._M_gd_x << __space << __x._M_gd_y;
2369 __os.flags(__flags);
2371 __os.precision(__precision);
2375 template<
typename _RealType,
typename _CharT,
typename _Traits>
2378 fisher_f_distribution<_RealType>& __x)
2381 typedef typename __istream_type::ios_base __ios_base;
2383 const typename __ios_base::fmtflags __flags = __is.
flags();
2387 __is >> __m >> __n >> __x._M_gd_x >> __x._M_gd_y;
2388 __x.param(
typename fisher_f_distribution<_RealType>::
2389 param_type(__m, __n));
2391 __is.
flags(__flags);
2396 template<
typename _RealType>
2397 template<
typename _ForwardIterator,
2398 typename _UniformRandomNumberGenerator>
2402 _UniformRandomNumberGenerator& __urng)
2404 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2406 *__f++ = _M_nd(__urng) * std::
sqrt(n() / _M_gd(__urng));
2409 template<typename _RealType>
2410 template<typename _ForwardIterator,
2411 typename _UniformRandomNumberGenerator>
2413 std::student_t_distribution<_RealType>::
2414 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2415 _UniformRandomNumberGenerator& __urng,
2416 const param_type& __p)
2418 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2419 typename std::gamma_distribution<
result_type>::param_type
2420 __p2(__p.n() / 2, 2);
2422 *__f++ = _M_nd(__urng) * std::
sqrt(__p.n() / _M_gd(__urng, __p2));
2425 template<typename _RealType, typename _CharT, typename _Traits>
2426 std::basic_ostream<_CharT, _Traits>&
2427 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2428 const student_t_distribution<_RealType>& __x)
2431 typedef typename __ostream_type::ios_base __ios_base;
2433 const typename __ios_base::fmtflags __flags = __os.
flags();
2434 const _CharT __fill = __os.fill();
2436 const _CharT __space = __os.widen(
' ');
2441 __os << __x.n() << __space << __x._M_nd << __space << __x._M_gd;
2443 __os.flags(__flags);
2445 __os.precision(__precision);
2449 template<
typename _RealType,
typename _CharT,
typename _Traits>
2452 student_t_distribution<_RealType>& __x)
2455 typedef typename __istream_type::ios_base __ios_base;
2457 const typename __ios_base::fmtflags __flags = __is.
flags();
2461 __is >> __n >> __x._M_nd >> __x._M_gd;
2462 __x.param(
typename student_t_distribution<_RealType>::param_type(__n));
2464 __is.
flags(__flags);
2469 template<
typename _RealType>
2471 gamma_distribution<_RealType>::param_type::
2474 _M_malpha = _M_alpha < 1.0 ? _M_alpha + _RealType(1.0) : _M_alpha;
2476 const _RealType __a1 = _M_malpha - _RealType(1.0) / _RealType(3.0);
2477 _M_a2 = _RealType(1.0) /
std::sqrt(_RealType(9.0) * __a1);
2485 template<
typename _RealType>
2486 template<
typename _UniformRandomNumberGenerator>
2487 typename gamma_distribution<_RealType>::result_type
2490 const param_type& __param)
2492 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2497 - _RealType(1.0) / _RealType(3.0));
2503 __n = _M_nd(__urng);
2508 __v = __v * __v * __v;
2511 while (__u >
result_type(1.0) - 0.331 * __n * __n * __n * __n
2512 && (
std::log(__u) > (0.5 * __n * __n + __a1
2515 if (__param.alpha() == __param._M_malpha)
2516 return __a1 * __v * __param.beta();
2524 * __a1 * __v * __param.beta());
2528 template<
typename _RealType>
2529 template<
typename _ForwardIterator,
2530 typename _UniformRandomNumberGenerator>
2534 _UniformRandomNumberGenerator& __urng,
2535 const param_type& __param)
2537 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2538 __detail::_Adaptor<_UniformRandomNumberGenerator,
result_type>
2543 - _RealType(1.0) / _RealType(3.0));
2545 if (__param.alpha() == __param._M_malpha)
2552 __n = _M_nd(__urng);
2557 __v = __v * __v * __v;
2560 while (__u >
result_type(1.0) - 0.331 * __n * __n * __n * __n
2561 && (
std::log(__u) > (0.5 * __n * __n + __a1
2564 *__f++ = __a1 * __v * __param.beta();
2573 __n = _M_nd(__urng);
2578 __v = __v * __v * __v;
2581 while (__u >
result_type(1.0) - 0.331 * __n * __n * __n * __n
2582 && (
std::log(__u) > (0.5 * __n * __n + __a1
2590 * __a1 * __v * __param.beta());
2594 template<
typename _RealType,
typename _CharT,
typename _Traits>
2596 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2597 const gamma_distribution<_RealType>& __x)
2600 typedef typename __ostream_type::ios_base __ios_base;
2602 const typename __ios_base::fmtflags __flags = __os.
flags();
2603 const _CharT __fill = __os.
fill();
2605 const _CharT __space = __os.
widen(
' ');
2610 __os << __x.alpha() << __space << __x.beta()
2611 << __space << __x._M_nd;
2613 __os.
flags(__flags);
2619 template<
typename _RealType,
typename _CharT,
typename _Traits>
2622 gamma_distribution<_RealType>& __x)
2625 typedef typename __istream_type::ios_base __ios_base;
2627 const typename __ios_base::fmtflags __flags = __is.
flags();
2630 _RealType __alpha_val, __beta_val;
2631 __is >> __alpha_val >> __beta_val >> __x._M_nd;
2632 __x.param(
typename gamma_distribution<_RealType>::
2633 param_type(__alpha_val, __beta_val));
2635 __is.
flags(__flags);
2640 template<
typename _RealType>
2641 template<
typename _UniformRandomNumberGenerator>
2642 typename weibull_distribution<_RealType>::result_type
2644 operator()(_UniformRandomNumberGenerator& __urng,
2645 const param_type& __p)
2647 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2653 template<
typename _RealType>
2654 template<
typename _ForwardIterator,
2655 typename _UniformRandomNumberGenerator>
2657 weibull_distribution<_RealType>::
2658 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2659 _UniformRandomNumberGenerator& __urng,
2660 const param_type& __p)
2662 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2663 __detail::_Adaptor<_UniformRandomNumberGenerator,
result_type>
2672 template<typename _RealType, typename _CharT, typename _Traits>
2673 std::basic_ostream<_CharT, _Traits>&
2678 typedef typename __ostream_type::ios_base __ios_base;
2680 const typename __ios_base::fmtflags __flags = __os.
flags();
2681 const _CharT __fill = __os.fill();
2683 const _CharT __space = __os.widen(
' ');
2688 __os << __x.a() << __space << __x.b();
2690 __os.flags(__flags);
2692 __os.precision(__precision);
2696 template<
typename _RealType,
typename _CharT,
typename _Traits>
2702 typedef typename __istream_type::ios_base __ios_base;
2704 const typename __ios_base::fmtflags __flags = __is.
flags();
2710 param_type(__a, __b));
2712 __is.
flags(__flags);
2717 template<
typename _RealType>
2718 template<
typename _UniformRandomNumberGenerator>
2719 typename extreme_value_distribution<_RealType>::result_type
2721 operator()(_UniformRandomNumberGenerator& __urng,
2722 const param_type& __p)
2724 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2730 template<
typename _RealType>
2731 template<
typename _ForwardIterator,
2732 typename _UniformRandomNumberGenerator>
2734 extreme_value_distribution<_RealType>::
2735 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2736 _UniformRandomNumberGenerator& __urng,
2737 const param_type& __p)
2739 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2740 __detail::_Adaptor<_UniformRandomNumberGenerator,
result_type>
2748 template<typename _RealType, typename _CharT, typename _Traits>
2749 std::basic_ostream<_CharT, _Traits>&
2754 typedef typename __ostream_type::ios_base __ios_base;
2756 const typename __ios_base::fmtflags __flags = __os.
flags();
2757 const _CharT __fill = __os.fill();
2759 const _CharT __space = __os.widen(
' ');
2764 __os << __x.a() << __space << __x.b();
2766 __os.flags(__flags);
2768 __os.precision(__precision);
2772 template<
typename _RealType,
typename _CharT,
typename _Traits>
2778 typedef typename __istream_type::ios_base __ios_base;
2780 const typename __ios_base::fmtflags __flags = __is.
flags();
2786 param_type(__a, __b));
2788 __is.
flags(__flags);
2793 template<
typename _IntType>
2795 discrete_distribution<_IntType>::param_type::
2798 if (_M_prob.size() < 2)
2805 _M_prob.end(), 0.0);
2807 __detail::__normalize(_M_prob.begin(), _M_prob.end(), _M_prob.begin(),
2810 _M_cp.reserve(_M_prob.size());
2814 _M_cp[_M_cp.size() - 1] = 1.0;
2817 template<
typename _IntType>
2818 template<
typename _Func>
2819 discrete_distribution<_IntType>::param_type::
2820 param_type(
size_t __nw,
double __xmin,
double __xmax, _Func __fw)
2821 : _M_prob(), _M_cp()
2823 const size_t __n = __nw == 0 ? 1 : __nw;
2824 const double __delta = (__xmax - __xmin) / __n;
2826 _M_prob.reserve(__n);
2827 for (
size_t __k = 0; __k < __nw; ++__k)
2828 _M_prob.push_back(__fw(__xmin + __k * __delta + 0.5 * __delta));
2833 template<
typename _IntType>
2834 template<
typename _UniformRandomNumberGenerator>
2835 typename discrete_distribution<_IntType>::result_type
2836 discrete_distribution<_IntType>::
2837 operator()(_UniformRandomNumberGenerator& __urng,
2838 const param_type& __param)
2840 if (__param._M_cp.empty())
2841 return result_type(0);
2843 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2846 const double __p = __aurng();
2848 __param._M_cp.end(), __p);
2850 return __pos - __param._M_cp.begin();
2853 template<
typename _IntType>
2854 template<
typename _ForwardIterator,
2855 typename _UniformRandomNumberGenerator>
2857 discrete_distribution<_IntType>::
2858 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2859 _UniformRandomNumberGenerator& __urng,
2860 const param_type& __param)
2862 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2864 if (__param._M_cp.empty())
2867 *__f++ = result_type(0);
2871 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2876 const double __p = __aurng();
2878 __param._M_cp.end(), __p);
2880 *__f++ = __pos - __param._M_cp.begin();
2884 template<
typename _IntType,
typename _CharT,
typename _Traits>
2886 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2887 const discrete_distribution<_IntType>& __x)
2890 typedef typename __ostream_type::ios_base __ios_base;
2892 const typename __ios_base::fmtflags __flags = __os.
flags();
2893 const _CharT __fill = __os.
fill();
2895 const _CharT __space = __os.
widen(
' ');
2901 __os << __prob.
size();
2902 for (
auto __dit = __prob.
begin(); __dit != __prob.
end(); ++__dit)
2903 __os << __space << *__dit;
2905 __os.
flags(__flags);
2911 template<
typename _IntType,
typename _CharT,
typename _Traits>
2914 discrete_distribution<_IntType>& __x)
2917 typedef typename __istream_type::ios_base __ios_base;
2919 const typename __ios_base::fmtflags __flags = __is.
flags();
2927 for (; __n != 0; --__n)
2934 __x.param(
typename discrete_distribution<_IntType>::
2935 param_type(__prob_vec.
begin(), __prob_vec.
end()));
2937 __is.
flags(__flags);
2942 template<
typename _RealType>
2944 piecewise_constant_distribution<_RealType>::param_type::
2947 if (_M_int.size() < 2
2948 || (_M_int.size() == 2
2949 && _M_int[0] == _RealType(0)
2950 && _M_int[1] == _RealType(1)))
2960 __detail::__normalize(_M_den.begin(), _M_den.end(), _M_den.begin(),
2963 _M_cp.reserve(_M_den.size());
2968 _M_cp[_M_cp.size() - 1] = 1.0;
2970 for (
size_t __k = 0; __k < _M_den.size(); ++__k)
2971 _M_den[__k] /= _M_int[__k + 1] - _M_int[__k];
2974 template<
typename _RealType>
2975 template<
typename _InputIteratorB,
typename _InputIteratorW>
2976 piecewise_constant_distribution<_RealType>::param_type::
2977 param_type(_InputIteratorB __bbegin,
2978 _InputIteratorB __bend,
2979 _InputIteratorW __wbegin)
2980 : _M_int(), _M_den(), _M_cp()
2982 if (__bbegin != __bend)
2986 _M_int.push_back(*__bbegin);
2988 if (__bbegin == __bend)
2991 _M_den.push_back(*__wbegin);
2999 template<
typename _RealType>
3000 template<
typename _Func>
3001 piecewise_constant_distribution<_RealType>::param_type::
3002 param_type(initializer_list<_RealType> __bl, _Func __fw)
3003 : _M_int(), _M_den(), _M_cp()
3005 _M_int.reserve(__bl.size());
3006 for (
auto __biter = __bl.begin(); __biter != __bl.end(); ++__biter)
3007 _M_int.push_back(*__biter);
3009 _M_den.reserve(_M_int.size() - 1);
3010 for (
size_t __k = 0; __k < _M_int.size() - 1; ++__k)
3011 _M_den.push_back(__fw(0.5 * (_M_int[__k + 1] + _M_int[__k])));
3016 template<
typename _RealType>
3017 template<
typename _Func>
3018 piecewise_constant_distribution<_RealType>::param_type::
3019 param_type(
size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
3020 : _M_int(), _M_den(), _M_cp()
3022 const size_t __n = __nw == 0 ? 1 : __nw;
3023 const _RealType __delta = (__xmax - __xmin) / __n;
3025 _M_int.reserve(__n + 1);
3026 for (
size_t __k = 0; __k <= __nw; ++__k)
3027 _M_int.push_back(__xmin + __k * __delta);
3029 _M_den.reserve(__n);
3030 for (
size_t __k = 0; __k < __nw; ++__k)
3031 _M_den.push_back(__fw(_M_int[__k] + 0.5 * __delta));
3036 template<
typename _RealType>
3037 template<
typename _UniformRandomNumberGenerator>
3038 typename piecewise_constant_distribution<_RealType>::result_type
3039 piecewise_constant_distribution<_RealType>::
3040 operator()(_UniformRandomNumberGenerator& __urng,
3041 const param_type& __param)
3043 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
3046 const double __p = __aurng();
3047 if (__param._M_cp.empty())
3051 __param._M_cp.end(), __p);
3052 const size_t __i = __pos - __param._M_cp.begin();
3054 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
3056 return __param._M_int[__i] + (__p - __pref) / __param._M_den[__i];
3059 template<
typename _RealType>
3060 template<
typename _ForwardIterator,
3061 typename _UniformRandomNumberGenerator>
3063 piecewise_constant_distribution<_RealType>::
3064 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3065 _UniformRandomNumberGenerator& __urng,
3066 const param_type& __param)
3068 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3069 __detail::_Adaptor<_UniformRandomNumberGenerator,
double>
3072 if (__param._M_cp.empty())
3081 const double __p = __aurng();
3084 __param._M_cp.end(), __p);
3085 const size_t __i = __pos - __param._M_cp.begin();
3087 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
3089 *__f++ = (__param._M_int[__i]
3090 + (__p - __pref) / __param._M_den[__i]);
3094 template<
typename _RealType,
typename _CharT,
typename _Traits>
3096 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3097 const piecewise_constant_distribution<_RealType>& __x)
3100 typedef typename __ostream_type::ios_base __ios_base;
3102 const typename __ios_base::fmtflags __flags = __os.
flags();
3103 const _CharT __fill = __os.
fill();
3105 const _CharT __space = __os.
widen(
' ');
3111 __os << __int.
size() - 1;
3113 for (
auto __xit = __int.
begin(); __xit != __int.
end(); ++__xit)
3114 __os << __space << *__xit;
3117 for (
auto __dit = __den.
begin(); __dit != __den.
end(); ++__dit)
3118 __os << __space << *__dit;
3120 __os.
flags(__flags);
3126 template<
typename _RealType,
typename _CharT,
typename _Traits>
3129 piecewise_constant_distribution<_RealType>& __x)
3132 typedef typename __istream_type::ios_base __ios_base;
3134 const typename __ios_base::fmtflags __flags = __is.
flags();
3142 for (
size_t __i = 0; __i <= __n; ++__i)
3151 for (
size_t __i = 0; __i < __n; ++__i)
3158 __x.param(
typename piecewise_constant_distribution<_RealType>::
3159 param_type(__int_vec.
begin(), __int_vec.
end(), __den_vec.
begin()));
3161 __is.
flags(__flags);
3166 template<
typename _RealType>
3168 piecewise_linear_distribution<_RealType>::param_type::
3171 if (_M_int.size() < 2
3172 || (_M_int.size() == 2
3173 && _M_int[0] == _RealType(0)
3174 && _M_int[1] == _RealType(1)
3175 && _M_den[0] == _M_den[1]))
3183 _M_cp.reserve(_M_int.size() - 1);
3184 _M_m.reserve(_M_int.size() - 1);
3185 for (
size_t __k = 0; __k < _M_int.size() - 1; ++__k)
3187 const _RealType __delta = _M_int[__k + 1] - _M_int[__k];
3188 __sum += 0.5 * (_M_den[__k + 1] + _M_den[__k]) * __delta;
3189 _M_cp.push_back(__sum);
3190 _M_m.push_back((_M_den[__k + 1] - _M_den[__k]) / __delta);
3194 __detail::__normalize(_M_den.begin(), _M_den.end(), _M_den.begin(),
3197 __detail::__normalize(_M_cp.begin(), _M_cp.end(), _M_cp.begin(), __sum);
3199 __detail::__normalize(_M_m.begin(), _M_m.end(), _M_m.begin(), __sum);
3202 _M_cp[_M_cp.size() - 1] = 1.0;
3205 template<
typename _RealType>
3206 template<
typename _InputIteratorB,
typename _InputIteratorW>
3207 piecewise_linear_distribution<_RealType>::param_type::
3208 param_type(_InputIteratorB __bbegin,
3209 _InputIteratorB __bend,
3210 _InputIteratorW __wbegin)
3211 : _M_int(), _M_den(), _M_cp(), _M_m()
3213 for (; __bbegin != __bend; ++__bbegin, ++__wbegin)
3215 _M_int.push_back(*__bbegin);
3216 _M_den.push_back(*__wbegin);
3222 template<
typename _RealType>
3223 template<
typename _Func>
3224 piecewise_linear_distribution<_RealType>::param_type::
3225 param_type(initializer_list<_RealType> __bl, _Func __fw)
3226 : _M_int(), _M_den(), _M_cp(), _M_m()
3228 _M_int.reserve(__bl.size());
3229 _M_den.reserve(__bl.size());
3230 for (
auto __biter = __bl.begin(); __biter != __bl.end(); ++__biter)
3232 _M_int.push_back(*__biter);
3233 _M_den.push_back(__fw(*__biter));
3239 template<
typename _RealType>
3240 template<
typename _Func>
3241 piecewise_linear_distribution<_RealType>::param_type::
3242 param_type(
size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
3243 : _M_int(), _M_den(), _M_cp(), _M_m()
3245 const size_t __n = __nw == 0 ? 1 : __nw;
3246 const _RealType __delta = (__xmax - __xmin) / __n;
3248 _M_int.reserve(__n + 1);
3249 _M_den.reserve(__n + 1);
3250 for (
size_t __k = 0; __k <= __nw; ++__k)
3252 _M_int.push_back(__xmin + __k * __delta);
3253 _M_den.push_back(__fw(_M_int[__k] + __delta));
3259 template<
typename _RealType>
3260 template<
typename _UniformRandomNumberGenerator>
3261 typename piecewise_linear_distribution<_RealType>::result_type
3262 piecewise_linear_distribution<_RealType>::
3263 operator()(_UniformRandomNumberGenerator& __urng,
3264 const param_type& __param)
3266 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
3269 const double __p = __aurng();
3270 if (__param._M_cp.empty())
3274 __param._M_cp.end(), __p);
3275 const size_t __i = __pos - __param._M_cp.begin();
3277 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
3279 const double __a = 0.5 * __param._M_m[__i];
3280 const double __b = __param._M_den[__i];
3281 const double __cm = __p - __pref;
3283 _RealType __x = __param._M_int[__i];
3288 const double __d = __b * __b + 4.0 * __a * __cm;
3289 __x += 0.5 * (
std::sqrt(__d) - __b) / __a;
3295 template<
typename _RealType>
3296 template<
typename _ForwardIterator,
3297 typename _UniformRandomNumberGenerator>
3299 piecewise_linear_distribution<_RealType>::
3300 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3301 _UniformRandomNumberGenerator& __urng,
3302 const param_type& __param)
3304 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3307 *__f++ = this->operator()(__urng, __param);
3310 template<typename _RealType, typename _CharT, typename _Traits>
3311 std::basic_ostream<_CharT, _Traits>&
3312 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3313 const piecewise_linear_distribution<_RealType>& __x)
3316 typedef typename __ostream_type::ios_base __ios_base;
3318 const typename __ios_base::fmtflags __flags = __os.
flags();
3319 const _CharT __fill = __os.fill();
3321 const _CharT __space = __os.widen(
' ');
3327 __os << __int.
size() - 1;
3329 for (
auto __xit = __int.
begin(); __xit != __int.
end(); ++__xit)
3330 __os << __space << *__xit;
3333 for (
auto __dit = __den.
begin(); __dit != __den.
end(); ++__dit)
3334 __os << __space << *__dit;
3336 __os.flags(__flags);
3338 __os.precision(__precision);
3342 template<
typename _RealType,
typename _CharT,
typename _Traits>
3345 piecewise_linear_distribution<_RealType>& __x)
3348 typedef typename __istream_type::ios_base __ios_base;
3350 const typename __ios_base::fmtflags __flags = __is.
flags();
3358 for (
size_t __i = 0; __i <= __n; ++__i)
3367 for (
size_t __i = 0; __i <= __n; ++__i)
3374 __x.param(
typename piecewise_linear_distribution<_RealType>::
3375 param_type(__int_vec.
begin(), __int_vec.
end(), __den_vec.
begin()));
3377 __is.
flags(__flags);
3382 template<
typename _IntType>
3385 for (
auto __iter = __il.begin(); __iter != __il.end(); ++__iter)
3386 _M_v.push_back(__detail::__mod<result_type,
3387 __detail::_Shift<result_type, 32>::__value>(*__iter));
3390 template<
typename _InputIterator>
3391 seed_seq::seed_seq(_InputIterator __begin, _InputIterator __end)
3393 for (_InputIterator __iter = __begin; __iter != __end; ++__iter)
3394 _M_v.push_back(__detail::__mod<result_type,
3395 __detail::_Shift<result_type, 32>::__value>(*__iter));
3398 template<
typename _RandomAccessIterator>
3400 seed_seq::generate(_RandomAccessIterator __begin,
3401 _RandomAccessIterator __end)
3403 typedef typename iterator_traits<_RandomAccessIterator>::value_type
3406 if (__begin == __end)
3409 std::fill(__begin, __end, _Type(0x8b8b8b8bu));
3411 const size_t __n = __end - __begin;
3412 const size_t __s = _M_v.size();
3413 const size_t __t = (__n >= 623) ? 11
3418 const size_t __p = (__n - __t) / 2;
3419 const size_t __q = __p + __t;
3420 const size_t __m =
std::max(
size_t(__s + 1), __n);
3422 for (
size_t __k = 0; __k < __m; ++__k)
3424 _Type __arg = (__begin[__k % __n]
3425 ^ __begin[(__k + __p) % __n]
3426 ^ __begin[(__k - 1) % __n]);
3427 _Type __r1 = __arg ^ (__arg >> 27);
3428 __r1 = __detail::__mod<_Type,
3429 __detail::_Shift<_Type, 32>::__value>(1664525u * __r1);
3433 else if (__k <= __s)
3434 __r2 += __k % __n + _M_v[__k - 1];
3437 __r2 = __detail::__mod<_Type,
3438 __detail::_Shift<_Type, 32>::__value>(__r2);
3439 __begin[(__k + __p) % __n] += __r1;
3440 __begin[(__k + __q) % __n] += __r2;
3441 __begin[__k % __n] = __r2;
3444 for (
size_t __k = __m; __k < __m + __n; ++__k)
3446 _Type __arg = (__begin[__k % __n]
3447 + __begin[(__k + __p) % __n]
3448 + __begin[(__k - 1) % __n]);
3449 _Type __r3 = __arg ^ (__arg >> 27);
3450 __r3 = __detail::__mod<_Type,
3451 __detail::_Shift<_Type, 32>::__value>(1566083941u * __r3);
3452 _Type __r4 = __r3 - __k % __n;
3453 __r4 = __detail::__mod<_Type,
3454 __detail::_Shift<_Type, 32>::__value>(__r4);
3455 __begin[(__k + __p) % __n] ^= __r3;
3456 __begin[(__k + __q) % __n] ^= __r4;
3457 __begin[__k % __n] = __r4;
3461 template<
typename _RealType,
size_t __bits,
3462 typename _UniformRandomNumberGenerator>
3469 const long double __r =
static_cast<long double>(__urng.max())
3470 - static_cast<long double>(__urng.min()) + 1.0L;
3472 size_t __k = std::max<size_t>(1UL, (__b + __log2r - 1UL) / __log2r);
3473 _RealType __sum = _RealType(0);
3474 _RealType __tmp = _RealType(1);
3475 for (; __k != 0; --__k)
3477 __sum += _RealType(__urng() - __urng.min()) * __tmp;
3480 return __sum / __tmp;
3483 _GLIBCXX_END_NAMESPACE_VERSION
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
ios_base & scientific(ios_base &__base)
Calls base.setf(ios_base::scientific, ios_base::floatfield).
friend bool operator==(const poisson_distribution &__d1, const poisson_distribution &__d2)
Return true if two Poisson distributions have the same parameters and the sequences that would be gen...
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
ios_base & dec(ios_base &__base)
Calls base.setf(ios_base::dec, ios_base::basefield).
param_type param() const
Returns the parameter set of the distribution.
A discrete geometric random number distribution.
param_type param() const
Returns the parameter set of the distribution.
A weibull_distribution random number distribution.
Produces random numbers by combining random numbers from some base engine to produce random numbers w...
_RandomNumberEngine::result_type result_type
complex< _Tp > exp(const complex< _Tp > &)
Return complex base e exponential of z.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
A fisher_f_distribution random number distribution.
streamsize precision() const
Flags access.
ios_base & fixed(ios_base &__base)
Calls base.setf(ios_base::fixed, ios_base::floatfield).
_Tp *return __arr
Return an iterator pointing to the first element of the array.
A Bernoulli random number distribution.
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...
_Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
Accumulate values in a range.
Template class basic_istream.
complex< _Tp > sqrt(const complex< _Tp > &)
Return complex square root of z.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
Properties of fundamental types.
_OutputIterator partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
Return list of partial sums.
complex< _Tp > pow(const complex< _Tp > &, int)
Return x to the y'th power.
A cauchy_distribution random number distribution.
constexpr int __lg(int __n)
This is a helper function for the sort routines and for random.tcc.
A student_t_distribution random number distribution.
A discrete binomial random number distribution.
A extreme_value_distribution random number distribution.
size_type size() const noexcept
param_type param() const
Returns the parameter set of the distribution.
static constexpr _Tp max() noexcept
ios_base & left(ios_base &__base)
Calls base.setf(ios_base::left, ios_base::adjustfield).
param_type param() const
Returns the parameter set of the distribution.
const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
iterator begin() noexcept
void clear(iostate __state=goodbit)
[Re]sets the error state.
A discrete Poisson random number distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
result_type operator()()
Gets the next value in the generated random number sequence.
void reserve(size_type __n)
Attempt to preallocate enough memory for specified number of elements.
_Tp abs(const complex< _Tp > &)
Return magnitude of z.
A chi_squared_distribution random number distribution.
A normal continuous distribution for random numbers.
void push_back(const value_type &__x)
Add data to the end of the vector.
param_type param() const
Returns the parameter set of the distribution.
complex< _Tp > tan(const complex< _Tp > &)
Return complex tangent of z.
ios_base & skipws(ios_base &__base)
Calls base.setf(ios_base::skipws).
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.
char_type widen(char __c) const
Widens characters.
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.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
_RealType generate_canonical(_UniformRandomNumberGenerator &__g)
A function template for converting the output of a (integral) uniform random number generator to a fl...
bitset< _Nb > operator>>(size_t __position) const noexcept
Self-explanatory.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
static constexpr _Tp epsilon() noexcept
fmtflags flags() const
Access to format flags.
char_type fill() const
Retrieves the empty character.
Uniform continuous distribution for random numbers.
Template class basic_ostream.
A model of a linear congruential random number generator.
static constexpr _Tp min() noexcept
param_type param() const
Returns the parameter set of the distribution.
Uniform discrete distribution for random numbers. A discrete random distribution on the range with e...
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
back_insert_iterator< _Container > back_inserter(_Container &__x)
complex< _Tp > log(const complex< _Tp > &)
Return complex natural logarithm of z.
An exponential continuous distribution for random numbers.
result_type operator()()
Gets the next value in the generated random number sequence.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
void seed(result_type __s=default_seed)
Reseeds the linear_congruential_engine random number generator engine sequence to the seed __s...