17a984708SDavid Chisnall// -*- C++ -*- 27a984708SDavid Chisnall//===--------------------------- random -----------------------------------===// 37a984708SDavid Chisnall// 47a984708SDavid Chisnall// The LLVM Compiler Infrastructure 57a984708SDavid Chisnall// 67a984708SDavid Chisnall// This file is dual licensed under the MIT and the University of Illinois Open 77a984708SDavid Chisnall// Source Licenses. See LICENSE.TXT for details. 87a984708SDavid Chisnall// 97a984708SDavid Chisnall//===----------------------------------------------------------------------===// 107a984708SDavid Chisnall 117a984708SDavid Chisnall#ifndef _LIBCPP_RANDOM 127a984708SDavid Chisnall#define _LIBCPP_RANDOM 137a984708SDavid Chisnall 147a984708SDavid Chisnall/* 157a984708SDavid Chisnall random synopsis 167a984708SDavid Chisnall 177a984708SDavid Chisnall#include <initializer_list> 187a984708SDavid Chisnall 197a984708SDavid Chisnallnamespace std 207a984708SDavid Chisnall{ 217a984708SDavid Chisnall 227a984708SDavid Chisnall// Engines 237a984708SDavid Chisnall 247a984708SDavid Chisnalltemplate <class UIntType, UIntType a, UIntType c, UIntType m> 257a984708SDavid Chisnallclass linear_congruential_engine 267a984708SDavid Chisnall{ 277a984708SDavid Chisnallpublic: 287a984708SDavid Chisnall // types 297a984708SDavid Chisnall typedef UIntType result_type; 307a984708SDavid Chisnall 317a984708SDavid Chisnall // engine characteristics 327a984708SDavid Chisnall static constexpr result_type multiplier = a; 337a984708SDavid Chisnall static constexpr result_type increment = c; 347a984708SDavid Chisnall static constexpr result_type modulus = m; 357a984708SDavid Chisnall static constexpr result_type min() { return c == 0u ? 1u: 0u;} 367a984708SDavid Chisnall static constexpr result_type max() { return m - 1u;} 377a984708SDavid Chisnall static constexpr result_type default_seed = 1u; 387a984708SDavid Chisnall 397a984708SDavid Chisnall // constructors and seeding functions 407a984708SDavid Chisnall explicit linear_congruential_engine(result_type s = default_seed); 417a984708SDavid Chisnall template<class Sseq> explicit linear_congruential_engine(Sseq& q); 427a984708SDavid Chisnall void seed(result_type s = default_seed); 437a984708SDavid Chisnall template<class Sseq> void seed(Sseq& q); 447a984708SDavid Chisnall 457a984708SDavid Chisnall // generating functions 467a984708SDavid Chisnall result_type operator()(); 477a984708SDavid Chisnall void discard(unsigned long long z); 487a984708SDavid Chisnall}; 497a984708SDavid Chisnall 507a984708SDavid Chisnalltemplate <class UIntType, UIntType a, UIntType c, UIntType m> 517a984708SDavid Chisnallbool 527a984708SDavid Chisnalloperator==(const linear_congruential_engine<UIntType, a, c, m>& x, 537a984708SDavid Chisnall const linear_congruential_engine<UIntType, a, c, m>& y); 547a984708SDavid Chisnall 557a984708SDavid Chisnalltemplate <class UIntType, UIntType a, UIntType c, UIntType m> 567a984708SDavid Chisnallbool 577a984708SDavid Chisnalloperator!=(const linear_congruential_engine<UIntType, a, c, m>& x, 587a984708SDavid Chisnall const linear_congruential_engine<UIntType, a, c, m>& y); 597a984708SDavid Chisnall 607a984708SDavid Chisnalltemplate <class charT, class traits, 617a984708SDavid Chisnall class UIntType, UIntType a, UIntType c, UIntType m> 627a984708SDavid Chisnallbasic_ostream<charT, traits>& 637a984708SDavid Chisnalloperator<<(basic_ostream<charT, traits>& os, 647a984708SDavid Chisnall const linear_congruential_engine<UIntType, a, c, m>& x); 657a984708SDavid Chisnall 667a984708SDavid Chisnalltemplate <class charT, class traits, 677a984708SDavid Chisnall class UIntType, UIntType a, UIntType c, UIntType m> 687a984708SDavid Chisnallbasic_istream<charT, traits>& 697a984708SDavid Chisnalloperator>>(basic_istream<charT, traits>& is, 707a984708SDavid Chisnall linear_congruential_engine<UIntType, a, c, m>& x); 717a984708SDavid Chisnall 727a984708SDavid Chisnalltemplate <class UIntType, size_t w, size_t n, size_t m, size_t r, 737a984708SDavid Chisnall UIntType a, size_t u, UIntType d, size_t s, 747a984708SDavid Chisnall UIntType b, size_t t, UIntType c, size_t l, UIntType f> 757a984708SDavid Chisnallclass mersenne_twister_engine 767a984708SDavid Chisnall{ 777a984708SDavid Chisnallpublic: 787a984708SDavid Chisnall // types 797a984708SDavid Chisnall typedef UIntType result_type; 807a984708SDavid Chisnall 817a984708SDavid Chisnall // engine characteristics 827a984708SDavid Chisnall static constexpr size_t word_size = w; 837a984708SDavid Chisnall static constexpr size_t state_size = n; 847a984708SDavid Chisnall static constexpr size_t shift_size = m; 857a984708SDavid Chisnall static constexpr size_t mask_bits = r; 867a984708SDavid Chisnall static constexpr result_type xor_mask = a; 877a984708SDavid Chisnall static constexpr size_t tempering_u = u; 887a984708SDavid Chisnall static constexpr result_type tempering_d = d; 897a984708SDavid Chisnall static constexpr size_t tempering_s = s; 907a984708SDavid Chisnall static constexpr result_type tempering_b = b; 917a984708SDavid Chisnall static constexpr size_t tempering_t = t; 927a984708SDavid Chisnall static constexpr result_type tempering_c = c; 937a984708SDavid Chisnall static constexpr size_t tempering_l = l; 947a984708SDavid Chisnall static constexpr result_type initialization_multiplier = f; 957a984708SDavid Chisnall static constexpr result_type min () { return 0; } 967a984708SDavid Chisnall static constexpr result_type max() { return 2^w - 1; } 977a984708SDavid Chisnall static constexpr result_type default_seed = 5489u; 987a984708SDavid Chisnall 997a984708SDavid Chisnall // constructors and seeding functions 1007a984708SDavid Chisnall explicit mersenne_twister_engine(result_type value = default_seed); 1017a984708SDavid Chisnall template<class Sseq> explicit mersenne_twister_engine(Sseq& q); 1027a984708SDavid Chisnall void seed(result_type value = default_seed); 1037a984708SDavid Chisnall template<class Sseq> void seed(Sseq& q); 1047a984708SDavid Chisnall 1057a984708SDavid Chisnall // generating functions 1067a984708SDavid Chisnall result_type operator()(); 1077a984708SDavid Chisnall void discard(unsigned long long z); 1087a984708SDavid Chisnall}; 1097a984708SDavid Chisnall 1107a984708SDavid Chisnalltemplate <class UIntType, size_t w, size_t n, size_t m, size_t r, 1117a984708SDavid Chisnall UIntType a, size_t u, UIntType d, size_t s, 1127a984708SDavid Chisnall UIntType b, size_t t, UIntType c, size_t l, UIntType f> 1137a984708SDavid Chisnallbool 1147a984708SDavid Chisnalloperator==( 1157a984708SDavid Chisnall const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x, 1167a984708SDavid Chisnall const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& y); 1177a984708SDavid Chisnall 1187a984708SDavid Chisnalltemplate <class UIntType, size_t w, size_t n, size_t m, size_t r, 1197a984708SDavid Chisnall UIntType a, size_t u, UIntType d, size_t s, 1207a984708SDavid Chisnall UIntType b, size_t t, UIntType c, size_t l, UIntType f> 1217a984708SDavid Chisnallbool 1227a984708SDavid Chisnalloperator!=( 1237a984708SDavid Chisnall const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x, 1247a984708SDavid Chisnall const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& y); 1257a984708SDavid Chisnall 1267a984708SDavid Chisnalltemplate <class charT, class traits, 1277a984708SDavid Chisnall class UIntType, size_t w, size_t n, size_t m, size_t r, 1287a984708SDavid Chisnall UIntType a, size_t u, UIntType d, size_t s, 1297a984708SDavid Chisnall UIntType b, size_t t, UIntType c, size_t l, UIntType f> 1307a984708SDavid Chisnallbasic_ostream<charT, traits>& 1317a984708SDavid Chisnalloperator<<(basic_ostream<charT, traits>& os, 1327a984708SDavid Chisnall const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x); 1337a984708SDavid Chisnall 1347a984708SDavid Chisnalltemplate <class charT, class traits, 1357a984708SDavid Chisnall class UIntType, size_t w, size_t n, size_t m, size_t r, 1367a984708SDavid Chisnall UIntType a, size_t u, UIntType d, size_t s, 1377a984708SDavid Chisnall UIntType b, size_t t, UIntType c, size_t l, UIntType f> 1387a984708SDavid Chisnallbasic_istream<charT, traits>& 1397a984708SDavid Chisnalloperator>>(basic_istream<charT, traits>& is, 1407a984708SDavid Chisnall mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x); 1417a984708SDavid Chisnall 1427a984708SDavid Chisnalltemplate<class UIntType, size_t w, size_t s, size_t r> 1437a984708SDavid Chisnallclass subtract_with_carry_engine 1447a984708SDavid Chisnall{ 1457a984708SDavid Chisnallpublic: 1467a984708SDavid Chisnall // types 1477a984708SDavid Chisnall typedef UIntType result_type; 1487a984708SDavid Chisnall 1497a984708SDavid Chisnall // engine characteristics 1507a984708SDavid Chisnall static constexpr size_t word_size = w; 1517a984708SDavid Chisnall static constexpr size_t short_lag = s; 1527a984708SDavid Chisnall static constexpr size_t long_lag = r; 1537a984708SDavid Chisnall static constexpr result_type min() { return 0; } 1547a984708SDavid Chisnall static constexpr result_type max() { return m-1; } 1557a984708SDavid Chisnall static constexpr result_type default_seed = 19780503u; 1567a984708SDavid Chisnall 1577a984708SDavid Chisnall // constructors and seeding functions 1587a984708SDavid Chisnall explicit subtract_with_carry_engine(result_type value = default_seed); 1597a984708SDavid Chisnall template<class Sseq> explicit subtract_with_carry_engine(Sseq& q); 1607a984708SDavid Chisnall void seed(result_type value = default_seed); 1617a984708SDavid Chisnall template<class Sseq> void seed(Sseq& q); 1627a984708SDavid Chisnall 1637a984708SDavid Chisnall // generating functions 1647a984708SDavid Chisnall result_type operator()(); 1657a984708SDavid Chisnall void discard(unsigned long long z); 1667a984708SDavid Chisnall}; 1677a984708SDavid Chisnall 1687a984708SDavid Chisnalltemplate<class UIntType, size_t w, size_t s, size_t r> 1697a984708SDavid Chisnallbool 1707a984708SDavid Chisnalloperator==( 1717a984708SDavid Chisnall const subtract_with_carry_engine<UIntType, w, s, r>& x, 1727a984708SDavid Chisnall const subtract_with_carry_engine<UIntType, w, s, r>& y); 1737a984708SDavid Chisnall 1747a984708SDavid Chisnalltemplate<class UIntType, size_t w, size_t s, size_t r> 1757a984708SDavid Chisnallbool 1767a984708SDavid Chisnalloperator!=( 1777a984708SDavid Chisnall const subtract_with_carry_engine<UIntType, w, s, r>& x, 1787a984708SDavid Chisnall const subtract_with_carry_engine<UIntType, w, s, r>& y); 1797a984708SDavid Chisnall 1807a984708SDavid Chisnalltemplate <class charT, class traits, 1817a984708SDavid Chisnall class UIntType, size_t w, size_t s, size_t r> 1827a984708SDavid Chisnallbasic_ostream<charT, traits>& 1837a984708SDavid Chisnalloperator<<(basic_ostream<charT, traits>& os, 1847a984708SDavid Chisnall const subtract_with_carry_engine<UIntType, w, s, r>& x); 1857a984708SDavid Chisnall 1867a984708SDavid Chisnalltemplate <class charT, class traits, 1877a984708SDavid Chisnall class UIntType, size_t w, size_t s, size_t r> 1887a984708SDavid Chisnallbasic_istream<charT, traits>& 1897a984708SDavid Chisnalloperator>>(basic_istream<charT, traits>& is, 1907a984708SDavid Chisnall subtract_with_carry_engine<UIntType, w, s, r>& x); 1917a984708SDavid Chisnall 1927a984708SDavid Chisnalltemplate<class Engine, size_t p, size_t r> 1937a984708SDavid Chisnallclass discard_block_engine 1947a984708SDavid Chisnall{ 1957a984708SDavid Chisnallpublic: 1967a984708SDavid Chisnall // types 1977a984708SDavid Chisnall typedef typename Engine::result_type result_type; 1987a984708SDavid Chisnall 1997a984708SDavid Chisnall // engine characteristics 2007a984708SDavid Chisnall static constexpr size_t block_size = p; 2017a984708SDavid Chisnall static constexpr size_t used_block = r; 2027a984708SDavid Chisnall static constexpr result_type min() { return Engine::min(); } 2037a984708SDavid Chisnall static constexpr result_type max() { return Engine::max(); } 2047a984708SDavid Chisnall 2057a984708SDavid Chisnall // constructors and seeding functions 2067a984708SDavid Chisnall discard_block_engine(); 2077a984708SDavid Chisnall explicit discard_block_engine(const Engine& e); 2087a984708SDavid Chisnall explicit discard_block_engine(Engine&& e); 2097a984708SDavid Chisnall explicit discard_block_engine(result_type s); 2107a984708SDavid Chisnall template<class Sseq> explicit discard_block_engine(Sseq& q); 2117a984708SDavid Chisnall void seed(); 2127a984708SDavid Chisnall void seed(result_type s); 2137a984708SDavid Chisnall template<class Sseq> void seed(Sseq& q); 2147a984708SDavid Chisnall 2157a984708SDavid Chisnall // generating functions 2167a984708SDavid Chisnall result_type operator()(); 2177a984708SDavid Chisnall void discard(unsigned long long z); 2187a984708SDavid Chisnall 2197a984708SDavid Chisnall // property functions 220936e9439SDimitry Andric const Engine& base() const noexcept; 2217a984708SDavid Chisnall}; 2227a984708SDavid Chisnall 2237a984708SDavid Chisnalltemplate<class Engine, size_t p, size_t r> 2247a984708SDavid Chisnallbool 2257a984708SDavid Chisnalloperator==( 2267a984708SDavid Chisnall const discard_block_engine<Engine, p, r>& x, 2277a984708SDavid Chisnall const discard_block_engine<Engine, p, r>& y); 2287a984708SDavid Chisnall 2297a984708SDavid Chisnalltemplate<class Engine, size_t p, size_t r> 2307a984708SDavid Chisnallbool 2317a984708SDavid Chisnalloperator!=( 2327a984708SDavid Chisnall const discard_block_engine<Engine, p, r>& x, 2337a984708SDavid Chisnall const discard_block_engine<Engine, p, r>& y); 2347a984708SDavid Chisnall 2357a984708SDavid Chisnalltemplate <class charT, class traits, 2367a984708SDavid Chisnall class Engine, size_t p, size_t r> 2377a984708SDavid Chisnallbasic_ostream<charT, traits>& 2387a984708SDavid Chisnalloperator<<(basic_ostream<charT, traits>& os, 2397a984708SDavid Chisnall const discard_block_engine<Engine, p, r>& x); 2407a984708SDavid Chisnall 2417a984708SDavid Chisnalltemplate <class charT, class traits, 2427a984708SDavid Chisnall class Engine, size_t p, size_t r> 2437a984708SDavid Chisnallbasic_istream<charT, traits>& 2447a984708SDavid Chisnalloperator>>(basic_istream<charT, traits>& is, 2457a984708SDavid Chisnall discard_block_engine<Engine, p, r>& x); 2467a984708SDavid Chisnall 2477a984708SDavid Chisnalltemplate<class Engine, size_t w, class UIntType> 2487a984708SDavid Chisnallclass independent_bits_engine 2497a984708SDavid Chisnall{ 2507a984708SDavid Chisnallpublic: 2517a984708SDavid Chisnall // types 2527a984708SDavid Chisnall typedef UIntType result_type; 2537a984708SDavid Chisnall 2547a984708SDavid Chisnall // engine characteristics 2557a984708SDavid Chisnall static constexpr result_type min() { return 0; } 2567a984708SDavid Chisnall static constexpr result_type max() { return 2^w - 1; } 2577a984708SDavid Chisnall 2587a984708SDavid Chisnall // constructors and seeding functions 2597a984708SDavid Chisnall independent_bits_engine(); 2607a984708SDavid Chisnall explicit independent_bits_engine(const Engine& e); 2617a984708SDavid Chisnall explicit independent_bits_engine(Engine&& e); 2627a984708SDavid Chisnall explicit independent_bits_engine(result_type s); 2637a984708SDavid Chisnall template<class Sseq> explicit independent_bits_engine(Sseq& q); 2647a984708SDavid Chisnall void seed(); 2657a984708SDavid Chisnall void seed(result_type s); 2667a984708SDavid Chisnall template<class Sseq> void seed(Sseq& q); 2677a984708SDavid Chisnall 2687a984708SDavid Chisnall // generating functions 2697a984708SDavid Chisnall result_type operator()(); void discard(unsigned long long z); 2707a984708SDavid Chisnall 2717a984708SDavid Chisnall // property functions 272936e9439SDimitry Andric const Engine& base() const noexcept; 2737a984708SDavid Chisnall}; 2747a984708SDavid Chisnall 2757a984708SDavid Chisnalltemplate<class Engine, size_t w, class UIntType> 2767a984708SDavid Chisnallbool 2777a984708SDavid Chisnalloperator==( 2787a984708SDavid Chisnall const independent_bits_engine<Engine, w, UIntType>& x, 2797a984708SDavid Chisnall const independent_bits_engine<Engine, w, UIntType>& y); 2807a984708SDavid Chisnall 2817a984708SDavid Chisnalltemplate<class Engine, size_t w, class UIntType> 2827a984708SDavid Chisnallbool 2837a984708SDavid Chisnalloperator!=( 2847a984708SDavid Chisnall const independent_bits_engine<Engine, w, UIntType>& x, 2857a984708SDavid Chisnall const independent_bits_engine<Engine, w, UIntType>& y); 2867a984708SDavid Chisnall 2877a984708SDavid Chisnalltemplate <class charT, class traits, 2887a984708SDavid Chisnall class Engine, size_t w, class UIntType> 2897a984708SDavid Chisnallbasic_ostream<charT, traits>& 2907a984708SDavid Chisnalloperator<<(basic_ostream<charT, traits>& os, 2917a984708SDavid Chisnall const independent_bits_engine<Engine, w, UIntType>& x); 2927a984708SDavid Chisnall 2937a984708SDavid Chisnalltemplate <class charT, class traits, 2947a984708SDavid Chisnall class Engine, size_t w, class UIntType> 2957a984708SDavid Chisnallbasic_istream<charT, traits>& 2967a984708SDavid Chisnalloperator>>(basic_istream<charT, traits>& is, 2977a984708SDavid Chisnall independent_bits_engine<Engine, w, UIntType>& x); 2987a984708SDavid Chisnall 2997a984708SDavid Chisnalltemplate<class Engine, size_t k> 3007a984708SDavid Chisnallclass shuffle_order_engine 3017a984708SDavid Chisnall{ 3027a984708SDavid Chisnallpublic: 3037a984708SDavid Chisnall // types 3047a984708SDavid Chisnall typedef typename Engine::result_type result_type; 3057a984708SDavid Chisnall 3067a984708SDavid Chisnall // engine characteristics 3077a984708SDavid Chisnall static constexpr size_t table_size = k; 3087a984708SDavid Chisnall static constexpr result_type min() { return Engine::min; } 3097a984708SDavid Chisnall static constexpr result_type max() { return Engine::max; } 3107a984708SDavid Chisnall 3117a984708SDavid Chisnall // constructors and seeding functions 3127a984708SDavid Chisnall shuffle_order_engine(); 3137a984708SDavid Chisnall explicit shuffle_order_engine(const Engine& e); 3147a984708SDavid Chisnall explicit shuffle_order_engine(Engine&& e); 3157a984708SDavid Chisnall explicit shuffle_order_engine(result_type s); 3167a984708SDavid Chisnall template<class Sseq> explicit shuffle_order_engine(Sseq& q); 3177a984708SDavid Chisnall void seed(); 3187a984708SDavid Chisnall void seed(result_type s); 3197a984708SDavid Chisnall template<class Sseq> void seed(Sseq& q); 3207a984708SDavid Chisnall 3217a984708SDavid Chisnall // generating functions 3227a984708SDavid Chisnall result_type operator()(); 3237a984708SDavid Chisnall void discard(unsigned long long z); 3247a984708SDavid Chisnall 3257a984708SDavid Chisnall // property functions 326936e9439SDimitry Andric const Engine& base() const noexcept; 3277a984708SDavid Chisnall}; 3287a984708SDavid Chisnall 3297a984708SDavid Chisnalltemplate<class Engine, size_t k> 3307a984708SDavid Chisnallbool 3317a984708SDavid Chisnalloperator==( 3327a984708SDavid Chisnall const shuffle_order_engine<Engine, k>& x, 3337a984708SDavid Chisnall const shuffle_order_engine<Engine, k>& y); 3347a984708SDavid Chisnall 3357a984708SDavid Chisnalltemplate<class Engine, size_t k> 3367a984708SDavid Chisnallbool 3377a984708SDavid Chisnalloperator!=( 3387a984708SDavid Chisnall const shuffle_order_engine<Engine, k>& x, 3397a984708SDavid Chisnall const shuffle_order_engine<Engine, k>& y); 3407a984708SDavid Chisnall 3417a984708SDavid Chisnalltemplate <class charT, class traits, 3427a984708SDavid Chisnall class Engine, size_t k> 3437a984708SDavid Chisnallbasic_ostream<charT, traits>& 3447a984708SDavid Chisnalloperator<<(basic_ostream<charT, traits>& os, 3457a984708SDavid Chisnall const shuffle_order_engine<Engine, k>& x); 3467a984708SDavid Chisnall 3477a984708SDavid Chisnalltemplate <class charT, class traits, 3487a984708SDavid Chisnall class Engine, size_t k> 3497a984708SDavid Chisnallbasic_istream<charT, traits>& 3507a984708SDavid Chisnalloperator>>(basic_istream<charT, traits>& is, 3517a984708SDavid Chisnall shuffle_order_engine<Engine, k>& x); 3527a984708SDavid Chisnall 3537a984708SDavid Chisnalltypedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647> 3547a984708SDavid Chisnall minstd_rand0; 3557a984708SDavid Chisnalltypedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647> 3567a984708SDavid Chisnall minstd_rand; 3577a984708SDavid Chisnalltypedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31, 3587a984708SDavid Chisnall 0x9908b0df, 3597a984708SDavid Chisnall 11, 0xffffffff, 3607a984708SDavid Chisnall 7, 0x9d2c5680, 3617a984708SDavid Chisnall 15, 0xefc60000, 3627a984708SDavid Chisnall 18, 1812433253> mt19937; 3637a984708SDavid Chisnalltypedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31, 3647a984708SDavid Chisnall 0xb5026f5aa96619e9, 3657a984708SDavid Chisnall 29, 0x5555555555555555, 3667a984708SDavid Chisnall 17, 0x71d67fffeda60000, 3677a984708SDavid Chisnall 37, 0xfff7eee000000000, 3687a984708SDavid Chisnall 43, 6364136223846793005> mt19937_64; 3697a984708SDavid Chisnalltypedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> ranlux24_base; 3707a984708SDavid Chisnalltypedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> ranlux48_base; 3717a984708SDavid Chisnalltypedef discard_block_engine<ranlux24_base, 223, 23> ranlux24; 3727a984708SDavid Chisnalltypedef discard_block_engine<ranlux48_base, 389, 11> ranlux48; 3737a984708SDavid Chisnalltypedef shuffle_order_engine<minstd_rand0, 256> knuth_b; 3747a984708SDavid Chisnalltypedef minstd_rand default_random_engine; 3757a984708SDavid Chisnall 3767a984708SDavid Chisnall// Generators 3777a984708SDavid Chisnall 3787a984708SDavid Chisnallclass random_device 3797a984708SDavid Chisnall{ 3807a984708SDavid Chisnallpublic: 3817a984708SDavid Chisnall // types 3827a984708SDavid Chisnall typedef unsigned int result_type; 3837a984708SDavid Chisnall 3847a984708SDavid Chisnall // generator characteristics 3857a984708SDavid Chisnall static constexpr result_type min() { return numeric_limits<result_type>::min(); } 3867a984708SDavid Chisnall static constexpr result_type max() { return numeric_limits<result_type>::max(); } 3877a984708SDavid Chisnall 3887a984708SDavid Chisnall // constructors 3897a984708SDavid Chisnall explicit random_device(const string& token = "/dev/urandom"); 3907a984708SDavid Chisnall 3917a984708SDavid Chisnall // generating functions 3927a984708SDavid Chisnall result_type operator()(); 3937a984708SDavid Chisnall 3947a984708SDavid Chisnall // property functions 395936e9439SDimitry Andric double entropy() const noexcept; 3967a984708SDavid Chisnall 3977a984708SDavid Chisnall // no copy functions 3987a984708SDavid Chisnall random_device(const random_device& ) = delete; 3997a984708SDavid Chisnall void operator=(const random_device& ) = delete; 4007a984708SDavid Chisnall}; 4017a984708SDavid Chisnall 4027a984708SDavid Chisnall// Utilities 4037a984708SDavid Chisnall 4047a984708SDavid Chisnallclass seed_seq 4057a984708SDavid Chisnall{ 4067a984708SDavid Chisnallpublic: 4077a984708SDavid Chisnall // types 4087a984708SDavid Chisnall typedef uint_least32_t result_type; 4097a984708SDavid Chisnall 4107a984708SDavid Chisnall // constructors 4117a984708SDavid Chisnall seed_seq(); 4127a984708SDavid Chisnall template<class T> 4137a984708SDavid Chisnall seed_seq(initializer_list<T> il); 4147a984708SDavid Chisnall template<class InputIterator> 4157a984708SDavid Chisnall seed_seq(InputIterator begin, InputIterator end); 4167a984708SDavid Chisnall 4177a984708SDavid Chisnall // generating functions 4187a984708SDavid Chisnall template<class RandomAccessIterator> 4197a984708SDavid Chisnall void generate(RandomAccessIterator begin, RandomAccessIterator end); 4207a984708SDavid Chisnall 4217a984708SDavid Chisnall // property functions 4227a984708SDavid Chisnall size_t size() const; 4237a984708SDavid Chisnall template<class OutputIterator> 4247a984708SDavid Chisnall void param(OutputIterator dest) const; 4257a984708SDavid Chisnall 4267a984708SDavid Chisnall // no copy functions 4277a984708SDavid Chisnall seed_seq(const seed_seq&) = delete; 4287a984708SDavid Chisnall void operator=(const seed_seq& ) = delete; 4297a984708SDavid Chisnall}; 4307a984708SDavid Chisnall 4317a984708SDavid Chisnalltemplate<class RealType, size_t bits, class URNG> 4327a984708SDavid Chisnall RealType generate_canonical(URNG& g); 4337a984708SDavid Chisnall 4347a984708SDavid Chisnall// Distributions 4357a984708SDavid Chisnall 4367a984708SDavid Chisnalltemplate<class IntType = int> 4377a984708SDavid Chisnallclass uniform_int_distribution 4387a984708SDavid Chisnall{ 4397a984708SDavid Chisnallpublic: 4407a984708SDavid Chisnall // types 4417a984708SDavid Chisnall typedef IntType result_type; 4427a984708SDavid Chisnall 4437a984708SDavid Chisnall class param_type 4447a984708SDavid Chisnall { 4457a984708SDavid Chisnall public: 4467a984708SDavid Chisnall typedef uniform_int_distribution distribution_type; 4477a984708SDavid Chisnall 4487a984708SDavid Chisnall explicit param_type(IntType a = 0, 4497a984708SDavid Chisnall IntType b = numeric_limits<IntType>::max()); 4507a984708SDavid Chisnall 4517a984708SDavid Chisnall result_type a() const; 4527a984708SDavid Chisnall result_type b() const; 4537a984708SDavid Chisnall 4547a984708SDavid Chisnall friend bool operator==(const param_type& x, const param_type& y); 4557a984708SDavid Chisnall friend bool operator!=(const param_type& x, const param_type& y); 4567a984708SDavid Chisnall }; 4577a984708SDavid Chisnall 4587a984708SDavid Chisnall // constructors and reset functions 4597a984708SDavid Chisnall explicit uniform_int_distribution(IntType a = 0, 4607a984708SDavid Chisnall IntType b = numeric_limits<IntType>::max()); 4617a984708SDavid Chisnall explicit uniform_int_distribution(const param_type& parm); 4627a984708SDavid Chisnall void reset(); 4637a984708SDavid Chisnall 4647a984708SDavid Chisnall // generating functions 4657a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g); 4667a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g, const param_type& parm); 4677a984708SDavid Chisnall 4687a984708SDavid Chisnall // property functions 4697a984708SDavid Chisnall result_type a() const; 4707a984708SDavid Chisnall result_type b() const; 4717a984708SDavid Chisnall 4727a984708SDavid Chisnall param_type param() const; 4737a984708SDavid Chisnall void param(const param_type& parm); 4747a984708SDavid Chisnall 4757a984708SDavid Chisnall result_type min() const; 4767a984708SDavid Chisnall result_type max() const; 4777a984708SDavid Chisnall 4787a984708SDavid Chisnall friend bool operator==(const uniform_int_distribution& x, 4797a984708SDavid Chisnall const uniform_int_distribution& y); 4807a984708SDavid Chisnall friend bool operator!=(const uniform_int_distribution& x, 4817a984708SDavid Chisnall const uniform_int_distribution& y); 4827a984708SDavid Chisnall 4837a984708SDavid Chisnall template <class charT, class traits> 4847a984708SDavid Chisnall friend 4857a984708SDavid Chisnall basic_ostream<charT, traits>& 4867a984708SDavid Chisnall operator<<(basic_ostream<charT, traits>& os, 4877a984708SDavid Chisnall const uniform_int_distribution& x); 4887a984708SDavid Chisnall 4897a984708SDavid Chisnall template <class charT, class traits> 4907a984708SDavid Chisnall friend 4917a984708SDavid Chisnall basic_istream<charT, traits>& 4927a984708SDavid Chisnall operator>>(basic_istream<charT, traits>& is, 4937a984708SDavid Chisnall uniform_int_distribution& x); 4947a984708SDavid Chisnall}; 4957a984708SDavid Chisnall 4967a984708SDavid Chisnalltemplate<class RealType = double> 4977a984708SDavid Chisnallclass uniform_real_distribution 4987a984708SDavid Chisnall{ 4997a984708SDavid Chisnallpublic: 5007a984708SDavid Chisnall // types 5017a984708SDavid Chisnall typedef RealType result_type; 5027a984708SDavid Chisnall 5037a984708SDavid Chisnall class param_type 5047a984708SDavid Chisnall { 5057a984708SDavid Chisnall public: 5067a984708SDavid Chisnall typedef uniform_real_distribution distribution_type; 5077a984708SDavid Chisnall 5087a984708SDavid Chisnall explicit param_type(RealType a = 0, 5097a984708SDavid Chisnall RealType b = 1); 5107a984708SDavid Chisnall 5117a984708SDavid Chisnall result_type a() const; 5127a984708SDavid Chisnall result_type b() const; 5137a984708SDavid Chisnall 5147a984708SDavid Chisnall friend bool operator==(const param_type& x, const param_type& y); 5157a984708SDavid Chisnall friend bool operator!=(const param_type& x, const param_type& y); 5167a984708SDavid Chisnall }; 5177a984708SDavid Chisnall 5187a984708SDavid Chisnall // constructors and reset functions 5197a984708SDavid Chisnall explicit uniform_real_distribution(RealType a = 0.0, RealType b = 1.0); 5207a984708SDavid Chisnall explicit uniform_real_distribution(const param_type& parm); 5217a984708SDavid Chisnall void reset(); 5227a984708SDavid Chisnall 5237a984708SDavid Chisnall // generating functions 5247a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g); 5257a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g, const param_type& parm); 5267a984708SDavid Chisnall 5277a984708SDavid Chisnall // property functions 5287a984708SDavid Chisnall result_type a() const; 5297a984708SDavid Chisnall result_type b() const; 5307a984708SDavid Chisnall 5317a984708SDavid Chisnall param_type param() const; 5327a984708SDavid Chisnall void param(const param_type& parm); 5337a984708SDavid Chisnall 5347a984708SDavid Chisnall result_type min() const; 5357a984708SDavid Chisnall result_type max() const; 5367a984708SDavid Chisnall 5377a984708SDavid Chisnall friend bool operator==(const uniform_real_distribution& x, 5387a984708SDavid Chisnall const uniform_real_distribution& y); 5397a984708SDavid Chisnall friend bool operator!=(const uniform_real_distribution& x, 5407a984708SDavid Chisnall const uniform_real_distribution& y); 5417a984708SDavid Chisnall 5427a984708SDavid Chisnall template <class charT, class traits> 5437a984708SDavid Chisnall friend 5447a984708SDavid Chisnall basic_ostream<charT, traits>& 5457a984708SDavid Chisnall operator<<(basic_ostream<charT, traits>& os, 5467a984708SDavid Chisnall const uniform_real_distribution& x); 5477a984708SDavid Chisnall 5487a984708SDavid Chisnall template <class charT, class traits> 5497a984708SDavid Chisnall friend 5507a984708SDavid Chisnall basic_istream<charT, traits>& 5517a984708SDavid Chisnall operator>>(basic_istream<charT, traits>& is, 5527a984708SDavid Chisnall uniform_real_distribution& x); 5537a984708SDavid Chisnall}; 5547a984708SDavid Chisnall 5557a984708SDavid Chisnallclass bernoulli_distribution 5567a984708SDavid Chisnall{ 5577a984708SDavid Chisnallpublic: 5587a984708SDavid Chisnall // types 5597a984708SDavid Chisnall typedef bool result_type; 5607a984708SDavid Chisnall 5617a984708SDavid Chisnall class param_type 5627a984708SDavid Chisnall { 5637a984708SDavid Chisnall public: 5647a984708SDavid Chisnall typedef bernoulli_distribution distribution_type; 5657a984708SDavid Chisnall 5667a984708SDavid Chisnall explicit param_type(double p = 0.5); 5677a984708SDavid Chisnall 5687a984708SDavid Chisnall double p() const; 5697a984708SDavid Chisnall 5707a984708SDavid Chisnall friend bool operator==(const param_type& x, const param_type& y); 5717a984708SDavid Chisnall friend bool operator!=(const param_type& x, const param_type& y); 5727a984708SDavid Chisnall }; 5737a984708SDavid Chisnall 5747a984708SDavid Chisnall // constructors and reset functions 5757a984708SDavid Chisnall explicit bernoulli_distribution(double p = 0.5); 5767a984708SDavid Chisnall explicit bernoulli_distribution(const param_type& parm); 5777a984708SDavid Chisnall void reset(); 5787a984708SDavid Chisnall 5797a984708SDavid Chisnall // generating functions 5807a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g); 5817a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g, const param_type& parm); 5827a984708SDavid Chisnall 5837a984708SDavid Chisnall // property functions 5847a984708SDavid Chisnall double p() const; 5857a984708SDavid Chisnall 5867a984708SDavid Chisnall param_type param() const; 5877a984708SDavid Chisnall void param(const param_type& parm); 5887a984708SDavid Chisnall 5897a984708SDavid Chisnall result_type min() const; 5907a984708SDavid Chisnall result_type max() const; 5917a984708SDavid Chisnall 5927a984708SDavid Chisnall friend bool operator==(const bernoulli_distribution& x, 5937a984708SDavid Chisnall const bernoulli_distribution& y); 5947a984708SDavid Chisnall friend bool operator!=(const bernoulli_distribution& x, 5957a984708SDavid Chisnall const bernoulli_distribution& y); 5967a984708SDavid Chisnall 5977a984708SDavid Chisnall template <class charT, class traits> 5987a984708SDavid Chisnall friend 5997a984708SDavid Chisnall basic_ostream<charT, traits>& 6007a984708SDavid Chisnall operator<<(basic_ostream<charT, traits>& os, 6017a984708SDavid Chisnall const bernoulli_distribution& x); 6027a984708SDavid Chisnall 6037a984708SDavid Chisnall template <class charT, class traits> 6047a984708SDavid Chisnall friend 6057a984708SDavid Chisnall basic_istream<charT, traits>& 6067a984708SDavid Chisnall operator>>(basic_istream<charT, traits>& is, 6077a984708SDavid Chisnall bernoulli_distribution& x); 6087a984708SDavid Chisnall}; 6097a984708SDavid Chisnall 6107a984708SDavid Chisnalltemplate<class IntType = int> 6117a984708SDavid Chisnallclass binomial_distribution 6127a984708SDavid Chisnall{ 6137a984708SDavid Chisnallpublic: 6147a984708SDavid Chisnall // types 6157a984708SDavid Chisnall typedef IntType result_type; 6167a984708SDavid Chisnall 6177a984708SDavid Chisnall class param_type 6187a984708SDavid Chisnall { 6197a984708SDavid Chisnall public: 6207a984708SDavid Chisnall typedef binomial_distribution distribution_type; 6217a984708SDavid Chisnall 6227a984708SDavid Chisnall explicit param_type(IntType t = 1, double p = 0.5); 6237a984708SDavid Chisnall 6247a984708SDavid Chisnall IntType t() const; 6257a984708SDavid Chisnall double p() const; 6267a984708SDavid Chisnall 6277a984708SDavid Chisnall friend bool operator==(const param_type& x, const param_type& y); 6287a984708SDavid Chisnall friend bool operator!=(const param_type& x, const param_type& y); 6297a984708SDavid Chisnall }; 6307a984708SDavid Chisnall 6317a984708SDavid Chisnall // constructors and reset functions 6327a984708SDavid Chisnall explicit binomial_distribution(IntType t = 1, double p = 0.5); 6337a984708SDavid Chisnall explicit binomial_distribution(const param_type& parm); 6347a984708SDavid Chisnall void reset(); 6357a984708SDavid Chisnall 6367a984708SDavid Chisnall // generating functions 6377a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g); 6387a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g, const param_type& parm); 6397a984708SDavid Chisnall 6407a984708SDavid Chisnall // property functions 6417a984708SDavid Chisnall IntType t() const; 6427a984708SDavid Chisnall double p() const; 6437a984708SDavid Chisnall 6447a984708SDavid Chisnall param_type param() const; 6457a984708SDavid Chisnall void param(const param_type& parm); 6467a984708SDavid Chisnall 6477a984708SDavid Chisnall result_type min() const; 6487a984708SDavid Chisnall result_type max() const; 6497a984708SDavid Chisnall 6507a984708SDavid Chisnall friend bool operator==(const binomial_distribution& x, 6517a984708SDavid Chisnall const binomial_distribution& y); 6527a984708SDavid Chisnall friend bool operator!=(const binomial_distribution& x, 6537a984708SDavid Chisnall const binomial_distribution& y); 6547a984708SDavid Chisnall 6557a984708SDavid Chisnall template <class charT, class traits> 6567a984708SDavid Chisnall friend 6577a984708SDavid Chisnall basic_ostream<charT, traits>& 6587a984708SDavid Chisnall operator<<(basic_ostream<charT, traits>& os, 6597a984708SDavid Chisnall const binomial_distribution& x); 6607a984708SDavid Chisnall 6617a984708SDavid Chisnall template <class charT, class traits> 6627a984708SDavid Chisnall friend 6637a984708SDavid Chisnall basic_istream<charT, traits>& 6647a984708SDavid Chisnall operator>>(basic_istream<charT, traits>& is, 6657a984708SDavid Chisnall binomial_distribution& x); 6667a984708SDavid Chisnall}; 6677a984708SDavid Chisnall 6687a984708SDavid Chisnalltemplate<class IntType = int> 6697a984708SDavid Chisnallclass geometric_distribution 6707a984708SDavid Chisnall{ 6717a984708SDavid Chisnallpublic: 6727a984708SDavid Chisnall // types 6737a984708SDavid Chisnall typedef IntType result_type; 6747a984708SDavid Chisnall 6757a984708SDavid Chisnall class param_type 6767a984708SDavid Chisnall { 6777a984708SDavid Chisnall public: 6787a984708SDavid Chisnall typedef geometric_distribution distribution_type; 6797a984708SDavid Chisnall 6807a984708SDavid Chisnall explicit param_type(double p = 0.5); 6817a984708SDavid Chisnall 6827a984708SDavid Chisnall double p() const; 6837a984708SDavid Chisnall 6847a984708SDavid Chisnall friend bool operator==(const param_type& x, const param_type& y); 6857a984708SDavid Chisnall friend bool operator!=(const param_type& x, const param_type& y); 6867a984708SDavid Chisnall }; 6877a984708SDavid Chisnall 6887a984708SDavid Chisnall // constructors and reset functions 6897a984708SDavid Chisnall explicit geometric_distribution(double p = 0.5); 6907a984708SDavid Chisnall explicit geometric_distribution(const param_type& parm); 6917a984708SDavid Chisnall void reset(); 6927a984708SDavid Chisnall 6937a984708SDavid Chisnall // generating functions 6947a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g); 6957a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g, const param_type& parm); 6967a984708SDavid Chisnall 6977a984708SDavid Chisnall // property functions 6987a984708SDavid Chisnall double p() const; 6997a984708SDavid Chisnall 7007a984708SDavid Chisnall param_type param() const; 7017a984708SDavid Chisnall void param(const param_type& parm); 7027a984708SDavid Chisnall 7037a984708SDavid Chisnall result_type min() const; 7047a984708SDavid Chisnall result_type max() const; 7057a984708SDavid Chisnall 7067a984708SDavid Chisnall friend bool operator==(const geometric_distribution& x, 7077a984708SDavid Chisnall const geometric_distribution& y); 7087a984708SDavid Chisnall friend bool operator!=(const geometric_distribution& x, 7097a984708SDavid Chisnall const geometric_distribution& y); 7107a984708SDavid Chisnall 7117a984708SDavid Chisnall template <class charT, class traits> 7127a984708SDavid Chisnall friend 7137a984708SDavid Chisnall basic_ostream<charT, traits>& 7147a984708SDavid Chisnall operator<<(basic_ostream<charT, traits>& os, 7157a984708SDavid Chisnall const geometric_distribution& x); 7167a984708SDavid Chisnall 7177a984708SDavid Chisnall template <class charT, class traits> 7187a984708SDavid Chisnall friend 7197a984708SDavid Chisnall basic_istream<charT, traits>& 7207a984708SDavid Chisnall operator>>(basic_istream<charT, traits>& is, 7217a984708SDavid Chisnall geometric_distribution& x); 7227a984708SDavid Chisnall}; 7237a984708SDavid Chisnall 7247a984708SDavid Chisnalltemplate<class IntType = int> 7257a984708SDavid Chisnallclass negative_binomial_distribution 7267a984708SDavid Chisnall{ 7277a984708SDavid Chisnallpublic: 7287a984708SDavid Chisnall // types 7297a984708SDavid Chisnall typedef IntType result_type; 7307a984708SDavid Chisnall 7317a984708SDavid Chisnall class param_type 7327a984708SDavid Chisnall { 7337a984708SDavid Chisnall public: 7347a984708SDavid Chisnall typedef negative_binomial_distribution distribution_type; 7357a984708SDavid Chisnall 7367a984708SDavid Chisnall explicit param_type(result_type k = 1, double p = 0.5); 7377a984708SDavid Chisnall 7387a984708SDavid Chisnall result_type k() const; 7397a984708SDavid Chisnall double p() const; 7407a984708SDavid Chisnall 7417a984708SDavid Chisnall friend bool operator==(const param_type& x, const param_type& y); 7427a984708SDavid Chisnall friend bool operator!=(const param_type& x, const param_type& y); 7437a984708SDavid Chisnall }; 7447a984708SDavid Chisnall 7457a984708SDavid Chisnall // constructor and reset functions 7467a984708SDavid Chisnall explicit negative_binomial_distribution(result_type k = 1, double p = 0.5); 7477a984708SDavid Chisnall explicit negative_binomial_distribution(const param_type& parm); 7487a984708SDavid Chisnall void reset(); 7497a984708SDavid Chisnall 7507a984708SDavid Chisnall // generating functions 7517a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g); 7527a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g, const param_type& parm); 7537a984708SDavid Chisnall 7547a984708SDavid Chisnall // property functions 7557a984708SDavid Chisnall result_type k() const; 7567a984708SDavid Chisnall double p() const; 7577a984708SDavid Chisnall 7587a984708SDavid Chisnall param_type param() const; 7597a984708SDavid Chisnall void param(const param_type& parm); 7607a984708SDavid Chisnall 7617a984708SDavid Chisnall result_type min() const; 7627a984708SDavid Chisnall result_type max() const; 7637a984708SDavid Chisnall 7647a984708SDavid Chisnall friend bool operator==(const negative_binomial_distribution& x, 7657a984708SDavid Chisnall const negative_binomial_distribution& y); 7667a984708SDavid Chisnall friend bool operator!=(const negative_binomial_distribution& x, 7677a984708SDavid Chisnall const negative_binomial_distribution& y); 7687a984708SDavid Chisnall 7697a984708SDavid Chisnall template <class charT, class traits> 7707a984708SDavid Chisnall friend 7717a984708SDavid Chisnall basic_ostream<charT, traits>& 7727a984708SDavid Chisnall operator<<(basic_ostream<charT, traits>& os, 7737a984708SDavid Chisnall const negative_binomial_distribution& x); 7747a984708SDavid Chisnall 7757a984708SDavid Chisnall template <class charT, class traits> 7767a984708SDavid Chisnall friend 7777a984708SDavid Chisnall basic_istream<charT, traits>& 7787a984708SDavid Chisnall operator>>(basic_istream<charT, traits>& is, 7797a984708SDavid Chisnall negative_binomial_distribution& x); 7807a984708SDavid Chisnall}; 7817a984708SDavid Chisnall 7827a984708SDavid Chisnalltemplate<class IntType = int> 7837a984708SDavid Chisnallclass poisson_distribution 7847a984708SDavid Chisnall{ 7857a984708SDavid Chisnallpublic: 7867a984708SDavid Chisnall // types 7877a984708SDavid Chisnall typedef IntType result_type; 7887a984708SDavid Chisnall 7897a984708SDavid Chisnall class param_type 7907a984708SDavid Chisnall { 7917a984708SDavid Chisnall public: 7927a984708SDavid Chisnall typedef poisson_distribution distribution_type; 7937a984708SDavid Chisnall 7947a984708SDavid Chisnall explicit param_type(double mean = 1.0); 7957a984708SDavid Chisnall 7967a984708SDavid Chisnall double mean() const; 7977a984708SDavid Chisnall 7987a984708SDavid Chisnall friend bool operator==(const param_type& x, const param_type& y); 7997a984708SDavid Chisnall friend bool operator!=(const param_type& x, const param_type& y); 8007a984708SDavid Chisnall }; 8017a984708SDavid Chisnall 8027a984708SDavid Chisnall // constructors and reset functions 8037a984708SDavid Chisnall explicit poisson_distribution(double mean = 1.0); 8047a984708SDavid Chisnall explicit poisson_distribution(const param_type& parm); 8057a984708SDavid Chisnall void reset(); 8067a984708SDavid Chisnall 8077a984708SDavid Chisnall // generating functions 8087a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g); 8097a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g, const param_type& parm); 8107a984708SDavid Chisnall 8117a984708SDavid Chisnall // property functions 8127a984708SDavid Chisnall double mean() const; 8137a984708SDavid Chisnall 8147a984708SDavid Chisnall param_type param() const; 8157a984708SDavid Chisnall void param(const param_type& parm); 8167a984708SDavid Chisnall 8177a984708SDavid Chisnall result_type min() const; 8187a984708SDavid Chisnall result_type max() const; 8197a984708SDavid Chisnall 8207a984708SDavid Chisnall friend bool operator==(const poisson_distribution& x, 8217a984708SDavid Chisnall const poisson_distribution& y); 8227a984708SDavid Chisnall friend bool operator!=(const poisson_distribution& x, 8237a984708SDavid Chisnall const poisson_distribution& y); 8247a984708SDavid Chisnall 8257a984708SDavid Chisnall template <class charT, class traits> 8267a984708SDavid Chisnall friend 8277a984708SDavid Chisnall basic_ostream<charT, traits>& 8287a984708SDavid Chisnall operator<<(basic_ostream<charT, traits>& os, 8297a984708SDavid Chisnall const poisson_distribution& x); 8307a984708SDavid Chisnall 8317a984708SDavid Chisnall template <class charT, class traits> 8327a984708SDavid Chisnall friend 8337a984708SDavid Chisnall basic_istream<charT, traits>& 8347a984708SDavid Chisnall operator>>(basic_istream<charT, traits>& is, 8357a984708SDavid Chisnall poisson_distribution& x); 8367a984708SDavid Chisnall}; 8377a984708SDavid Chisnall 8387a984708SDavid Chisnalltemplate<class RealType = double> 8397a984708SDavid Chisnallclass exponential_distribution 8407a984708SDavid Chisnall{ 8417a984708SDavid Chisnallpublic: 8427a984708SDavid Chisnall // types 8437a984708SDavid Chisnall typedef RealType result_type; 8447a984708SDavid Chisnall 8457a984708SDavid Chisnall class param_type 8467a984708SDavid Chisnall { 8477a984708SDavid Chisnall public: 8487a984708SDavid Chisnall typedef exponential_distribution distribution_type; 8497a984708SDavid Chisnall 8507a984708SDavid Chisnall explicit param_type(result_type lambda = 1.0); 8517a984708SDavid Chisnall 8527a984708SDavid Chisnall result_type lambda() const; 8537a984708SDavid Chisnall 8547a984708SDavid Chisnall friend bool operator==(const param_type& x, const param_type& y); 8557a984708SDavid Chisnall friend bool operator!=(const param_type& x, const param_type& y); 8567a984708SDavid Chisnall }; 8577a984708SDavid Chisnall 8587a984708SDavid Chisnall // constructors and reset functions 8597a984708SDavid Chisnall explicit exponential_distribution(result_type lambda = 1.0); 8607a984708SDavid Chisnall explicit exponential_distribution(const param_type& parm); 8617a984708SDavid Chisnall void reset(); 8627a984708SDavid Chisnall 8637a984708SDavid Chisnall // generating functions 8647a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g); 8657a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g, const param_type& parm); 8667a984708SDavid Chisnall 8677a984708SDavid Chisnall // property functions 8687a984708SDavid Chisnall result_type lambda() const; 8697a984708SDavid Chisnall 8707a984708SDavid Chisnall param_type param() const; 8717a984708SDavid Chisnall void param(const param_type& parm); 8727a984708SDavid Chisnall 8737a984708SDavid Chisnall result_type min() const; 8747a984708SDavid Chisnall result_type max() const; 8757a984708SDavid Chisnall 8767a984708SDavid Chisnall friend bool operator==(const exponential_distribution& x, 8777a984708SDavid Chisnall const exponential_distribution& y); 8787a984708SDavid Chisnall friend bool operator!=(const exponential_distribution& x, 8797a984708SDavid Chisnall const exponential_distribution& y); 8807a984708SDavid Chisnall 8817a984708SDavid Chisnall template <class charT, class traits> 8827a984708SDavid Chisnall friend 8837a984708SDavid Chisnall basic_ostream<charT, traits>& 8847a984708SDavid Chisnall operator<<(basic_ostream<charT, traits>& os, 8857a984708SDavid Chisnall const exponential_distribution& x); 8867a984708SDavid Chisnall 8877a984708SDavid Chisnall template <class charT, class traits> 8887a984708SDavid Chisnall friend 8897a984708SDavid Chisnall basic_istream<charT, traits>& 8907a984708SDavid Chisnall operator>>(basic_istream<charT, traits>& is, 8917a984708SDavid Chisnall exponential_distribution& x); 8927a984708SDavid Chisnall}; 8937a984708SDavid Chisnall 8947a984708SDavid Chisnalltemplate<class RealType = double> 8957a984708SDavid Chisnallclass gamma_distribution 8967a984708SDavid Chisnall{ 8977a984708SDavid Chisnallpublic: 8987a984708SDavid Chisnall // types 8997a984708SDavid Chisnall typedef RealType result_type; 9007a984708SDavid Chisnall 9017a984708SDavid Chisnall class param_type 9027a984708SDavid Chisnall { 9037a984708SDavid Chisnall public: 9047a984708SDavid Chisnall typedef gamma_distribution distribution_type; 9057a984708SDavid Chisnall 9067a984708SDavid Chisnall explicit param_type(result_type alpha = 1, result_type beta = 1); 9077a984708SDavid Chisnall 9087a984708SDavid Chisnall result_type alpha() const; 9097a984708SDavid Chisnall result_type beta() const; 9107a984708SDavid Chisnall 9117a984708SDavid Chisnall friend bool operator==(const param_type& x, const param_type& y); 9127a984708SDavid Chisnall friend bool operator!=(const param_type& x, const param_type& y); 9137a984708SDavid Chisnall }; 9147a984708SDavid Chisnall 9157a984708SDavid Chisnall // constructors and reset functions 9167a984708SDavid Chisnall explicit gamma_distribution(result_type alpha = 1, result_type beta = 1); 9177a984708SDavid Chisnall explicit gamma_distribution(const param_type& parm); 9187a984708SDavid Chisnall void reset(); 9197a984708SDavid Chisnall 9207a984708SDavid Chisnall // generating functions 9217a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g); 9227a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g, const param_type& parm); 9237a984708SDavid Chisnall 9247a984708SDavid Chisnall // property functions 9257a984708SDavid Chisnall result_type alpha() const; 9267a984708SDavid Chisnall result_type beta() const; 9277a984708SDavid Chisnall 9287a984708SDavid Chisnall param_type param() const; 9297a984708SDavid Chisnall void param(const param_type& parm); 9307a984708SDavid Chisnall 9317a984708SDavid Chisnall result_type min() const; 9327a984708SDavid Chisnall result_type max() const; 9337a984708SDavid Chisnall 9347a984708SDavid Chisnall friend bool operator==(const gamma_distribution& x, 9357a984708SDavid Chisnall const gamma_distribution& y); 9367a984708SDavid Chisnall friend bool operator!=(const gamma_distribution& x, 9377a984708SDavid Chisnall const gamma_distribution& y); 9387a984708SDavid Chisnall 9397a984708SDavid Chisnall template <class charT, class traits> 9407a984708SDavid Chisnall friend 9417a984708SDavid Chisnall basic_ostream<charT, traits>& 9427a984708SDavid Chisnall operator<<(basic_ostream<charT, traits>& os, 9437a984708SDavid Chisnall const gamma_distribution& x); 9447a984708SDavid Chisnall 9457a984708SDavid Chisnall template <class charT, class traits> 9467a984708SDavid Chisnall friend 9477a984708SDavid Chisnall basic_istream<charT, traits>& 9487a984708SDavid Chisnall operator>>(basic_istream<charT, traits>& is, 9497a984708SDavid Chisnall gamma_distribution& x); 9507a984708SDavid Chisnall}; 9517a984708SDavid Chisnall 9527a984708SDavid Chisnalltemplate<class RealType = double> 9537a984708SDavid Chisnallclass weibull_distribution 9547a984708SDavid Chisnall{ 9557a984708SDavid Chisnallpublic: 9567a984708SDavid Chisnall // types 9577a984708SDavid Chisnall typedef RealType result_type; 9587a984708SDavid Chisnall 9597a984708SDavid Chisnall class param_type 9607a984708SDavid Chisnall { 9617a984708SDavid Chisnall public: 9627a984708SDavid Chisnall typedef weibull_distribution distribution_type; 9637a984708SDavid Chisnall 9647a984708SDavid Chisnall explicit param_type(result_type alpha = 1, result_type beta = 1); 9657a984708SDavid Chisnall 9667a984708SDavid Chisnall result_type a() const; 9677a984708SDavid Chisnall result_type b() const; 9687a984708SDavid Chisnall 9697a984708SDavid Chisnall friend bool operator==(const param_type& x, const param_type& y); 9707a984708SDavid Chisnall friend bool operator!=(const param_type& x, const param_type& y); 9717a984708SDavid Chisnall }; 9727a984708SDavid Chisnall 9737a984708SDavid Chisnall // constructor and reset functions 9747a984708SDavid Chisnall explicit weibull_distribution(result_type a = 1, result_type b = 1); 9757a984708SDavid Chisnall explicit weibull_distribution(const param_type& parm); 9767a984708SDavid Chisnall void reset(); 9777a984708SDavid Chisnall 9787a984708SDavid Chisnall // generating functions 9797a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g); 9807a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g, const param_type& parm); 9817a984708SDavid Chisnall 9827a984708SDavid Chisnall // property functions 9837a984708SDavid Chisnall result_type a() const; 9847a984708SDavid Chisnall result_type b() const; 9857a984708SDavid Chisnall 9867a984708SDavid Chisnall param_type param() const; 9877a984708SDavid Chisnall void param(const param_type& parm); 9887a984708SDavid Chisnall 9897a984708SDavid Chisnall result_type min() const; 9907a984708SDavid Chisnall result_type max() const; 9917a984708SDavid Chisnall 9927a984708SDavid Chisnall friend bool operator==(const weibull_distribution& x, 9937a984708SDavid Chisnall const weibull_distribution& y); 9947a984708SDavid Chisnall friend bool operator!=(const weibull_distribution& x, 9957a984708SDavid Chisnall const weibull_distribution& y); 9967a984708SDavid Chisnall 9977a984708SDavid Chisnall template <class charT, class traits> 9987a984708SDavid Chisnall friend 9997a984708SDavid Chisnall basic_ostream<charT, traits>& 10007a984708SDavid Chisnall operator<<(basic_ostream<charT, traits>& os, 10017a984708SDavid Chisnall const weibull_distribution& x); 10027a984708SDavid Chisnall 10037a984708SDavid Chisnall template <class charT, class traits> 10047a984708SDavid Chisnall friend 10057a984708SDavid Chisnall basic_istream<charT, traits>& 10067a984708SDavid Chisnall operator>>(basic_istream<charT, traits>& is, 10077a984708SDavid Chisnall weibull_distribution& x); 10087a984708SDavid Chisnall}; 10097a984708SDavid Chisnall 10107a984708SDavid Chisnalltemplate<class RealType = double> 10117a984708SDavid Chisnallclass extreme_value_distribution 10127a984708SDavid Chisnall{ 10137a984708SDavid Chisnallpublic: 10147a984708SDavid Chisnall // types 10157a984708SDavid Chisnall typedef RealType result_type; 10167a984708SDavid Chisnall 10177a984708SDavid Chisnall class param_type 10187a984708SDavid Chisnall { 10197a984708SDavid Chisnall public: 10207a984708SDavid Chisnall typedef extreme_value_distribution distribution_type; 10217a984708SDavid Chisnall 10227a984708SDavid Chisnall explicit param_type(result_type a = 0, result_type b = 1); 10237a984708SDavid Chisnall 10247a984708SDavid Chisnall result_type a() const; 10257a984708SDavid Chisnall result_type b() const; 10267a984708SDavid Chisnall 10277a984708SDavid Chisnall friend bool operator==(const param_type& x, const param_type& y); 10287a984708SDavid Chisnall friend bool operator!=(const param_type& x, const param_type& y); 10297a984708SDavid Chisnall }; 10307a984708SDavid Chisnall 10317a984708SDavid Chisnall // constructor and reset functions 10327a984708SDavid Chisnall explicit extreme_value_distribution(result_type a = 0, result_type b = 1); 10337a984708SDavid Chisnall explicit extreme_value_distribution(const param_type& parm); 10347a984708SDavid Chisnall void reset(); 10357a984708SDavid Chisnall 10367a984708SDavid Chisnall // generating functions 10377a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g); 10387a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g, const param_type& parm); 10397a984708SDavid Chisnall 10407a984708SDavid Chisnall // property functions 10417a984708SDavid Chisnall result_type a() const; 10427a984708SDavid Chisnall result_type b() const; 10437a984708SDavid Chisnall 10447a984708SDavid Chisnall param_type param() const; 10457a984708SDavid Chisnall void param(const param_type& parm); 10467a984708SDavid Chisnall 10477a984708SDavid Chisnall result_type min() const; 10487a984708SDavid Chisnall result_type max() const; 10497a984708SDavid Chisnall 10507a984708SDavid Chisnall friend bool operator==(const extreme_value_distribution& x, 10517a984708SDavid Chisnall const extreme_value_distribution& y); 10527a984708SDavid Chisnall friend bool operator!=(const extreme_value_distribution& x, 10537a984708SDavid Chisnall const extreme_value_distribution& y); 10547a984708SDavid Chisnall 10557a984708SDavid Chisnall template <class charT, class traits> 10567a984708SDavid Chisnall friend 10577a984708SDavid Chisnall basic_ostream<charT, traits>& 10587a984708SDavid Chisnall operator<<(basic_ostream<charT, traits>& os, 10597a984708SDavid Chisnall const extreme_value_distribution& x); 10607a984708SDavid Chisnall 10617a984708SDavid Chisnall template <class charT, class traits> 10627a984708SDavid Chisnall friend 10637a984708SDavid Chisnall basic_istream<charT, traits>& 10647a984708SDavid Chisnall operator>>(basic_istream<charT, traits>& is, 10657a984708SDavid Chisnall extreme_value_distribution& x); 10667a984708SDavid Chisnall}; 10677a984708SDavid Chisnall 10687a984708SDavid Chisnalltemplate<class RealType = double> 10697a984708SDavid Chisnallclass normal_distribution 10707a984708SDavid Chisnall{ 10717a984708SDavid Chisnallpublic: 10727a984708SDavid Chisnall // types 10737a984708SDavid Chisnall typedef RealType result_type; 10747a984708SDavid Chisnall 10757a984708SDavid Chisnall class param_type 10767a984708SDavid Chisnall { 10777a984708SDavid Chisnall public: 10787a984708SDavid Chisnall typedef normal_distribution distribution_type; 10797a984708SDavid Chisnall 10807a984708SDavid Chisnall explicit param_type(result_type mean = 0, result_type stddev = 1); 10817a984708SDavid Chisnall 10827a984708SDavid Chisnall result_type mean() const; 10837a984708SDavid Chisnall result_type stddev() const; 10847a984708SDavid Chisnall 10857a984708SDavid Chisnall friend bool operator==(const param_type& x, const param_type& y); 10867a984708SDavid Chisnall friend bool operator!=(const param_type& x, const param_type& y); 10877a984708SDavid Chisnall }; 10887a984708SDavid Chisnall 10897a984708SDavid Chisnall // constructors and reset functions 10907a984708SDavid Chisnall explicit normal_distribution(result_type mean = 0, result_type stddev = 1); 10917a984708SDavid Chisnall explicit normal_distribution(const param_type& parm); 10927a984708SDavid Chisnall void reset(); 10937a984708SDavid Chisnall 10947a984708SDavid Chisnall // generating functions 10957a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g); 10967a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g, const param_type& parm); 10977a984708SDavid Chisnall 10987a984708SDavid Chisnall // property functions 10997a984708SDavid Chisnall result_type mean() const; 11007a984708SDavid Chisnall result_type stddev() const; 11017a984708SDavid Chisnall 11027a984708SDavid Chisnall param_type param() const; 11037a984708SDavid Chisnall void param(const param_type& parm); 11047a984708SDavid Chisnall 11057a984708SDavid Chisnall result_type min() const; 11067a984708SDavid Chisnall result_type max() const; 11077a984708SDavid Chisnall 11087a984708SDavid Chisnall friend bool operator==(const normal_distribution& x, 11097a984708SDavid Chisnall const normal_distribution& y); 11107a984708SDavid Chisnall friend bool operator!=(const normal_distribution& x, 11117a984708SDavid Chisnall const normal_distribution& y); 11127a984708SDavid Chisnall 11137a984708SDavid Chisnall template <class charT, class traits> 11147a984708SDavid Chisnall friend 11157a984708SDavid Chisnall basic_ostream<charT, traits>& 11167a984708SDavid Chisnall operator<<(basic_ostream<charT, traits>& os, 11177a984708SDavid Chisnall const normal_distribution& x); 11187a984708SDavid Chisnall 11197a984708SDavid Chisnall template <class charT, class traits> 11207a984708SDavid Chisnall friend 11217a984708SDavid Chisnall basic_istream<charT, traits>& 11227a984708SDavid Chisnall operator>>(basic_istream<charT, traits>& is, 11237a984708SDavid Chisnall normal_distribution& x); 11247a984708SDavid Chisnall}; 11257a984708SDavid Chisnall 11267a984708SDavid Chisnalltemplate<class RealType = double> 11277a984708SDavid Chisnallclass lognormal_distribution 11287a984708SDavid Chisnall{ 11297a984708SDavid Chisnallpublic: 11307a984708SDavid Chisnall // types 11317a984708SDavid Chisnall typedef RealType result_type; 11327a984708SDavid Chisnall 11337a984708SDavid Chisnall class param_type 11347a984708SDavid Chisnall { 11357a984708SDavid Chisnall public: 11367a984708SDavid Chisnall typedef lognormal_distribution distribution_type; 11377a984708SDavid Chisnall 11387a984708SDavid Chisnall explicit param_type(result_type m = 0, result_type s = 1); 11397a984708SDavid Chisnall 11407a984708SDavid Chisnall result_type m() const; 11417a984708SDavid Chisnall result_type s() const; 11427a984708SDavid Chisnall 11437a984708SDavid Chisnall friend bool operator==(const param_type& x, const param_type& y); 11447a984708SDavid Chisnall friend bool operator!=(const param_type& x, const param_type& y); 11457a984708SDavid Chisnall }; 11467a984708SDavid Chisnall 11477a984708SDavid Chisnall // constructor and reset functions 11487a984708SDavid Chisnall explicit lognormal_distribution(result_type m = 0, result_type s = 1); 11497a984708SDavid Chisnall explicit lognormal_distribution(const param_type& parm); 11507a984708SDavid Chisnall void reset(); 11517a984708SDavid Chisnall 11527a984708SDavid Chisnall // generating functions 11537a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g); 11547a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g, const param_type& parm); 11557a984708SDavid Chisnall 11567a984708SDavid Chisnall // property functions 11577a984708SDavid Chisnall result_type m() const; 11587a984708SDavid Chisnall result_type s() const; 11597a984708SDavid Chisnall 11607a984708SDavid Chisnall param_type param() const; 11617a984708SDavid Chisnall void param(const param_type& parm); 11627a984708SDavid Chisnall 11637a984708SDavid Chisnall result_type min() const; 11647a984708SDavid Chisnall result_type max() const; 11657a984708SDavid Chisnall 11667a984708SDavid Chisnall friend bool operator==(const lognormal_distribution& x, 11677a984708SDavid Chisnall const lognormal_distribution& y); 11687a984708SDavid Chisnall friend bool operator!=(const lognormal_distribution& x, 11697a984708SDavid Chisnall const lognormal_distribution& y); 11707a984708SDavid Chisnall 11717a984708SDavid Chisnall template <class charT, class traits> 11727a984708SDavid Chisnall friend 11737a984708SDavid Chisnall basic_ostream<charT, traits>& 11747a984708SDavid Chisnall operator<<(basic_ostream<charT, traits>& os, 11757a984708SDavid Chisnall const lognormal_distribution& x); 11767a984708SDavid Chisnall 11777a984708SDavid Chisnall template <class charT, class traits> 11787a984708SDavid Chisnall friend 11797a984708SDavid Chisnall basic_istream<charT, traits>& 11807a984708SDavid Chisnall operator>>(basic_istream<charT, traits>& is, 11817a984708SDavid Chisnall lognormal_distribution& x); 11827a984708SDavid Chisnall}; 11837a984708SDavid Chisnall 11847a984708SDavid Chisnalltemplate<class RealType = double> 11857a984708SDavid Chisnallclass chi_squared_distribution 11867a984708SDavid Chisnall{ 11877a984708SDavid Chisnallpublic: 11887a984708SDavid Chisnall // types 11897a984708SDavid Chisnall typedef RealType result_type; 11907a984708SDavid Chisnall 11917a984708SDavid Chisnall class param_type 11927a984708SDavid Chisnall { 11937a984708SDavid Chisnall public: 11947a984708SDavid Chisnall typedef chi_squared_distribution distribution_type; 11957a984708SDavid Chisnall 11967a984708SDavid Chisnall explicit param_type(result_type n = 1); 11977a984708SDavid Chisnall 11987a984708SDavid Chisnall result_type n() const; 11997a984708SDavid Chisnall 12007a984708SDavid Chisnall friend bool operator==(const param_type& x, const param_type& y); 12017a984708SDavid Chisnall friend bool operator!=(const param_type& x, const param_type& y); 12027a984708SDavid Chisnall }; 12037a984708SDavid Chisnall 12047a984708SDavid Chisnall // constructor and reset functions 12057a984708SDavid Chisnall explicit chi_squared_distribution(result_type n = 1); 12067a984708SDavid Chisnall explicit chi_squared_distribution(const param_type& parm); 12077a984708SDavid Chisnall void reset(); 12087a984708SDavid Chisnall 12097a984708SDavid Chisnall // generating functions 12107a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g); 12117a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g, const param_type& parm); 12127a984708SDavid Chisnall 12137a984708SDavid Chisnall // property functions 12147a984708SDavid Chisnall result_type n() const; 12157a984708SDavid Chisnall 12167a984708SDavid Chisnall param_type param() const; 12177a984708SDavid Chisnall void param(const param_type& parm); 12187a984708SDavid Chisnall 12197a984708SDavid Chisnall result_type min() const; 12207a984708SDavid Chisnall result_type max() const; 12217a984708SDavid Chisnall 12227a984708SDavid Chisnall friend bool operator==(const chi_squared_distribution& x, 12237a984708SDavid Chisnall const chi_squared_distribution& y); 12247a984708SDavid Chisnall friend bool operator!=(const chi_squared_distribution& x, 12257a984708SDavid Chisnall const chi_squared_distribution& y); 12267a984708SDavid Chisnall 12277a984708SDavid Chisnall template <class charT, class traits> 12287a984708SDavid Chisnall friend 12297a984708SDavid Chisnall basic_ostream<charT, traits>& 12307a984708SDavid Chisnall operator<<(basic_ostream<charT, traits>& os, 12317a984708SDavid Chisnall const chi_squared_distribution& x); 12327a984708SDavid Chisnall 12337a984708SDavid Chisnall template <class charT, class traits> 12347a984708SDavid Chisnall friend 12357a984708SDavid Chisnall basic_istream<charT, traits>& 12367a984708SDavid Chisnall operator>>(basic_istream<charT, traits>& is, 12377a984708SDavid Chisnall chi_squared_distribution& x); 12387a984708SDavid Chisnall}; 12397a984708SDavid Chisnall 12407a984708SDavid Chisnalltemplate<class RealType = double> 12417a984708SDavid Chisnallclass cauchy_distribution 12427a984708SDavid Chisnall{ 12437a984708SDavid Chisnallpublic: 12447a984708SDavid Chisnall // types 12457a984708SDavid Chisnall typedef RealType result_type; 12467a984708SDavid Chisnall 12477a984708SDavid Chisnall class param_type 12487a984708SDavid Chisnall { 12497a984708SDavid Chisnall public: 12507a984708SDavid Chisnall typedef cauchy_distribution distribution_type; 12517a984708SDavid Chisnall 12527a984708SDavid Chisnall explicit param_type(result_type a = 0, result_type b = 1); 12537a984708SDavid Chisnall 12547a984708SDavid Chisnall result_type a() const; 12557a984708SDavid Chisnall result_type b() const; 12567a984708SDavid Chisnall 12577a984708SDavid Chisnall friend bool operator==(const param_type& x, const param_type& y); 12587a984708SDavid Chisnall friend bool operator!=(const param_type& x, const param_type& y); 12597a984708SDavid Chisnall }; 12607a984708SDavid Chisnall 12617a984708SDavid Chisnall // constructor and reset functions 12627a984708SDavid Chisnall explicit cauchy_distribution(result_type a = 0, result_type b = 1); 12637a984708SDavid Chisnall explicit cauchy_distribution(const param_type& parm); 12647a984708SDavid Chisnall void reset(); 12657a984708SDavid Chisnall 12667a984708SDavid Chisnall // generating functions 12677a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g); 12687a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g, const param_type& parm); 12697a984708SDavid Chisnall 12707a984708SDavid Chisnall // property functions 12717a984708SDavid Chisnall result_type a() const; 12727a984708SDavid Chisnall result_type b() const; 12737a984708SDavid Chisnall 12747a984708SDavid Chisnall param_type param() const; 12757a984708SDavid Chisnall void param(const param_type& parm); 12767a984708SDavid Chisnall 12777a984708SDavid Chisnall result_type min() const; 12787a984708SDavid Chisnall result_type max() const; 12797a984708SDavid Chisnall 12807a984708SDavid Chisnall friend bool operator==(const cauchy_distribution& x, 12817a984708SDavid Chisnall const cauchy_distribution& y); 12827a984708SDavid Chisnall friend bool operator!=(const cauchy_distribution& x, 12837a984708SDavid Chisnall const cauchy_distribution& y); 12847a984708SDavid Chisnall 12857a984708SDavid Chisnall template <class charT, class traits> 12867a984708SDavid Chisnall friend 12877a984708SDavid Chisnall basic_ostream<charT, traits>& 12887a984708SDavid Chisnall operator<<(basic_ostream<charT, traits>& os, 12897a984708SDavid Chisnall const cauchy_distribution& x); 12907a984708SDavid Chisnall 12917a984708SDavid Chisnall template <class charT, class traits> 12927a984708SDavid Chisnall friend 12937a984708SDavid Chisnall basic_istream<charT, traits>& 12947a984708SDavid Chisnall operator>>(basic_istream<charT, traits>& is, 12957a984708SDavid Chisnall cauchy_distribution& x); 12967a984708SDavid Chisnall}; 12977a984708SDavid Chisnall 12987a984708SDavid Chisnalltemplate<class RealType = double> 12997a984708SDavid Chisnallclass fisher_f_distribution 13007a984708SDavid Chisnall{ 13017a984708SDavid Chisnallpublic: 13027a984708SDavid Chisnall // types 13037a984708SDavid Chisnall typedef RealType result_type; 13047a984708SDavid Chisnall 13057a984708SDavid Chisnall class param_type 13067a984708SDavid Chisnall { 13077a984708SDavid Chisnall public: 13087a984708SDavid Chisnall typedef fisher_f_distribution distribution_type; 13097a984708SDavid Chisnall 13107a984708SDavid Chisnall explicit param_type(result_type m = 1, result_type n = 1); 13117a984708SDavid Chisnall 13127a984708SDavid Chisnall result_type m() const; 13137a984708SDavid Chisnall result_type n() const; 13147a984708SDavid Chisnall 13157a984708SDavid Chisnall friend bool operator==(const param_type& x, const param_type& y); 13167a984708SDavid Chisnall friend bool operator!=(const param_type& x, const param_type& y); 13177a984708SDavid Chisnall }; 13187a984708SDavid Chisnall 13197a984708SDavid Chisnall // constructor and reset functions 13207a984708SDavid Chisnall explicit fisher_f_distribution(result_type m = 1, result_type n = 1); 13217a984708SDavid Chisnall explicit fisher_f_distribution(const param_type& parm); 13227a984708SDavid Chisnall void reset(); 13237a984708SDavid Chisnall 13247a984708SDavid Chisnall // generating functions 13257a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g); 13267a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g, const param_type& parm); 13277a984708SDavid Chisnall 13287a984708SDavid Chisnall // property functions 13297a984708SDavid Chisnall result_type m() const; 13307a984708SDavid Chisnall result_type n() const; 13317a984708SDavid Chisnall 13327a984708SDavid Chisnall param_type param() const; 13337a984708SDavid Chisnall void param(const param_type& parm); 13347a984708SDavid Chisnall 13357a984708SDavid Chisnall result_type min() const; 13367a984708SDavid Chisnall result_type max() const; 13377a984708SDavid Chisnall 13387a984708SDavid Chisnall friend bool operator==(const fisher_f_distribution& x, 13397a984708SDavid Chisnall const fisher_f_distribution& y); 13407a984708SDavid Chisnall friend bool operator!=(const fisher_f_distribution& x, 13417a984708SDavid Chisnall const fisher_f_distribution& y); 13427a984708SDavid Chisnall 13437a984708SDavid Chisnall template <class charT, class traits> 13447a984708SDavid Chisnall friend 13457a984708SDavid Chisnall basic_ostream<charT, traits>& 13467a984708SDavid Chisnall operator<<(basic_ostream<charT, traits>& os, 13477a984708SDavid Chisnall const fisher_f_distribution& x); 13487a984708SDavid Chisnall 13497a984708SDavid Chisnall template <class charT, class traits> 13507a984708SDavid Chisnall friend 13517a984708SDavid Chisnall basic_istream<charT, traits>& 13527a984708SDavid Chisnall operator>>(basic_istream<charT, traits>& is, 13537a984708SDavid Chisnall fisher_f_distribution& x); 13547a984708SDavid Chisnall}; 13557a984708SDavid Chisnall 13567a984708SDavid Chisnalltemplate<class RealType = double> 13577a984708SDavid Chisnallclass student_t_distribution 13587a984708SDavid Chisnall{ 13597a984708SDavid Chisnallpublic: 13607a984708SDavid Chisnall // types 13617a984708SDavid Chisnall typedef RealType result_type; 13627a984708SDavid Chisnall 13637a984708SDavid Chisnall class param_type 13647a984708SDavid Chisnall { 13657a984708SDavid Chisnall public: 13667a984708SDavid Chisnall typedef student_t_distribution distribution_type; 13677a984708SDavid Chisnall 13687a984708SDavid Chisnall explicit param_type(result_type n = 1); 13697a984708SDavid Chisnall 13707a984708SDavid Chisnall result_type n() const; 13717a984708SDavid Chisnall 13727a984708SDavid Chisnall friend bool operator==(const param_type& x, const param_type& y); 13737a984708SDavid Chisnall friend bool operator!=(const param_type& x, const param_type& y); 13747a984708SDavid Chisnall }; 13757a984708SDavid Chisnall 13767a984708SDavid Chisnall // constructor and reset functions 13777a984708SDavid Chisnall explicit student_t_distribution(result_type n = 1); 13787a984708SDavid Chisnall explicit student_t_distribution(const param_type& parm); 13797a984708SDavid Chisnall void reset(); 13807a984708SDavid Chisnall 13817a984708SDavid Chisnall // generating functions 13827a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g); 13837a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g, const param_type& parm); 13847a984708SDavid Chisnall 13857a984708SDavid Chisnall // property functions 13867a984708SDavid Chisnall result_type n() const; 13877a984708SDavid Chisnall 13887a984708SDavid Chisnall param_type param() const; 13897a984708SDavid Chisnall void param(const param_type& parm); 13907a984708SDavid Chisnall 13917a984708SDavid Chisnall result_type min() const; 13927a984708SDavid Chisnall result_type max() const; 13937a984708SDavid Chisnall 13947a984708SDavid Chisnall friend bool operator==(const student_t_distribution& x, 13957a984708SDavid Chisnall const student_t_distribution& y); 13967a984708SDavid Chisnall friend bool operator!=(const student_t_distribution& x, 13977a984708SDavid Chisnall const student_t_distribution& y); 13987a984708SDavid Chisnall 13997a984708SDavid Chisnall template <class charT, class traits> 14007a984708SDavid Chisnall friend 14017a984708SDavid Chisnall basic_ostream<charT, traits>& 14027a984708SDavid Chisnall operator<<(basic_ostream<charT, traits>& os, 14037a984708SDavid Chisnall const student_t_distribution& x); 14047a984708SDavid Chisnall 14057a984708SDavid Chisnall template <class charT, class traits> 14067a984708SDavid Chisnall friend 14077a984708SDavid Chisnall basic_istream<charT, traits>& 14087a984708SDavid Chisnall operator>>(basic_istream<charT, traits>& is, 14097a984708SDavid Chisnall student_t_distribution& x); 14107a984708SDavid Chisnall}; 14117a984708SDavid Chisnall 14127a984708SDavid Chisnalltemplate<class IntType = int> 14137a984708SDavid Chisnallclass discrete_distribution 14147a984708SDavid Chisnall{ 14157a984708SDavid Chisnallpublic: 14167a984708SDavid Chisnall // types 14177a984708SDavid Chisnall typedef IntType result_type; 14187a984708SDavid Chisnall 14197a984708SDavid Chisnall class param_type 14207a984708SDavid Chisnall { 14217a984708SDavid Chisnall public: 14227a984708SDavid Chisnall typedef discrete_distribution distribution_type; 14237a984708SDavid Chisnall 14247a984708SDavid Chisnall param_type(); 14257a984708SDavid Chisnall template<class InputIterator> 14267a984708SDavid Chisnall param_type(InputIterator firstW, InputIterator lastW); 14277a984708SDavid Chisnall param_type(initializer_list<double> wl); 14287a984708SDavid Chisnall template<class UnaryOperation> 14297a984708SDavid Chisnall param_type(size_t nw, double xmin, double xmax, UnaryOperation fw); 14307a984708SDavid Chisnall 14317a984708SDavid Chisnall vector<double> probabilities() const; 14327a984708SDavid Chisnall 14337a984708SDavid Chisnall friend bool operator==(const param_type& x, const param_type& y); 14347a984708SDavid Chisnall friend bool operator!=(const param_type& x, const param_type& y); 14357a984708SDavid Chisnall }; 14367a984708SDavid Chisnall 14377a984708SDavid Chisnall // constructor and reset functions 14387a984708SDavid Chisnall discrete_distribution(); 14397a984708SDavid Chisnall template<class InputIterator> 14407a984708SDavid Chisnall discrete_distribution(InputIterator firstW, InputIterator lastW); 14417a984708SDavid Chisnall discrete_distribution(initializer_list<double> wl); 14427a984708SDavid Chisnall template<class UnaryOperation> 14437a984708SDavid Chisnall discrete_distribution(size_t nw, double xmin, double xmax, 14447a984708SDavid Chisnall UnaryOperation fw); 14457a984708SDavid Chisnall explicit discrete_distribution(const param_type& parm); 14467a984708SDavid Chisnall void reset(); 14477a984708SDavid Chisnall 14487a984708SDavid Chisnall // generating functions 14497a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g); 14507a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g, const param_type& parm); 14517a984708SDavid Chisnall 14527a984708SDavid Chisnall // property functions 14537a984708SDavid Chisnall vector<double> probabilities() const; 14547a984708SDavid Chisnall 14557a984708SDavid Chisnall param_type param() const; 14567a984708SDavid Chisnall void param(const param_type& parm); 14577a984708SDavid Chisnall 14587a984708SDavid Chisnall result_type min() const; 14597a984708SDavid Chisnall result_type max() const; 14607a984708SDavid Chisnall 14617a984708SDavid Chisnall friend bool operator==(const discrete_distribution& x, 14627a984708SDavid Chisnall const discrete_distribution& y); 14637a984708SDavid Chisnall friend bool operator!=(const discrete_distribution& x, 14647a984708SDavid Chisnall const discrete_distribution& y); 14657a984708SDavid Chisnall 14667a984708SDavid Chisnall template <class charT, class traits> 14677a984708SDavid Chisnall friend 14687a984708SDavid Chisnall basic_ostream<charT, traits>& 14697a984708SDavid Chisnall operator<<(basic_ostream<charT, traits>& os, 14707a984708SDavid Chisnall const discrete_distribution& x); 14717a984708SDavid Chisnall 14727a984708SDavid Chisnall template <class charT, class traits> 14737a984708SDavid Chisnall friend 14747a984708SDavid Chisnall basic_istream<charT, traits>& 14757a984708SDavid Chisnall operator>>(basic_istream<charT, traits>& is, 14767a984708SDavid Chisnall discrete_distribution& x); 14777a984708SDavid Chisnall}; 14787a984708SDavid Chisnall 14797a984708SDavid Chisnalltemplate<class RealType = double> 14807a984708SDavid Chisnallclass piecewise_constant_distribution 14817a984708SDavid Chisnall{ 14827a984708SDavid Chisnall // types 14837a984708SDavid Chisnall typedef RealType result_type; 14847a984708SDavid Chisnall 14857a984708SDavid Chisnall class param_type 14867a984708SDavid Chisnall { 14877a984708SDavid Chisnall public: 14887a984708SDavid Chisnall typedef piecewise_constant_distribution distribution_type; 14897a984708SDavid Chisnall 14907a984708SDavid Chisnall param_type(); 14917a984708SDavid Chisnall template<class InputIteratorB, class InputIteratorW> 14927a984708SDavid Chisnall param_type(InputIteratorB firstB, InputIteratorB lastB, 14937a984708SDavid Chisnall InputIteratorW firstW); 14947a984708SDavid Chisnall template<class UnaryOperation> 14957a984708SDavid Chisnall param_type(initializer_list<result_type> bl, UnaryOperation fw); 14967a984708SDavid Chisnall template<class UnaryOperation> 14977a984708SDavid Chisnall param_type(size_t nw, result_type xmin, result_type xmax, 14987a984708SDavid Chisnall UnaryOperation fw); 14997a984708SDavid Chisnall 15007a984708SDavid Chisnall vector<result_type> intervals() const; 15017a984708SDavid Chisnall vector<result_type> densities() const; 15027a984708SDavid Chisnall 15037a984708SDavid Chisnall friend bool operator==(const param_type& x, const param_type& y); 15047a984708SDavid Chisnall friend bool operator!=(const param_type& x, const param_type& y); 15057a984708SDavid Chisnall }; 15067a984708SDavid Chisnall 15077a984708SDavid Chisnall // constructor and reset functions 15087a984708SDavid Chisnall piecewise_constant_distribution(); 15097a984708SDavid Chisnall template<class InputIteratorB, class InputIteratorW> 15107a984708SDavid Chisnall piecewise_constant_distribution(InputIteratorB firstB, 15117a984708SDavid Chisnall InputIteratorB lastB, 15127a984708SDavid Chisnall InputIteratorW firstW); 15137a984708SDavid Chisnall template<class UnaryOperation> 15147a984708SDavid Chisnall piecewise_constant_distribution(initializer_list<result_type> bl, 15157a984708SDavid Chisnall UnaryOperation fw); 15167a984708SDavid Chisnall template<class UnaryOperation> 15177a984708SDavid Chisnall piecewise_constant_distribution(size_t nw, result_type xmin, 15187a984708SDavid Chisnall result_type xmax, UnaryOperation fw); 15197a984708SDavid Chisnall explicit piecewise_constant_distribution(const param_type& parm); 15207a984708SDavid Chisnall void reset(); 15217a984708SDavid Chisnall 15227a984708SDavid Chisnall // generating functions 15237a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g); 15247a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g, const param_type& parm); 15257a984708SDavid Chisnall 15267a984708SDavid Chisnall // property functions 15277a984708SDavid Chisnall vector<result_type> intervals() const; 15287a984708SDavid Chisnall vector<result_type> densities() const; 15297a984708SDavid Chisnall 15307a984708SDavid Chisnall param_type param() const; 15317a984708SDavid Chisnall void param(const param_type& parm); 15327a984708SDavid Chisnall 15337a984708SDavid Chisnall result_type min() const; 15347a984708SDavid Chisnall result_type max() const; 15357a984708SDavid Chisnall 15367a984708SDavid Chisnall friend bool operator==(const piecewise_constant_distribution& x, 15377a984708SDavid Chisnall const piecewise_constant_distribution& y); 15387a984708SDavid Chisnall friend bool operator!=(const piecewise_constant_distribution& x, 15397a984708SDavid Chisnall const piecewise_constant_distribution& y); 15407a984708SDavid Chisnall 15417a984708SDavid Chisnall template <class charT, class traits> 15427a984708SDavid Chisnall friend 15437a984708SDavid Chisnall basic_ostream<charT, traits>& 15447a984708SDavid Chisnall operator<<(basic_ostream<charT, traits>& os, 15457a984708SDavid Chisnall const piecewise_constant_distribution& x); 15467a984708SDavid Chisnall 15477a984708SDavid Chisnall template <class charT, class traits> 15487a984708SDavid Chisnall friend 15497a984708SDavid Chisnall basic_istream<charT, traits>& 15507a984708SDavid Chisnall operator>>(basic_istream<charT, traits>& is, 15517a984708SDavid Chisnall piecewise_constant_distribution& x); 15527a984708SDavid Chisnall}; 15537a984708SDavid Chisnall 15547a984708SDavid Chisnalltemplate<class RealType = double> 15557a984708SDavid Chisnallclass piecewise_linear_distribution 15567a984708SDavid Chisnall{ 15577a984708SDavid Chisnall // types 15587a984708SDavid Chisnall typedef RealType result_type; 15597a984708SDavid Chisnall 15607a984708SDavid Chisnall class param_type 15617a984708SDavid Chisnall { 15627a984708SDavid Chisnall public: 15637a984708SDavid Chisnall typedef piecewise_linear_distribution distribution_type; 15647a984708SDavid Chisnall 15657a984708SDavid Chisnall param_type(); 15667a984708SDavid Chisnall template<class InputIteratorB, class InputIteratorW> 15677a984708SDavid Chisnall param_type(InputIteratorB firstB, InputIteratorB lastB, 15687a984708SDavid Chisnall InputIteratorW firstW); 15697a984708SDavid Chisnall template<class UnaryOperation> 15707a984708SDavid Chisnall param_type(initializer_list<result_type> bl, UnaryOperation fw); 15717a984708SDavid Chisnall template<class UnaryOperation> 15727a984708SDavid Chisnall param_type(size_t nw, result_type xmin, result_type xmax, 15737a984708SDavid Chisnall UnaryOperation fw); 15747a984708SDavid Chisnall 15757a984708SDavid Chisnall vector<result_type> intervals() const; 15767a984708SDavid Chisnall vector<result_type> densities() const; 15777a984708SDavid Chisnall 15787a984708SDavid Chisnall friend bool operator==(const param_type& x, const param_type& y); 15797a984708SDavid Chisnall friend bool operator!=(const param_type& x, const param_type& y); 15807a984708SDavid Chisnall }; 15817a984708SDavid Chisnall 15827a984708SDavid Chisnall // constructor and reset functions 15837a984708SDavid Chisnall piecewise_linear_distribution(); 15847a984708SDavid Chisnall template<class InputIteratorB, class InputIteratorW> 15857a984708SDavid Chisnall piecewise_linear_distribution(InputIteratorB firstB, 15867a984708SDavid Chisnall InputIteratorB lastB, 15877a984708SDavid Chisnall InputIteratorW firstW); 15887a984708SDavid Chisnall 15897a984708SDavid Chisnall template<class UnaryOperation> 15907a984708SDavid Chisnall piecewise_linear_distribution(initializer_list<result_type> bl, 15917a984708SDavid Chisnall UnaryOperation fw); 15927a984708SDavid Chisnall 15937a984708SDavid Chisnall template<class UnaryOperation> 15947a984708SDavid Chisnall piecewise_linear_distribution(size_t nw, result_type xmin, 15957a984708SDavid Chisnall result_type xmax, UnaryOperation fw); 15967a984708SDavid Chisnall 15977a984708SDavid Chisnall explicit piecewise_linear_distribution(const param_type& parm); 15987a984708SDavid Chisnall void reset(); 15997a984708SDavid Chisnall 16007a984708SDavid Chisnall // generating functions 16017a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g); 16027a984708SDavid Chisnall template<class URNG> result_type operator()(URNG& g, const param_type& parm); 16037a984708SDavid Chisnall 16047a984708SDavid Chisnall // property functions 16057a984708SDavid Chisnall vector<result_type> intervals() const; 16067a984708SDavid Chisnall vector<result_type> densities() const; 16077a984708SDavid Chisnall 16087a984708SDavid Chisnall param_type param() const; 16097a984708SDavid Chisnall void param(const param_type& parm); 16107a984708SDavid Chisnall 16117a984708SDavid Chisnall result_type min() const; 16127a984708SDavid Chisnall result_type max() const; 16137a984708SDavid Chisnall 16147a984708SDavid Chisnall friend bool operator==(const piecewise_linear_distribution& x, 16157a984708SDavid Chisnall const piecewise_linear_distribution& y); 16167a984708SDavid Chisnall friend bool operator!=(const piecewise_linear_distribution& x, 16177a984708SDavid Chisnall const piecewise_linear_distribution& y); 16187a984708SDavid Chisnall 16197a984708SDavid Chisnall template <class charT, class traits> 16207a984708SDavid Chisnall friend 16217a984708SDavid Chisnall basic_ostream<charT, traits>& 16227a984708SDavid Chisnall operator<<(basic_ostream<charT, traits>& os, 16237a984708SDavid Chisnall const piecewise_linear_distribution& x); 16247a984708SDavid Chisnall 16257a984708SDavid Chisnall template <class charT, class traits> 16267a984708SDavid Chisnall friend 16277a984708SDavid Chisnall basic_istream<charT, traits>& 16287a984708SDavid Chisnall operator>>(basic_istream<charT, traits>& is, 16297a984708SDavid Chisnall piecewise_linear_distribution& x); 16307a984708SDavid Chisnall}; 16317a984708SDavid Chisnall 16327a984708SDavid Chisnall} // std 16337a984708SDavid Chisnall*/ 16347a984708SDavid Chisnall 16357a984708SDavid Chisnall#include <__config> 16367a984708SDavid Chisnall#include <cstddef> 1637854fa44bSDimitry Andric#include <cstdint> 1638854fa44bSDimitry Andric#include <cmath> 16397a984708SDavid Chisnall#include <type_traits> 16407a984708SDavid Chisnall#include <initializer_list> 16417a984708SDavid Chisnall#include <limits> 16427a984708SDavid Chisnall#include <algorithm> 16437a984708SDavid Chisnall#include <numeric> 16447a984708SDavid Chisnall#include <vector> 16457a984708SDavid Chisnall#include <string> 16467a984708SDavid Chisnall#include <istream> 16477a984708SDavid Chisnall#include <ostream> 16487a984708SDavid Chisnall 16497a984708SDavid Chisnall#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 16507a984708SDavid Chisnall#pragma GCC system_header 16517a984708SDavid Chisnall#endif 16527a984708SDavid Chisnall 1653f9448bf3SDimitry Andric_LIBCPP_PUSH_MACROS 1654f9448bf3SDimitry Andric#include <__undef_macros> 1655f9448bf3SDimitry Andric 1656f9448bf3SDimitry Andric 16577a984708SDavid Chisnall_LIBCPP_BEGIN_NAMESPACE_STD 16587a984708SDavid Chisnall 16597a984708SDavid Chisnall// __is_seed_sequence 16607a984708SDavid Chisnall 16617a984708SDavid Chisnalltemplate <class _Sseq, class _Engine> 16627a984708SDavid Chisnallstruct __is_seed_sequence 16637a984708SDavid Chisnall{ 1664b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const bool value = 16657a984708SDavid Chisnall !is_convertible<_Sseq, typename _Engine::result_type>::value && 16667a984708SDavid Chisnall !is_same<typename remove_cv<_Sseq>::type, _Engine>::value; 16677a984708SDavid Chisnall}; 16687a984708SDavid Chisnall 16697a984708SDavid Chisnall// linear_congruential_engine 16707a984708SDavid Chisnall 16717a984708SDavid Chisnalltemplate <unsigned long long __a, unsigned long long __c, 167294e3ee44SDavid Chisnall unsigned long long __m, unsigned long long _Mp, 167394e3ee44SDavid Chisnall bool _MightOverflow = (__a != 0 && __m != 0 && __m-1 > (_Mp-__c)/__a)> 16747a984708SDavid Chisnallstruct __lce_ta; 16757a984708SDavid Chisnall 16767a984708SDavid Chisnall// 64 16777a984708SDavid Chisnall 16787a984708SDavid Chisnalltemplate <unsigned long long __a, unsigned long long __c, unsigned long long __m> 16797a984708SDavid Chisnallstruct __lce_ta<__a, __c, __m, (unsigned long long)(~0), true> 16807a984708SDavid Chisnall{ 16817a984708SDavid Chisnall typedef unsigned long long result_type; 16827a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 16837a984708SDavid Chisnall static result_type next(result_type __x) 16847a984708SDavid Chisnall { 16857a984708SDavid Chisnall // Schrage's algorithm 16867a984708SDavid Chisnall const result_type __q = __m / __a; 16877a984708SDavid Chisnall const result_type __r = __m % __a; 16887a984708SDavid Chisnall const result_type __t0 = __a * (__x % __q); 16897a984708SDavid Chisnall const result_type __t1 = __r * (__x / __q); 16907a984708SDavid Chisnall __x = __t0 + (__t0 < __t1) * __m - __t1; 16917a984708SDavid Chisnall __x += __c - (__x >= __m - __c) * __m; 16927a984708SDavid Chisnall return __x; 16937a984708SDavid Chisnall } 16947a984708SDavid Chisnall}; 16957a984708SDavid Chisnall 16967a984708SDavid Chisnalltemplate <unsigned long long __a, unsigned long long __m> 16977a984708SDavid Chisnallstruct __lce_ta<__a, 0, __m, (unsigned long long)(~0), true> 16987a984708SDavid Chisnall{ 16997a984708SDavid Chisnall typedef unsigned long long result_type; 17007a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 17017a984708SDavid Chisnall static result_type next(result_type __x) 17027a984708SDavid Chisnall { 17037a984708SDavid Chisnall // Schrage's algorithm 17047a984708SDavid Chisnall const result_type __q = __m / __a; 17057a984708SDavid Chisnall const result_type __r = __m % __a; 17067a984708SDavid Chisnall const result_type __t0 = __a * (__x % __q); 17077a984708SDavid Chisnall const result_type __t1 = __r * (__x / __q); 17087a984708SDavid Chisnall __x = __t0 + (__t0 < __t1) * __m - __t1; 17097a984708SDavid Chisnall return __x; 17107a984708SDavid Chisnall } 17117a984708SDavid Chisnall}; 17127a984708SDavid Chisnall 17137a984708SDavid Chisnalltemplate <unsigned long long __a, unsigned long long __c, unsigned long long __m> 17147a984708SDavid Chisnallstruct __lce_ta<__a, __c, __m, (unsigned long long)(~0), false> 17157a984708SDavid Chisnall{ 17167a984708SDavid Chisnall typedef unsigned long long result_type; 17177a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 17187a984708SDavid Chisnall static result_type next(result_type __x) 17197a984708SDavid Chisnall { 17207a984708SDavid Chisnall return (__a * __x + __c) % __m; 17217a984708SDavid Chisnall } 17227a984708SDavid Chisnall}; 17237a984708SDavid Chisnall 17247a984708SDavid Chisnalltemplate <unsigned long long __a, unsigned long long __c> 17257a984708SDavid Chisnallstruct __lce_ta<__a, __c, 0, (unsigned long long)(~0), false> 17267a984708SDavid Chisnall{ 17277a984708SDavid Chisnall typedef unsigned long long result_type; 17287a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 17297a984708SDavid Chisnall static result_type next(result_type __x) 17307a984708SDavid Chisnall { 17317a984708SDavid Chisnall return __a * __x + __c; 17327a984708SDavid Chisnall } 17337a984708SDavid Chisnall}; 17347a984708SDavid Chisnall 17357a984708SDavid Chisnall// 32 17367a984708SDavid Chisnall 173794e3ee44SDavid Chisnalltemplate <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp> 173894e3ee44SDavid Chisnallstruct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), true> 17397a984708SDavid Chisnall{ 17407a984708SDavid Chisnall typedef unsigned result_type; 17417a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 17427a984708SDavid Chisnall static result_type next(result_type __x) 17437a984708SDavid Chisnall { 174494e3ee44SDavid Chisnall const result_type __a = static_cast<result_type>(_Ap); 174594e3ee44SDavid Chisnall const result_type __c = static_cast<result_type>(_Cp); 174694e3ee44SDavid Chisnall const result_type __m = static_cast<result_type>(_Mp); 17477a984708SDavid Chisnall // Schrage's algorithm 17487a984708SDavid Chisnall const result_type __q = __m / __a; 17497a984708SDavid Chisnall const result_type __r = __m % __a; 17507a984708SDavid Chisnall const result_type __t0 = __a * (__x % __q); 17517a984708SDavid Chisnall const result_type __t1 = __r * (__x / __q); 17527a984708SDavid Chisnall __x = __t0 + (__t0 < __t1) * __m - __t1; 17537a984708SDavid Chisnall __x += __c - (__x >= __m - __c) * __m; 17547a984708SDavid Chisnall return __x; 17557a984708SDavid Chisnall } 17567a984708SDavid Chisnall}; 17577a984708SDavid Chisnall 175894e3ee44SDavid Chisnalltemplate <unsigned long long _Ap, unsigned long long _Mp> 175994e3ee44SDavid Chisnallstruct __lce_ta<_Ap, 0, _Mp, unsigned(~0), true> 17607a984708SDavid Chisnall{ 17617a984708SDavid Chisnall typedef unsigned result_type; 17627a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 17637a984708SDavid Chisnall static result_type next(result_type __x) 17647a984708SDavid Chisnall { 176594e3ee44SDavid Chisnall const result_type __a = static_cast<result_type>(_Ap); 176694e3ee44SDavid Chisnall const result_type __m = static_cast<result_type>(_Mp); 17677a984708SDavid Chisnall // Schrage's algorithm 17687a984708SDavid Chisnall const result_type __q = __m / __a; 17697a984708SDavid Chisnall const result_type __r = __m % __a; 17707a984708SDavid Chisnall const result_type __t0 = __a * (__x % __q); 17717a984708SDavid Chisnall const result_type __t1 = __r * (__x / __q); 17727a984708SDavid Chisnall __x = __t0 + (__t0 < __t1) * __m - __t1; 17737a984708SDavid Chisnall return __x; 17747a984708SDavid Chisnall } 17757a984708SDavid Chisnall}; 17767a984708SDavid Chisnall 177794e3ee44SDavid Chisnalltemplate <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp> 177894e3ee44SDavid Chisnallstruct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), false> 17797a984708SDavid Chisnall{ 17807a984708SDavid Chisnall typedef unsigned result_type; 17817a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 17827a984708SDavid Chisnall static result_type next(result_type __x) 17837a984708SDavid Chisnall { 178494e3ee44SDavid Chisnall const result_type __a = static_cast<result_type>(_Ap); 178594e3ee44SDavid Chisnall const result_type __c = static_cast<result_type>(_Cp); 178694e3ee44SDavid Chisnall const result_type __m = static_cast<result_type>(_Mp); 17877a984708SDavid Chisnall return (__a * __x + __c) % __m; 17887a984708SDavid Chisnall } 17897a984708SDavid Chisnall}; 17907a984708SDavid Chisnall 179194e3ee44SDavid Chisnalltemplate <unsigned long long _Ap, unsigned long long _Cp> 179294e3ee44SDavid Chisnallstruct __lce_ta<_Ap, _Cp, 0, unsigned(~0), false> 17937a984708SDavid Chisnall{ 17947a984708SDavid Chisnall typedef unsigned result_type; 17957a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 17967a984708SDavid Chisnall static result_type next(result_type __x) 17977a984708SDavid Chisnall { 179894e3ee44SDavid Chisnall const result_type __a = static_cast<result_type>(_Ap); 179994e3ee44SDavid Chisnall const result_type __c = static_cast<result_type>(_Cp); 18007a984708SDavid Chisnall return __a * __x + __c; 18017a984708SDavid Chisnall } 18027a984708SDavid Chisnall}; 18037a984708SDavid Chisnall 18047a984708SDavid Chisnall// 16 18057a984708SDavid Chisnall 18067a984708SDavid Chisnalltemplate <unsigned long long __a, unsigned long long __c, unsigned long long __m, bool __b> 18077a984708SDavid Chisnallstruct __lce_ta<__a, __c, __m, (unsigned short)(~0), __b> 18087a984708SDavid Chisnall{ 18097a984708SDavid Chisnall typedef unsigned short result_type; 18107a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 18117a984708SDavid Chisnall static result_type next(result_type __x) 18127a984708SDavid Chisnall { 18137a984708SDavid Chisnall return static_cast<result_type>(__lce_ta<__a, __c, __m, unsigned(~0)>::next(__x)); 18147a984708SDavid Chisnall } 18157a984708SDavid Chisnall}; 18167a984708SDavid Chisnall 18177a984708SDavid Chisnalltemplate <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 1818aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS linear_congruential_engine; 18197a984708SDavid Chisnall 18207a984708SDavid Chisnalltemplate <class _CharT, class _Traits, 182194e3ee44SDavid Chisnall class _Up, _Up _Ap, _Up _Cp, _Up _Np> 1822936e9439SDimitry Andric_LIBCPP_INLINE_VISIBILITY 18237a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 18247a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 182594e3ee44SDavid Chisnall const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&); 18267a984708SDavid Chisnall 18277a984708SDavid Chisnalltemplate <class _CharT, class _Traits, 182894e3ee44SDavid Chisnall class _Up, _Up _Ap, _Up _Cp, _Up _Np> 18297a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 18307a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 183194e3ee44SDavid Chisnall linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x); 18327a984708SDavid Chisnall 18337a984708SDavid Chisnalltemplate <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 1834aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS linear_congruential_engine 18357a984708SDavid Chisnall{ 18367a984708SDavid Chisnallpublic: 18377a984708SDavid Chisnall // types 18387a984708SDavid Chisnall typedef _UIntType result_type; 18397a984708SDavid Chisnall 18407a984708SDavid Chisnallprivate: 18417a984708SDavid Chisnall result_type __x_; 18427a984708SDavid Chisnall 1843b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type _Mp = result_type(~0); 18447a984708SDavid Chisnall 18457a984708SDavid Chisnall static_assert(__m == 0 || __a < __m, "linear_congruential_engine invalid parameters"); 18467a984708SDavid Chisnall static_assert(__m == 0 || __c < __m, "linear_congruential_engine invalid parameters"); 18477a984708SDavid Chisnallpublic: 1848b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type _Min = __c == 0u ? 1u: 0u; 1849b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type _Max = __m - 1u; 18507a984708SDavid Chisnall static_assert(_Min < _Max, "linear_congruential_engine invalid parameters"); 18517a984708SDavid Chisnall 18527a984708SDavid Chisnall // engine characteristics 1853b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type multiplier = __a; 1854b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type increment = __c; 1855b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type modulus = __m; 18567a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 1857b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR result_type min() {return _Min;} 18587a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 1859b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR result_type max() {return _Max;} 1860b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type default_seed = 1u; 18617a984708SDavid Chisnall 18627a984708SDavid Chisnall // constructors and seeding functions 18637a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 18647a984708SDavid Chisnall explicit linear_congruential_engine(result_type __s = default_seed) 18657a984708SDavid Chisnall {seed(__s);} 186694e3ee44SDavid Chisnall template<class _Sseq> 18677a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 186894e3ee44SDavid Chisnall explicit linear_congruential_engine(_Sseq& __q, 18697a984708SDavid Chisnall typename enable_if<__is_seed_sequence<_Sseq, linear_congruential_engine>::value>::type* = 0) 18707a984708SDavid Chisnall {seed(__q);} 18717a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 18727a984708SDavid Chisnall void seed(result_type __s = default_seed) 18737a984708SDavid Chisnall {seed(integral_constant<bool, __m == 0>(), 18747a984708SDavid Chisnall integral_constant<bool, __c == 0>(), __s);} 18757a984708SDavid Chisnall template<class _Sseq> 18767a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 18777a984708SDavid Chisnall typename enable_if 18787a984708SDavid Chisnall < 18797a984708SDavid Chisnall __is_seed_sequence<_Sseq, linear_congruential_engine>::value, 18807a984708SDavid Chisnall void 18817a984708SDavid Chisnall >::type 18827a984708SDavid Chisnall seed(_Sseq& __q) 18837a984708SDavid Chisnall {__seed(__q, integral_constant<unsigned, 18847a984708SDavid Chisnall 1 + (__m == 0 ? (sizeof(result_type) * __CHAR_BIT__ - 1)/32 18854bab9fd9SDavid Chisnall : (__m > 0x100000000ull))>());} 18867a984708SDavid Chisnall 18877a984708SDavid Chisnall // generating functions 18887a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 18897a984708SDavid Chisnall result_type operator()() 189094e3ee44SDavid Chisnall {return __x_ = static_cast<result_type>(__lce_ta<__a, __c, __m, _Mp>::next(__x_));} 18917a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 18927a984708SDavid Chisnall void discard(unsigned long long __z) {for (; __z; --__z) operator()();} 18937a984708SDavid Chisnall 18947a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 18957a984708SDavid Chisnall bool operator==(const linear_congruential_engine& __x, 18967a984708SDavid Chisnall const linear_congruential_engine& __y) 18977a984708SDavid Chisnall {return __x.__x_ == __y.__x_;} 18987a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 18997a984708SDavid Chisnall bool operator!=(const linear_congruential_engine& __x, 19007a984708SDavid Chisnall const linear_congruential_engine& __y) 19017a984708SDavid Chisnall {return !(__x == __y);} 19027a984708SDavid Chisnall 19037a984708SDavid Chisnallprivate: 19047a984708SDavid Chisnall 19057a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 19067a984708SDavid Chisnall void seed(true_type, true_type, result_type __s) {__x_ = __s == 0 ? 1 : __s;} 19077a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 19087a984708SDavid Chisnall void seed(true_type, false_type, result_type __s) {__x_ = __s;} 19097a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 19107a984708SDavid Chisnall void seed(false_type, true_type, result_type __s) {__x_ = __s % __m == 0 ? 19117a984708SDavid Chisnall 1 : __s % __m;} 19127a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 19137a984708SDavid Chisnall void seed(false_type, false_type, result_type __s) {__x_ = __s % __m;} 19147a984708SDavid Chisnall 19157a984708SDavid Chisnall template<class _Sseq> 19167a984708SDavid Chisnall void __seed(_Sseq& __q, integral_constant<unsigned, 1>); 19177a984708SDavid Chisnall template<class _Sseq> 19187a984708SDavid Chisnall void __seed(_Sseq& __q, integral_constant<unsigned, 2>); 19197a984708SDavid Chisnall 19207a984708SDavid Chisnall template <class _CharT, class _Traits, 192194e3ee44SDavid Chisnall class _Up, _Up _Ap, _Up _Cp, _Up _Np> 19227a984708SDavid Chisnall friend 19237a984708SDavid Chisnall basic_ostream<_CharT, _Traits>& 19247a984708SDavid Chisnall operator<<(basic_ostream<_CharT, _Traits>& __os, 192594e3ee44SDavid Chisnall const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&); 19267a984708SDavid Chisnall 19277a984708SDavid Chisnall template <class _CharT, class _Traits, 192894e3ee44SDavid Chisnall class _Up, _Up _Ap, _Up _Cp, _Up _Np> 19297a984708SDavid Chisnall friend 19307a984708SDavid Chisnall basic_istream<_CharT, _Traits>& 19317a984708SDavid Chisnall operator>>(basic_istream<_CharT, _Traits>& __is, 193294e3ee44SDavid Chisnall linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x); 19337a984708SDavid Chisnall}; 19347a984708SDavid Chisnall 19357a984708SDavid Chisnalltemplate <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 1936cfdf2879SDavid Chisnall _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type 1937cfdf2879SDavid Chisnall linear_congruential_engine<_UIntType, __a, __c, __m>::multiplier; 1938cfdf2879SDavid Chisnall 1939cfdf2879SDavid Chisnalltemplate <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 1940cfdf2879SDavid Chisnall _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type 1941cfdf2879SDavid Chisnall linear_congruential_engine<_UIntType, __a, __c, __m>::increment; 1942cfdf2879SDavid Chisnall 1943cfdf2879SDavid Chisnalltemplate <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 1944cfdf2879SDavid Chisnall _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type 1945cfdf2879SDavid Chisnall linear_congruential_engine<_UIntType, __a, __c, __m>::modulus; 1946cfdf2879SDavid Chisnall 1947cfdf2879SDavid Chisnalltemplate <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 1948cfdf2879SDavid Chisnall _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type 1949cfdf2879SDavid Chisnall linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed; 1950cfdf2879SDavid Chisnall 1951cfdf2879SDavid Chisnalltemplate <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 19527a984708SDavid Chisnalltemplate<class _Sseq> 19537a984708SDavid Chisnallvoid 19547a984708SDavid Chisnalllinear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, 19557a984708SDavid Chisnall integral_constant<unsigned, 1>) 19567a984708SDavid Chisnall{ 19577a984708SDavid Chisnall const unsigned __k = 1; 19587a984708SDavid Chisnall uint32_t __ar[__k+3]; 19597a984708SDavid Chisnall __q.generate(__ar, __ar + __k + 3); 19607a984708SDavid Chisnall result_type __s = static_cast<result_type>(__ar[3] % __m); 19617a984708SDavid Chisnall __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; 19627a984708SDavid Chisnall} 19637a984708SDavid Chisnall 19647a984708SDavid Chisnalltemplate <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 19657a984708SDavid Chisnalltemplate<class _Sseq> 19667a984708SDavid Chisnallvoid 19677a984708SDavid Chisnalllinear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, 19687a984708SDavid Chisnall integral_constant<unsigned, 2>) 19697a984708SDavid Chisnall{ 19707a984708SDavid Chisnall const unsigned __k = 2; 19717a984708SDavid Chisnall uint32_t __ar[__k+3]; 19727a984708SDavid Chisnall __q.generate(__ar, __ar + __k + 3); 19737a984708SDavid Chisnall result_type __s = static_cast<result_type>((__ar[3] + 19744bab9fd9SDavid Chisnall ((uint64_t)__ar[4] << 32)) % __m); 19757a984708SDavid Chisnall __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; 19767a984708SDavid Chisnall} 19777a984708SDavid Chisnall 19787a984708SDavid Chisnalltemplate <class _CharT, class _Traits, 19797a984708SDavid Chisnall class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 19807a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY 19817a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 19827a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 19837a984708SDavid Chisnall const linear_congruential_engine<_UIntType, __a, __c, __m>& __x) 19847a984708SDavid Chisnall{ 19851e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__os); 19867a984708SDavid Chisnall __os.flags(ios_base::dec | ios_base::left); 19877a984708SDavid Chisnall __os.fill(__os.widen(' ')); 19887a984708SDavid Chisnall return __os << __x.__x_; 19897a984708SDavid Chisnall} 19907a984708SDavid Chisnall 19917a984708SDavid Chisnalltemplate <class _CharT, class _Traits, 19927a984708SDavid Chisnall class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 19937a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 19947a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 19957a984708SDavid Chisnall linear_congruential_engine<_UIntType, __a, __c, __m>& __x) 19967a984708SDavid Chisnall{ 19971e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__is); 19987a984708SDavid Chisnall __is.flags(ios_base::dec | ios_base::skipws); 19997a984708SDavid Chisnall _UIntType __t; 20007a984708SDavid Chisnall __is >> __t; 20017a984708SDavid Chisnall if (!__is.fail()) 20027a984708SDavid Chisnall __x.__x_ = __t; 20037a984708SDavid Chisnall return __is; 20047a984708SDavid Chisnall} 20057a984708SDavid Chisnall 20067a984708SDavid Chisnalltypedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647> 20077a984708SDavid Chisnall minstd_rand0; 20087a984708SDavid Chisnalltypedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647> 20097a984708SDavid Chisnall minstd_rand; 20107a984708SDavid Chisnalltypedef minstd_rand default_random_engine; 20117a984708SDavid Chisnall// mersenne_twister_engine 20127a984708SDavid Chisnall 20137a984708SDavid Chisnalltemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 20147a984708SDavid Chisnall _UIntType __a, size_t __u, _UIntType __d, size_t __s, 20157a984708SDavid Chisnall _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2016aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS mersenne_twister_engine; 20177a984708SDavid Chisnall 2018f9448bf3SDimitry Andrictemplate <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 2019f9448bf3SDimitry Andric _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, 2020f9448bf3SDimitry Andric _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> 20217a984708SDavid Chisnallbool 2022f9448bf3SDimitry Andricoperator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 202394e3ee44SDavid Chisnall _Bp, _Tp, _Cp, _Lp, _Fp>& __x, 2024f9448bf3SDimitry Andric const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 202594e3ee44SDavid Chisnall _Bp, _Tp, _Cp, _Lp, _Fp>& __y); 20267a984708SDavid Chisnall 2027f9448bf3SDimitry Andrictemplate <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 2028f9448bf3SDimitry Andric _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, 2029f9448bf3SDimitry Andric _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> 2030936e9439SDimitry Andric_LIBCPP_INLINE_VISIBILITY 20317a984708SDavid Chisnallbool 2032f9448bf3SDimitry Andricoperator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 203394e3ee44SDavid Chisnall _Bp, _Tp, _Cp, _Lp, _Fp>& __x, 2034f9448bf3SDimitry Andric const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 203594e3ee44SDavid Chisnall _Bp, _Tp, _Cp, _Lp, _Fp>& __y); 20367a984708SDavid Chisnall 20377a984708SDavid Chisnalltemplate <class _CharT, class _Traits, 2038f9448bf3SDimitry Andric class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 2039f9448bf3SDimitry Andric _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, 2040f9448bf3SDimitry Andric _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> 20417a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 20427a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 2043f9448bf3SDimitry Andric const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 204494e3ee44SDavid Chisnall _Bp, _Tp, _Cp, _Lp, _Fp>& __x); 20457a984708SDavid Chisnall 20467a984708SDavid Chisnalltemplate <class _CharT, class _Traits, 2047f9448bf3SDimitry Andric class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 2048f9448bf3SDimitry Andric _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, 2049f9448bf3SDimitry Andric _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> 20507a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 20517a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 2052f9448bf3SDimitry Andric mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 205394e3ee44SDavid Chisnall _Bp, _Tp, _Cp, _Lp, _Fp>& __x); 20547a984708SDavid Chisnall 20557a984708SDavid Chisnalltemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 20567a984708SDavid Chisnall _UIntType __a, size_t __u, _UIntType __d, size_t __s, 20577a984708SDavid Chisnall _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2058aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS mersenne_twister_engine 20597a984708SDavid Chisnall{ 20607a984708SDavid Chisnallpublic: 20617a984708SDavid Chisnall // types 20627a984708SDavid Chisnall typedef _UIntType result_type; 20637a984708SDavid Chisnall 20647a984708SDavid Chisnallprivate: 20657a984708SDavid Chisnall result_type __x_[__n]; 20667a984708SDavid Chisnall size_t __i_; 20677a984708SDavid Chisnall 20687a984708SDavid Chisnall static_assert( 0 < __m, "mersenne_twister_engine invalid parameters"); 20697a984708SDavid Chisnall static_assert(__m <= __n, "mersenne_twister_engine invalid parameters"); 2070b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; 20717a984708SDavid Chisnall static_assert(__w <= _Dt, "mersenne_twister_engine invalid parameters"); 20727a984708SDavid Chisnall static_assert( 2 <= __w, "mersenne_twister_engine invalid parameters"); 20737a984708SDavid Chisnall static_assert(__r <= __w, "mersenne_twister_engine invalid parameters"); 20747a984708SDavid Chisnall static_assert(__u <= __w, "mersenne_twister_engine invalid parameters"); 20757a984708SDavid Chisnall static_assert(__s <= __w, "mersenne_twister_engine invalid parameters"); 20767a984708SDavid Chisnall static_assert(__t <= __w, "mersenne_twister_engine invalid parameters"); 20777a984708SDavid Chisnall static_assert(__l <= __w, "mersenne_twister_engine invalid parameters"); 20787a984708SDavid Chisnallpublic: 2079b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type _Min = 0; 2080b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : 20817a984708SDavid Chisnall (result_type(1) << __w) - result_type(1); 20827a984708SDavid Chisnall static_assert(_Min < _Max, "mersenne_twister_engine invalid parameters"); 20837a984708SDavid Chisnall static_assert(__a <= _Max, "mersenne_twister_engine invalid parameters"); 20847a984708SDavid Chisnall static_assert(__b <= _Max, "mersenne_twister_engine invalid parameters"); 20857a984708SDavid Chisnall static_assert(__c <= _Max, "mersenne_twister_engine invalid parameters"); 20867a984708SDavid Chisnall static_assert(__d <= _Max, "mersenne_twister_engine invalid parameters"); 20877a984708SDavid Chisnall static_assert(__f <= _Max, "mersenne_twister_engine invalid parameters"); 20887a984708SDavid Chisnall 20897a984708SDavid Chisnall // engine characteristics 2090b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const size_t word_size = __w; 2091b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const size_t state_size = __n; 2092b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const size_t shift_size = __m; 2093b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const size_t mask_bits = __r; 2094b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type xor_mask = __a; 2095b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const size_t tempering_u = __u; 2096b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type tempering_d = __d; 2097b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const size_t tempering_s = __s; 2098b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type tempering_b = __b; 2099b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const size_t tempering_t = __t; 2100b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type tempering_c = __c; 2101b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const size_t tempering_l = __l; 2102b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type initialization_multiplier = __f; 21037a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 2104b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR result_type min() { return _Min; } 21057a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 2106b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR result_type max() { return _Max; } 2107b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type default_seed = 5489u; 21087a984708SDavid Chisnall 21097a984708SDavid Chisnall // constructors and seeding functions 21107a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 21117a984708SDavid Chisnall explicit mersenne_twister_engine(result_type __sd = default_seed) 21127a984708SDavid Chisnall {seed(__sd);} 211394e3ee44SDavid Chisnall template<class _Sseq> 21147a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 211594e3ee44SDavid Chisnall explicit mersenne_twister_engine(_Sseq& __q, 21167a984708SDavid Chisnall typename enable_if<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value>::type* = 0) 21177a984708SDavid Chisnall {seed(__q);} 21187a984708SDavid Chisnall void seed(result_type __sd = default_seed); 21197a984708SDavid Chisnall template<class _Sseq> 21207a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 21217a984708SDavid Chisnall typename enable_if 21227a984708SDavid Chisnall < 21237a984708SDavid Chisnall __is_seed_sequence<_Sseq, mersenne_twister_engine>::value, 21247a984708SDavid Chisnall void 21257a984708SDavid Chisnall >::type 21267a984708SDavid Chisnall seed(_Sseq& __q) 21277a984708SDavid Chisnall {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());} 21287a984708SDavid Chisnall 21297a984708SDavid Chisnall // generating functions 21307a984708SDavid Chisnall result_type operator()(); 21317a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 21327a984708SDavid Chisnall void discard(unsigned long long __z) {for (; __z; --__z) operator()();} 21337a984708SDavid Chisnall 2134f9448bf3SDimitry Andric template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 2135f9448bf3SDimitry Andric _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, 2136f9448bf3SDimitry Andric _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> 21377a984708SDavid Chisnall friend 21387a984708SDavid Chisnall bool 2139f9448bf3SDimitry Andric operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 214094e3ee44SDavid Chisnall _Bp, _Tp, _Cp, _Lp, _Fp>& __x, 2141f9448bf3SDimitry Andric const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 214294e3ee44SDavid Chisnall _Bp, _Tp, _Cp, _Lp, _Fp>& __y); 21437a984708SDavid Chisnall 2144f9448bf3SDimitry Andric template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 2145f9448bf3SDimitry Andric _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, 2146f9448bf3SDimitry Andric _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> 21477a984708SDavid Chisnall friend 21487a984708SDavid Chisnall bool 2149f9448bf3SDimitry Andric operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 215094e3ee44SDavid Chisnall _Bp, _Tp, _Cp, _Lp, _Fp>& __x, 2151f9448bf3SDimitry Andric const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 215294e3ee44SDavid Chisnall _Bp, _Tp, _Cp, _Lp, _Fp>& __y); 21537a984708SDavid Chisnall 21547a984708SDavid Chisnall template <class _CharT, class _Traits, 2155f9448bf3SDimitry Andric class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 2156f9448bf3SDimitry Andric _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, 2157f9448bf3SDimitry Andric _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> 21587a984708SDavid Chisnall friend 21597a984708SDavid Chisnall basic_ostream<_CharT, _Traits>& 21607a984708SDavid Chisnall operator<<(basic_ostream<_CharT, _Traits>& __os, 2161f9448bf3SDimitry Andric const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 216294e3ee44SDavid Chisnall _Bp, _Tp, _Cp, _Lp, _Fp>& __x); 21637a984708SDavid Chisnall 21647a984708SDavid Chisnall template <class _CharT, class _Traits, 2165f9448bf3SDimitry Andric class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 2166f9448bf3SDimitry Andric _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, 2167f9448bf3SDimitry Andric _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> 21687a984708SDavid Chisnall friend 21697a984708SDavid Chisnall basic_istream<_CharT, _Traits>& 21707a984708SDavid Chisnall operator>>(basic_istream<_CharT, _Traits>& __is, 2171f9448bf3SDimitry Andric mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 217294e3ee44SDavid Chisnall _Bp, _Tp, _Cp, _Lp, _Fp>& __x); 21737a984708SDavid Chisnallprivate: 21747a984708SDavid Chisnall 21757a984708SDavid Chisnall template<class _Sseq> 21767a984708SDavid Chisnall void __seed(_Sseq& __q, integral_constant<unsigned, 1>); 21777a984708SDavid Chisnall template<class _Sseq> 21787a984708SDavid Chisnall void __seed(_Sseq& __q, integral_constant<unsigned, 2>); 21797a984708SDavid Chisnall 21807a984708SDavid Chisnall template <size_t __count> 21817a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 21827a984708SDavid Chisnall static 21837a984708SDavid Chisnall typename enable_if 21847a984708SDavid Chisnall < 21857a984708SDavid Chisnall __count < __w, 21867a984708SDavid Chisnall result_type 21877a984708SDavid Chisnall >::type 21887a984708SDavid Chisnall __lshift(result_type __x) {return (__x << __count) & _Max;} 21897a984708SDavid Chisnall 21907a984708SDavid Chisnall template <size_t __count> 21917a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 21927a984708SDavid Chisnall static 21937a984708SDavid Chisnall typename enable_if 21947a984708SDavid Chisnall < 21957a984708SDavid Chisnall (__count >= __w), 21967a984708SDavid Chisnall result_type 21977a984708SDavid Chisnall >::type 219894e3ee44SDavid Chisnall __lshift(result_type) {return result_type(0);} 21997a984708SDavid Chisnall 22007a984708SDavid Chisnall template <size_t __count> 22017a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 22027a984708SDavid Chisnall static 22037a984708SDavid Chisnall typename enable_if 22047a984708SDavid Chisnall < 22057a984708SDavid Chisnall __count < _Dt, 22067a984708SDavid Chisnall result_type 22077a984708SDavid Chisnall >::type 22087a984708SDavid Chisnall __rshift(result_type __x) {return __x >> __count;} 22097a984708SDavid Chisnall 22107a984708SDavid Chisnall template <size_t __count> 22117a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 22127a984708SDavid Chisnall static 22137a984708SDavid Chisnall typename enable_if 22147a984708SDavid Chisnall < 22157a984708SDavid Chisnall (__count >= _Dt), 22167a984708SDavid Chisnall result_type 22177a984708SDavid Chisnall >::type 221894e3ee44SDavid Chisnall __rshift(result_type) {return result_type(0);} 22197a984708SDavid Chisnall}; 22207a984708SDavid Chisnall 22217a984708SDavid Chisnalltemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 22227a984708SDavid Chisnall _UIntType __a, size_t __u, _UIntType __d, size_t __s, 22237a984708SDavid Chisnall _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2224cfdf2879SDavid Chisnall _LIBCPP_CONSTEXPR const size_t 2225cfdf2879SDavid Chisnall mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::word_size; 2226cfdf2879SDavid Chisnall 2227cfdf2879SDavid Chisnalltemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2228cfdf2879SDavid Chisnall _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2229cfdf2879SDavid Chisnall _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2230cfdf2879SDavid Chisnall _LIBCPP_CONSTEXPR const size_t 2231cfdf2879SDavid Chisnall mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::state_size; 2232cfdf2879SDavid Chisnall 2233cfdf2879SDavid Chisnalltemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2234cfdf2879SDavid Chisnall _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2235cfdf2879SDavid Chisnall _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2236cfdf2879SDavid Chisnall _LIBCPP_CONSTEXPR const size_t 2237cfdf2879SDavid Chisnall mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::shift_size; 2238cfdf2879SDavid Chisnall 2239cfdf2879SDavid Chisnalltemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2240cfdf2879SDavid Chisnall _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2241cfdf2879SDavid Chisnall _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2242cfdf2879SDavid Chisnall _LIBCPP_CONSTEXPR const size_t 2243cfdf2879SDavid Chisnall mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mask_bits; 2244cfdf2879SDavid Chisnall 2245cfdf2879SDavid Chisnalltemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2246cfdf2879SDavid Chisnall _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2247cfdf2879SDavid Chisnall _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2248cfdf2879SDavid Chisnall _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type 2249cfdf2879SDavid Chisnall mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::xor_mask; 2250cfdf2879SDavid Chisnall 2251cfdf2879SDavid Chisnalltemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2252cfdf2879SDavid Chisnall _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2253cfdf2879SDavid Chisnall _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2254cfdf2879SDavid Chisnall _LIBCPP_CONSTEXPR const size_t 2255cfdf2879SDavid Chisnall mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_u; 2256cfdf2879SDavid Chisnall 2257cfdf2879SDavid Chisnalltemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2258cfdf2879SDavid Chisnall _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2259cfdf2879SDavid Chisnall _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2260cfdf2879SDavid Chisnall _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type 2261cfdf2879SDavid Chisnall mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_d; 2262cfdf2879SDavid Chisnall 2263cfdf2879SDavid Chisnalltemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2264cfdf2879SDavid Chisnall _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2265cfdf2879SDavid Chisnall _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2266cfdf2879SDavid Chisnall _LIBCPP_CONSTEXPR const size_t 2267cfdf2879SDavid Chisnall mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_s; 2268cfdf2879SDavid Chisnall 2269cfdf2879SDavid Chisnalltemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2270cfdf2879SDavid Chisnall _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2271cfdf2879SDavid Chisnall _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2272cfdf2879SDavid Chisnall _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type 2273cfdf2879SDavid Chisnall mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_b; 2274cfdf2879SDavid Chisnall 2275cfdf2879SDavid Chisnalltemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2276cfdf2879SDavid Chisnall _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2277cfdf2879SDavid Chisnall _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2278cfdf2879SDavid Chisnall _LIBCPP_CONSTEXPR const size_t 2279cfdf2879SDavid Chisnall mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_t; 2280cfdf2879SDavid Chisnall 2281cfdf2879SDavid Chisnalltemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2282cfdf2879SDavid Chisnall _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2283cfdf2879SDavid Chisnall _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2284cfdf2879SDavid Chisnall _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type 2285cfdf2879SDavid Chisnall mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_c; 2286cfdf2879SDavid Chisnall 2287cfdf2879SDavid Chisnalltemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2288cfdf2879SDavid Chisnall _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2289cfdf2879SDavid Chisnall _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2290cfdf2879SDavid Chisnall _LIBCPP_CONSTEXPR const size_t 2291cfdf2879SDavid Chisnall mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_l; 2292cfdf2879SDavid Chisnall 2293cfdf2879SDavid Chisnalltemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2294cfdf2879SDavid Chisnall _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2295cfdf2879SDavid Chisnall _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2296cfdf2879SDavid Chisnall _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type 2297cfdf2879SDavid Chisnall mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::initialization_multiplier; 2298cfdf2879SDavid Chisnall 2299cfdf2879SDavid Chisnalltemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2300cfdf2879SDavid Chisnall _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2301cfdf2879SDavid Chisnall _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2302cfdf2879SDavid Chisnall _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type 2303cfdf2879SDavid Chisnall mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::default_seed; 2304cfdf2879SDavid Chisnall 2305cfdf2879SDavid Chisnalltemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2306cfdf2879SDavid Chisnall _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2307cfdf2879SDavid Chisnall _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 23087a984708SDavid Chisnallvoid 23097a984708SDavid Chisnallmersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, 23107a984708SDavid Chisnall __t, __c, __l, __f>::seed(result_type __sd) 2311b2c7081bSDimitry Andric _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 23127a984708SDavid Chisnall{ // __w >= 2 23137a984708SDavid Chisnall __x_[0] = __sd & _Max; 23147a984708SDavid Chisnall for (size_t __i = 1; __i < __n; ++__i) 23157a984708SDavid Chisnall __x_[__i] = (__f * (__x_[__i-1] ^ __rshift<__w - 2>(__x_[__i-1])) + __i) & _Max; 23167a984708SDavid Chisnall __i_ = 0; 23177a984708SDavid Chisnall} 23187a984708SDavid Chisnall 23197a984708SDavid Chisnalltemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 23207a984708SDavid Chisnall _UIntType __a, size_t __u, _UIntType __d, size_t __s, 23217a984708SDavid Chisnall _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 23227a984708SDavid Chisnalltemplate<class _Sseq> 23237a984708SDavid Chisnallvoid 23247a984708SDavid Chisnallmersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, 23257a984708SDavid Chisnall __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 1>) 23267a984708SDavid Chisnall{ 23277a984708SDavid Chisnall const unsigned __k = 1; 23287a984708SDavid Chisnall uint32_t __ar[__n * __k]; 23297a984708SDavid Chisnall __q.generate(__ar, __ar + __n * __k); 23307a984708SDavid Chisnall for (size_t __i = 0; __i < __n; ++__i) 23317a984708SDavid Chisnall __x_[__i] = static_cast<result_type>(__ar[__i] & _Max); 23327a984708SDavid Chisnall const result_type __mask = __r == _Dt ? result_type(~0) : 23337a984708SDavid Chisnall (result_type(1) << __r) - result_type(1); 23347a984708SDavid Chisnall __i_ = 0; 23357a984708SDavid Chisnall if ((__x_[0] & ~__mask) == 0) 23367a984708SDavid Chisnall { 23377a984708SDavid Chisnall for (size_t __i = 1; __i < __n; ++__i) 23387a984708SDavid Chisnall if (__x_[__i] != 0) 23397a984708SDavid Chisnall return; 2340*b5893f02SDimitry Andric __x_[0] = result_type(1) << (__w - 1); 23417a984708SDavid Chisnall } 23427a984708SDavid Chisnall} 23437a984708SDavid Chisnall 23447a984708SDavid Chisnalltemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 23457a984708SDavid Chisnall _UIntType __a, size_t __u, _UIntType __d, size_t __s, 23467a984708SDavid Chisnall _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 23477a984708SDavid Chisnalltemplate<class _Sseq> 23487a984708SDavid Chisnallvoid 23497a984708SDavid Chisnallmersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, 23507a984708SDavid Chisnall __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 2>) 23517a984708SDavid Chisnall{ 23527a984708SDavid Chisnall const unsigned __k = 2; 23537a984708SDavid Chisnall uint32_t __ar[__n * __k]; 23547a984708SDavid Chisnall __q.generate(__ar, __ar + __n * __k); 23557a984708SDavid Chisnall for (size_t __i = 0; __i < __n; ++__i) 23567a984708SDavid Chisnall __x_[__i] = static_cast<result_type>( 23577a984708SDavid Chisnall (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); 23587a984708SDavid Chisnall const result_type __mask = __r == _Dt ? result_type(~0) : 23597a984708SDavid Chisnall (result_type(1) << __r) - result_type(1); 23607a984708SDavid Chisnall __i_ = 0; 23617a984708SDavid Chisnall if ((__x_[0] & ~__mask) == 0) 23627a984708SDavid Chisnall { 23637a984708SDavid Chisnall for (size_t __i = 1; __i < __n; ++__i) 23647a984708SDavid Chisnall if (__x_[__i] != 0) 23657a984708SDavid Chisnall return; 2366*b5893f02SDimitry Andric __x_[0] = result_type(1) << (__w - 1); 23677a984708SDavid Chisnall } 23687a984708SDavid Chisnall} 23697a984708SDavid Chisnall 23707a984708SDavid Chisnalltemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 23717a984708SDavid Chisnall _UIntType __a, size_t __u, _UIntType __d, size_t __s, 23727a984708SDavid Chisnall _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 23737a984708SDavid Chisnall_UIntType 23747a984708SDavid Chisnallmersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, 23757a984708SDavid Chisnall __t, __c, __l, __f>::operator()() 23767a984708SDavid Chisnall{ 23777a984708SDavid Chisnall const size_t __j = (__i_ + 1) % __n; 23787a984708SDavid Chisnall const result_type __mask = __r == _Dt ? result_type(~0) : 23797a984708SDavid Chisnall (result_type(1) << __r) - result_type(1); 238094e3ee44SDavid Chisnall const result_type _Yp = (__x_[__i_] & ~__mask) | (__x_[__j] & __mask); 23817a984708SDavid Chisnall const size_t __k = (__i_ + __m) % __n; 238294e3ee44SDavid Chisnall __x_[__i_] = __x_[__k] ^ __rshift<1>(_Yp) ^ (__a * (_Yp & 1)); 23837a984708SDavid Chisnall result_type __z = __x_[__i_] ^ (__rshift<__u>(__x_[__i_]) & __d); 23847a984708SDavid Chisnall __i_ = __j; 23857a984708SDavid Chisnall __z ^= __lshift<__s>(__z) & __b; 23867a984708SDavid Chisnall __z ^= __lshift<__t>(__z) & __c; 23877a984708SDavid Chisnall return __z ^ __rshift<__l>(__z); 23887a984708SDavid Chisnall} 23897a984708SDavid Chisnall 2390f9448bf3SDimitry Andrictemplate <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 2391f9448bf3SDimitry Andric _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, 2392f9448bf3SDimitry Andric _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> 23937a984708SDavid Chisnallbool 2394f9448bf3SDimitry Andricoperator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 239594e3ee44SDavid Chisnall _Bp, _Tp, _Cp, _Lp, _Fp>& __x, 2396f9448bf3SDimitry Andric const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 239794e3ee44SDavid Chisnall _Bp, _Tp, _Cp, _Lp, _Fp>& __y) 23987a984708SDavid Chisnall{ 23997a984708SDavid Chisnall if (__x.__i_ == __y.__i_) 240094e3ee44SDavid Chisnall return _VSTD::equal(__x.__x_, __x.__x_ + _Np, __y.__x_); 24017a984708SDavid Chisnall if (__x.__i_ == 0 || __y.__i_ == 0) 24027a984708SDavid Chisnall { 240394e3ee44SDavid Chisnall size_t __j = _VSTD::min(_Np - __x.__i_, _Np - __y.__i_); 24047a984708SDavid Chisnall if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, 24057a984708SDavid Chisnall __y.__x_ + __y.__i_)) 24067a984708SDavid Chisnall return false; 24077a984708SDavid Chisnall if (__x.__i_ == 0) 240894e3ee44SDavid Chisnall return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Np, __y.__x_); 240994e3ee44SDavid Chisnall return _VSTD::equal(__x.__x_, __x.__x_ + (_Np - __j), __y.__x_ + __j); 24107a984708SDavid Chisnall } 24117a984708SDavid Chisnall if (__x.__i_ < __y.__i_) 24127a984708SDavid Chisnall { 241394e3ee44SDavid Chisnall size_t __j = _Np - __y.__i_; 24147a984708SDavid Chisnall if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), 24157a984708SDavid Chisnall __y.__x_ + __y.__i_)) 24167a984708SDavid Chisnall return false; 241794e3ee44SDavid Chisnall if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Np, 24187a984708SDavid Chisnall __y.__x_)) 24197a984708SDavid Chisnall return false; 24207a984708SDavid Chisnall return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_, 242194e3ee44SDavid Chisnall __y.__x_ + (_Np - (__x.__i_ + __j))); 24227a984708SDavid Chisnall } 242394e3ee44SDavid Chisnall size_t __j = _Np - __x.__i_; 24247a984708SDavid Chisnall if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), 24257a984708SDavid Chisnall __x.__x_ + __x.__i_)) 24267a984708SDavid Chisnall return false; 242794e3ee44SDavid Chisnall if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Np, 24287a984708SDavid Chisnall __x.__x_)) 24297a984708SDavid Chisnall return false; 24307a984708SDavid Chisnall return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_, 243194e3ee44SDavid Chisnall __x.__x_ + (_Np - (__y.__i_ + __j))); 24327a984708SDavid Chisnall} 24337a984708SDavid Chisnall 2434f9448bf3SDimitry Andrictemplate <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 2435f9448bf3SDimitry Andric _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, 2436f9448bf3SDimitry Andric _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> 24377a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY 24387a984708SDavid Chisnallbool 2439f9448bf3SDimitry Andricoperator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 244094e3ee44SDavid Chisnall _Bp, _Tp, _Cp, _Lp, _Fp>& __x, 2441f9448bf3SDimitry Andric const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 244294e3ee44SDavid Chisnall _Bp, _Tp, _Cp, _Lp, _Fp>& __y) 24437a984708SDavid Chisnall{ 24447a984708SDavid Chisnall return !(__x == __y); 24457a984708SDavid Chisnall} 24467a984708SDavid Chisnall 24477a984708SDavid Chisnalltemplate <class _CharT, class _Traits, 2448f9448bf3SDimitry Andric class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 2449f9448bf3SDimitry Andric _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, 2450f9448bf3SDimitry Andric _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> 24517a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 24527a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 2453f9448bf3SDimitry Andric const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 245494e3ee44SDavid Chisnall _Bp, _Tp, _Cp, _Lp, _Fp>& __x) 24557a984708SDavid Chisnall{ 24561e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__os); 24577a984708SDavid Chisnall __os.flags(ios_base::dec | ios_base::left); 24587a984708SDavid Chisnall _CharT __sp = __os.widen(' '); 24597a984708SDavid Chisnall __os.fill(__sp); 24607a984708SDavid Chisnall __os << __x.__x_[__x.__i_]; 246194e3ee44SDavid Chisnall for (size_t __j = __x.__i_ + 1; __j < _Np; ++__j) 24627a984708SDavid Chisnall __os << __sp << __x.__x_[__j]; 24637a984708SDavid Chisnall for (size_t __j = 0; __j < __x.__i_; ++__j) 24647a984708SDavid Chisnall __os << __sp << __x.__x_[__j]; 24657a984708SDavid Chisnall return __os; 24667a984708SDavid Chisnall} 24677a984708SDavid Chisnall 24687a984708SDavid Chisnalltemplate <class _CharT, class _Traits, 2469f9448bf3SDimitry Andric class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 2470f9448bf3SDimitry Andric _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, 2471f9448bf3SDimitry Andric _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> 24727a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 24737a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 2474f9448bf3SDimitry Andric mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 247594e3ee44SDavid Chisnall _Bp, _Tp, _Cp, _Lp, _Fp>& __x) 24767a984708SDavid Chisnall{ 24771e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__is); 24787a984708SDavid Chisnall __is.flags(ios_base::dec | ios_base::skipws); 2479f9448bf3SDimitry Andric _UInt __t[_Np]; 248094e3ee44SDavid Chisnall for (size_t __i = 0; __i < _Np; ++__i) 24817a984708SDavid Chisnall __is >> __t[__i]; 24827a984708SDavid Chisnall if (!__is.fail()) 24837a984708SDavid Chisnall { 248494e3ee44SDavid Chisnall for (size_t __i = 0; __i < _Np; ++__i) 24857a984708SDavid Chisnall __x.__x_[__i] = __t[__i]; 24867a984708SDavid Chisnall __x.__i_ = 0; 24877a984708SDavid Chisnall } 24887a984708SDavid Chisnall return __is; 24897a984708SDavid Chisnall} 24907a984708SDavid Chisnall 24917a984708SDavid Chisnalltypedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31, 24927a984708SDavid Chisnall 0x9908b0df, 11, 0xffffffff, 24937a984708SDavid Chisnall 7, 0x9d2c5680, 24947a984708SDavid Chisnall 15, 0xefc60000, 24957a984708SDavid Chisnall 18, 1812433253> mt19937; 24967a984708SDavid Chisnalltypedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31, 24977a984708SDavid Chisnall 0xb5026f5aa96619e9ULL, 29, 0x5555555555555555ULL, 24987a984708SDavid Chisnall 17, 0x71d67fffeda60000ULL, 24997a984708SDavid Chisnall 37, 0xfff7eee000000000ULL, 25007a984708SDavid Chisnall 43, 6364136223846793005ULL> mt19937_64; 25017a984708SDavid Chisnall 25027a984708SDavid Chisnall// subtract_with_carry_engine 25037a984708SDavid Chisnall 25047a984708SDavid Chisnalltemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 2505aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine; 25067a984708SDavid Chisnall 2507f9448bf3SDimitry Andrictemplate<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> 25087a984708SDavid Chisnallbool 25097a984708SDavid Chisnalloperator==( 2510f9448bf3SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, 2511f9448bf3SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); 25127a984708SDavid Chisnall 2513f9448bf3SDimitry Andrictemplate<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> 2514936e9439SDimitry Andric_LIBCPP_INLINE_VISIBILITY 25157a984708SDavid Chisnallbool 25167a984708SDavid Chisnalloperator!=( 2517f9448bf3SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, 2518f9448bf3SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); 25197a984708SDavid Chisnall 25207a984708SDavid Chisnalltemplate <class _CharT, class _Traits, 2521f9448bf3SDimitry Andric class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> 25227a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 25237a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 2524f9448bf3SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); 25257a984708SDavid Chisnall 25267a984708SDavid Chisnalltemplate <class _CharT, class _Traits, 2527f9448bf3SDimitry Andric class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> 25287a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 25297a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 2530f9448bf3SDimitry Andric subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); 25317a984708SDavid Chisnall 25327a984708SDavid Chisnalltemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 2533aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine 25347a984708SDavid Chisnall{ 25357a984708SDavid Chisnallpublic: 25367a984708SDavid Chisnall // types 25377a984708SDavid Chisnall typedef _UIntType result_type; 25387a984708SDavid Chisnall 25397a984708SDavid Chisnallprivate: 25407a984708SDavid Chisnall result_type __x_[__r]; 25417a984708SDavid Chisnall result_type __c_; 25427a984708SDavid Chisnall size_t __i_; 25437a984708SDavid Chisnall 2544b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; 25457a984708SDavid Chisnall static_assert( 0 < __w, "subtract_with_carry_engine invalid parameters"); 25467a984708SDavid Chisnall static_assert(__w <= _Dt, "subtract_with_carry_engine invalid parameters"); 25477a984708SDavid Chisnall static_assert( 0 < __s, "subtract_with_carry_engine invalid parameters"); 25487a984708SDavid Chisnall static_assert(__s < __r, "subtract_with_carry_engine invalid parameters"); 25497a984708SDavid Chisnallpublic: 2550b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type _Min = 0; 2551b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : 25527a984708SDavid Chisnall (result_type(1) << __w) - result_type(1); 25537a984708SDavid Chisnall static_assert(_Min < _Max, "subtract_with_carry_engine invalid parameters"); 25547a984708SDavid Chisnall 25557a984708SDavid Chisnall // engine characteristics 2556b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const size_t word_size = __w; 2557b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const size_t short_lag = __s; 2558b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const size_t long_lag = __r; 25597a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 2560b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR result_type min() { return _Min; } 25617a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 2562b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR result_type max() { return _Max; } 2563b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type default_seed = 19780503u; 25647a984708SDavid Chisnall 25657a984708SDavid Chisnall // constructors and seeding functions 25667a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 25677a984708SDavid Chisnall explicit subtract_with_carry_engine(result_type __sd = default_seed) 25687a984708SDavid Chisnall {seed(__sd);} 256994e3ee44SDavid Chisnall template<class _Sseq> 25707a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 257194e3ee44SDavid Chisnall explicit subtract_with_carry_engine(_Sseq& __q, 25727a984708SDavid Chisnall typename enable_if<__is_seed_sequence<_Sseq, subtract_with_carry_engine>::value>::type* = 0) 25737a984708SDavid Chisnall {seed(__q);} 25747a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 25757a984708SDavid Chisnall void seed(result_type __sd = default_seed) 25767a984708SDavid Chisnall {seed(__sd, integral_constant<unsigned, 1 + (__w - 1) / 32>());} 25777a984708SDavid Chisnall template<class _Sseq> 25787a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 25797a984708SDavid Chisnall typename enable_if 25807a984708SDavid Chisnall < 25817a984708SDavid Chisnall __is_seed_sequence<_Sseq, subtract_with_carry_engine>::value, 25827a984708SDavid Chisnall void 25837a984708SDavid Chisnall >::type 25847a984708SDavid Chisnall seed(_Sseq& __q) 25857a984708SDavid Chisnall {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());} 25867a984708SDavid Chisnall 25877a984708SDavid Chisnall // generating functions 25887a984708SDavid Chisnall result_type operator()(); 25897a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 25907a984708SDavid Chisnall void discard(unsigned long long __z) {for (; __z; --__z) operator()();} 25917a984708SDavid Chisnall 2592f9448bf3SDimitry Andric template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> 25937a984708SDavid Chisnall friend 25947a984708SDavid Chisnall bool 25957a984708SDavid Chisnall operator==( 2596f9448bf3SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, 2597f9448bf3SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); 25987a984708SDavid Chisnall 2599f9448bf3SDimitry Andric template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> 26007a984708SDavid Chisnall friend 26017a984708SDavid Chisnall bool 26027a984708SDavid Chisnall operator!=( 2603f9448bf3SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, 2604f9448bf3SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); 26057a984708SDavid Chisnall 26067a984708SDavid Chisnall template <class _CharT, class _Traits, 2607f9448bf3SDimitry Andric class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> 26087a984708SDavid Chisnall friend 26097a984708SDavid Chisnall basic_ostream<_CharT, _Traits>& 26107a984708SDavid Chisnall operator<<(basic_ostream<_CharT, _Traits>& __os, 2611f9448bf3SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); 26127a984708SDavid Chisnall 26137a984708SDavid Chisnall template <class _CharT, class _Traits, 2614f9448bf3SDimitry Andric class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> 26157a984708SDavid Chisnall friend 26167a984708SDavid Chisnall basic_istream<_CharT, _Traits>& 26177a984708SDavid Chisnall operator>>(basic_istream<_CharT, _Traits>& __is, 2618f9448bf3SDimitry Andric subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); 26197a984708SDavid Chisnall 26207a984708SDavid Chisnallprivate: 26217a984708SDavid Chisnall 26227a984708SDavid Chisnall void seed(result_type __sd, integral_constant<unsigned, 1>); 26237a984708SDavid Chisnall void seed(result_type __sd, integral_constant<unsigned, 2>); 26247a984708SDavid Chisnall template<class _Sseq> 26257a984708SDavid Chisnall void __seed(_Sseq& __q, integral_constant<unsigned, 1>); 26267a984708SDavid Chisnall template<class _Sseq> 26277a984708SDavid Chisnall void __seed(_Sseq& __q, integral_constant<unsigned, 2>); 26287a984708SDavid Chisnall}; 26297a984708SDavid Chisnall 26307a984708SDavid Chisnalltemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 2631cfdf2879SDavid Chisnall _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size; 2632cfdf2879SDavid Chisnall 2633cfdf2879SDavid Chisnalltemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 2634cfdf2879SDavid Chisnall _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::short_lag; 2635cfdf2879SDavid Chisnall 2636cfdf2879SDavid Chisnalltemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 2637cfdf2879SDavid Chisnall _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag; 2638cfdf2879SDavid Chisnall 2639cfdf2879SDavid Chisnalltemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 2640cfdf2879SDavid Chisnall _LIBCPP_CONSTEXPR const typename subtract_with_carry_engine<_UIntType, __w, __s, __r>::result_type 2641cfdf2879SDavid Chisnall subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed; 2642cfdf2879SDavid Chisnall 2643cfdf2879SDavid Chisnalltemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 26447a984708SDavid Chisnallvoid 26457a984708SDavid Chisnallsubtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, 26467a984708SDavid Chisnall integral_constant<unsigned, 1>) 26477a984708SDavid Chisnall{ 26487a984708SDavid Chisnall linear_congruential_engine<result_type, 40014u, 0u, 2147483563u> 26497a984708SDavid Chisnall __e(__sd == 0u ? default_seed : __sd); 26507a984708SDavid Chisnall for (size_t __i = 0; __i < __r; ++__i) 26517a984708SDavid Chisnall __x_[__i] = static_cast<result_type>(__e() & _Max); 26527a984708SDavid Chisnall __c_ = __x_[__r-1] == 0; 26537a984708SDavid Chisnall __i_ = 0; 26547a984708SDavid Chisnall} 26557a984708SDavid Chisnall 26567a984708SDavid Chisnalltemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 26577a984708SDavid Chisnallvoid 26587a984708SDavid Chisnallsubtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, 26597a984708SDavid Chisnall integral_constant<unsigned, 2>) 26607a984708SDavid Chisnall{ 26617a984708SDavid Chisnall linear_congruential_engine<result_type, 40014u, 0u, 2147483563u> 26627a984708SDavid Chisnall __e(__sd == 0u ? default_seed : __sd); 26637a984708SDavid Chisnall for (size_t __i = 0; __i < __r; ++__i) 26647a984708SDavid Chisnall { 26657a984708SDavid Chisnall result_type __e0 = __e(); 26667a984708SDavid Chisnall __x_[__i] = static_cast<result_type>( 26677a984708SDavid Chisnall (__e0 + ((uint64_t)__e() << 32)) & _Max); 26687a984708SDavid Chisnall } 26697a984708SDavid Chisnall __c_ = __x_[__r-1] == 0; 26707a984708SDavid Chisnall __i_ = 0; 26717a984708SDavid Chisnall} 26727a984708SDavid Chisnall 26737a984708SDavid Chisnalltemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 26747a984708SDavid Chisnalltemplate<class _Sseq> 26757a984708SDavid Chisnallvoid 26767a984708SDavid Chisnallsubtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q, 26777a984708SDavid Chisnall integral_constant<unsigned, 1>) 26787a984708SDavid Chisnall{ 26797a984708SDavid Chisnall const unsigned __k = 1; 26807a984708SDavid Chisnall uint32_t __ar[__r * __k]; 26817a984708SDavid Chisnall __q.generate(__ar, __ar + __r * __k); 26827a984708SDavid Chisnall for (size_t __i = 0; __i < __r; ++__i) 26837a984708SDavid Chisnall __x_[__i] = static_cast<result_type>(__ar[__i] & _Max); 26847a984708SDavid Chisnall __c_ = __x_[__r-1] == 0; 26857a984708SDavid Chisnall __i_ = 0; 26867a984708SDavid Chisnall} 26877a984708SDavid Chisnall 26887a984708SDavid Chisnalltemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 26897a984708SDavid Chisnalltemplate<class _Sseq> 26907a984708SDavid Chisnallvoid 26917a984708SDavid Chisnallsubtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q, 26927a984708SDavid Chisnall integral_constant<unsigned, 2>) 26937a984708SDavid Chisnall{ 26947a984708SDavid Chisnall const unsigned __k = 2; 26957a984708SDavid Chisnall uint32_t __ar[__r * __k]; 26967a984708SDavid Chisnall __q.generate(__ar, __ar + __r * __k); 26977a984708SDavid Chisnall for (size_t __i = 0; __i < __r; ++__i) 26987a984708SDavid Chisnall __x_[__i] = static_cast<result_type>( 26997a984708SDavid Chisnall (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); 27007a984708SDavid Chisnall __c_ = __x_[__r-1] == 0; 27017a984708SDavid Chisnall __i_ = 0; 27027a984708SDavid Chisnall} 27037a984708SDavid Chisnall 27047a984708SDavid Chisnalltemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 27057a984708SDavid Chisnall_UIntType 27067a984708SDavid Chisnallsubtract_with_carry_engine<_UIntType, __w, __s, __r>::operator()() 27077a984708SDavid Chisnall{ 27087a984708SDavid Chisnall const result_type& __xs = __x_[(__i_ + (__r - __s)) % __r]; 27097a984708SDavid Chisnall result_type& __xr = __x_[__i_]; 27107a984708SDavid Chisnall result_type __new_c = __c_ == 0 ? __xs < __xr : __xs != 0 ? __xs <= __xr : 1; 27117a984708SDavid Chisnall __xr = (__xs - __xr - __c_) & _Max; 27127a984708SDavid Chisnall __c_ = __new_c; 27137a984708SDavid Chisnall __i_ = (__i_ + 1) % __r; 27147a984708SDavid Chisnall return __xr; 27157a984708SDavid Chisnall} 27167a984708SDavid Chisnall 2717f9448bf3SDimitry Andrictemplate<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> 27187a984708SDavid Chisnallbool 27197a984708SDavid Chisnalloperator==( 2720f9448bf3SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, 2721f9448bf3SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y) 27227a984708SDavid Chisnall{ 27237a984708SDavid Chisnall if (__x.__c_ != __y.__c_) 27247a984708SDavid Chisnall return false; 27257a984708SDavid Chisnall if (__x.__i_ == __y.__i_) 272694e3ee44SDavid Chisnall return _VSTD::equal(__x.__x_, __x.__x_ + _Rp, __y.__x_); 27277a984708SDavid Chisnall if (__x.__i_ == 0 || __y.__i_ == 0) 27287a984708SDavid Chisnall { 272994e3ee44SDavid Chisnall size_t __j = _VSTD::min(_Rp - __x.__i_, _Rp - __y.__i_); 27307a984708SDavid Chisnall if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, 27317a984708SDavid Chisnall __y.__x_ + __y.__i_)) 27327a984708SDavid Chisnall return false; 27337a984708SDavid Chisnall if (__x.__i_ == 0) 273494e3ee44SDavid Chisnall return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Rp, __y.__x_); 273594e3ee44SDavid Chisnall return _VSTD::equal(__x.__x_, __x.__x_ + (_Rp - __j), __y.__x_ + __j); 27367a984708SDavid Chisnall } 27377a984708SDavid Chisnall if (__x.__i_ < __y.__i_) 27387a984708SDavid Chisnall { 273994e3ee44SDavid Chisnall size_t __j = _Rp - __y.__i_; 27407a984708SDavid Chisnall if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), 27417a984708SDavid Chisnall __y.__x_ + __y.__i_)) 27427a984708SDavid Chisnall return false; 274394e3ee44SDavid Chisnall if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Rp, 27447a984708SDavid Chisnall __y.__x_)) 27457a984708SDavid Chisnall return false; 27467a984708SDavid Chisnall return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_, 274794e3ee44SDavid Chisnall __y.__x_ + (_Rp - (__x.__i_ + __j))); 27487a984708SDavid Chisnall } 274994e3ee44SDavid Chisnall size_t __j = _Rp - __x.__i_; 27507a984708SDavid Chisnall if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), 27517a984708SDavid Chisnall __x.__x_ + __x.__i_)) 27527a984708SDavid Chisnall return false; 275394e3ee44SDavid Chisnall if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Rp, 27547a984708SDavid Chisnall __x.__x_)) 27557a984708SDavid Chisnall return false; 27567a984708SDavid Chisnall return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_, 275794e3ee44SDavid Chisnall __x.__x_ + (_Rp - (__y.__i_ + __j))); 27587a984708SDavid Chisnall} 27597a984708SDavid Chisnall 2760f9448bf3SDimitry Andrictemplate<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> 27617a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY 27627a984708SDavid Chisnallbool 27637a984708SDavid Chisnalloperator!=( 2764f9448bf3SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, 2765f9448bf3SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y) 27667a984708SDavid Chisnall{ 27677a984708SDavid Chisnall return !(__x == __y); 27687a984708SDavid Chisnall} 27697a984708SDavid Chisnall 27707a984708SDavid Chisnalltemplate <class _CharT, class _Traits, 2771f9448bf3SDimitry Andric class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> 27727a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 27737a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 2774f9448bf3SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x) 27757a984708SDavid Chisnall{ 27761e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__os); 27777a984708SDavid Chisnall __os.flags(ios_base::dec | ios_base::left); 27787a984708SDavid Chisnall _CharT __sp = __os.widen(' '); 27797a984708SDavid Chisnall __os.fill(__sp); 27807a984708SDavid Chisnall __os << __x.__x_[__x.__i_]; 278194e3ee44SDavid Chisnall for (size_t __j = __x.__i_ + 1; __j < _Rp; ++__j) 27827a984708SDavid Chisnall __os << __sp << __x.__x_[__j]; 27837a984708SDavid Chisnall for (size_t __j = 0; __j < __x.__i_; ++__j) 27847a984708SDavid Chisnall __os << __sp << __x.__x_[__j]; 27857a984708SDavid Chisnall __os << __sp << __x.__c_; 27867a984708SDavid Chisnall return __os; 27877a984708SDavid Chisnall} 27887a984708SDavid Chisnall 27897a984708SDavid Chisnalltemplate <class _CharT, class _Traits, 2790f9448bf3SDimitry Andric class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> 27917a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 27927a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 2793f9448bf3SDimitry Andric subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x) 27947a984708SDavid Chisnall{ 27951e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__is); 27967a984708SDavid Chisnall __is.flags(ios_base::dec | ios_base::skipws); 2797f9448bf3SDimitry Andric _UInt __t[_Rp+1]; 279894e3ee44SDavid Chisnall for (size_t __i = 0; __i < _Rp+1; ++__i) 27997a984708SDavid Chisnall __is >> __t[__i]; 28007a984708SDavid Chisnall if (!__is.fail()) 28017a984708SDavid Chisnall { 280294e3ee44SDavid Chisnall for (size_t __i = 0; __i < _Rp; ++__i) 28037a984708SDavid Chisnall __x.__x_[__i] = __t[__i]; 280494e3ee44SDavid Chisnall __x.__c_ = __t[_Rp]; 28057a984708SDavid Chisnall __x.__i_ = 0; 28067a984708SDavid Chisnall } 28077a984708SDavid Chisnall return __is; 28087a984708SDavid Chisnall} 28097a984708SDavid Chisnall 28107a984708SDavid Chisnalltypedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> ranlux24_base; 28117a984708SDavid Chisnalltypedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> ranlux48_base; 28127a984708SDavid Chisnall 28137a984708SDavid Chisnall// discard_block_engine 28147a984708SDavid Chisnall 28157a984708SDavid Chisnalltemplate<class _Engine, size_t __p, size_t __r> 2816aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS discard_block_engine 28177a984708SDavid Chisnall{ 28187a984708SDavid Chisnall _Engine __e_; 28197a984708SDavid Chisnall int __n_; 28207a984708SDavid Chisnall 28217a984708SDavid Chisnall static_assert( 0 < __r, "discard_block_engine invalid parameters"); 28227a984708SDavid Chisnall static_assert(__r <= __p, "discard_block_engine invalid parameters"); 2823aed8d94eSDimitry Andric static_assert(__r <= INT_MAX, "discard_block_engine invalid parameters"); 28247a984708SDavid Chisnallpublic: 28257a984708SDavid Chisnall // types 28267a984708SDavid Chisnall typedef typename _Engine::result_type result_type; 28277a984708SDavid Chisnall 28287a984708SDavid Chisnall // engine characteristics 2829b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const size_t block_size = __p; 2830b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const size_t used_block = __r; 28317a984708SDavid Chisnall 2832540d2a8bSDimitry Andric#ifdef _LIBCPP_CXX03_LANG 28337a984708SDavid Chisnall static const result_type _Min = _Engine::_Min; 28347a984708SDavid Chisnall static const result_type _Max = _Engine::_Max; 2835b03f91a8SDavid Chisnall#else 2836b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min(); 2837b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max(); 2838b03f91a8SDavid Chisnall#endif 28397a984708SDavid Chisnall 28407a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 2841b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR result_type min() { return _Engine::min(); } 28427a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 2843b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR result_type max() { return _Engine::max(); } 28447a984708SDavid Chisnall 28457a984708SDavid Chisnall // constructors and seeding functions 28467a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 28477a984708SDavid Chisnall discard_block_engine() : __n_(0) {} 28487a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 28497a984708SDavid Chisnall explicit discard_block_engine(const _Engine& __e) 28507a984708SDavid Chisnall : __e_(__e), __n_(0) {} 2851540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 28527a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 28537a984708SDavid Chisnall explicit discard_block_engine(_Engine&& __e) 28547a984708SDavid Chisnall : __e_(_VSTD::move(__e)), __n_(0) {} 2855540d2a8bSDimitry Andric#endif // _LIBCPP_CXX03_LANG 28567a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 28577a984708SDavid Chisnall explicit discard_block_engine(result_type __sd) : __e_(__sd), __n_(0) {} 28587a984708SDavid Chisnall template<class _Sseq> 28597a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 28607a984708SDavid Chisnall explicit discard_block_engine(_Sseq& __q, 28617a984708SDavid Chisnall typename enable_if<__is_seed_sequence<_Sseq, discard_block_engine>::value && 28627a984708SDavid Chisnall !is_convertible<_Sseq, _Engine>::value>::type* = 0) 28637a984708SDavid Chisnall : __e_(__q), __n_(0) {} 28647a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 28657a984708SDavid Chisnall void seed() {__e_.seed(); __n_ = 0;} 28667a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 28677a984708SDavid Chisnall void seed(result_type __sd) {__e_.seed(__sd); __n_ = 0;} 28687a984708SDavid Chisnall template<class _Sseq> 28697a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 28707a984708SDavid Chisnall typename enable_if 28717a984708SDavid Chisnall < 28727a984708SDavid Chisnall __is_seed_sequence<_Sseq, discard_block_engine>::value, 28737a984708SDavid Chisnall void 28747a984708SDavid Chisnall >::type 28757a984708SDavid Chisnall seed(_Sseq& __q) {__e_.seed(__q); __n_ = 0;} 28767a984708SDavid Chisnall 28777a984708SDavid Chisnall // generating functions 28787a984708SDavid Chisnall result_type operator()(); 28797a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 28807a984708SDavid Chisnall void discard(unsigned long long __z) {for (; __z; --__z) operator()();} 28817a984708SDavid Chisnall 28827a984708SDavid Chisnall // property functions 28837a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 2884936e9439SDimitry Andric const _Engine& base() const _NOEXCEPT {return __e_;} 28857a984708SDavid Chisnall 288694e3ee44SDavid Chisnall template<class _Eng, size_t _Pp, size_t _Rp> 28877a984708SDavid Chisnall friend 28887a984708SDavid Chisnall bool 28897a984708SDavid Chisnall operator==( 289094e3ee44SDavid Chisnall const discard_block_engine<_Eng, _Pp, _Rp>& __x, 289194e3ee44SDavid Chisnall const discard_block_engine<_Eng, _Pp, _Rp>& __y); 28927a984708SDavid Chisnall 289394e3ee44SDavid Chisnall template<class _Eng, size_t _Pp, size_t _Rp> 28947a984708SDavid Chisnall friend 28957a984708SDavid Chisnall bool 28967a984708SDavid Chisnall operator!=( 289794e3ee44SDavid Chisnall const discard_block_engine<_Eng, _Pp, _Rp>& __x, 289894e3ee44SDavid Chisnall const discard_block_engine<_Eng, _Pp, _Rp>& __y); 28997a984708SDavid Chisnall 29007a984708SDavid Chisnall template <class _CharT, class _Traits, 290194e3ee44SDavid Chisnall class _Eng, size_t _Pp, size_t _Rp> 29027a984708SDavid Chisnall friend 29037a984708SDavid Chisnall basic_ostream<_CharT, _Traits>& 29047a984708SDavid Chisnall operator<<(basic_ostream<_CharT, _Traits>& __os, 290594e3ee44SDavid Chisnall const discard_block_engine<_Eng, _Pp, _Rp>& __x); 29067a984708SDavid Chisnall 29077a984708SDavid Chisnall template <class _CharT, class _Traits, 290894e3ee44SDavid Chisnall class _Eng, size_t _Pp, size_t _Rp> 29097a984708SDavid Chisnall friend 29107a984708SDavid Chisnall basic_istream<_CharT, _Traits>& 29117a984708SDavid Chisnall operator>>(basic_istream<_CharT, _Traits>& __is, 291294e3ee44SDavid Chisnall discard_block_engine<_Eng, _Pp, _Rp>& __x); 29137a984708SDavid Chisnall}; 29147a984708SDavid Chisnall 29157a984708SDavid Chisnalltemplate<class _Engine, size_t __p, size_t __r> 2916cfdf2879SDavid Chisnall _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::block_size; 2917cfdf2879SDavid Chisnall 2918cfdf2879SDavid Chisnalltemplate<class _Engine, size_t __p, size_t __r> 2919cfdf2879SDavid Chisnall _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::used_block; 2920cfdf2879SDavid Chisnall 2921cfdf2879SDavid Chisnalltemplate<class _Engine, size_t __p, size_t __r> 29227a984708SDavid Chisnalltypename discard_block_engine<_Engine, __p, __r>::result_type 29237a984708SDavid Chisnalldiscard_block_engine<_Engine, __p, __r>::operator()() 29247a984708SDavid Chisnall{ 2925aed8d94eSDimitry Andric if (__n_ >= static_cast<int>(__r)) 29267a984708SDavid Chisnall { 29277a984708SDavid Chisnall __e_.discard(__p - __r); 29287a984708SDavid Chisnall __n_ = 0; 29297a984708SDavid Chisnall } 29307a984708SDavid Chisnall ++__n_; 29317a984708SDavid Chisnall return __e_(); 29327a984708SDavid Chisnall} 29337a984708SDavid Chisnall 293494e3ee44SDavid Chisnalltemplate<class _Eng, size_t _Pp, size_t _Rp> 29357a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY 29367a984708SDavid Chisnallbool 293794e3ee44SDavid Chisnalloperator==(const discard_block_engine<_Eng, _Pp, _Rp>& __x, 293894e3ee44SDavid Chisnall const discard_block_engine<_Eng, _Pp, _Rp>& __y) 29397a984708SDavid Chisnall{ 29407a984708SDavid Chisnall return __x.__n_ == __y.__n_ && __x.__e_ == __y.__e_; 29417a984708SDavid Chisnall} 29427a984708SDavid Chisnall 294394e3ee44SDavid Chisnalltemplate<class _Eng, size_t _Pp, size_t _Rp> 29447a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY 29457a984708SDavid Chisnallbool 294694e3ee44SDavid Chisnalloperator!=(const discard_block_engine<_Eng, _Pp, _Rp>& __x, 294794e3ee44SDavid Chisnall const discard_block_engine<_Eng, _Pp, _Rp>& __y) 29487a984708SDavid Chisnall{ 29497a984708SDavid Chisnall return !(__x == __y); 29507a984708SDavid Chisnall} 29517a984708SDavid Chisnall 29527a984708SDavid Chisnalltemplate <class _CharT, class _Traits, 295394e3ee44SDavid Chisnall class _Eng, size_t _Pp, size_t _Rp> 29547a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 29557a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 295694e3ee44SDavid Chisnall const discard_block_engine<_Eng, _Pp, _Rp>& __x) 29577a984708SDavid Chisnall{ 29581e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__os); 29597a984708SDavid Chisnall __os.flags(ios_base::dec | ios_base::left); 29607a984708SDavid Chisnall _CharT __sp = __os.widen(' '); 29617a984708SDavid Chisnall __os.fill(__sp); 29627a984708SDavid Chisnall return __os << __x.__e_ << __sp << __x.__n_; 29637a984708SDavid Chisnall} 29647a984708SDavid Chisnall 29657a984708SDavid Chisnalltemplate <class _CharT, class _Traits, 296694e3ee44SDavid Chisnall class _Eng, size_t _Pp, size_t _Rp> 29677a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 29687a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 296994e3ee44SDavid Chisnall discard_block_engine<_Eng, _Pp, _Rp>& __x) 29707a984708SDavid Chisnall{ 29711e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__is); 29727a984708SDavid Chisnall __is.flags(ios_base::dec | ios_base::skipws); 29737a984708SDavid Chisnall _Eng __e; 29747a984708SDavid Chisnall int __n; 29757a984708SDavid Chisnall __is >> __e >> __n; 29767a984708SDavid Chisnall if (!__is.fail()) 29777a984708SDavid Chisnall { 29787a984708SDavid Chisnall __x.__e_ = __e; 29797a984708SDavid Chisnall __x.__n_ = __n; 29807a984708SDavid Chisnall } 29817a984708SDavid Chisnall return __is; 29827a984708SDavid Chisnall} 29837a984708SDavid Chisnall 29847a984708SDavid Chisnalltypedef discard_block_engine<ranlux24_base, 223, 23> ranlux24; 29857a984708SDavid Chisnalltypedef discard_block_engine<ranlux48_base, 389, 11> ranlux48; 29867a984708SDavid Chisnall 29877a984708SDavid Chisnall// independent_bits_engine 29887a984708SDavid Chisnall 29897a984708SDavid Chisnalltemplate<class _Engine, size_t __w, class _UIntType> 2990aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS independent_bits_engine 29917a984708SDavid Chisnall{ 2992f9448bf3SDimitry Andric template <class _UInt, _UInt _R0, size_t _Wp, size_t _Mp> 29937a984708SDavid Chisnall class __get_n 29947a984708SDavid Chisnall { 2995f9448bf3SDimitry Andric static _LIBCPP_CONSTEXPR const size_t _Dt = numeric_limits<_UInt>::digits; 2996b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const size_t _Np = _Wp / _Mp + (_Wp % _Mp != 0); 2997b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const size_t _W0 = _Wp / _Np; 2998f9448bf3SDimitry Andric static _LIBCPP_CONSTEXPR const _UInt _Y0 = _W0 >= _Dt ? 0 : (_R0 >> _W0) << _W0; 29997a984708SDavid Chisnall public: 3000b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const size_t value = _R0 - _Y0 > _Y0 / _Np ? _Np + 1 : _Np; 30017a984708SDavid Chisnall }; 30027a984708SDavid Chisnallpublic: 30037a984708SDavid Chisnall // types 30047a984708SDavid Chisnall typedef _UIntType result_type; 30057a984708SDavid Chisnall 30067a984708SDavid Chisnallprivate: 30077a984708SDavid Chisnall _Engine __e_; 30087a984708SDavid Chisnall 3009b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; 30107a984708SDavid Chisnall static_assert( 0 < __w, "independent_bits_engine invalid parameters"); 30117a984708SDavid Chisnall static_assert(__w <= _Dt, "independent_bits_engine invalid parameters"); 30127a984708SDavid Chisnall 30137a984708SDavid Chisnall typedef typename _Engine::result_type _Engine_result_type; 30147a984708SDavid Chisnall typedef typename conditional 30157a984708SDavid Chisnall < 30167a984708SDavid Chisnall sizeof(_Engine_result_type) <= sizeof(result_type), 30177a984708SDavid Chisnall result_type, 30187a984708SDavid Chisnall _Engine_result_type 30197a984708SDavid Chisnall >::type _Working_result_type; 3020540d2a8bSDimitry Andric#ifdef _LIBCPP_CXX03_LANG 302194e3ee44SDavid Chisnall static const _Working_result_type _Rp = _Engine::_Max - _Engine::_Min 30227a984708SDavid Chisnall + _Working_result_type(1); 3023b03f91a8SDavid Chisnall#else 3024b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const _Working_result_type _Rp = _Engine::max() - _Engine::min() 3025b03f91a8SDavid Chisnall + _Working_result_type(1); 3026b03f91a8SDavid Chisnall#endif 3027b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const size_t __m = __log2<_Working_result_type, _Rp>::value; 3028b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const size_t __n = __get_n<_Working_result_type, _Rp, __w, __m>::value; 3029b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const size_t __w0 = __w / __n; 3030b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const size_t __n0 = __n - __w % __n; 3031b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const size_t _WDt = numeric_limits<_Working_result_type>::digits; 3032b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const size_t _EDt = numeric_limits<_Engine_result_type>::digits; 3033b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const _Working_result_type __y0 = __w0 >= _WDt ? 0 : 303494e3ee44SDavid Chisnall (_Rp >> __w0) << __w0; 3035b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const _Working_result_type __y1 = __w0 >= _WDt - 1 ? 0 : 303694e3ee44SDavid Chisnall (_Rp >> (__w0+1)) << (__w0+1); 3037b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const _Engine_result_type __mask0 = __w0 > 0 ? 30387a984708SDavid Chisnall _Engine_result_type(~0) >> (_EDt - __w0) : 30397a984708SDavid Chisnall _Engine_result_type(0); 3040b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const _Engine_result_type __mask1 = __w0 < _EDt - 1 ? 30417a984708SDavid Chisnall _Engine_result_type(~0) >> (_EDt - (__w0 + 1)) : 30427a984708SDavid Chisnall _Engine_result_type(~0); 30437a984708SDavid Chisnallpublic: 3044b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type _Min = 0; 3045b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : 30467a984708SDavid Chisnall (result_type(1) << __w) - result_type(1); 30477a984708SDavid Chisnall static_assert(_Min < _Max, "independent_bits_engine invalid parameters"); 30487a984708SDavid Chisnall 30497a984708SDavid Chisnall // engine characteristics 30507a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 3051b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR result_type min() { return _Min; } 30527a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 3053b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR result_type max() { return _Max; } 30547a984708SDavid Chisnall 30557a984708SDavid Chisnall // constructors and seeding functions 30567a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 30577a984708SDavid Chisnall independent_bits_engine() {} 30587a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 30597a984708SDavid Chisnall explicit independent_bits_engine(const _Engine& __e) 30607a984708SDavid Chisnall : __e_(__e) {} 3061540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 30627a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 30637a984708SDavid Chisnall explicit independent_bits_engine(_Engine&& __e) 30647a984708SDavid Chisnall : __e_(_VSTD::move(__e)) {} 3065540d2a8bSDimitry Andric#endif // _LIBCPP_CXX03_LANG 30667a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 30677a984708SDavid Chisnall explicit independent_bits_engine(result_type __sd) : __e_(__sd) {} 306894e3ee44SDavid Chisnall template<class _Sseq> 30697a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 307094e3ee44SDavid Chisnall explicit independent_bits_engine(_Sseq& __q, 30717a984708SDavid Chisnall typename enable_if<__is_seed_sequence<_Sseq, independent_bits_engine>::value && 30727a984708SDavid Chisnall !is_convertible<_Sseq, _Engine>::value>::type* = 0) 30737a984708SDavid Chisnall : __e_(__q) {} 30747a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 30757a984708SDavid Chisnall void seed() {__e_.seed();} 30767a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 30777a984708SDavid Chisnall void seed(result_type __sd) {__e_.seed(__sd);} 30787a984708SDavid Chisnall template<class _Sseq> 30797a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 30807a984708SDavid Chisnall typename enable_if 30817a984708SDavid Chisnall < 30827a984708SDavid Chisnall __is_seed_sequence<_Sseq, independent_bits_engine>::value, 30837a984708SDavid Chisnall void 30847a984708SDavid Chisnall >::type 30857a984708SDavid Chisnall seed(_Sseq& __q) {__e_.seed(__q);} 30867a984708SDavid Chisnall 30877a984708SDavid Chisnall // generating functions 30887a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 308994e3ee44SDavid Chisnall result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());} 30907a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 30917a984708SDavid Chisnall void discard(unsigned long long __z) {for (; __z; --__z) operator()();} 30927a984708SDavid Chisnall 30937a984708SDavid Chisnall // property functions 30947a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 3095936e9439SDimitry Andric const _Engine& base() const _NOEXCEPT {return __e_;} 30967a984708SDavid Chisnall 3097f9448bf3SDimitry Andric template<class _Eng, size_t _Wp, class _UInt> 30987a984708SDavid Chisnall friend 30997a984708SDavid Chisnall bool 31007a984708SDavid Chisnall operator==( 3101f9448bf3SDimitry Andric const independent_bits_engine<_Eng, _Wp, _UInt>& __x, 3102f9448bf3SDimitry Andric const independent_bits_engine<_Eng, _Wp, _UInt>& __y); 31037a984708SDavid Chisnall 3104f9448bf3SDimitry Andric template<class _Eng, size_t _Wp, class _UInt> 31057a984708SDavid Chisnall friend 31067a984708SDavid Chisnall bool 31077a984708SDavid Chisnall operator!=( 3108f9448bf3SDimitry Andric const independent_bits_engine<_Eng, _Wp, _UInt>& __x, 3109f9448bf3SDimitry Andric const independent_bits_engine<_Eng, _Wp, _UInt>& __y); 31107a984708SDavid Chisnall 31117a984708SDavid Chisnall template <class _CharT, class _Traits, 3112f9448bf3SDimitry Andric class _Eng, size_t _Wp, class _UInt> 31137a984708SDavid Chisnall friend 31147a984708SDavid Chisnall basic_ostream<_CharT, _Traits>& 31157a984708SDavid Chisnall operator<<(basic_ostream<_CharT, _Traits>& __os, 3116f9448bf3SDimitry Andric const independent_bits_engine<_Eng, _Wp, _UInt>& __x); 31177a984708SDavid Chisnall 31187a984708SDavid Chisnall template <class _CharT, class _Traits, 3119f9448bf3SDimitry Andric class _Eng, size_t _Wp, class _UInt> 31207a984708SDavid Chisnall friend 31217a984708SDavid Chisnall basic_istream<_CharT, _Traits>& 31227a984708SDavid Chisnall operator>>(basic_istream<_CharT, _Traits>& __is, 3123f9448bf3SDimitry Andric independent_bits_engine<_Eng, _Wp, _UInt>& __x); 31247a984708SDavid Chisnall 31257a984708SDavid Chisnallprivate: 31269729cf09SDimitry Andric _LIBCPP_INLINE_VISIBILITY 31277a984708SDavid Chisnall result_type __eval(false_type); 31287a984708SDavid Chisnall result_type __eval(true_type); 31297a984708SDavid Chisnall 31307a984708SDavid Chisnall template <size_t __count> 31317a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 31327a984708SDavid Chisnall static 31337a984708SDavid Chisnall typename enable_if 31347a984708SDavid Chisnall < 31357a984708SDavid Chisnall __count < _Dt, 31367a984708SDavid Chisnall result_type 31377a984708SDavid Chisnall >::type 31387a984708SDavid Chisnall __lshift(result_type __x) {return __x << __count;} 31397a984708SDavid Chisnall 31407a984708SDavid Chisnall template <size_t __count> 31417a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 31427a984708SDavid Chisnall static 31437a984708SDavid Chisnall typename enable_if 31447a984708SDavid Chisnall < 31457a984708SDavid Chisnall (__count >= _Dt), 31467a984708SDavid Chisnall result_type 31477a984708SDavid Chisnall >::type 314894e3ee44SDavid Chisnall __lshift(result_type) {return result_type(0);} 31497a984708SDavid Chisnall}; 31507a984708SDavid Chisnall 31517a984708SDavid Chisnalltemplate<class _Engine, size_t __w, class _UIntType> 31529729cf09SDimitry Andricinline 31537a984708SDavid Chisnall_UIntType 31547a984708SDavid Chisnallindependent_bits_engine<_Engine, __w, _UIntType>::__eval(false_type) 31557a984708SDavid Chisnall{ 31567a984708SDavid Chisnall return static_cast<result_type>(__e_() & __mask0); 31577a984708SDavid Chisnall} 31587a984708SDavid Chisnall 31597a984708SDavid Chisnalltemplate<class _Engine, size_t __w, class _UIntType> 31607a984708SDavid Chisnall_UIntType 31617a984708SDavid Chisnallindependent_bits_engine<_Engine, __w, _UIntType>::__eval(true_type) 31627a984708SDavid Chisnall{ 316394e3ee44SDavid Chisnall result_type _Sp = 0; 31647a984708SDavid Chisnall for (size_t __k = 0; __k < __n0; ++__k) 31657a984708SDavid Chisnall { 31667a984708SDavid Chisnall _Engine_result_type __u; 31677a984708SDavid Chisnall do 31687a984708SDavid Chisnall { 31697a984708SDavid Chisnall __u = __e_() - _Engine::min(); 31707a984708SDavid Chisnall } while (__u >= __y0); 317194e3ee44SDavid Chisnall _Sp = static_cast<result_type>(__lshift<__w0>(_Sp) + (__u & __mask0)); 31727a984708SDavid Chisnall } 31737a984708SDavid Chisnall for (size_t __k = __n0; __k < __n; ++__k) 31747a984708SDavid Chisnall { 31757a984708SDavid Chisnall _Engine_result_type __u; 31767a984708SDavid Chisnall do 31777a984708SDavid Chisnall { 31787a984708SDavid Chisnall __u = __e_() - _Engine::min(); 31797a984708SDavid Chisnall } while (__u >= __y1); 318094e3ee44SDavid Chisnall _Sp = static_cast<result_type>(__lshift<__w0+1>(_Sp) + (__u & __mask1)); 31817a984708SDavid Chisnall } 318294e3ee44SDavid Chisnall return _Sp; 31837a984708SDavid Chisnall} 31847a984708SDavid Chisnall 3185f9448bf3SDimitry Andrictemplate<class _Eng, size_t _Wp, class _UInt> 31867a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY 31877a984708SDavid Chisnallbool 31887a984708SDavid Chisnalloperator==( 3189f9448bf3SDimitry Andric const independent_bits_engine<_Eng, _Wp, _UInt>& __x, 3190f9448bf3SDimitry Andric const independent_bits_engine<_Eng, _Wp, _UInt>& __y) 31917a984708SDavid Chisnall{ 31927a984708SDavid Chisnall return __x.base() == __y.base(); 31937a984708SDavid Chisnall} 31947a984708SDavid Chisnall 3195f9448bf3SDimitry Andrictemplate<class _Eng, size_t _Wp, class _UInt> 31967a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY 31977a984708SDavid Chisnallbool 31987a984708SDavid Chisnalloperator!=( 3199f9448bf3SDimitry Andric const independent_bits_engine<_Eng, _Wp, _UInt>& __x, 3200f9448bf3SDimitry Andric const independent_bits_engine<_Eng, _Wp, _UInt>& __y) 32017a984708SDavid Chisnall{ 32027a984708SDavid Chisnall return !(__x == __y); 32037a984708SDavid Chisnall} 32047a984708SDavid Chisnall 32057a984708SDavid Chisnalltemplate <class _CharT, class _Traits, 3206f9448bf3SDimitry Andric class _Eng, size_t _Wp, class _UInt> 32077a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 32087a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 3209f9448bf3SDimitry Andric const independent_bits_engine<_Eng, _Wp, _UInt>& __x) 32107a984708SDavid Chisnall{ 32117a984708SDavid Chisnall return __os << __x.base(); 32127a984708SDavid Chisnall} 32137a984708SDavid Chisnall 32147a984708SDavid Chisnalltemplate <class _CharT, class _Traits, 3215f9448bf3SDimitry Andric class _Eng, size_t _Wp, class _UInt> 32167a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 32177a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 3218f9448bf3SDimitry Andric independent_bits_engine<_Eng, _Wp, _UInt>& __x) 32197a984708SDavid Chisnall{ 32207a984708SDavid Chisnall _Eng __e; 32217a984708SDavid Chisnall __is >> __e; 32227a984708SDavid Chisnall if (!__is.fail()) 32237a984708SDavid Chisnall __x.__e_ = __e; 32247a984708SDavid Chisnall return __is; 32257a984708SDavid Chisnall} 32267a984708SDavid Chisnall 32277a984708SDavid Chisnall// shuffle_order_engine 32287a984708SDavid Chisnall 32297a984708SDavid Chisnalltemplate <uint64_t _Xp, uint64_t _Yp> 32307a984708SDavid Chisnallstruct __ugcd 32317a984708SDavid Chisnall{ 3232b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const uint64_t value = __ugcd<_Yp, _Xp % _Yp>::value; 32337a984708SDavid Chisnall}; 32347a984708SDavid Chisnall 32357a984708SDavid Chisnalltemplate <uint64_t _Xp> 32367a984708SDavid Chisnallstruct __ugcd<_Xp, 0> 32377a984708SDavid Chisnall{ 3238b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const uint64_t value = _Xp; 32397a984708SDavid Chisnall}; 32407a984708SDavid Chisnall 324194e3ee44SDavid Chisnalltemplate <uint64_t _Np, uint64_t _Dp> 32427a984708SDavid Chisnallclass __uratio 32437a984708SDavid Chisnall{ 324494e3ee44SDavid Chisnall static_assert(_Dp != 0, "__uratio divide by 0"); 3245b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const uint64_t __gcd = __ugcd<_Np, _Dp>::value; 32467a984708SDavid Chisnallpublic: 3247b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const uint64_t num = _Np / __gcd; 3248b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const uint64_t den = _Dp / __gcd; 32497a984708SDavid Chisnall 32507a984708SDavid Chisnall typedef __uratio<num, den> type; 32517a984708SDavid Chisnall}; 32527a984708SDavid Chisnall 32537a984708SDavid Chisnalltemplate<class _Engine, size_t __k> 3254aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS shuffle_order_engine 32557a984708SDavid Chisnall{ 32567a984708SDavid Chisnall static_assert(0 < __k, "shuffle_order_engine invalid parameters"); 32577a984708SDavid Chisnallpublic: 32587a984708SDavid Chisnall // types 32597a984708SDavid Chisnall typedef typename _Engine::result_type result_type; 32607a984708SDavid Chisnall 32617a984708SDavid Chisnallprivate: 32627a984708SDavid Chisnall _Engine __e_; 32637a984708SDavid Chisnall result_type _V_[__k]; 32647a984708SDavid Chisnall result_type _Y_; 32657a984708SDavid Chisnall 32667a984708SDavid Chisnallpublic: 32677a984708SDavid Chisnall // engine characteristics 3268b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const size_t table_size = __k; 32697a984708SDavid Chisnall 3270540d2a8bSDimitry Andric#ifdef _LIBCPP_CXX03_LANG 32717a984708SDavid Chisnall static const result_type _Min = _Engine::_Min; 32727a984708SDavid Chisnall static const result_type _Max = _Engine::_Max; 3273b03f91a8SDavid Chisnall#else 3274b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min(); 3275b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max(); 3276b03f91a8SDavid Chisnall#endif 32777a984708SDavid Chisnall static_assert(_Min < _Max, "shuffle_order_engine invalid parameters"); 32787a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 3279b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR result_type min() { return _Min; } 32807a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 3281b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR result_type max() { return _Max; } 32827a984708SDavid Chisnall 3283b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const unsigned long long _Rp = _Max - _Min + 1ull; 32847a984708SDavid Chisnall 32857a984708SDavid Chisnall // constructors and seeding functions 32867a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 32877a984708SDavid Chisnall shuffle_order_engine() {__init();} 32887a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 32897a984708SDavid Chisnall explicit shuffle_order_engine(const _Engine& __e) 32907a984708SDavid Chisnall : __e_(__e) {__init();} 3291540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 32927a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 32937a984708SDavid Chisnall explicit shuffle_order_engine(_Engine&& __e) 32947a984708SDavid Chisnall : __e_(_VSTD::move(__e)) {__init();} 3295540d2a8bSDimitry Andric#endif // _LIBCPP_CXX03_LANG 32967a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 32977a984708SDavid Chisnall explicit shuffle_order_engine(result_type __sd) : __e_(__sd) {__init();} 329894e3ee44SDavid Chisnall template<class _Sseq> 32997a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 330094e3ee44SDavid Chisnall explicit shuffle_order_engine(_Sseq& __q, 33017a984708SDavid Chisnall typename enable_if<__is_seed_sequence<_Sseq, shuffle_order_engine>::value && 33027a984708SDavid Chisnall !is_convertible<_Sseq, _Engine>::value>::type* = 0) 33037a984708SDavid Chisnall : __e_(__q) {__init();} 33047a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 33057a984708SDavid Chisnall void seed() {__e_.seed(); __init();} 33067a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 33077a984708SDavid Chisnall void seed(result_type __sd) {__e_.seed(__sd); __init();} 33087a984708SDavid Chisnall template<class _Sseq> 33097a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 33107a984708SDavid Chisnall typename enable_if 33117a984708SDavid Chisnall < 33127a984708SDavid Chisnall __is_seed_sequence<_Sseq, shuffle_order_engine>::value, 33137a984708SDavid Chisnall void 33147a984708SDavid Chisnall >::type 33157a984708SDavid Chisnall seed(_Sseq& __q) {__e_.seed(__q); __init();} 33167a984708SDavid Chisnall 33177a984708SDavid Chisnall // generating functions 33187a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 331994e3ee44SDavid Chisnall result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());} 33207a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 33217a984708SDavid Chisnall void discard(unsigned long long __z) {for (; __z; --__z) operator()();} 33227a984708SDavid Chisnall 33237a984708SDavid Chisnall // property functions 33247a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 3325936e9439SDimitry Andric const _Engine& base() const _NOEXCEPT {return __e_;} 33267a984708SDavid Chisnall 33277a984708SDavid Chisnallprivate: 332894e3ee44SDavid Chisnall template<class _Eng, size_t _Kp> 33297a984708SDavid Chisnall friend 33307a984708SDavid Chisnall bool 33317a984708SDavid Chisnall operator==( 333294e3ee44SDavid Chisnall const shuffle_order_engine<_Eng, _Kp>& __x, 333394e3ee44SDavid Chisnall const shuffle_order_engine<_Eng, _Kp>& __y); 33347a984708SDavid Chisnall 333594e3ee44SDavid Chisnall template<class _Eng, size_t _Kp> 33367a984708SDavid Chisnall friend 33377a984708SDavid Chisnall bool 33387a984708SDavid Chisnall operator!=( 333994e3ee44SDavid Chisnall const shuffle_order_engine<_Eng, _Kp>& __x, 334094e3ee44SDavid Chisnall const shuffle_order_engine<_Eng, _Kp>& __y); 33417a984708SDavid Chisnall 33427a984708SDavid Chisnall template <class _CharT, class _Traits, 334394e3ee44SDavid Chisnall class _Eng, size_t _Kp> 33447a984708SDavid Chisnall friend 33457a984708SDavid Chisnall basic_ostream<_CharT, _Traits>& 33467a984708SDavid Chisnall operator<<(basic_ostream<_CharT, _Traits>& __os, 334794e3ee44SDavid Chisnall const shuffle_order_engine<_Eng, _Kp>& __x); 33487a984708SDavid Chisnall 33497a984708SDavid Chisnall template <class _CharT, class _Traits, 335094e3ee44SDavid Chisnall class _Eng, size_t _Kp> 33517a984708SDavid Chisnall friend 33527a984708SDavid Chisnall basic_istream<_CharT, _Traits>& 33537a984708SDavid Chisnall operator>>(basic_istream<_CharT, _Traits>& __is, 335494e3ee44SDavid Chisnall shuffle_order_engine<_Eng, _Kp>& __x); 33557a984708SDavid Chisnall 33567a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 33577a984708SDavid Chisnall void __init() 33587a984708SDavid Chisnall { 33597a984708SDavid Chisnall for (size_t __i = 0; __i < __k; ++__i) 33607a984708SDavid Chisnall _V_[__i] = __e_(); 33617a984708SDavid Chisnall _Y_ = __e_(); 33627a984708SDavid Chisnall } 33637a984708SDavid Chisnall 33647a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 33657a984708SDavid Chisnall result_type __eval(false_type) {return __eval2(integral_constant<bool, __k & 1>());} 33667a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 336794e3ee44SDavid Chisnall result_type __eval(true_type) {return __eval(__uratio<__k, _Rp>());} 33687a984708SDavid Chisnall 33697a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 33707a984708SDavid Chisnall result_type __eval2(false_type) {return __eval(__uratio<__k/2, 0x8000000000000000ull>());} 33717a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 33727a984708SDavid Chisnall result_type __eval2(true_type) {return __evalf<__k, 0>();} 33737a984708SDavid Chisnall 337494e3ee44SDavid Chisnall template <uint64_t _Np, uint64_t _Dp> 33757a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 33767a984708SDavid Chisnall typename enable_if 33777a984708SDavid Chisnall < 337894e3ee44SDavid Chisnall (__uratio<_Np, _Dp>::num > 0xFFFFFFFFFFFFFFFFull / (_Max - _Min)), 33797a984708SDavid Chisnall result_type 33807a984708SDavid Chisnall >::type 338194e3ee44SDavid Chisnall __eval(__uratio<_Np, _Dp>) 338294e3ee44SDavid Chisnall {return __evalf<__uratio<_Np, _Dp>::num, __uratio<_Np, _Dp>::den>();} 33837a984708SDavid Chisnall 338494e3ee44SDavid Chisnall template <uint64_t _Np, uint64_t _Dp> 33857a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 33867a984708SDavid Chisnall typename enable_if 33877a984708SDavid Chisnall < 338894e3ee44SDavid Chisnall __uratio<_Np, _Dp>::num <= 0xFFFFFFFFFFFFFFFFull / (_Max - _Min), 33897a984708SDavid Chisnall result_type 33907a984708SDavid Chisnall >::type 339194e3ee44SDavid Chisnall __eval(__uratio<_Np, _Dp>) 33927a984708SDavid Chisnall { 339394e3ee44SDavid Chisnall const size_t __j = static_cast<size_t>(__uratio<_Np, _Dp>::num * (_Y_ - _Min) 339494e3ee44SDavid Chisnall / __uratio<_Np, _Dp>::den); 33957a984708SDavid Chisnall _Y_ = _V_[__j]; 33967a984708SDavid Chisnall _V_[__j] = __e_(); 33977a984708SDavid Chisnall return _Y_; 33987a984708SDavid Chisnall } 33997a984708SDavid Chisnall 34007a984708SDavid Chisnall template <uint64_t __n, uint64_t __d> 34017a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 34027a984708SDavid Chisnall result_type __evalf() 34037a984708SDavid Chisnall { 340494e3ee44SDavid Chisnall const double _Fp = __d == 0 ? 34057a984708SDavid Chisnall __n / (2. * 0x8000000000000000ull) : 34067a984708SDavid Chisnall __n / (double)__d; 340794e3ee44SDavid Chisnall const size_t __j = static_cast<size_t>(_Fp * (_Y_ - _Min)); 34087a984708SDavid Chisnall _Y_ = _V_[__j]; 34097a984708SDavid Chisnall _V_[__j] = __e_(); 34107a984708SDavid Chisnall return _Y_; 34117a984708SDavid Chisnall } 34127a984708SDavid Chisnall}; 34137a984708SDavid Chisnall 3414cfdf2879SDavid Chisnalltemplate<class _Engine, size_t __k> 3415cfdf2879SDavid Chisnall _LIBCPP_CONSTEXPR const size_t shuffle_order_engine<_Engine, __k>::table_size; 3416cfdf2879SDavid Chisnall 341794e3ee44SDavid Chisnalltemplate<class _Eng, size_t _Kp> 34187a984708SDavid Chisnallbool 34197a984708SDavid Chisnalloperator==( 342094e3ee44SDavid Chisnall const shuffle_order_engine<_Eng, _Kp>& __x, 342194e3ee44SDavid Chisnall const shuffle_order_engine<_Eng, _Kp>& __y) 34227a984708SDavid Chisnall{ 342394e3ee44SDavid Chisnall return __x._Y_ == __y._Y_ && _VSTD::equal(__x._V_, __x._V_ + _Kp, __y._V_) && 34247a984708SDavid Chisnall __x.__e_ == __y.__e_; 34257a984708SDavid Chisnall} 34267a984708SDavid Chisnall 342794e3ee44SDavid Chisnalltemplate<class _Eng, size_t _Kp> 34287a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY 34297a984708SDavid Chisnallbool 34307a984708SDavid Chisnalloperator!=( 343194e3ee44SDavid Chisnall const shuffle_order_engine<_Eng, _Kp>& __x, 343294e3ee44SDavid Chisnall const shuffle_order_engine<_Eng, _Kp>& __y) 34337a984708SDavid Chisnall{ 34347a984708SDavid Chisnall return !(__x == __y); 34357a984708SDavid Chisnall} 34367a984708SDavid Chisnall 34377a984708SDavid Chisnalltemplate <class _CharT, class _Traits, 343894e3ee44SDavid Chisnall class _Eng, size_t _Kp> 34397a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 34407a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 344194e3ee44SDavid Chisnall const shuffle_order_engine<_Eng, _Kp>& __x) 34427a984708SDavid Chisnall{ 34431e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__os); 34447a984708SDavid Chisnall __os.flags(ios_base::dec | ios_base::left); 34457a984708SDavid Chisnall _CharT __sp = __os.widen(' '); 34467a984708SDavid Chisnall __os.fill(__sp); 34477a984708SDavid Chisnall __os << __x.__e_ << __sp << __x._V_[0]; 344894e3ee44SDavid Chisnall for (size_t __i = 1; __i < _Kp; ++__i) 34497a984708SDavid Chisnall __os << __sp << __x._V_[__i]; 34507a984708SDavid Chisnall return __os << __sp << __x._Y_; 34517a984708SDavid Chisnall} 34527a984708SDavid Chisnall 34537a984708SDavid Chisnalltemplate <class _CharT, class _Traits, 345494e3ee44SDavid Chisnall class _Eng, size_t _Kp> 34557a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 34567a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 345794e3ee44SDavid Chisnall shuffle_order_engine<_Eng, _Kp>& __x) 34587a984708SDavid Chisnall{ 345994e3ee44SDavid Chisnall typedef typename shuffle_order_engine<_Eng, _Kp>::result_type result_type; 34601e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__is); 34617a984708SDavid Chisnall __is.flags(ios_base::dec | ios_base::skipws); 34627a984708SDavid Chisnall _Eng __e; 346394e3ee44SDavid Chisnall result_type _Vp[_Kp+1]; 34647a984708SDavid Chisnall __is >> __e; 346594e3ee44SDavid Chisnall for (size_t __i = 0; __i < _Kp+1; ++__i) 346694e3ee44SDavid Chisnall __is >> _Vp[__i]; 34677a984708SDavid Chisnall if (!__is.fail()) 34687a984708SDavid Chisnall { 34697a984708SDavid Chisnall __x.__e_ = __e; 347094e3ee44SDavid Chisnall for (size_t __i = 0; __i < _Kp; ++__i) 347194e3ee44SDavid Chisnall __x._V_[__i] = _Vp[__i]; 347294e3ee44SDavid Chisnall __x._Y_ = _Vp[_Kp]; 34737a984708SDavid Chisnall } 34747a984708SDavid Chisnall return __is; 34757a984708SDavid Chisnall} 34767a984708SDavid Chisnall 34777a984708SDavid Chisnalltypedef shuffle_order_engine<minstd_rand0, 256> knuth_b; 34787a984708SDavid Chisnall 34797a984708SDavid Chisnall// random_device 34807a984708SDavid Chisnall 34811bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS random_device 34827a984708SDavid Chisnall{ 3483854fa44bSDimitry Andric#ifdef _LIBCPP_USING_DEV_RANDOM 34847a984708SDavid Chisnall int __f_; 3485854fa44bSDimitry Andric#endif // defined(_LIBCPP_USING_DEV_RANDOM) 34867a984708SDavid Chisnallpublic: 34877a984708SDavid Chisnall // types 34887a984708SDavid Chisnall typedef unsigned result_type; 34897a984708SDavid Chisnall 34907a984708SDavid Chisnall // generator characteristics 3491b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type _Min = 0; 3492b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR const result_type _Max = 0xFFFFFFFFu; 34937a984708SDavid Chisnall 34947a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 3495b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR result_type min() { return _Min;} 34967a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 3497b03f91a8SDavid Chisnall static _LIBCPP_CONSTEXPR result_type max() { return _Max;} 34987a984708SDavid Chisnall 34997a984708SDavid Chisnall // constructors 35007a984708SDavid Chisnall explicit random_device(const string& __token = "/dev/urandom"); 35017a984708SDavid Chisnall ~random_device(); 35027a984708SDavid Chisnall 35037a984708SDavid Chisnall // generating functions 35047a984708SDavid Chisnall result_type operator()(); 35057a984708SDavid Chisnall 35067a984708SDavid Chisnall // property functions 3507936e9439SDimitry Andric double entropy() const _NOEXCEPT; 35087a984708SDavid Chisnall 35097a984708SDavid Chisnallprivate: 35107a984708SDavid Chisnall // no copy functions 35117a984708SDavid Chisnall random_device(const random_device&); // = delete; 35127a984708SDavid Chisnall random_device& operator=(const random_device&); // = delete; 35137a984708SDavid Chisnall}; 35147a984708SDavid Chisnall 35157a984708SDavid Chisnall// seed_seq 35167a984708SDavid Chisnall 3517aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS seed_seq 35187a984708SDavid Chisnall{ 35197a984708SDavid Chisnallpublic: 35207a984708SDavid Chisnall // types 35217a984708SDavid Chisnall typedef uint32_t result_type; 35227a984708SDavid Chisnall 35237a984708SDavid Chisnallprivate: 35247a984708SDavid Chisnall vector<result_type> __v_; 35257a984708SDavid Chisnall 35267a984708SDavid Chisnall template<class _InputIterator> 35277a984708SDavid Chisnall void init(_InputIterator __first, _InputIterator __last); 35287a984708SDavid Chisnallpublic: 35297a984708SDavid Chisnall // constructors 35307a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 35314f7ab58eSDimitry Andric seed_seq() _NOEXCEPT {} 3532540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 35337a984708SDavid Chisnall template<class _Tp> 35347a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 35357a984708SDavid Chisnall seed_seq(initializer_list<_Tp> __il) {init(__il.begin(), __il.end());} 3536540d2a8bSDimitry Andric#endif // _LIBCPP_CXX03_LANG 35377a984708SDavid Chisnall 35387a984708SDavid Chisnall template<class _InputIterator> 35397a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 35407a984708SDavid Chisnall seed_seq(_InputIterator __first, _InputIterator __last) 35417a984708SDavid Chisnall {init(__first, __last);} 35427a984708SDavid Chisnall 35437a984708SDavid Chisnall // generating functions 35447a984708SDavid Chisnall template<class _RandomAccessIterator> 35457a984708SDavid Chisnall void generate(_RandomAccessIterator __first, _RandomAccessIterator __last); 35467a984708SDavid Chisnall 35477a984708SDavid Chisnall // property functions 35487a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 35494f7ab58eSDimitry Andric size_t size() const _NOEXCEPT {return __v_.size();} 35507a984708SDavid Chisnall template<class _OutputIterator> 35517a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 35527a984708SDavid Chisnall void param(_OutputIterator __dest) const 35537a984708SDavid Chisnall {_VSTD::copy(__v_.begin(), __v_.end(), __dest);} 35547a984708SDavid Chisnall 35557a984708SDavid Chisnallprivate: 35567a984708SDavid Chisnall // no copy functions 35577a984708SDavid Chisnall seed_seq(const seed_seq&); // = delete; 35587a984708SDavid Chisnall void operator=(const seed_seq&); // = delete; 35597a984708SDavid Chisnall 35607a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 356194e3ee44SDavid Chisnall static result_type _Tp(result_type __x) {return __x ^ (__x >> 27);} 35627a984708SDavid Chisnall}; 35637a984708SDavid Chisnall 35647a984708SDavid Chisnalltemplate<class _InputIterator> 35657a984708SDavid Chisnallvoid 35667a984708SDavid Chisnallseed_seq::init(_InputIterator __first, _InputIterator __last) 35677a984708SDavid Chisnall{ 35687a984708SDavid Chisnall for (_InputIterator __s = __first; __s != __last; ++__s) 35697a984708SDavid Chisnall __v_.push_back(*__s & 0xFFFFFFFF); 35707a984708SDavid Chisnall} 35717a984708SDavid Chisnall 35727a984708SDavid Chisnalltemplate<class _RandomAccessIterator> 35737a984708SDavid Chisnallvoid 35747a984708SDavid Chisnallseed_seq::generate(_RandomAccessIterator __first, _RandomAccessIterator __last) 35757a984708SDavid Chisnall{ 35767a984708SDavid Chisnall if (__first != __last) 35777a984708SDavid Chisnall { 35787a984708SDavid Chisnall _VSTD::fill(__first, __last, 0x8b8b8b8b); 35797a984708SDavid Chisnall const size_t __n = static_cast<size_t>(__last - __first); 35807a984708SDavid Chisnall const size_t __s = __v_.size(); 35817a984708SDavid Chisnall const size_t __t = (__n >= 623) ? 11 35827a984708SDavid Chisnall : (__n >= 68) ? 7 35837a984708SDavid Chisnall : (__n >= 39) ? 5 35847a984708SDavid Chisnall : (__n >= 7) ? 3 35857a984708SDavid Chisnall : (__n - 1) / 2; 35867a984708SDavid Chisnall const size_t __p = (__n - __t) / 2; 35877a984708SDavid Chisnall const size_t __q = __p + __t; 35887a984708SDavid Chisnall const size_t __m = _VSTD::max(__s + 1, __n); 35897a984708SDavid Chisnall // __k = 0; 35907a984708SDavid Chisnall { 359194e3ee44SDavid Chisnall result_type __r = 1664525 * _Tp(__first[0] ^ __first[__p] 35927a984708SDavid Chisnall ^ __first[__n - 1]); 35937a984708SDavid Chisnall __first[__p] += __r; 35947a984708SDavid Chisnall __r += __s; 35957a984708SDavid Chisnall __first[__q] += __r; 35967a984708SDavid Chisnall __first[0] = __r; 35977a984708SDavid Chisnall } 35987a984708SDavid Chisnall for (size_t __k = 1; __k <= __s; ++__k) 35997a984708SDavid Chisnall { 36007a984708SDavid Chisnall const size_t __kmodn = __k % __n; 36017a984708SDavid Chisnall const size_t __kpmodn = (__k + __p) % __n; 360294e3ee44SDavid Chisnall result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn] 36037a984708SDavid Chisnall ^ __first[(__k - 1) % __n]); 36047a984708SDavid Chisnall __first[__kpmodn] += __r; 36057a984708SDavid Chisnall __r += __kmodn + __v_[__k-1]; 36067a984708SDavid Chisnall __first[(__k + __q) % __n] += __r; 36077a984708SDavid Chisnall __first[__kmodn] = __r; 36087a984708SDavid Chisnall } 36097a984708SDavid Chisnall for (size_t __k = __s + 1; __k < __m; ++__k) 36107a984708SDavid Chisnall { 36117a984708SDavid Chisnall const size_t __kmodn = __k % __n; 36127a984708SDavid Chisnall const size_t __kpmodn = (__k + __p) % __n; 361394e3ee44SDavid Chisnall result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn] 36147a984708SDavid Chisnall ^ __first[(__k - 1) % __n]); 36157a984708SDavid Chisnall __first[__kpmodn] += __r; 36167a984708SDavid Chisnall __r += __kmodn; 36177a984708SDavid Chisnall __first[(__k + __q) % __n] += __r; 36187a984708SDavid Chisnall __first[__kmodn] = __r; 36197a984708SDavid Chisnall } 36207a984708SDavid Chisnall for (size_t __k = __m; __k < __m + __n; ++__k) 36217a984708SDavid Chisnall { 36227a984708SDavid Chisnall const size_t __kmodn = __k % __n; 36237a984708SDavid Chisnall const size_t __kpmodn = (__k + __p) % __n; 362494e3ee44SDavid Chisnall result_type __r = 1566083941 * _Tp(__first[__kmodn] + 36257a984708SDavid Chisnall __first[__kpmodn] + 36267a984708SDavid Chisnall __first[(__k - 1) % __n]); 36277a984708SDavid Chisnall __first[__kpmodn] ^= __r; 36287a984708SDavid Chisnall __r -= __kmodn; 36297a984708SDavid Chisnall __first[(__k + __q) % __n] ^= __r; 36307a984708SDavid Chisnall __first[__kmodn] = __r; 36317a984708SDavid Chisnall } 36327a984708SDavid Chisnall } 36337a984708SDavid Chisnall} 36347a984708SDavid Chisnall 36357a984708SDavid Chisnall// generate_canonical 36367a984708SDavid Chisnall 36377a984708SDavid Chisnalltemplate<class _RealType, size_t __bits, class _URNG> 36387a984708SDavid Chisnall_RealType 36397a984708SDavid Chisnallgenerate_canonical(_URNG& __g) 36407a984708SDavid Chisnall{ 36417a984708SDavid Chisnall const size_t _Dt = numeric_limits<_RealType>::digits; 36427a984708SDavid Chisnall const size_t __b = _Dt < __bits ? _Dt : __bits; 3643540d2a8bSDimitry Andric#ifdef _LIBCPP_CXX03_LANG 36447a984708SDavid Chisnall const size_t __logR = __log2<uint64_t, _URNG::_Max - _URNG::_Min + uint64_t(1)>::value; 3645b03f91a8SDavid Chisnall#else 3646b03f91a8SDavid Chisnall const size_t __logR = __log2<uint64_t, _URNG::max() - _URNG::min() + uint64_t(1)>::value; 3647b03f91a8SDavid Chisnall#endif 36487a984708SDavid Chisnall const size_t __k = __b / __logR + (__b % __logR != 0) + (__b == 0); 3649b03f91a8SDavid Chisnall const _RealType _Rp = _URNG::max() - _URNG::min() + _RealType(1); 365094e3ee44SDavid Chisnall _RealType __base = _Rp; 3651b03f91a8SDavid Chisnall _RealType _Sp = __g() - _URNG::min(); 365294e3ee44SDavid Chisnall for (size_t __i = 1; __i < __k; ++__i, __base *= _Rp) 3653b03f91a8SDavid Chisnall _Sp += (__g() - _URNG::min()) * __base; 365494e3ee44SDavid Chisnall return _Sp / __base; 36557a984708SDavid Chisnall} 36567a984708SDavid Chisnall 36577a984708SDavid Chisnall// uniform_int_distribution 36587a984708SDavid Chisnall 36597a984708SDavid Chisnall// in <algorithm> 36607a984708SDavid Chisnall 36617a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _IT> 36627a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 36637a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 36647a984708SDavid Chisnall const uniform_int_distribution<_IT>& __x) 36657a984708SDavid Chisnall{ 36661e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__os); 36677a984708SDavid Chisnall __os.flags(ios_base::dec | ios_base::left); 36687a984708SDavid Chisnall _CharT __sp = __os.widen(' '); 36697a984708SDavid Chisnall __os.fill(__sp); 36707a984708SDavid Chisnall return __os << __x.a() << __sp << __x.b(); 36717a984708SDavid Chisnall} 36727a984708SDavid Chisnall 36737a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _IT> 36747a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 36757a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 36767a984708SDavid Chisnall uniform_int_distribution<_IT>& __x) 36777a984708SDavid Chisnall{ 36787a984708SDavid Chisnall typedef uniform_int_distribution<_IT> _Eng; 36797a984708SDavid Chisnall typedef typename _Eng::result_type result_type; 36807a984708SDavid Chisnall typedef typename _Eng::param_type param_type; 36811e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__is); 36827a984708SDavid Chisnall __is.flags(ios_base::dec | ios_base::skipws); 36837a984708SDavid Chisnall result_type __a; 36847a984708SDavid Chisnall result_type __b; 36857a984708SDavid Chisnall __is >> __a >> __b; 36867a984708SDavid Chisnall if (!__is.fail()) 36877a984708SDavid Chisnall __x.param(param_type(__a, __b)); 36887a984708SDavid Chisnall return __is; 36897a984708SDavid Chisnall} 36907a984708SDavid Chisnall 36917a984708SDavid Chisnall// uniform_real_distribution 36927a984708SDavid Chisnall 36937a984708SDavid Chisnalltemplate<class _RealType = double> 3694aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS uniform_real_distribution 36957a984708SDavid Chisnall{ 36967a984708SDavid Chisnallpublic: 36977a984708SDavid Chisnall // types 36987a984708SDavid Chisnall typedef _RealType result_type; 36997a984708SDavid Chisnall 3700aed8d94eSDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 37017a984708SDavid Chisnall { 37027a984708SDavid Chisnall result_type __a_; 37037a984708SDavid Chisnall result_type __b_; 37047a984708SDavid Chisnall public: 37057a984708SDavid Chisnall typedef uniform_real_distribution distribution_type; 37067a984708SDavid Chisnall 37077a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 37087a984708SDavid Chisnall explicit param_type(result_type __a = 0, 37097a984708SDavid Chisnall result_type __b = 1) 37107a984708SDavid Chisnall : __a_(__a), __b_(__b) {} 37117a984708SDavid Chisnall 37127a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 37137a984708SDavid Chisnall result_type a() const {return __a_;} 37147a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 37157a984708SDavid Chisnall result_type b() const {return __b_;} 37167a984708SDavid Chisnall 37177a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 37187a984708SDavid Chisnall bool operator==(const param_type& __x, const param_type& __y) 37197a984708SDavid Chisnall {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} 37207a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 37217a984708SDavid Chisnall bool operator!=(const param_type& __x, const param_type& __y) 37227a984708SDavid Chisnall {return !(__x == __y);} 37237a984708SDavid Chisnall }; 37247a984708SDavid Chisnall 37257a984708SDavid Chisnallprivate: 37267a984708SDavid Chisnall param_type __p_; 37277a984708SDavid Chisnall 37287a984708SDavid Chisnallpublic: 37297a984708SDavid Chisnall // constructors and reset functions 37307a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 37317a984708SDavid Chisnall explicit uniform_real_distribution(result_type __a = 0, result_type __b = 1) 37327a984708SDavid Chisnall : __p_(param_type(__a, __b)) {} 37337a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 37347a984708SDavid Chisnall explicit uniform_real_distribution(const param_type& __p) : __p_(__p) {} 37357a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 37367a984708SDavid Chisnall void reset() {} 37377a984708SDavid Chisnall 37387a984708SDavid Chisnall // generating functions 37397a984708SDavid Chisnall template<class _URNG> 37407a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 37417a984708SDavid Chisnall result_type operator()(_URNG& __g) 37427a984708SDavid Chisnall {return (*this)(__g, __p_);} 37439729cf09SDimitry Andric template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p); 37447a984708SDavid Chisnall 37457a984708SDavid Chisnall // property functions 37467a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 37477a984708SDavid Chisnall result_type a() const {return __p_.a();} 37487a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 37497a984708SDavid Chisnall result_type b() const {return __p_.b();} 37507a984708SDavid Chisnall 37517a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 37527a984708SDavid Chisnall param_type param() const {return __p_;} 37537a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 37547a984708SDavid Chisnall void param(const param_type& __p) {__p_ = __p;} 37557a984708SDavid Chisnall 37567a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 37577a984708SDavid Chisnall result_type min() const {return a();} 37587a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 37597a984708SDavid Chisnall result_type max() const {return b();} 37607a984708SDavid Chisnall 37617a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 37627a984708SDavid Chisnall bool operator==(const uniform_real_distribution& __x, 37637a984708SDavid Chisnall const uniform_real_distribution& __y) 37647a984708SDavid Chisnall {return __x.__p_ == __y.__p_;} 37657a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 37667a984708SDavid Chisnall bool operator!=(const uniform_real_distribution& __x, 37677a984708SDavid Chisnall const uniform_real_distribution& __y) 37687a984708SDavid Chisnall {return !(__x == __y);} 37697a984708SDavid Chisnall}; 37707a984708SDavid Chisnall 37717a984708SDavid Chisnalltemplate<class _RealType> 37727a984708SDavid Chisnalltemplate<class _URNG> 37739729cf09SDimitry Andricinline 37747a984708SDavid Chisnalltypename uniform_real_distribution<_RealType>::result_type 37757a984708SDavid Chisnalluniform_real_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 37767a984708SDavid Chisnall{ 37777a984708SDavid Chisnall return (__p.b() - __p.a()) 37787a984708SDavid Chisnall * _VSTD::generate_canonical<_RealType, numeric_limits<_RealType>::digits>(__g) 37797a984708SDavid Chisnall + __p.a(); 37807a984708SDavid Chisnall} 37817a984708SDavid Chisnall 37827a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _RT> 37837a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 37847a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 37857a984708SDavid Chisnall const uniform_real_distribution<_RT>& __x) 37867a984708SDavid Chisnall{ 37871e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__os); 37887a984708SDavid Chisnall __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 37897a984708SDavid Chisnall ios_base::scientific); 37907a984708SDavid Chisnall _CharT __sp = __os.widen(' '); 37917a984708SDavid Chisnall __os.fill(__sp); 37927a984708SDavid Chisnall return __os << __x.a() << __sp << __x.b(); 37937a984708SDavid Chisnall} 37947a984708SDavid Chisnall 37957a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _RT> 37967a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 37977a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 37987a984708SDavid Chisnall uniform_real_distribution<_RT>& __x) 37997a984708SDavid Chisnall{ 38007a984708SDavid Chisnall typedef uniform_real_distribution<_RT> _Eng; 38017a984708SDavid Chisnall typedef typename _Eng::result_type result_type; 38027a984708SDavid Chisnall typedef typename _Eng::param_type param_type; 38031e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__is); 38047a984708SDavid Chisnall __is.flags(ios_base::dec | ios_base::skipws); 38057a984708SDavid Chisnall result_type __a; 38067a984708SDavid Chisnall result_type __b; 38077a984708SDavid Chisnall __is >> __a >> __b; 38087a984708SDavid Chisnall if (!__is.fail()) 38097a984708SDavid Chisnall __x.param(param_type(__a, __b)); 38107a984708SDavid Chisnall return __is; 38117a984708SDavid Chisnall} 38127a984708SDavid Chisnall 38137a984708SDavid Chisnall// bernoulli_distribution 38147a984708SDavid Chisnall 3815aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS bernoulli_distribution 38167a984708SDavid Chisnall{ 38177a984708SDavid Chisnallpublic: 38187a984708SDavid Chisnall // types 38197a984708SDavid Chisnall typedef bool result_type; 38207a984708SDavid Chisnall 3821aed8d94eSDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 38227a984708SDavid Chisnall { 38237a984708SDavid Chisnall double __p_; 38247a984708SDavid Chisnall public: 38257a984708SDavid Chisnall typedef bernoulli_distribution distribution_type; 38267a984708SDavid Chisnall 38277a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 38287a984708SDavid Chisnall explicit param_type(double __p = 0.5) : __p_(__p) {} 38297a984708SDavid Chisnall 38307a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 38317a984708SDavid Chisnall double p() const {return __p_;} 38327a984708SDavid Chisnall 38337a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 38347a984708SDavid Chisnall bool operator==(const param_type& __x, const param_type& __y) 38357a984708SDavid Chisnall {return __x.__p_ == __y.__p_;} 38367a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 38377a984708SDavid Chisnall bool operator!=(const param_type& __x, const param_type& __y) 38387a984708SDavid Chisnall {return !(__x == __y);} 38397a984708SDavid Chisnall }; 38407a984708SDavid Chisnall 38417a984708SDavid Chisnallprivate: 38427a984708SDavid Chisnall param_type __p_; 38437a984708SDavid Chisnall 38447a984708SDavid Chisnallpublic: 38457a984708SDavid Chisnall // constructors and reset functions 38467a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 38477a984708SDavid Chisnall explicit bernoulli_distribution(double __p = 0.5) 38487a984708SDavid Chisnall : __p_(param_type(__p)) {} 38497a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 38507a984708SDavid Chisnall explicit bernoulli_distribution(const param_type& __p) : __p_(__p) {} 38517a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 38527a984708SDavid Chisnall void reset() {} 38537a984708SDavid Chisnall 38547a984708SDavid Chisnall // generating functions 38557a984708SDavid Chisnall template<class _URNG> 38567a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 38577a984708SDavid Chisnall result_type operator()(_URNG& __g) 38587a984708SDavid Chisnall {return (*this)(__g, __p_);} 38599729cf09SDimitry Andric template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p); 38607a984708SDavid Chisnall 38617a984708SDavid Chisnall // property functions 38627a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 38637a984708SDavid Chisnall double p() const {return __p_.p();} 38647a984708SDavid Chisnall 38657a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 38667a984708SDavid Chisnall param_type param() const {return __p_;} 38677a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 38687a984708SDavid Chisnall void param(const param_type& __p) {__p_ = __p;} 38697a984708SDavid Chisnall 38707a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 38717a984708SDavid Chisnall result_type min() const {return false;} 38727a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 38737a984708SDavid Chisnall result_type max() const {return true;} 38747a984708SDavid Chisnall 38757a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 38767a984708SDavid Chisnall bool operator==(const bernoulli_distribution& __x, 38777a984708SDavid Chisnall const bernoulli_distribution& __y) 38787a984708SDavid Chisnall {return __x.__p_ == __y.__p_;} 38797a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 38807a984708SDavid Chisnall bool operator!=(const bernoulli_distribution& __x, 38817a984708SDavid Chisnall const bernoulli_distribution& __y) 38827a984708SDavid Chisnall {return !(__x == __y);} 38837a984708SDavid Chisnall}; 38847a984708SDavid Chisnall 38857a984708SDavid Chisnalltemplate<class _URNG> 38869729cf09SDimitry Andricinline 38877a984708SDavid Chisnallbernoulli_distribution::result_type 38887a984708SDavid Chisnallbernoulli_distribution::operator()(_URNG& __g, const param_type& __p) 38897a984708SDavid Chisnall{ 38907a984708SDavid Chisnall uniform_real_distribution<double> __gen; 38917a984708SDavid Chisnall return __gen(__g) < __p.p(); 38927a984708SDavid Chisnall} 38937a984708SDavid Chisnall 38947a984708SDavid Chisnalltemplate <class _CharT, class _Traits> 38957a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 38967a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, const bernoulli_distribution& __x) 38977a984708SDavid Chisnall{ 38981e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__os); 38997a984708SDavid Chisnall __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 39007a984708SDavid Chisnall ios_base::scientific); 39017a984708SDavid Chisnall _CharT __sp = __os.widen(' '); 39027a984708SDavid Chisnall __os.fill(__sp); 39037a984708SDavid Chisnall return __os << __x.p(); 39047a984708SDavid Chisnall} 39057a984708SDavid Chisnall 39067a984708SDavid Chisnalltemplate <class _CharT, class _Traits> 39077a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 39087a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, bernoulli_distribution& __x) 39097a984708SDavid Chisnall{ 39107a984708SDavid Chisnall typedef bernoulli_distribution _Eng; 39117a984708SDavid Chisnall typedef typename _Eng::param_type param_type; 39121e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__is); 39137a984708SDavid Chisnall __is.flags(ios_base::dec | ios_base::skipws); 39147a984708SDavid Chisnall double __p; 39157a984708SDavid Chisnall __is >> __p; 39167a984708SDavid Chisnall if (!__is.fail()) 39177a984708SDavid Chisnall __x.param(param_type(__p)); 39187a984708SDavid Chisnall return __is; 39197a984708SDavid Chisnall} 39207a984708SDavid Chisnall 39217a984708SDavid Chisnall// binomial_distribution 39227a984708SDavid Chisnall 39237a984708SDavid Chisnalltemplate<class _IntType = int> 3924aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS binomial_distribution 39257a984708SDavid Chisnall{ 39267a984708SDavid Chisnallpublic: 39277a984708SDavid Chisnall // types 39287a984708SDavid Chisnall typedef _IntType result_type; 39297a984708SDavid Chisnall 3930aed8d94eSDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 39317a984708SDavid Chisnall { 39327a984708SDavid Chisnall result_type __t_; 39337a984708SDavid Chisnall double __p_; 39347a984708SDavid Chisnall double __pr_; 39357a984708SDavid Chisnall double __odds_ratio_; 39367a984708SDavid Chisnall result_type __r0_; 39377a984708SDavid Chisnall public: 39387a984708SDavid Chisnall typedef binomial_distribution distribution_type; 39397a984708SDavid Chisnall 39407a984708SDavid Chisnall explicit param_type(result_type __t = 1, double __p = 0.5); 39417a984708SDavid Chisnall 39427a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 39437a984708SDavid Chisnall result_type t() const {return __t_;} 39447a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 39457a984708SDavid Chisnall double p() const {return __p_;} 39467a984708SDavid Chisnall 39477a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 39487a984708SDavid Chisnall bool operator==(const param_type& __x, const param_type& __y) 39497a984708SDavid Chisnall {return __x.__t_ == __y.__t_ && __x.__p_ == __y.__p_;} 39507a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 39517a984708SDavid Chisnall bool operator!=(const param_type& __x, const param_type& __y) 39527a984708SDavid Chisnall {return !(__x == __y);} 39537a984708SDavid Chisnall 39547a984708SDavid Chisnall friend class binomial_distribution; 39557a984708SDavid Chisnall }; 39567a984708SDavid Chisnall 39577a984708SDavid Chisnallprivate: 39587a984708SDavid Chisnall param_type __p_; 39597a984708SDavid Chisnall 39607a984708SDavid Chisnallpublic: 39617a984708SDavid Chisnall // constructors and reset functions 39627a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 39637a984708SDavid Chisnall explicit binomial_distribution(result_type __t = 1, double __p = 0.5) 39647a984708SDavid Chisnall : __p_(param_type(__t, __p)) {} 39657a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 39667a984708SDavid Chisnall explicit binomial_distribution(const param_type& __p) : __p_(__p) {} 39677a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 39687a984708SDavid Chisnall void reset() {} 39697a984708SDavid Chisnall 39707a984708SDavid Chisnall // generating functions 39717a984708SDavid Chisnall template<class _URNG> 39727a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 39737a984708SDavid Chisnall result_type operator()(_URNG& __g) 39747a984708SDavid Chisnall {return (*this)(__g, __p_);} 39757a984708SDavid Chisnall template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 39767a984708SDavid Chisnall 39777a984708SDavid Chisnall // property functions 39787a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 39797a984708SDavid Chisnall result_type t() const {return __p_.t();} 39807a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 39817a984708SDavid Chisnall double p() const {return __p_.p();} 39827a984708SDavid Chisnall 39837a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 39847a984708SDavid Chisnall param_type param() const {return __p_;} 39857a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 39867a984708SDavid Chisnall void param(const param_type& __p) {__p_ = __p;} 39877a984708SDavid Chisnall 39887a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 39897a984708SDavid Chisnall result_type min() const {return 0;} 39907a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 39917a984708SDavid Chisnall result_type max() const {return t();} 39927a984708SDavid Chisnall 39937a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 39947a984708SDavid Chisnall bool operator==(const binomial_distribution& __x, 39957a984708SDavid Chisnall const binomial_distribution& __y) 39967a984708SDavid Chisnall {return __x.__p_ == __y.__p_;} 39977a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 39987a984708SDavid Chisnall bool operator!=(const binomial_distribution& __x, 39997a984708SDavid Chisnall const binomial_distribution& __y) 40007a984708SDavid Chisnall {return !(__x == __y);} 40017a984708SDavid Chisnall}; 40027a984708SDavid Chisnall 40030f5676f4SDimitry Andric#ifndef _LIBCPP_MSVCRT 40040f5676f4SDimitry Andricextern "C" double lgamma_r(double, int *); 40050f5676f4SDimitry Andric#endif 40060f5676f4SDimitry Andric 40070f5676f4SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY double __libcpp_lgamma(double __d) { 40080f5676f4SDimitry Andric#if defined(_LIBCPP_MSVCRT) 40090f5676f4SDimitry Andric return lgamma(__d); 40100f5676f4SDimitry Andric#else 40110f5676f4SDimitry Andric int __sign; 40120f5676f4SDimitry Andric return lgamma_r(__d, &__sign); 40130f5676f4SDimitry Andric#endif 40140f5676f4SDimitry Andric} 40150f5676f4SDimitry Andric 40167a984708SDavid Chisnalltemplate<class _IntType> 40170f5676f4SDimitry Andricbinomial_distribution<_IntType>::param_type::param_type(const result_type __t, const double __p) 40187a984708SDavid Chisnall : __t_(__t), __p_(__p) 40197a984708SDavid Chisnall{ 40207a984708SDavid Chisnall if (0 < __p_ && __p_ < 1) 40217a984708SDavid Chisnall { 40227a984708SDavid Chisnall __r0_ = static_cast<result_type>((__t_ + 1) * __p_); 40230f5676f4SDimitry Andric __pr_ = _VSTD::exp(__libcpp_lgamma(__t_ + 1.) - 40240f5676f4SDimitry Andric __libcpp_lgamma(__r0_ + 1.) - 40250f5676f4SDimitry Andric __libcpp_lgamma(__t_ - __r0_ + 1.) + __r0_ * _VSTD::log(__p_) + 40267a984708SDavid Chisnall (__t_ - __r0_) * _VSTD::log(1 - __p_)); 40277a984708SDavid Chisnall __odds_ratio_ = __p_ / (1 - __p_); 40287a984708SDavid Chisnall } 40297a984708SDavid Chisnall} 40307a984708SDavid Chisnall 4031d72607e9SDimitry Andric// Reference: Kemp, C.D. (1986). `A modal method for generating binomial 4032d72607e9SDimitry Andric// variables', Commun. Statist. - Theor. Meth. 15(3), 805-813. 40337a984708SDavid Chisnalltemplate<class _IntType> 40347a984708SDavid Chisnalltemplate<class _URNG> 40357a984708SDavid Chisnall_IntType 40367a984708SDavid Chisnallbinomial_distribution<_IntType>::operator()(_URNG& __g, const param_type& __pr) 40377a984708SDavid Chisnall{ 40387a984708SDavid Chisnall if (__pr.__t_ == 0 || __pr.__p_ == 0) 40397a984708SDavid Chisnall return 0; 40407a984708SDavid Chisnall if (__pr.__p_ == 1) 40417a984708SDavid Chisnall return __pr.__t_; 40427a984708SDavid Chisnall uniform_real_distribution<double> __gen; 40437a984708SDavid Chisnall double __u = __gen(__g) - __pr.__pr_; 40447a984708SDavid Chisnall if (__u < 0) 40457a984708SDavid Chisnall return __pr.__r0_; 40467a984708SDavid Chisnall double __pu = __pr.__pr_; 40477a984708SDavid Chisnall double __pd = __pu; 40487a984708SDavid Chisnall result_type __ru = __pr.__r0_; 40497a984708SDavid Chisnall result_type __rd = __ru; 40507a984708SDavid Chisnall while (true) 40517a984708SDavid Chisnall { 40527a984708SDavid Chisnall if (__rd >= 1) 40537a984708SDavid Chisnall { 40547a984708SDavid Chisnall __pd *= __rd / (__pr.__odds_ratio_ * (__pr.__t_ - __rd + 1)); 40557a984708SDavid Chisnall __u -= __pd; 40567a984708SDavid Chisnall if (__u < 0) 40577a984708SDavid Chisnall return __rd - 1; 40587a984708SDavid Chisnall } 4059d72607e9SDimitry Andric if ( __rd != 0 ) 40607a984708SDavid Chisnall --__rd; 40617a984708SDavid Chisnall ++__ru; 40627a984708SDavid Chisnall if (__ru <= __pr.__t_) 40637a984708SDavid Chisnall { 40647a984708SDavid Chisnall __pu *= (__pr.__t_ - __ru + 1) * __pr.__odds_ratio_ / __ru; 40657a984708SDavid Chisnall __u -= __pu; 40667a984708SDavid Chisnall if (__u < 0) 40677a984708SDavid Chisnall return __ru; 40687a984708SDavid Chisnall } 40697a984708SDavid Chisnall } 40707a984708SDavid Chisnall} 40717a984708SDavid Chisnall 40727a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _IntType> 40737a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 40747a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 40757a984708SDavid Chisnall const binomial_distribution<_IntType>& __x) 40767a984708SDavid Chisnall{ 40771e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__os); 40787a984708SDavid Chisnall __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 40797a984708SDavid Chisnall ios_base::scientific); 40807a984708SDavid Chisnall _CharT __sp = __os.widen(' '); 40817a984708SDavid Chisnall __os.fill(__sp); 40827a984708SDavid Chisnall return __os << __x.t() << __sp << __x.p(); 40837a984708SDavid Chisnall} 40847a984708SDavid Chisnall 40857a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _IntType> 40867a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 40877a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 40887a984708SDavid Chisnall binomial_distribution<_IntType>& __x) 40897a984708SDavid Chisnall{ 40907a984708SDavid Chisnall typedef binomial_distribution<_IntType> _Eng; 40917a984708SDavid Chisnall typedef typename _Eng::result_type result_type; 40927a984708SDavid Chisnall typedef typename _Eng::param_type param_type; 40931e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__is); 40947a984708SDavid Chisnall __is.flags(ios_base::dec | ios_base::skipws); 40957a984708SDavid Chisnall result_type __t; 40967a984708SDavid Chisnall double __p; 40977a984708SDavid Chisnall __is >> __t >> __p; 40987a984708SDavid Chisnall if (!__is.fail()) 40997a984708SDavid Chisnall __x.param(param_type(__t, __p)); 41007a984708SDavid Chisnall return __is; 41017a984708SDavid Chisnall} 41027a984708SDavid Chisnall 41037a984708SDavid Chisnall// exponential_distribution 41047a984708SDavid Chisnall 41057a984708SDavid Chisnalltemplate<class _RealType = double> 4106aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS exponential_distribution 41077a984708SDavid Chisnall{ 41087a984708SDavid Chisnallpublic: 41097a984708SDavid Chisnall // types 41107a984708SDavid Chisnall typedef _RealType result_type; 41117a984708SDavid Chisnall 4112aed8d94eSDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 41137a984708SDavid Chisnall { 41147a984708SDavid Chisnall result_type __lambda_; 41157a984708SDavid Chisnall public: 41167a984708SDavid Chisnall typedef exponential_distribution distribution_type; 41177a984708SDavid Chisnall 41187a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 41197a984708SDavid Chisnall explicit param_type(result_type __lambda = 1) : __lambda_(__lambda) {} 41207a984708SDavid Chisnall 41217a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 41227a984708SDavid Chisnall result_type lambda() const {return __lambda_;} 41237a984708SDavid Chisnall 41247a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 41257a984708SDavid Chisnall bool operator==(const param_type& __x, const param_type& __y) 41267a984708SDavid Chisnall {return __x.__lambda_ == __y.__lambda_;} 41277a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 41287a984708SDavid Chisnall bool operator!=(const param_type& __x, const param_type& __y) 41297a984708SDavid Chisnall {return !(__x == __y);} 41307a984708SDavid Chisnall }; 41317a984708SDavid Chisnall 41327a984708SDavid Chisnallprivate: 41337a984708SDavid Chisnall param_type __p_; 41347a984708SDavid Chisnall 41357a984708SDavid Chisnallpublic: 41367a984708SDavid Chisnall // constructors and reset functions 41377a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 41387a984708SDavid Chisnall explicit exponential_distribution(result_type __lambda = 1) 41397a984708SDavid Chisnall : __p_(param_type(__lambda)) {} 41407a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 41417a984708SDavid Chisnall explicit exponential_distribution(const param_type& __p) : __p_(__p) {} 41427a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 41437a984708SDavid Chisnall void reset() {} 41447a984708SDavid Chisnall 41457a984708SDavid Chisnall // generating functions 41467a984708SDavid Chisnall template<class _URNG> 41477a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 41487a984708SDavid Chisnall result_type operator()(_URNG& __g) 41497a984708SDavid Chisnall {return (*this)(__g, __p_);} 41507a984708SDavid Chisnall template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 41517a984708SDavid Chisnall 41527a984708SDavid Chisnall // property functions 41537a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 41547a984708SDavid Chisnall result_type lambda() const {return __p_.lambda();} 41557a984708SDavid Chisnall 41567a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 41577a984708SDavid Chisnall param_type param() const {return __p_;} 41587a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 41597a984708SDavid Chisnall void param(const param_type& __p) {__p_ = __p;} 41607a984708SDavid Chisnall 41617a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 41627a984708SDavid Chisnall result_type min() const {return 0;} 41637a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 41647a984708SDavid Chisnall result_type max() const {return numeric_limits<result_type>::infinity();} 41657a984708SDavid Chisnall 41667a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 41677a984708SDavid Chisnall bool operator==(const exponential_distribution& __x, 41687a984708SDavid Chisnall const exponential_distribution& __y) 41697a984708SDavid Chisnall {return __x.__p_ == __y.__p_;} 41707a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 41717a984708SDavid Chisnall bool operator!=(const exponential_distribution& __x, 41727a984708SDavid Chisnall const exponential_distribution& __y) 41737a984708SDavid Chisnall {return !(__x == __y);} 41747a984708SDavid Chisnall}; 41757a984708SDavid Chisnall 41767a984708SDavid Chisnalltemplate <class _RealType> 41777a984708SDavid Chisnalltemplate<class _URNG> 41787a984708SDavid Chisnall_RealType 41797a984708SDavid Chisnallexponential_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 41807a984708SDavid Chisnall{ 41817a984708SDavid Chisnall return -_VSTD::log 41827a984708SDavid Chisnall ( 41837a984708SDavid Chisnall result_type(1) - 41847a984708SDavid Chisnall _VSTD::generate_canonical<result_type, 41857a984708SDavid Chisnall numeric_limits<result_type>::digits>(__g) 41867a984708SDavid Chisnall ) 41877a984708SDavid Chisnall / __p.lambda(); 41887a984708SDavid Chisnall} 41897a984708SDavid Chisnall 41907a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _RealType> 41917a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 41927a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 41937a984708SDavid Chisnall const exponential_distribution<_RealType>& __x) 41947a984708SDavid Chisnall{ 41951e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__os); 41967a984708SDavid Chisnall __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 41977a984708SDavid Chisnall ios_base::scientific); 41987a984708SDavid Chisnall return __os << __x.lambda(); 41997a984708SDavid Chisnall} 42007a984708SDavid Chisnall 42017a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _RealType> 42027a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 42037a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 42047a984708SDavid Chisnall exponential_distribution<_RealType>& __x) 42057a984708SDavid Chisnall{ 42067a984708SDavid Chisnall typedef exponential_distribution<_RealType> _Eng; 42077a984708SDavid Chisnall typedef typename _Eng::result_type result_type; 42087a984708SDavid Chisnall typedef typename _Eng::param_type param_type; 42091e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__is); 42107a984708SDavid Chisnall __is.flags(ios_base::dec | ios_base::skipws); 42117a984708SDavid Chisnall result_type __lambda; 42127a984708SDavid Chisnall __is >> __lambda; 42137a984708SDavid Chisnall if (!__is.fail()) 42147a984708SDavid Chisnall __x.param(param_type(__lambda)); 42157a984708SDavid Chisnall return __is; 42167a984708SDavid Chisnall} 42177a984708SDavid Chisnall 42187a984708SDavid Chisnall// normal_distribution 42197a984708SDavid Chisnall 42207a984708SDavid Chisnalltemplate<class _RealType = double> 4221aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS normal_distribution 42227a984708SDavid Chisnall{ 42237a984708SDavid Chisnallpublic: 42247a984708SDavid Chisnall // types 42257a984708SDavid Chisnall typedef _RealType result_type; 42267a984708SDavid Chisnall 4227aed8d94eSDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 42287a984708SDavid Chisnall { 42297a984708SDavid Chisnall result_type __mean_; 42307a984708SDavid Chisnall result_type __stddev_; 42317a984708SDavid Chisnall public: 42327a984708SDavid Chisnall typedef normal_distribution distribution_type; 42337a984708SDavid Chisnall 42347a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 42357a984708SDavid Chisnall explicit param_type(result_type __mean = 0, result_type __stddev = 1) 42367a984708SDavid Chisnall : __mean_(__mean), __stddev_(__stddev) {} 42377a984708SDavid Chisnall 42387a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 42397a984708SDavid Chisnall result_type mean() const {return __mean_;} 42407a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 42417a984708SDavid Chisnall result_type stddev() const {return __stddev_;} 42427a984708SDavid Chisnall 42437a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 42447a984708SDavid Chisnall bool operator==(const param_type& __x, const param_type& __y) 42457a984708SDavid Chisnall {return __x.__mean_ == __y.__mean_ && __x.__stddev_ == __y.__stddev_;} 42467a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 42477a984708SDavid Chisnall bool operator!=(const param_type& __x, const param_type& __y) 42487a984708SDavid Chisnall {return !(__x == __y);} 42497a984708SDavid Chisnall }; 42507a984708SDavid Chisnall 42517a984708SDavid Chisnallprivate: 42527a984708SDavid Chisnall param_type __p_; 42537a984708SDavid Chisnall result_type _V_; 42547a984708SDavid Chisnall bool _V_hot_; 42557a984708SDavid Chisnall 42567a984708SDavid Chisnallpublic: 42577a984708SDavid Chisnall // constructors and reset functions 42587a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 42597a984708SDavid Chisnall explicit normal_distribution(result_type __mean = 0, result_type __stddev = 1) 42607a984708SDavid Chisnall : __p_(param_type(__mean, __stddev)), _V_hot_(false) {} 42617a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 42627a984708SDavid Chisnall explicit normal_distribution(const param_type& __p) 42637a984708SDavid Chisnall : __p_(__p), _V_hot_(false) {} 42647a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 42657a984708SDavid Chisnall void reset() {_V_hot_ = false;} 42667a984708SDavid Chisnall 42677a984708SDavid Chisnall // generating functions 42687a984708SDavid Chisnall template<class _URNG> 42697a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 42707a984708SDavid Chisnall result_type operator()(_URNG& __g) 42717a984708SDavid Chisnall {return (*this)(__g, __p_);} 42727a984708SDavid Chisnall template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 42737a984708SDavid Chisnall 42747a984708SDavid Chisnall // property functions 42757a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 42767a984708SDavid Chisnall result_type mean() const {return __p_.mean();} 42777a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 42787a984708SDavid Chisnall result_type stddev() const {return __p_.stddev();} 42797a984708SDavid Chisnall 42807a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 42817a984708SDavid Chisnall param_type param() const {return __p_;} 42827a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 42837a984708SDavid Chisnall void param(const param_type& __p) {__p_ = __p;} 42847a984708SDavid Chisnall 42857a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 42867a984708SDavid Chisnall result_type min() const {return -numeric_limits<result_type>::infinity();} 42877a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 42887a984708SDavid Chisnall result_type max() const {return numeric_limits<result_type>::infinity();} 42897a984708SDavid Chisnall 42907a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 42917a984708SDavid Chisnall bool operator==(const normal_distribution& __x, 42927a984708SDavid Chisnall const normal_distribution& __y) 42937a984708SDavid Chisnall {return __x.__p_ == __y.__p_ && __x._V_hot_ == __y._V_hot_ && 42947a984708SDavid Chisnall (!__x._V_hot_ || __x._V_ == __y._V_);} 42957a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 42967a984708SDavid Chisnall bool operator!=(const normal_distribution& __x, 42977a984708SDavid Chisnall const normal_distribution& __y) 42987a984708SDavid Chisnall {return !(__x == __y);} 42997a984708SDavid Chisnall 43007a984708SDavid Chisnall template <class _CharT, class _Traits, class _RT> 43017a984708SDavid Chisnall friend 43027a984708SDavid Chisnall basic_ostream<_CharT, _Traits>& 43037a984708SDavid Chisnall operator<<(basic_ostream<_CharT, _Traits>& __os, 43047a984708SDavid Chisnall const normal_distribution<_RT>& __x); 43057a984708SDavid Chisnall 43067a984708SDavid Chisnall template <class _CharT, class _Traits, class _RT> 43077a984708SDavid Chisnall friend 43087a984708SDavid Chisnall basic_istream<_CharT, _Traits>& 43097a984708SDavid Chisnall operator>>(basic_istream<_CharT, _Traits>& __is, 43107a984708SDavid Chisnall normal_distribution<_RT>& __x); 43117a984708SDavid Chisnall}; 43127a984708SDavid Chisnall 43137a984708SDavid Chisnalltemplate <class _RealType> 43147a984708SDavid Chisnalltemplate<class _URNG> 43157a984708SDavid Chisnall_RealType 43167a984708SDavid Chisnallnormal_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 43177a984708SDavid Chisnall{ 431894e3ee44SDavid Chisnall result_type _Up; 43197a984708SDavid Chisnall if (_V_hot_) 43207a984708SDavid Chisnall { 43217a984708SDavid Chisnall _V_hot_ = false; 432294e3ee44SDavid Chisnall _Up = _V_; 43237a984708SDavid Chisnall } 43247a984708SDavid Chisnall else 43257a984708SDavid Chisnall { 43267a984708SDavid Chisnall uniform_real_distribution<result_type> _Uni(-1, 1); 43277a984708SDavid Chisnall result_type __u; 43287a984708SDavid Chisnall result_type __v; 43297a984708SDavid Chisnall result_type __s; 43307a984708SDavid Chisnall do 43317a984708SDavid Chisnall { 43327a984708SDavid Chisnall __u = _Uni(__g); 43337a984708SDavid Chisnall __v = _Uni(__g); 43347a984708SDavid Chisnall __s = __u * __u + __v * __v; 43357a984708SDavid Chisnall } while (__s > 1 || __s == 0); 433694e3ee44SDavid Chisnall result_type _Fp = _VSTD::sqrt(-2 * _VSTD::log(__s) / __s); 433794e3ee44SDavid Chisnall _V_ = __v * _Fp; 43387a984708SDavid Chisnall _V_hot_ = true; 433994e3ee44SDavid Chisnall _Up = __u * _Fp; 43407a984708SDavid Chisnall } 434194e3ee44SDavid Chisnall return _Up * __p.stddev() + __p.mean(); 43427a984708SDavid Chisnall} 43437a984708SDavid Chisnall 43447a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _RT> 43457a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 43467a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 43477a984708SDavid Chisnall const normal_distribution<_RT>& __x) 43487a984708SDavid Chisnall{ 43491e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__os); 43507a984708SDavid Chisnall __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 43517a984708SDavid Chisnall ios_base::scientific); 43527a984708SDavid Chisnall _CharT __sp = __os.widen(' '); 43537a984708SDavid Chisnall __os.fill(__sp); 43547a984708SDavid Chisnall __os << __x.mean() << __sp << __x.stddev() << __sp << __x._V_hot_; 43557a984708SDavid Chisnall if (__x._V_hot_) 43567a984708SDavid Chisnall __os << __sp << __x._V_; 43577a984708SDavid Chisnall return __os; 43587a984708SDavid Chisnall} 43597a984708SDavid Chisnall 43607a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _RT> 43617a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 43627a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 43637a984708SDavid Chisnall normal_distribution<_RT>& __x) 43647a984708SDavid Chisnall{ 43657a984708SDavid Chisnall typedef normal_distribution<_RT> _Eng; 43667a984708SDavid Chisnall typedef typename _Eng::result_type result_type; 43677a984708SDavid Chisnall typedef typename _Eng::param_type param_type; 43681e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__is); 43697a984708SDavid Chisnall __is.flags(ios_base::dec | ios_base::skipws); 43707a984708SDavid Chisnall result_type __mean; 43717a984708SDavid Chisnall result_type __stddev; 437294e3ee44SDavid Chisnall result_type _Vp = 0; 43737a984708SDavid Chisnall bool _V_hot = false; 43747a984708SDavid Chisnall __is >> __mean >> __stddev >> _V_hot; 43757a984708SDavid Chisnall if (_V_hot) 437694e3ee44SDavid Chisnall __is >> _Vp; 43777a984708SDavid Chisnall if (!__is.fail()) 43787a984708SDavid Chisnall { 43797a984708SDavid Chisnall __x.param(param_type(__mean, __stddev)); 43807a984708SDavid Chisnall __x._V_hot_ = _V_hot; 438194e3ee44SDavid Chisnall __x._V_ = _Vp; 43827a984708SDavid Chisnall } 43837a984708SDavid Chisnall return __is; 43847a984708SDavid Chisnall} 43857a984708SDavid Chisnall 43867a984708SDavid Chisnall// lognormal_distribution 43877a984708SDavid Chisnall 43887a984708SDavid Chisnalltemplate<class _RealType = double> 4389aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS lognormal_distribution 43907a984708SDavid Chisnall{ 43917a984708SDavid Chisnallpublic: 43927a984708SDavid Chisnall // types 43937a984708SDavid Chisnall typedef _RealType result_type; 43947a984708SDavid Chisnall 4395aed8d94eSDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 43967a984708SDavid Chisnall { 43977a984708SDavid Chisnall normal_distribution<result_type> __nd_; 43987a984708SDavid Chisnall public: 43997a984708SDavid Chisnall typedef lognormal_distribution distribution_type; 44007a984708SDavid Chisnall 44017a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 44027a984708SDavid Chisnall explicit param_type(result_type __m = 0, result_type __s = 1) 44037a984708SDavid Chisnall : __nd_(__m, __s) {} 44047a984708SDavid Chisnall 44057a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 44067a984708SDavid Chisnall result_type m() const {return __nd_.mean();} 44077a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 44087a984708SDavid Chisnall result_type s() const {return __nd_.stddev();} 44097a984708SDavid Chisnall 44107a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 44117a984708SDavid Chisnall bool operator==(const param_type& __x, const param_type& __y) 44127a984708SDavid Chisnall {return __x.__nd_ == __y.__nd_;} 44137a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 44147a984708SDavid Chisnall bool operator!=(const param_type& __x, const param_type& __y) 44157a984708SDavid Chisnall {return !(__x == __y);} 44167a984708SDavid Chisnall friend class lognormal_distribution; 44177a984708SDavid Chisnall 44187a984708SDavid Chisnall template <class _CharT, class _Traits, class _RT> 44197a984708SDavid Chisnall friend 44207a984708SDavid Chisnall basic_ostream<_CharT, _Traits>& 44217a984708SDavid Chisnall operator<<(basic_ostream<_CharT, _Traits>& __os, 44227a984708SDavid Chisnall const lognormal_distribution<_RT>& __x); 44237a984708SDavid Chisnall 44247a984708SDavid Chisnall template <class _CharT, class _Traits, class _RT> 44257a984708SDavid Chisnall friend 44267a984708SDavid Chisnall basic_istream<_CharT, _Traits>& 44277a984708SDavid Chisnall operator>>(basic_istream<_CharT, _Traits>& __is, 44287a984708SDavid Chisnall lognormal_distribution<_RT>& __x); 44297a984708SDavid Chisnall }; 44307a984708SDavid Chisnall 44317a984708SDavid Chisnallprivate: 44327a984708SDavid Chisnall param_type __p_; 44337a984708SDavid Chisnall 44347a984708SDavid Chisnallpublic: 44357a984708SDavid Chisnall // constructor and reset functions 44367a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 44377a984708SDavid Chisnall explicit lognormal_distribution(result_type __m = 0, result_type __s = 1) 44387a984708SDavid Chisnall : __p_(param_type(__m, __s)) {} 44397a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 44407a984708SDavid Chisnall explicit lognormal_distribution(const param_type& __p) 44417a984708SDavid Chisnall : __p_(__p) {} 44427a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 44437a984708SDavid Chisnall void reset() {__p_.__nd_.reset();} 44447a984708SDavid Chisnall 44457a984708SDavid Chisnall // generating functions 44467a984708SDavid Chisnall template<class _URNG> 44477a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 44487a984708SDavid Chisnall result_type operator()(_URNG& __g) 44497a984708SDavid Chisnall {return (*this)(__g, __p_);} 44507a984708SDavid Chisnall template<class _URNG> 44517a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 44527a984708SDavid Chisnall result_type operator()(_URNG& __g, const param_type& __p) 44537a984708SDavid Chisnall {return _VSTD::exp(const_cast<normal_distribution<result_type>&>(__p.__nd_)(__g));} 44547a984708SDavid Chisnall 44557a984708SDavid Chisnall // property functions 44567a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 44577a984708SDavid Chisnall result_type m() const {return __p_.m();} 44587a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 44597a984708SDavid Chisnall result_type s() const {return __p_.s();} 44607a984708SDavid Chisnall 44617a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 44627a984708SDavid Chisnall param_type param() const {return __p_;} 44637a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 44647a984708SDavid Chisnall void param(const param_type& __p) {__p_ = __p;} 44657a984708SDavid Chisnall 44667a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 44677a984708SDavid Chisnall result_type min() const {return 0;} 44687a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 44697a984708SDavid Chisnall result_type max() const {return numeric_limits<result_type>::infinity();} 44707a984708SDavid Chisnall 44717a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 44727a984708SDavid Chisnall bool operator==(const lognormal_distribution& __x, 44737a984708SDavid Chisnall const lognormal_distribution& __y) 44747a984708SDavid Chisnall {return __x.__p_ == __y.__p_;} 44757a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 44767a984708SDavid Chisnall bool operator!=(const lognormal_distribution& __x, 44777a984708SDavid Chisnall const lognormal_distribution& __y) 44787a984708SDavid Chisnall {return !(__x == __y);} 44797a984708SDavid Chisnall 44807a984708SDavid Chisnall template <class _CharT, class _Traits, class _RT> 44817a984708SDavid Chisnall friend 44827a984708SDavid Chisnall basic_ostream<_CharT, _Traits>& 44837a984708SDavid Chisnall operator<<(basic_ostream<_CharT, _Traits>& __os, 44847a984708SDavid Chisnall const lognormal_distribution<_RT>& __x); 44857a984708SDavid Chisnall 44867a984708SDavid Chisnall template <class _CharT, class _Traits, class _RT> 44877a984708SDavid Chisnall friend 44887a984708SDavid Chisnall basic_istream<_CharT, _Traits>& 44897a984708SDavid Chisnall operator>>(basic_istream<_CharT, _Traits>& __is, 44907a984708SDavid Chisnall lognormal_distribution<_RT>& __x); 44917a984708SDavid Chisnall}; 44927a984708SDavid Chisnall 44937a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _RT> 44947a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY 44957a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 44967a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 44977a984708SDavid Chisnall const lognormal_distribution<_RT>& __x) 44987a984708SDavid Chisnall{ 44997a984708SDavid Chisnall return __os << __x.__p_.__nd_; 45007a984708SDavid Chisnall} 45017a984708SDavid Chisnall 45027a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _RT> 45037a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY 45047a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 45057a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 45067a984708SDavid Chisnall lognormal_distribution<_RT>& __x) 45077a984708SDavid Chisnall{ 45087a984708SDavid Chisnall return __is >> __x.__p_.__nd_; 45097a984708SDavid Chisnall} 45107a984708SDavid Chisnall 45117a984708SDavid Chisnall// poisson_distribution 45127a984708SDavid Chisnall 45137a984708SDavid Chisnalltemplate<class _IntType = int> 4514aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS poisson_distribution 45157a984708SDavid Chisnall{ 45167a984708SDavid Chisnallpublic: 45177a984708SDavid Chisnall // types 45187a984708SDavid Chisnall typedef _IntType result_type; 45197a984708SDavid Chisnall 4520aed8d94eSDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 45217a984708SDavid Chisnall { 45227a984708SDavid Chisnall double __mean_; 45237a984708SDavid Chisnall double __s_; 45247a984708SDavid Chisnall double __d_; 45257a984708SDavid Chisnall double __l_; 45267a984708SDavid Chisnall double __omega_; 45277a984708SDavid Chisnall double __c0_; 45287a984708SDavid Chisnall double __c1_; 45297a984708SDavid Chisnall double __c2_; 45307a984708SDavid Chisnall double __c3_; 45317a984708SDavid Chisnall double __c_; 45327a984708SDavid Chisnall 45337a984708SDavid Chisnall public: 45347a984708SDavid Chisnall typedef poisson_distribution distribution_type; 45357a984708SDavid Chisnall 45367a984708SDavid Chisnall explicit param_type(double __mean = 1.0); 45377a984708SDavid Chisnall 45387a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 45397a984708SDavid Chisnall double mean() const {return __mean_;} 45407a984708SDavid Chisnall 45417a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 45427a984708SDavid Chisnall bool operator==(const param_type& __x, const param_type& __y) 45437a984708SDavid Chisnall {return __x.__mean_ == __y.__mean_;} 45447a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 45457a984708SDavid Chisnall bool operator!=(const param_type& __x, const param_type& __y) 45467a984708SDavid Chisnall {return !(__x == __y);} 45477a984708SDavid Chisnall 45487a984708SDavid Chisnall friend class poisson_distribution; 45497a984708SDavid Chisnall }; 45507a984708SDavid Chisnall 45517a984708SDavid Chisnallprivate: 45527a984708SDavid Chisnall param_type __p_; 45537a984708SDavid Chisnall 45547a984708SDavid Chisnallpublic: 45557a984708SDavid Chisnall // constructors and reset functions 45567a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 45577a984708SDavid Chisnall explicit poisson_distribution(double __mean = 1.0) : __p_(__mean) {} 45587a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 45597a984708SDavid Chisnall explicit poisson_distribution(const param_type& __p) : __p_(__p) {} 45607a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 45617a984708SDavid Chisnall void reset() {} 45627a984708SDavid Chisnall 45637a984708SDavid Chisnall // generating functions 45647a984708SDavid Chisnall template<class _URNG> 45657a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 45667a984708SDavid Chisnall result_type operator()(_URNG& __g) 45677a984708SDavid Chisnall {return (*this)(__g, __p_);} 45687a984708SDavid Chisnall template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 45697a984708SDavid Chisnall 45707a984708SDavid Chisnall // property functions 45717a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 45727a984708SDavid Chisnall double mean() const {return __p_.mean();} 45737a984708SDavid Chisnall 45747a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 45757a984708SDavid Chisnall param_type param() const {return __p_;} 45767a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 45777a984708SDavid Chisnall void param(const param_type& __p) {__p_ = __p;} 45787a984708SDavid Chisnall 45797a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 45807a984708SDavid Chisnall result_type min() const {return 0;} 45817a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 45827a984708SDavid Chisnall result_type max() const {return numeric_limits<result_type>::max();} 45837a984708SDavid Chisnall 45847a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 45857a984708SDavid Chisnall bool operator==(const poisson_distribution& __x, 45867a984708SDavid Chisnall const poisson_distribution& __y) 45877a984708SDavid Chisnall {return __x.__p_ == __y.__p_;} 45887a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 45897a984708SDavid Chisnall bool operator!=(const poisson_distribution& __x, 45907a984708SDavid Chisnall const poisson_distribution& __y) 45917a984708SDavid Chisnall {return !(__x == __y);} 45927a984708SDavid Chisnall}; 45937a984708SDavid Chisnall 45947a984708SDavid Chisnalltemplate<class _IntType> 45957a984708SDavid Chisnallpoisson_distribution<_IntType>::param_type::param_type(double __mean) 45967a984708SDavid Chisnall : __mean_(__mean) 45977a984708SDavid Chisnall{ 45987a984708SDavid Chisnall if (__mean_ < 10) 45997a984708SDavid Chisnall { 46007a984708SDavid Chisnall __s_ = 0; 46017a984708SDavid Chisnall __d_ = 0; 46027a984708SDavid Chisnall __l_ = _VSTD::exp(-__mean_); 46037a984708SDavid Chisnall __omega_ = 0; 46047a984708SDavid Chisnall __c3_ = 0; 46057a984708SDavid Chisnall __c2_ = 0; 46067a984708SDavid Chisnall __c1_ = 0; 46077a984708SDavid Chisnall __c0_ = 0; 46087a984708SDavid Chisnall __c_ = 0; 46097a984708SDavid Chisnall } 46107a984708SDavid Chisnall else 46117a984708SDavid Chisnall { 46127a984708SDavid Chisnall __s_ = _VSTD::sqrt(__mean_); 46137a984708SDavid Chisnall __d_ = 6 * __mean_ * __mean_; 46147a984708SDavid Chisnall __l_ = static_cast<result_type>(__mean_ - 1.1484); 46157a984708SDavid Chisnall __omega_ = .3989423 / __s_; 46167a984708SDavid Chisnall double __b1_ = .4166667E-1 / __mean_; 46177a984708SDavid Chisnall double __b2_ = .3 * __b1_ * __b1_; 46187a984708SDavid Chisnall __c3_ = .1428571 * __b1_ * __b2_; 46197a984708SDavid Chisnall __c2_ = __b2_ - 15. * __c3_; 46207a984708SDavid Chisnall __c1_ = __b1_ - 6. * __b2_ + 45. * __c3_; 46217a984708SDavid Chisnall __c0_ = 1. - __b1_ + 3. * __b2_ - 15. * __c3_; 46227a984708SDavid Chisnall __c_ = .1069 / __mean_; 46237a984708SDavid Chisnall } 46247a984708SDavid Chisnall} 46257a984708SDavid Chisnall 46267a984708SDavid Chisnalltemplate <class _IntType> 46277a984708SDavid Chisnalltemplate<class _URNG> 46287a984708SDavid Chisnall_IntType 46297a984708SDavid Chisnallpoisson_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr) 46307a984708SDavid Chisnall{ 46317a984708SDavid Chisnall result_type __x; 46327a984708SDavid Chisnall uniform_real_distribution<double> __urd; 46337a984708SDavid Chisnall if (__pr.__mean_ < 10) 46347a984708SDavid Chisnall { 46357a984708SDavid Chisnall __x = 0; 46367a984708SDavid Chisnall for (double __p = __urd(__urng); __p > __pr.__l_; ++__x) 46377a984708SDavid Chisnall __p *= __urd(__urng); 46387a984708SDavid Chisnall } 46397a984708SDavid Chisnall else 46407a984708SDavid Chisnall { 46417a984708SDavid Chisnall double __difmuk; 46427a984708SDavid Chisnall double __g = __pr.__mean_ + __pr.__s_ * normal_distribution<double>()(__urng); 46437a984708SDavid Chisnall double __u; 46447a984708SDavid Chisnall if (__g > 0) 46457a984708SDavid Chisnall { 46467a984708SDavid Chisnall __x = static_cast<result_type>(__g); 46477a984708SDavid Chisnall if (__x >= __pr.__l_) 46487a984708SDavid Chisnall return __x; 46497a984708SDavid Chisnall __difmuk = __pr.__mean_ - __x; 46507a984708SDavid Chisnall __u = __urd(__urng); 46517a984708SDavid Chisnall if (__pr.__d_ * __u >= __difmuk * __difmuk * __difmuk) 46527a984708SDavid Chisnall return __x; 46537a984708SDavid Chisnall } 46547a984708SDavid Chisnall exponential_distribution<double> __edist; 46557a984708SDavid Chisnall for (bool __using_exp_dist = false; true; __using_exp_dist = true) 46567a984708SDavid Chisnall { 46577a984708SDavid Chisnall double __e; 46587a984708SDavid Chisnall if (__using_exp_dist || __g < 0) 46597a984708SDavid Chisnall { 46607a984708SDavid Chisnall double __t; 46617a984708SDavid Chisnall do 46627a984708SDavid Chisnall { 46637a984708SDavid Chisnall __e = __edist(__urng); 46647a984708SDavid Chisnall __u = __urd(__urng); 46657a984708SDavid Chisnall __u += __u - 1; 46667a984708SDavid Chisnall __t = 1.8 + (__u < 0 ? -__e : __e); 46677a984708SDavid Chisnall } while (__t <= -.6744); 46687a984708SDavid Chisnall __x = __pr.__mean_ + __pr.__s_ * __t; 46697a984708SDavid Chisnall __difmuk = __pr.__mean_ - __x; 46707a984708SDavid Chisnall __using_exp_dist = true; 46717a984708SDavid Chisnall } 46727a984708SDavid Chisnall double __px; 46737a984708SDavid Chisnall double __py; 46747a984708SDavid Chisnall if (__x < 10) 46757a984708SDavid Chisnall { 46764ba319b5SDimitry Andric const double __fac[] = {1, 1, 2, 6, 24, 120, 720, 5040, 46777a984708SDavid Chisnall 40320, 362880}; 46787a984708SDavid Chisnall __px = -__pr.__mean_; 46797a984708SDavid Chisnall __py = _VSTD::pow(__pr.__mean_, (double)__x) / __fac[__x]; 46807a984708SDavid Chisnall } 46817a984708SDavid Chisnall else 46827a984708SDavid Chisnall { 46837a984708SDavid Chisnall double __del = .8333333E-1 / __x; 46847a984708SDavid Chisnall __del -= 4.8 * __del * __del * __del; 46857a984708SDavid Chisnall double __v = __difmuk / __x; 46867a984708SDavid Chisnall if (_VSTD::abs(__v) > 0.25) 46877a984708SDavid Chisnall __px = __x * _VSTD::log(1 + __v) - __difmuk - __del; 46887a984708SDavid Chisnall else 46897a984708SDavid Chisnall __px = __x * __v * __v * (((((((.1250060 * __v + -.1384794) * 46907a984708SDavid Chisnall __v + .1421878) * __v + -.1661269) * __v + .2000118) * 46917a984708SDavid Chisnall __v + -.2500068) * __v + .3333333) * __v + -.5) - __del; 46927a984708SDavid Chisnall __py = .3989423 / _VSTD::sqrt(__x); 46937a984708SDavid Chisnall } 46947a984708SDavid Chisnall double __r = (0.5 - __difmuk) / __pr.__s_; 46957a984708SDavid Chisnall double __r2 = __r * __r; 46967a984708SDavid Chisnall double __fx = -0.5 * __r2; 46977a984708SDavid Chisnall double __fy = __pr.__omega_ * (((__pr.__c3_ * __r2 + __pr.__c2_) * 46987a984708SDavid Chisnall __r2 + __pr.__c1_) * __r2 + __pr.__c0_); 46997a984708SDavid Chisnall if (__using_exp_dist) 47007a984708SDavid Chisnall { 47017a984708SDavid Chisnall if (__pr.__c_ * _VSTD::abs(__u) <= __py * _VSTD::exp(__px + __e) - 47027a984708SDavid Chisnall __fy * _VSTD::exp(__fx + __e)) 47037a984708SDavid Chisnall break; 47047a984708SDavid Chisnall } 47057a984708SDavid Chisnall else 47067a984708SDavid Chisnall { 47077a984708SDavid Chisnall if (__fy - __u * __fy <= __py * _VSTD::exp(__px - __fx)) 47087a984708SDavid Chisnall break; 47097a984708SDavid Chisnall } 47107a984708SDavid Chisnall } 47117a984708SDavid Chisnall } 47127a984708SDavid Chisnall return __x; 47137a984708SDavid Chisnall} 47147a984708SDavid Chisnall 47157a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _IntType> 47167a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 47177a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 47187a984708SDavid Chisnall const poisson_distribution<_IntType>& __x) 47197a984708SDavid Chisnall{ 47201e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__os); 47217a984708SDavid Chisnall __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 47227a984708SDavid Chisnall ios_base::scientific); 47237a984708SDavid Chisnall return __os << __x.mean(); 47247a984708SDavid Chisnall} 47257a984708SDavid Chisnall 47267a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _IntType> 47277a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 47287a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 47297a984708SDavid Chisnall poisson_distribution<_IntType>& __x) 47307a984708SDavid Chisnall{ 47317a984708SDavid Chisnall typedef poisson_distribution<_IntType> _Eng; 47327a984708SDavid Chisnall typedef typename _Eng::param_type param_type; 47331e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__is); 47347a984708SDavid Chisnall __is.flags(ios_base::dec | ios_base::skipws); 47357a984708SDavid Chisnall double __mean; 47367a984708SDavid Chisnall __is >> __mean; 47377a984708SDavid Chisnall if (!__is.fail()) 47387a984708SDavid Chisnall __x.param(param_type(__mean)); 47397a984708SDavid Chisnall return __is; 47407a984708SDavid Chisnall} 47417a984708SDavid Chisnall 47427a984708SDavid Chisnall// weibull_distribution 47437a984708SDavid Chisnall 47447a984708SDavid Chisnalltemplate<class _RealType = double> 4745aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS weibull_distribution 47467a984708SDavid Chisnall{ 47477a984708SDavid Chisnallpublic: 47487a984708SDavid Chisnall // types 47497a984708SDavid Chisnall typedef _RealType result_type; 47507a984708SDavid Chisnall 4751aed8d94eSDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 47527a984708SDavid Chisnall { 47537a984708SDavid Chisnall result_type __a_; 47547a984708SDavid Chisnall result_type __b_; 47557a984708SDavid Chisnall public: 47567a984708SDavid Chisnall typedef weibull_distribution distribution_type; 47577a984708SDavid Chisnall 47587a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 47597a984708SDavid Chisnall explicit param_type(result_type __a = 1, result_type __b = 1) 47607a984708SDavid Chisnall : __a_(__a), __b_(__b) {} 47617a984708SDavid Chisnall 47627a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 47637a984708SDavid Chisnall result_type a() const {return __a_;} 47647a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 47657a984708SDavid Chisnall result_type b() const {return __b_;} 47667a984708SDavid Chisnall 47677a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 47687a984708SDavid Chisnall bool operator==(const param_type& __x, const param_type& __y) 47697a984708SDavid Chisnall {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} 47707a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 47717a984708SDavid Chisnall bool operator!=(const param_type& __x, const param_type& __y) 47727a984708SDavid Chisnall {return !(__x == __y);} 47737a984708SDavid Chisnall }; 47747a984708SDavid Chisnall 47757a984708SDavid Chisnallprivate: 47767a984708SDavid Chisnall param_type __p_; 47777a984708SDavid Chisnall 47787a984708SDavid Chisnallpublic: 47797a984708SDavid Chisnall // constructor and reset functions 47807a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 47817a984708SDavid Chisnall explicit weibull_distribution(result_type __a = 1, result_type __b = 1) 47827a984708SDavid Chisnall : __p_(param_type(__a, __b)) {} 47837a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 47847a984708SDavid Chisnall explicit weibull_distribution(const param_type& __p) 47857a984708SDavid Chisnall : __p_(__p) {} 47867a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 47877a984708SDavid Chisnall void reset() {} 47887a984708SDavid Chisnall 47897a984708SDavid Chisnall // generating functions 47907a984708SDavid Chisnall template<class _URNG> 47917a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 47927a984708SDavid Chisnall result_type operator()(_URNG& __g) 47937a984708SDavid Chisnall {return (*this)(__g, __p_);} 47947a984708SDavid Chisnall template<class _URNG> 47957a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 47967a984708SDavid Chisnall result_type operator()(_URNG& __g, const param_type& __p) 47977a984708SDavid Chisnall {return __p.b() * 47987a984708SDavid Chisnall _VSTD::pow(exponential_distribution<result_type>()(__g), 1/__p.a());} 47997a984708SDavid Chisnall 48007a984708SDavid Chisnall // property functions 48017a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 48027a984708SDavid Chisnall result_type a() const {return __p_.a();} 48037a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 48047a984708SDavid Chisnall result_type b() const {return __p_.b();} 48057a984708SDavid Chisnall 48067a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 48077a984708SDavid Chisnall param_type param() const {return __p_;} 48087a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 48097a984708SDavid Chisnall void param(const param_type& __p) {__p_ = __p;} 48107a984708SDavid Chisnall 48117a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 48127a984708SDavid Chisnall result_type min() const {return 0;} 48137a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 48147a984708SDavid Chisnall result_type max() const {return numeric_limits<result_type>::infinity();} 48157a984708SDavid Chisnall 48167a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 48177a984708SDavid Chisnall bool operator==(const weibull_distribution& __x, 48187a984708SDavid Chisnall const weibull_distribution& __y) 48197a984708SDavid Chisnall {return __x.__p_ == __y.__p_;} 48207a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 48217a984708SDavid Chisnall bool operator!=(const weibull_distribution& __x, 48227a984708SDavid Chisnall const weibull_distribution& __y) 48237a984708SDavid Chisnall {return !(__x == __y);} 48247a984708SDavid Chisnall}; 48257a984708SDavid Chisnall 48267a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _RT> 48277a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 48287a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 48297a984708SDavid Chisnall const weibull_distribution<_RT>& __x) 48307a984708SDavid Chisnall{ 48311e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__os); 48327a984708SDavid Chisnall __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 48337a984708SDavid Chisnall ios_base::scientific); 48347a984708SDavid Chisnall _CharT __sp = __os.widen(' '); 48357a984708SDavid Chisnall __os.fill(__sp); 48367a984708SDavid Chisnall __os << __x.a() << __sp << __x.b(); 48377a984708SDavid Chisnall return __os; 48387a984708SDavid Chisnall} 48397a984708SDavid Chisnall 48407a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _RT> 48417a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 48427a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 48437a984708SDavid Chisnall weibull_distribution<_RT>& __x) 48447a984708SDavid Chisnall{ 48457a984708SDavid Chisnall typedef weibull_distribution<_RT> _Eng; 48467a984708SDavid Chisnall typedef typename _Eng::result_type result_type; 48477a984708SDavid Chisnall typedef typename _Eng::param_type param_type; 48481e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__is); 48497a984708SDavid Chisnall __is.flags(ios_base::dec | ios_base::skipws); 48507a984708SDavid Chisnall result_type __a; 48517a984708SDavid Chisnall result_type __b; 48527a984708SDavid Chisnall __is >> __a >> __b; 48537a984708SDavid Chisnall if (!__is.fail()) 48547a984708SDavid Chisnall __x.param(param_type(__a, __b)); 48557a984708SDavid Chisnall return __is; 48567a984708SDavid Chisnall} 48577a984708SDavid Chisnall 48587a984708SDavid Chisnalltemplate<class _RealType = double> 4859aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS extreme_value_distribution 48607a984708SDavid Chisnall{ 48617a984708SDavid Chisnallpublic: 48627a984708SDavid Chisnall // types 48637a984708SDavid Chisnall typedef _RealType result_type; 48647a984708SDavid Chisnall 4865aed8d94eSDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 48667a984708SDavid Chisnall { 48677a984708SDavid Chisnall result_type __a_; 48687a984708SDavid Chisnall result_type __b_; 48697a984708SDavid Chisnall public: 48707a984708SDavid Chisnall typedef extreme_value_distribution distribution_type; 48717a984708SDavid Chisnall 48727a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 48737a984708SDavid Chisnall explicit param_type(result_type __a = 0, result_type __b = 1) 48747a984708SDavid Chisnall : __a_(__a), __b_(__b) {} 48757a984708SDavid Chisnall 48767a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 48777a984708SDavid Chisnall result_type a() const {return __a_;} 48787a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 48797a984708SDavid Chisnall result_type b() const {return __b_;} 48807a984708SDavid Chisnall 48817a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 48827a984708SDavid Chisnall bool operator==(const param_type& __x, const param_type& __y) 48837a984708SDavid Chisnall {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} 48847a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 48857a984708SDavid Chisnall bool operator!=(const param_type& __x, const param_type& __y) 48867a984708SDavid Chisnall {return !(__x == __y);} 48877a984708SDavid Chisnall }; 48887a984708SDavid Chisnall 48897a984708SDavid Chisnallprivate: 48907a984708SDavid Chisnall param_type __p_; 48917a984708SDavid Chisnall 48927a984708SDavid Chisnallpublic: 48937a984708SDavid Chisnall // constructor and reset functions 48947a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 48957a984708SDavid Chisnall explicit extreme_value_distribution(result_type __a = 0, result_type __b = 1) 48967a984708SDavid Chisnall : __p_(param_type(__a, __b)) {} 48977a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 48987a984708SDavid Chisnall explicit extreme_value_distribution(const param_type& __p) 48997a984708SDavid Chisnall : __p_(__p) {} 49007a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 49017a984708SDavid Chisnall void reset() {} 49027a984708SDavid Chisnall 49037a984708SDavid Chisnall // generating functions 49047a984708SDavid Chisnall template<class _URNG> 49057a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 49067a984708SDavid Chisnall result_type operator()(_URNG& __g) 49077a984708SDavid Chisnall {return (*this)(__g, __p_);} 49087a984708SDavid Chisnall template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 49097a984708SDavid Chisnall 49107a984708SDavid Chisnall // property functions 49117a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 49127a984708SDavid Chisnall result_type a() const {return __p_.a();} 49137a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 49147a984708SDavid Chisnall result_type b() const {return __p_.b();} 49157a984708SDavid Chisnall 49167a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 49177a984708SDavid Chisnall param_type param() const {return __p_;} 49187a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 49197a984708SDavid Chisnall void param(const param_type& __p) {__p_ = __p;} 49207a984708SDavid Chisnall 49217a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 49227a984708SDavid Chisnall result_type min() const {return -numeric_limits<result_type>::infinity();} 49237a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 49247a984708SDavid Chisnall result_type max() const {return numeric_limits<result_type>::infinity();} 49257a984708SDavid Chisnall 49267a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 49277a984708SDavid Chisnall bool operator==(const extreme_value_distribution& __x, 49287a984708SDavid Chisnall const extreme_value_distribution& __y) 49297a984708SDavid Chisnall {return __x.__p_ == __y.__p_;} 49307a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 49317a984708SDavid Chisnall bool operator!=(const extreme_value_distribution& __x, 49327a984708SDavid Chisnall const extreme_value_distribution& __y) 49337a984708SDavid Chisnall {return !(__x == __y);} 49347a984708SDavid Chisnall}; 49357a984708SDavid Chisnall 49367a984708SDavid Chisnalltemplate<class _RealType> 49377a984708SDavid Chisnalltemplate<class _URNG> 49387a984708SDavid Chisnall_RealType 49397a984708SDavid Chisnallextreme_value_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 49407a984708SDavid Chisnall{ 49417a984708SDavid Chisnall return __p.a() - __p.b() * 49427a984708SDavid Chisnall _VSTD::log(-_VSTD::log(1-uniform_real_distribution<result_type>()(__g))); 49437a984708SDavid Chisnall} 49447a984708SDavid Chisnall 49457a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _RT> 49467a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 49477a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 49487a984708SDavid Chisnall const extreme_value_distribution<_RT>& __x) 49497a984708SDavid Chisnall{ 49501e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__os); 49517a984708SDavid Chisnall __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 49527a984708SDavid Chisnall ios_base::scientific); 49537a984708SDavid Chisnall _CharT __sp = __os.widen(' '); 49547a984708SDavid Chisnall __os.fill(__sp); 49557a984708SDavid Chisnall __os << __x.a() << __sp << __x.b(); 49567a984708SDavid Chisnall return __os; 49577a984708SDavid Chisnall} 49587a984708SDavid Chisnall 49597a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _RT> 49607a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 49617a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 49627a984708SDavid Chisnall extreme_value_distribution<_RT>& __x) 49637a984708SDavid Chisnall{ 49647a984708SDavid Chisnall typedef extreme_value_distribution<_RT> _Eng; 49657a984708SDavid Chisnall typedef typename _Eng::result_type result_type; 49667a984708SDavid Chisnall typedef typename _Eng::param_type param_type; 49671e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__is); 49687a984708SDavid Chisnall __is.flags(ios_base::dec | ios_base::skipws); 49697a984708SDavid Chisnall result_type __a; 49707a984708SDavid Chisnall result_type __b; 49717a984708SDavid Chisnall __is >> __a >> __b; 49727a984708SDavid Chisnall if (!__is.fail()) 49737a984708SDavid Chisnall __x.param(param_type(__a, __b)); 49747a984708SDavid Chisnall return __is; 49757a984708SDavid Chisnall} 49767a984708SDavid Chisnall 49777a984708SDavid Chisnall// gamma_distribution 49787a984708SDavid Chisnall 49797a984708SDavid Chisnalltemplate<class _RealType = double> 4980aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS gamma_distribution 49817a984708SDavid Chisnall{ 49827a984708SDavid Chisnallpublic: 49837a984708SDavid Chisnall // types 49847a984708SDavid Chisnall typedef _RealType result_type; 49857a984708SDavid Chisnall 4986aed8d94eSDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 49877a984708SDavid Chisnall { 49887a984708SDavid Chisnall result_type __alpha_; 49897a984708SDavid Chisnall result_type __beta_; 49907a984708SDavid Chisnall public: 49917a984708SDavid Chisnall typedef gamma_distribution distribution_type; 49927a984708SDavid Chisnall 49937a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 49947a984708SDavid Chisnall explicit param_type(result_type __alpha = 1, result_type __beta = 1) 49957a984708SDavid Chisnall : __alpha_(__alpha), __beta_(__beta) {} 49967a984708SDavid Chisnall 49977a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 49987a984708SDavid Chisnall result_type alpha() const {return __alpha_;} 49997a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 50007a984708SDavid Chisnall result_type beta() const {return __beta_;} 50017a984708SDavid Chisnall 50027a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 50037a984708SDavid Chisnall bool operator==(const param_type& __x, const param_type& __y) 50047a984708SDavid Chisnall {return __x.__alpha_ == __y.__alpha_ && __x.__beta_ == __y.__beta_;} 50057a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 50067a984708SDavid Chisnall bool operator!=(const param_type& __x, const param_type& __y) 50077a984708SDavid Chisnall {return !(__x == __y);} 50087a984708SDavid Chisnall }; 50097a984708SDavid Chisnall 50107a984708SDavid Chisnallprivate: 50117a984708SDavid Chisnall param_type __p_; 50127a984708SDavid Chisnall 50137a984708SDavid Chisnallpublic: 50147a984708SDavid Chisnall // constructors and reset functions 50157a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 50167a984708SDavid Chisnall explicit gamma_distribution(result_type __alpha = 1, result_type __beta = 1) 50177a984708SDavid Chisnall : __p_(param_type(__alpha, __beta)) {} 50187a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 50197a984708SDavid Chisnall explicit gamma_distribution(const param_type& __p) 50207a984708SDavid Chisnall : __p_(__p) {} 50217a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 50227a984708SDavid Chisnall void reset() {} 50237a984708SDavid Chisnall 50247a984708SDavid Chisnall // generating functions 50257a984708SDavid Chisnall template<class _URNG> 50267a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 50277a984708SDavid Chisnall result_type operator()(_URNG& __g) 50287a984708SDavid Chisnall {return (*this)(__g, __p_);} 50297a984708SDavid Chisnall template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 50307a984708SDavid Chisnall 50317a984708SDavid Chisnall // property functions 50327a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 50337a984708SDavid Chisnall result_type alpha() const {return __p_.alpha();} 50347a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 50357a984708SDavid Chisnall result_type beta() const {return __p_.beta();} 50367a984708SDavid Chisnall 50377a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 50387a984708SDavid Chisnall param_type param() const {return __p_;} 50397a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 50407a984708SDavid Chisnall void param(const param_type& __p) {__p_ = __p;} 50417a984708SDavid Chisnall 50427a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 50437a984708SDavid Chisnall result_type min() const {return 0;} 50447a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 50457a984708SDavid Chisnall result_type max() const {return numeric_limits<result_type>::infinity();} 50467a984708SDavid Chisnall 50477a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 50487a984708SDavid Chisnall bool operator==(const gamma_distribution& __x, 50497a984708SDavid Chisnall const gamma_distribution& __y) 50507a984708SDavid Chisnall {return __x.__p_ == __y.__p_;} 50517a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 50527a984708SDavid Chisnall bool operator!=(const gamma_distribution& __x, 50537a984708SDavid Chisnall const gamma_distribution& __y) 50547a984708SDavid Chisnall {return !(__x == __y);} 50557a984708SDavid Chisnall}; 50567a984708SDavid Chisnall 50577a984708SDavid Chisnalltemplate <class _RealType> 50587a984708SDavid Chisnalltemplate<class _URNG> 50597a984708SDavid Chisnall_RealType 50607a984708SDavid Chisnallgamma_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 50617a984708SDavid Chisnall{ 50627a984708SDavid Chisnall result_type __a = __p.alpha(); 50637a984708SDavid Chisnall uniform_real_distribution<result_type> __gen(0, 1); 50647a984708SDavid Chisnall exponential_distribution<result_type> __egen; 50657a984708SDavid Chisnall result_type __x; 50667a984708SDavid Chisnall if (__a == 1) 50677a984708SDavid Chisnall __x = __egen(__g); 50687a984708SDavid Chisnall else if (__a > 1) 50697a984708SDavid Chisnall { 50707a984708SDavid Chisnall const result_type __b = __a - 1; 50717a984708SDavid Chisnall const result_type __c = 3 * __a - result_type(0.75); 50727a984708SDavid Chisnall while (true) 50737a984708SDavid Chisnall { 50747a984708SDavid Chisnall const result_type __u = __gen(__g); 50757a984708SDavid Chisnall const result_type __v = __gen(__g); 50767a984708SDavid Chisnall const result_type __w = __u * (1 - __u); 50777a984708SDavid Chisnall if (__w != 0) 50787a984708SDavid Chisnall { 50797a984708SDavid Chisnall const result_type __y = _VSTD::sqrt(__c / __w) * 50807a984708SDavid Chisnall (__u - result_type(0.5)); 50817a984708SDavid Chisnall __x = __b + __y; 50827a984708SDavid Chisnall if (__x >= 0) 50837a984708SDavid Chisnall { 50847a984708SDavid Chisnall const result_type __z = 64 * __w * __w * __w * __v * __v; 50857a984708SDavid Chisnall if (__z <= 1 - 2 * __y * __y / __x) 50867a984708SDavid Chisnall break; 50877a984708SDavid Chisnall if (_VSTD::log(__z) <= 2 * (__b * _VSTD::log(__x / __b) - __y)) 50887a984708SDavid Chisnall break; 50897a984708SDavid Chisnall } 50907a984708SDavid Chisnall } 50917a984708SDavid Chisnall } 50927a984708SDavid Chisnall } 50937a984708SDavid Chisnall else // __a < 1 50947a984708SDavid Chisnall { 50957a984708SDavid Chisnall while (true) 50967a984708SDavid Chisnall { 50977a984708SDavid Chisnall const result_type __u = __gen(__g); 50987a984708SDavid Chisnall const result_type __es = __egen(__g); 50997a984708SDavid Chisnall if (__u <= 1 - __a) 51007a984708SDavid Chisnall { 51017a984708SDavid Chisnall __x = _VSTD::pow(__u, 1 / __a); 51027a984708SDavid Chisnall if (__x <= __es) 51037a984708SDavid Chisnall break; 51047a984708SDavid Chisnall } 51057a984708SDavid Chisnall else 51067a984708SDavid Chisnall { 51077a984708SDavid Chisnall const result_type __e = -_VSTD::log((1-__u)/__a); 51087a984708SDavid Chisnall __x = _VSTD::pow(1 - __a + __a * __e, 1 / __a); 51097a984708SDavid Chisnall if (__x <= __e + __es) 51107a984708SDavid Chisnall break; 51117a984708SDavid Chisnall } 51127a984708SDavid Chisnall } 51137a984708SDavid Chisnall } 51147a984708SDavid Chisnall return __x * __p.beta(); 51157a984708SDavid Chisnall} 51167a984708SDavid Chisnall 51177a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _RT> 51187a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 51197a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 51207a984708SDavid Chisnall const gamma_distribution<_RT>& __x) 51217a984708SDavid Chisnall{ 51221e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__os); 51237a984708SDavid Chisnall __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 51247a984708SDavid Chisnall ios_base::scientific); 51257a984708SDavid Chisnall _CharT __sp = __os.widen(' '); 51267a984708SDavid Chisnall __os.fill(__sp); 51277a984708SDavid Chisnall __os << __x.alpha() << __sp << __x.beta(); 51287a984708SDavid Chisnall return __os; 51297a984708SDavid Chisnall} 51307a984708SDavid Chisnall 51317a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _RT> 51327a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 51337a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 51347a984708SDavid Chisnall gamma_distribution<_RT>& __x) 51357a984708SDavid Chisnall{ 51367a984708SDavid Chisnall typedef gamma_distribution<_RT> _Eng; 51377a984708SDavid Chisnall typedef typename _Eng::result_type result_type; 51387a984708SDavid Chisnall typedef typename _Eng::param_type param_type; 51391e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__is); 51407a984708SDavid Chisnall __is.flags(ios_base::dec | ios_base::skipws); 51417a984708SDavid Chisnall result_type __alpha; 51427a984708SDavid Chisnall result_type __beta; 51437a984708SDavid Chisnall __is >> __alpha >> __beta; 51447a984708SDavid Chisnall if (!__is.fail()) 51457a984708SDavid Chisnall __x.param(param_type(__alpha, __beta)); 51467a984708SDavid Chisnall return __is; 51477a984708SDavid Chisnall} 51487a984708SDavid Chisnall 51497a984708SDavid Chisnall// negative_binomial_distribution 51507a984708SDavid Chisnall 51517a984708SDavid Chisnalltemplate<class _IntType = int> 5152aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS negative_binomial_distribution 51537a984708SDavid Chisnall{ 51547a984708SDavid Chisnallpublic: 51557a984708SDavid Chisnall // types 51567a984708SDavid Chisnall typedef _IntType result_type; 51577a984708SDavid Chisnall 5158aed8d94eSDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 51597a984708SDavid Chisnall { 51607a984708SDavid Chisnall result_type __k_; 51617a984708SDavid Chisnall double __p_; 51627a984708SDavid Chisnall public: 51637a984708SDavid Chisnall typedef negative_binomial_distribution distribution_type; 51647a984708SDavid Chisnall 51657a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 51667a984708SDavid Chisnall explicit param_type(result_type __k = 1, double __p = 0.5) 51677a984708SDavid Chisnall : __k_(__k), __p_(__p) {} 51687a984708SDavid Chisnall 51697a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 51707a984708SDavid Chisnall result_type k() const {return __k_;} 51717a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 51727a984708SDavid Chisnall double p() const {return __p_;} 51737a984708SDavid Chisnall 51747a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 51757a984708SDavid Chisnall bool operator==(const param_type& __x, const param_type& __y) 51767a984708SDavid Chisnall {return __x.__k_ == __y.__k_ && __x.__p_ == __y.__p_;} 51777a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 51787a984708SDavid Chisnall bool operator!=(const param_type& __x, const param_type& __y) 51797a984708SDavid Chisnall {return !(__x == __y);} 51807a984708SDavid Chisnall }; 51817a984708SDavid Chisnall 51827a984708SDavid Chisnallprivate: 51837a984708SDavid Chisnall param_type __p_; 51847a984708SDavid Chisnall 51857a984708SDavid Chisnallpublic: 51867a984708SDavid Chisnall // constructor and reset functions 51877a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 51887a984708SDavid Chisnall explicit negative_binomial_distribution(result_type __k = 1, double __p = 0.5) 51897a984708SDavid Chisnall : __p_(__k, __p) {} 51907a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 51917a984708SDavid Chisnall explicit negative_binomial_distribution(const param_type& __p) : __p_(__p) {} 51927a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 51937a984708SDavid Chisnall void reset() {} 51947a984708SDavid Chisnall 51957a984708SDavid Chisnall // generating functions 51967a984708SDavid Chisnall template<class _URNG> 51977a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 51987a984708SDavid Chisnall result_type operator()(_URNG& __g) 51997a984708SDavid Chisnall {return (*this)(__g, __p_);} 52007a984708SDavid Chisnall template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 52017a984708SDavid Chisnall 52027a984708SDavid Chisnall // property functions 52037a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 52047a984708SDavid Chisnall result_type k() const {return __p_.k();} 52057a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 52067a984708SDavid Chisnall double p() const {return __p_.p();} 52077a984708SDavid Chisnall 52087a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 52097a984708SDavid Chisnall param_type param() const {return __p_;} 52107a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 52117a984708SDavid Chisnall void param(const param_type& __p) {__p_ = __p;} 52127a984708SDavid Chisnall 52137a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 52147a984708SDavid Chisnall result_type min() const {return 0;} 52157a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 52167a984708SDavid Chisnall result_type max() const {return numeric_limits<result_type>::max();} 52177a984708SDavid Chisnall 52187a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 52197a984708SDavid Chisnall bool operator==(const negative_binomial_distribution& __x, 52207a984708SDavid Chisnall const negative_binomial_distribution& __y) 52217a984708SDavid Chisnall {return __x.__p_ == __y.__p_;} 52227a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 52237a984708SDavid Chisnall bool operator!=(const negative_binomial_distribution& __x, 52247a984708SDavid Chisnall const negative_binomial_distribution& __y) 52257a984708SDavid Chisnall {return !(__x == __y);} 52267a984708SDavid Chisnall}; 52277a984708SDavid Chisnall 52287a984708SDavid Chisnalltemplate <class _IntType> 52297a984708SDavid Chisnalltemplate<class _URNG> 52307a984708SDavid Chisnall_IntType 52317a984708SDavid Chisnallnegative_binomial_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr) 52327a984708SDavid Chisnall{ 52337a984708SDavid Chisnall result_type __k = __pr.k(); 52347a984708SDavid Chisnall double __p = __pr.p(); 52357a984708SDavid Chisnall if (__k <= 21 * __p) 52367a984708SDavid Chisnall { 52377a984708SDavid Chisnall bernoulli_distribution __gen(__p); 52387a984708SDavid Chisnall result_type __f = 0; 52397a984708SDavid Chisnall result_type __s = 0; 52407a984708SDavid Chisnall while (__s < __k) 52417a984708SDavid Chisnall { 52427a984708SDavid Chisnall if (__gen(__urng)) 52437a984708SDavid Chisnall ++__s; 52447a984708SDavid Chisnall else 52457a984708SDavid Chisnall ++__f; 52467a984708SDavid Chisnall } 52477a984708SDavid Chisnall return __f; 52487a984708SDavid Chisnall } 52497a984708SDavid Chisnall return poisson_distribution<result_type>(gamma_distribution<double> 52507a984708SDavid Chisnall (__k, (1-__p)/__p)(__urng))(__urng); 52517a984708SDavid Chisnall} 52527a984708SDavid Chisnall 52537a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _IntType> 52547a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 52557a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 52567a984708SDavid Chisnall const negative_binomial_distribution<_IntType>& __x) 52577a984708SDavid Chisnall{ 52581e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__os); 52597a984708SDavid Chisnall __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 52607a984708SDavid Chisnall ios_base::scientific); 52617a984708SDavid Chisnall _CharT __sp = __os.widen(' '); 52627a984708SDavid Chisnall __os.fill(__sp); 52637a984708SDavid Chisnall return __os << __x.k() << __sp << __x.p(); 52647a984708SDavid Chisnall} 52657a984708SDavid Chisnall 52667a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _IntType> 52677a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 52687a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 52697a984708SDavid Chisnall negative_binomial_distribution<_IntType>& __x) 52707a984708SDavid Chisnall{ 52717a984708SDavid Chisnall typedef negative_binomial_distribution<_IntType> _Eng; 52727a984708SDavid Chisnall typedef typename _Eng::result_type result_type; 52737a984708SDavid Chisnall typedef typename _Eng::param_type param_type; 52741e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__is); 52757a984708SDavid Chisnall __is.flags(ios_base::dec | ios_base::skipws); 52767a984708SDavid Chisnall result_type __k; 52777a984708SDavid Chisnall double __p; 52787a984708SDavid Chisnall __is >> __k >> __p; 52797a984708SDavid Chisnall if (!__is.fail()) 52807a984708SDavid Chisnall __x.param(param_type(__k, __p)); 52817a984708SDavid Chisnall return __is; 52827a984708SDavid Chisnall} 52837a984708SDavid Chisnall 52847a984708SDavid Chisnall// geometric_distribution 52857a984708SDavid Chisnall 52867a984708SDavid Chisnalltemplate<class _IntType = int> 5287aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS geometric_distribution 52887a984708SDavid Chisnall{ 52897a984708SDavid Chisnallpublic: 52907a984708SDavid Chisnall // types 52917a984708SDavid Chisnall typedef _IntType result_type; 52927a984708SDavid Chisnall 5293aed8d94eSDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 52947a984708SDavid Chisnall { 52957a984708SDavid Chisnall double __p_; 52967a984708SDavid Chisnall public: 52977a984708SDavid Chisnall typedef geometric_distribution distribution_type; 52987a984708SDavid Chisnall 52997a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 53007a984708SDavid Chisnall explicit param_type(double __p = 0.5) : __p_(__p) {} 53017a984708SDavid Chisnall 53027a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 53037a984708SDavid Chisnall double p() const {return __p_;} 53047a984708SDavid Chisnall 53057a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 53067a984708SDavid Chisnall bool operator==(const param_type& __x, const param_type& __y) 53077a984708SDavid Chisnall {return __x.__p_ == __y.__p_;} 53087a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 53097a984708SDavid Chisnall bool operator!=(const param_type& __x, const param_type& __y) 53107a984708SDavid Chisnall {return !(__x == __y);} 53117a984708SDavid Chisnall }; 53127a984708SDavid Chisnall 53137a984708SDavid Chisnallprivate: 53147a984708SDavid Chisnall param_type __p_; 53157a984708SDavid Chisnall 53167a984708SDavid Chisnallpublic: 53177a984708SDavid Chisnall // constructors and reset functions 53187a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 53197a984708SDavid Chisnall explicit geometric_distribution(double __p = 0.5) : __p_(__p) {} 53207a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 53217a984708SDavid Chisnall explicit geometric_distribution(const param_type& __p) : __p_(__p) {} 53227a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 53237a984708SDavid Chisnall void reset() {} 53247a984708SDavid Chisnall 53257a984708SDavid Chisnall // generating functions 53267a984708SDavid Chisnall template<class _URNG> 53277a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 53287a984708SDavid Chisnall result_type operator()(_URNG& __g) 53297a984708SDavid Chisnall {return (*this)(__g, __p_);} 53307a984708SDavid Chisnall template<class _URNG> 53317a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 53327a984708SDavid Chisnall result_type operator()(_URNG& __g, const param_type& __p) 53337a984708SDavid Chisnall {return negative_binomial_distribution<result_type>(1, __p.p())(__g);} 53347a984708SDavid Chisnall 53357a984708SDavid Chisnall // property functions 53367a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 53377a984708SDavid Chisnall double p() const {return __p_.p();} 53387a984708SDavid Chisnall 53397a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 53407a984708SDavid Chisnall param_type param() const {return __p_;} 53417a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 53427a984708SDavid Chisnall void param(const param_type& __p) {__p_ = __p;} 53437a984708SDavid Chisnall 53447a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 53457a984708SDavid Chisnall result_type min() const {return 0;} 53467a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 53477a984708SDavid Chisnall result_type max() const {return numeric_limits<result_type>::max();} 53487a984708SDavid Chisnall 53497a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 53507a984708SDavid Chisnall bool operator==(const geometric_distribution& __x, 53517a984708SDavid Chisnall const geometric_distribution& __y) 53527a984708SDavid Chisnall {return __x.__p_ == __y.__p_;} 53537a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 53547a984708SDavid Chisnall bool operator!=(const geometric_distribution& __x, 53557a984708SDavid Chisnall const geometric_distribution& __y) 53567a984708SDavid Chisnall {return !(__x == __y);} 53577a984708SDavid Chisnall}; 53587a984708SDavid Chisnall 53597a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _IntType> 53607a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 53617a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 53627a984708SDavid Chisnall const geometric_distribution<_IntType>& __x) 53637a984708SDavid Chisnall{ 53641e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__os); 53657a984708SDavid Chisnall __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 53667a984708SDavid Chisnall ios_base::scientific); 53677a984708SDavid Chisnall return __os << __x.p(); 53687a984708SDavid Chisnall} 53697a984708SDavid Chisnall 53707a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _IntType> 53717a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 53727a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 53737a984708SDavid Chisnall geometric_distribution<_IntType>& __x) 53747a984708SDavid Chisnall{ 53757a984708SDavid Chisnall typedef geometric_distribution<_IntType> _Eng; 53767a984708SDavid Chisnall typedef typename _Eng::param_type param_type; 53771e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__is); 53787a984708SDavid Chisnall __is.flags(ios_base::dec | ios_base::skipws); 53797a984708SDavid Chisnall double __p; 53807a984708SDavid Chisnall __is >> __p; 53817a984708SDavid Chisnall if (!__is.fail()) 53827a984708SDavid Chisnall __x.param(param_type(__p)); 53837a984708SDavid Chisnall return __is; 53847a984708SDavid Chisnall} 53857a984708SDavid Chisnall 53867a984708SDavid Chisnall// chi_squared_distribution 53877a984708SDavid Chisnall 53887a984708SDavid Chisnalltemplate<class _RealType = double> 5389aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS chi_squared_distribution 53907a984708SDavid Chisnall{ 53917a984708SDavid Chisnallpublic: 53927a984708SDavid Chisnall // types 53937a984708SDavid Chisnall typedef _RealType result_type; 53947a984708SDavid Chisnall 5395aed8d94eSDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 53967a984708SDavid Chisnall { 53977a984708SDavid Chisnall result_type __n_; 53987a984708SDavid Chisnall public: 53997a984708SDavid Chisnall typedef chi_squared_distribution distribution_type; 54007a984708SDavid Chisnall 54017a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 54027a984708SDavid Chisnall explicit param_type(result_type __n = 1) : __n_(__n) {} 54037a984708SDavid Chisnall 54047a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 54057a984708SDavid Chisnall result_type n() const {return __n_;} 54067a984708SDavid Chisnall 54077a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 54087a984708SDavid Chisnall bool operator==(const param_type& __x, const param_type& __y) 54097a984708SDavid Chisnall {return __x.__n_ == __y.__n_;} 54107a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 54117a984708SDavid Chisnall bool operator!=(const param_type& __x, const param_type& __y) 54127a984708SDavid Chisnall {return !(__x == __y);} 54137a984708SDavid Chisnall }; 54147a984708SDavid Chisnall 54157a984708SDavid Chisnallprivate: 54167a984708SDavid Chisnall param_type __p_; 54177a984708SDavid Chisnall 54187a984708SDavid Chisnallpublic: 54197a984708SDavid Chisnall // constructor and reset functions 54207a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 54217a984708SDavid Chisnall explicit chi_squared_distribution(result_type __n = 1) 54227a984708SDavid Chisnall : __p_(param_type(__n)) {} 54237a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 54247a984708SDavid Chisnall explicit chi_squared_distribution(const param_type& __p) 54257a984708SDavid Chisnall : __p_(__p) {} 54267a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 54277a984708SDavid Chisnall void reset() {} 54287a984708SDavid Chisnall 54297a984708SDavid Chisnall // generating functions 54307a984708SDavid Chisnall template<class _URNG> 54317a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 54327a984708SDavid Chisnall result_type operator()(_URNG& __g) 54337a984708SDavid Chisnall {return (*this)(__g, __p_);} 54347a984708SDavid Chisnall template<class _URNG> 54357a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 54367a984708SDavid Chisnall result_type operator()(_URNG& __g, const param_type& __p) 54377a984708SDavid Chisnall {return gamma_distribution<result_type>(__p.n() / 2, 2)(__g);} 54387a984708SDavid Chisnall 54397a984708SDavid Chisnall // property functions 54407a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 54417a984708SDavid Chisnall result_type n() const {return __p_.n();} 54427a984708SDavid Chisnall 54437a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 54447a984708SDavid Chisnall param_type param() const {return __p_;} 54457a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 54467a984708SDavid Chisnall void param(const param_type& __p) {__p_ = __p;} 54477a984708SDavid Chisnall 54487a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 54497a984708SDavid Chisnall result_type min() const {return 0;} 54507a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 54517a984708SDavid Chisnall result_type max() const {return numeric_limits<result_type>::infinity();} 54527a984708SDavid Chisnall 54537a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 54547a984708SDavid Chisnall bool operator==(const chi_squared_distribution& __x, 54557a984708SDavid Chisnall const chi_squared_distribution& __y) 54567a984708SDavid Chisnall {return __x.__p_ == __y.__p_;} 54577a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 54587a984708SDavid Chisnall bool operator!=(const chi_squared_distribution& __x, 54597a984708SDavid Chisnall const chi_squared_distribution& __y) 54607a984708SDavid Chisnall {return !(__x == __y);} 54617a984708SDavid Chisnall}; 54627a984708SDavid Chisnall 54637a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _RT> 54647a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 54657a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 54667a984708SDavid Chisnall const chi_squared_distribution<_RT>& __x) 54677a984708SDavid Chisnall{ 54681e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__os); 54697a984708SDavid Chisnall __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 54707a984708SDavid Chisnall ios_base::scientific); 54717a984708SDavid Chisnall __os << __x.n(); 54727a984708SDavid Chisnall return __os; 54737a984708SDavid Chisnall} 54747a984708SDavid Chisnall 54757a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _RT> 54767a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 54777a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 54787a984708SDavid Chisnall chi_squared_distribution<_RT>& __x) 54797a984708SDavid Chisnall{ 54807a984708SDavid Chisnall typedef chi_squared_distribution<_RT> _Eng; 54817a984708SDavid Chisnall typedef typename _Eng::result_type result_type; 54827a984708SDavid Chisnall typedef typename _Eng::param_type param_type; 54831e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__is); 54847a984708SDavid Chisnall __is.flags(ios_base::dec | ios_base::skipws); 54857a984708SDavid Chisnall result_type __n; 54867a984708SDavid Chisnall __is >> __n; 54877a984708SDavid Chisnall if (!__is.fail()) 54887a984708SDavid Chisnall __x.param(param_type(__n)); 54897a984708SDavid Chisnall return __is; 54907a984708SDavid Chisnall} 54917a984708SDavid Chisnall 54927a984708SDavid Chisnall// cauchy_distribution 54937a984708SDavid Chisnall 54947a984708SDavid Chisnalltemplate<class _RealType = double> 5495aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS cauchy_distribution 54967a984708SDavid Chisnall{ 54977a984708SDavid Chisnallpublic: 54987a984708SDavid Chisnall // types 54997a984708SDavid Chisnall typedef _RealType result_type; 55007a984708SDavid Chisnall 5501aed8d94eSDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 55027a984708SDavid Chisnall { 55037a984708SDavid Chisnall result_type __a_; 55047a984708SDavid Chisnall result_type __b_; 55057a984708SDavid Chisnall public: 55067a984708SDavid Chisnall typedef cauchy_distribution distribution_type; 55077a984708SDavid Chisnall 55087a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 55097a984708SDavid Chisnall explicit param_type(result_type __a = 0, result_type __b = 1) 55107a984708SDavid Chisnall : __a_(__a), __b_(__b) {} 55117a984708SDavid Chisnall 55127a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 55137a984708SDavid Chisnall result_type a() const {return __a_;} 55147a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 55157a984708SDavid Chisnall result_type b() const {return __b_;} 55167a984708SDavid Chisnall 55177a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 55187a984708SDavid Chisnall bool operator==(const param_type& __x, const param_type& __y) 55197a984708SDavid Chisnall {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} 55207a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 55217a984708SDavid Chisnall bool operator!=(const param_type& __x, const param_type& __y) 55227a984708SDavid Chisnall {return !(__x == __y);} 55237a984708SDavid Chisnall }; 55247a984708SDavid Chisnall 55257a984708SDavid Chisnallprivate: 55267a984708SDavid Chisnall param_type __p_; 55277a984708SDavid Chisnall 55287a984708SDavid Chisnallpublic: 55297a984708SDavid Chisnall // constructor and reset functions 55307a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 55317a984708SDavid Chisnall explicit cauchy_distribution(result_type __a = 0, result_type __b = 1) 55327a984708SDavid Chisnall : __p_(param_type(__a, __b)) {} 55337a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 55347a984708SDavid Chisnall explicit cauchy_distribution(const param_type& __p) 55357a984708SDavid Chisnall : __p_(__p) {} 55367a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 55377a984708SDavid Chisnall void reset() {} 55387a984708SDavid Chisnall 55397a984708SDavid Chisnall // generating functions 55407a984708SDavid Chisnall template<class _URNG> 55417a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 55427a984708SDavid Chisnall result_type operator()(_URNG& __g) 55437a984708SDavid Chisnall {return (*this)(__g, __p_);} 55449729cf09SDimitry Andric template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p); 55457a984708SDavid Chisnall 55467a984708SDavid Chisnall // property functions 55477a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 55487a984708SDavid Chisnall result_type a() const {return __p_.a();} 55497a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 55507a984708SDavid Chisnall result_type b() const {return __p_.b();} 55517a984708SDavid Chisnall 55527a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 55537a984708SDavid Chisnall param_type param() const {return __p_;} 55547a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 55557a984708SDavid Chisnall void param(const param_type& __p) {__p_ = __p;} 55567a984708SDavid Chisnall 55577a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 55587a984708SDavid Chisnall result_type min() const {return -numeric_limits<result_type>::infinity();} 55597a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 55607a984708SDavid Chisnall result_type max() const {return numeric_limits<result_type>::infinity();} 55617a984708SDavid Chisnall 55627a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 55637a984708SDavid Chisnall bool operator==(const cauchy_distribution& __x, 55647a984708SDavid Chisnall const cauchy_distribution& __y) 55657a984708SDavid Chisnall {return __x.__p_ == __y.__p_;} 55667a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 55677a984708SDavid Chisnall bool operator!=(const cauchy_distribution& __x, 55687a984708SDavid Chisnall const cauchy_distribution& __y) 55697a984708SDavid Chisnall {return !(__x == __y);} 55707a984708SDavid Chisnall}; 55717a984708SDavid Chisnall 55727a984708SDavid Chisnalltemplate <class _RealType> 55737a984708SDavid Chisnalltemplate<class _URNG> 55749729cf09SDimitry Andricinline 55757a984708SDavid Chisnall_RealType 55767a984708SDavid Chisnallcauchy_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 55777a984708SDavid Chisnall{ 55787a984708SDavid Chisnall uniform_real_distribution<result_type> __gen; 55797a984708SDavid Chisnall // purposefully let tan arg get as close to pi/2 as it wants, tan will return a finite 55807a984708SDavid Chisnall return __p.a() + __p.b() * _VSTD::tan(3.1415926535897932384626433832795 * __gen(__g)); 55817a984708SDavid Chisnall} 55827a984708SDavid Chisnall 55837a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _RT> 55847a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 55857a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 55867a984708SDavid Chisnall const cauchy_distribution<_RT>& __x) 55877a984708SDavid Chisnall{ 55881e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__os); 55897a984708SDavid Chisnall __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 55907a984708SDavid Chisnall ios_base::scientific); 55917a984708SDavid Chisnall _CharT __sp = __os.widen(' '); 55927a984708SDavid Chisnall __os.fill(__sp); 55937a984708SDavid Chisnall __os << __x.a() << __sp << __x.b(); 55947a984708SDavid Chisnall return __os; 55957a984708SDavid Chisnall} 55967a984708SDavid Chisnall 55977a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _RT> 55987a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 55997a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 56007a984708SDavid Chisnall cauchy_distribution<_RT>& __x) 56017a984708SDavid Chisnall{ 56027a984708SDavid Chisnall typedef cauchy_distribution<_RT> _Eng; 56037a984708SDavid Chisnall typedef typename _Eng::result_type result_type; 56047a984708SDavid Chisnall typedef typename _Eng::param_type param_type; 56051e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__is); 56067a984708SDavid Chisnall __is.flags(ios_base::dec | ios_base::skipws); 56077a984708SDavid Chisnall result_type __a; 56087a984708SDavid Chisnall result_type __b; 56097a984708SDavid Chisnall __is >> __a >> __b; 56107a984708SDavid Chisnall if (!__is.fail()) 56117a984708SDavid Chisnall __x.param(param_type(__a, __b)); 56127a984708SDavid Chisnall return __is; 56137a984708SDavid Chisnall} 56147a984708SDavid Chisnall 56157a984708SDavid Chisnall// fisher_f_distribution 56167a984708SDavid Chisnall 56177a984708SDavid Chisnalltemplate<class _RealType = double> 5618aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS fisher_f_distribution 56197a984708SDavid Chisnall{ 56207a984708SDavid Chisnallpublic: 56217a984708SDavid Chisnall // types 56227a984708SDavid Chisnall typedef _RealType result_type; 56237a984708SDavid Chisnall 5624aed8d94eSDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 56257a984708SDavid Chisnall { 56267a984708SDavid Chisnall result_type __m_; 56277a984708SDavid Chisnall result_type __n_; 56287a984708SDavid Chisnall public: 56297a984708SDavid Chisnall typedef fisher_f_distribution distribution_type; 56307a984708SDavid Chisnall 56317a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 56327a984708SDavid Chisnall explicit param_type(result_type __m = 1, result_type __n = 1) 56337a984708SDavid Chisnall : __m_(__m), __n_(__n) {} 56347a984708SDavid Chisnall 56357a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 56367a984708SDavid Chisnall result_type m() const {return __m_;} 56377a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 56387a984708SDavid Chisnall result_type n() const {return __n_;} 56397a984708SDavid Chisnall 56407a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 56417a984708SDavid Chisnall bool operator==(const param_type& __x, const param_type& __y) 56427a984708SDavid Chisnall {return __x.__m_ == __y.__m_ && __x.__n_ == __y.__n_;} 56437a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 56447a984708SDavid Chisnall bool operator!=(const param_type& __x, const param_type& __y) 56457a984708SDavid Chisnall {return !(__x == __y);} 56467a984708SDavid Chisnall }; 56477a984708SDavid Chisnall 56487a984708SDavid Chisnallprivate: 56497a984708SDavid Chisnall param_type __p_; 56507a984708SDavid Chisnall 56517a984708SDavid Chisnallpublic: 56527a984708SDavid Chisnall // constructor and reset functions 56537a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 56547a984708SDavid Chisnall explicit fisher_f_distribution(result_type __m = 1, result_type __n = 1) 56557a984708SDavid Chisnall : __p_(param_type(__m, __n)) {} 56567a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 56577a984708SDavid Chisnall explicit fisher_f_distribution(const param_type& __p) 56587a984708SDavid Chisnall : __p_(__p) {} 56597a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 56607a984708SDavid Chisnall void reset() {} 56617a984708SDavid Chisnall 56627a984708SDavid Chisnall // generating functions 56637a984708SDavid Chisnall template<class _URNG> 56647a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 56657a984708SDavid Chisnall result_type operator()(_URNG& __g) 56667a984708SDavid Chisnall {return (*this)(__g, __p_);} 56677a984708SDavid Chisnall template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 56687a984708SDavid Chisnall 56697a984708SDavid Chisnall // property functions 56707a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 56717a984708SDavid Chisnall result_type m() const {return __p_.m();} 56727a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 56737a984708SDavid Chisnall result_type n() const {return __p_.n();} 56747a984708SDavid Chisnall 56757a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 56767a984708SDavid Chisnall param_type param() const {return __p_;} 56777a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 56787a984708SDavid Chisnall void param(const param_type& __p) {__p_ = __p;} 56797a984708SDavid Chisnall 56807a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 56817a984708SDavid Chisnall result_type min() const {return 0;} 56827a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 56837a984708SDavid Chisnall result_type max() const {return numeric_limits<result_type>::infinity();} 56847a984708SDavid Chisnall 56857a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 56867a984708SDavid Chisnall bool operator==(const fisher_f_distribution& __x, 56877a984708SDavid Chisnall const fisher_f_distribution& __y) 56887a984708SDavid Chisnall {return __x.__p_ == __y.__p_;} 56897a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 56907a984708SDavid Chisnall bool operator!=(const fisher_f_distribution& __x, 56917a984708SDavid Chisnall const fisher_f_distribution& __y) 56927a984708SDavid Chisnall {return !(__x == __y);} 56937a984708SDavid Chisnall}; 56947a984708SDavid Chisnall 56957a984708SDavid Chisnalltemplate <class _RealType> 56967a984708SDavid Chisnalltemplate<class _URNG> 56977a984708SDavid Chisnall_RealType 56987a984708SDavid Chisnallfisher_f_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 56997a984708SDavid Chisnall{ 57007a984708SDavid Chisnall gamma_distribution<result_type> __gdm(__p.m() * result_type(.5)); 57017a984708SDavid Chisnall gamma_distribution<result_type> __gdn(__p.n() * result_type(.5)); 57027a984708SDavid Chisnall return __p.n() * __gdm(__g) / (__p.m() * __gdn(__g)); 57037a984708SDavid Chisnall} 57047a984708SDavid Chisnall 57057a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _RT> 57067a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 57077a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 57087a984708SDavid Chisnall const fisher_f_distribution<_RT>& __x) 57097a984708SDavid Chisnall{ 57101e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__os); 57117a984708SDavid Chisnall __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 57127a984708SDavid Chisnall ios_base::scientific); 57137a984708SDavid Chisnall _CharT __sp = __os.widen(' '); 57147a984708SDavid Chisnall __os.fill(__sp); 57157a984708SDavid Chisnall __os << __x.m() << __sp << __x.n(); 57167a984708SDavid Chisnall return __os; 57177a984708SDavid Chisnall} 57187a984708SDavid Chisnall 57197a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _RT> 57207a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 57217a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 57227a984708SDavid Chisnall fisher_f_distribution<_RT>& __x) 57237a984708SDavid Chisnall{ 57247a984708SDavid Chisnall typedef fisher_f_distribution<_RT> _Eng; 57257a984708SDavid Chisnall typedef typename _Eng::result_type result_type; 57267a984708SDavid Chisnall typedef typename _Eng::param_type param_type; 57271e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__is); 57287a984708SDavid Chisnall __is.flags(ios_base::dec | ios_base::skipws); 57297a984708SDavid Chisnall result_type __m; 57307a984708SDavid Chisnall result_type __n; 57317a984708SDavid Chisnall __is >> __m >> __n; 57327a984708SDavid Chisnall if (!__is.fail()) 57337a984708SDavid Chisnall __x.param(param_type(__m, __n)); 57347a984708SDavid Chisnall return __is; 57357a984708SDavid Chisnall} 57367a984708SDavid Chisnall 57377a984708SDavid Chisnall// student_t_distribution 57387a984708SDavid Chisnall 57397a984708SDavid Chisnalltemplate<class _RealType = double> 5740aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS student_t_distribution 57417a984708SDavid Chisnall{ 57427a984708SDavid Chisnallpublic: 57437a984708SDavid Chisnall // types 57447a984708SDavid Chisnall typedef _RealType result_type; 57457a984708SDavid Chisnall 5746aed8d94eSDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 57477a984708SDavid Chisnall { 57487a984708SDavid Chisnall result_type __n_; 57497a984708SDavid Chisnall public: 57507a984708SDavid Chisnall typedef student_t_distribution distribution_type; 57517a984708SDavid Chisnall 57527a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 57537a984708SDavid Chisnall explicit param_type(result_type __n = 1) : __n_(__n) {} 57547a984708SDavid Chisnall 57557a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 57567a984708SDavid Chisnall result_type n() const {return __n_;} 57577a984708SDavid Chisnall 57587a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 57597a984708SDavid Chisnall bool operator==(const param_type& __x, const param_type& __y) 57607a984708SDavid Chisnall {return __x.__n_ == __y.__n_;} 57617a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 57627a984708SDavid Chisnall bool operator!=(const param_type& __x, const param_type& __y) 57637a984708SDavid Chisnall {return !(__x == __y);} 57647a984708SDavid Chisnall }; 57657a984708SDavid Chisnall 57667a984708SDavid Chisnallprivate: 57677a984708SDavid Chisnall param_type __p_; 57687a984708SDavid Chisnall normal_distribution<result_type> __nd_; 57697a984708SDavid Chisnall 57707a984708SDavid Chisnallpublic: 57717a984708SDavid Chisnall // constructor and reset functions 57727a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 57737a984708SDavid Chisnall explicit student_t_distribution(result_type __n = 1) 57747a984708SDavid Chisnall : __p_(param_type(__n)) {} 57757a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 57767a984708SDavid Chisnall explicit student_t_distribution(const param_type& __p) 57777a984708SDavid Chisnall : __p_(__p) {} 57787a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 57797a984708SDavid Chisnall void reset() {__nd_.reset();} 57807a984708SDavid Chisnall 57817a984708SDavid Chisnall // generating functions 57827a984708SDavid Chisnall template<class _URNG> 57837a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 57847a984708SDavid Chisnall result_type operator()(_URNG& __g) 57857a984708SDavid Chisnall {return (*this)(__g, __p_);} 57867a984708SDavid Chisnall template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 57877a984708SDavid Chisnall 57887a984708SDavid Chisnall // property functions 57897a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 57907a984708SDavid Chisnall result_type n() const {return __p_.n();} 57917a984708SDavid Chisnall 57927a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 57937a984708SDavid Chisnall param_type param() const {return __p_;} 57947a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 57957a984708SDavid Chisnall void param(const param_type& __p) {__p_ = __p;} 57967a984708SDavid Chisnall 57977a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 57987a984708SDavid Chisnall result_type min() const {return -numeric_limits<result_type>::infinity();} 57997a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 58007a984708SDavid Chisnall result_type max() const {return numeric_limits<result_type>::infinity();} 58017a984708SDavid Chisnall 58027a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 58037a984708SDavid Chisnall bool operator==(const student_t_distribution& __x, 58047a984708SDavid Chisnall const student_t_distribution& __y) 58057a984708SDavid Chisnall {return __x.__p_ == __y.__p_;} 58067a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 58077a984708SDavid Chisnall bool operator!=(const student_t_distribution& __x, 58087a984708SDavid Chisnall const student_t_distribution& __y) 58097a984708SDavid Chisnall {return !(__x == __y);} 58107a984708SDavid Chisnall}; 58117a984708SDavid Chisnall 58127a984708SDavid Chisnalltemplate <class _RealType> 58137a984708SDavid Chisnalltemplate<class _URNG> 58147a984708SDavid Chisnall_RealType 58157a984708SDavid Chisnallstudent_t_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 58167a984708SDavid Chisnall{ 58177a984708SDavid Chisnall gamma_distribution<result_type> __gd(__p.n() * .5, 2); 58187a984708SDavid Chisnall return __nd_(__g) * _VSTD::sqrt(__p.n()/__gd(__g)); 58197a984708SDavid Chisnall} 58207a984708SDavid Chisnall 58217a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _RT> 58227a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 58237a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 58247a984708SDavid Chisnall const student_t_distribution<_RT>& __x) 58257a984708SDavid Chisnall{ 58261e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__os); 58277a984708SDavid Chisnall __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 58287a984708SDavid Chisnall ios_base::scientific); 58297a984708SDavid Chisnall __os << __x.n(); 58307a984708SDavid Chisnall return __os; 58317a984708SDavid Chisnall} 58327a984708SDavid Chisnall 58337a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _RT> 58347a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 58357a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 58367a984708SDavid Chisnall student_t_distribution<_RT>& __x) 58377a984708SDavid Chisnall{ 58387a984708SDavid Chisnall typedef student_t_distribution<_RT> _Eng; 58397a984708SDavid Chisnall typedef typename _Eng::result_type result_type; 58407a984708SDavid Chisnall typedef typename _Eng::param_type param_type; 58411e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__is); 58427a984708SDavid Chisnall __is.flags(ios_base::dec | ios_base::skipws); 58437a984708SDavid Chisnall result_type __n; 58447a984708SDavid Chisnall __is >> __n; 58457a984708SDavid Chisnall if (!__is.fail()) 58467a984708SDavid Chisnall __x.param(param_type(__n)); 58477a984708SDavid Chisnall return __is; 58487a984708SDavid Chisnall} 58497a984708SDavid Chisnall 58507a984708SDavid Chisnall// discrete_distribution 58517a984708SDavid Chisnall 58527a984708SDavid Chisnalltemplate<class _IntType = int> 5853aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS discrete_distribution 58547a984708SDavid Chisnall{ 58557a984708SDavid Chisnallpublic: 58567a984708SDavid Chisnall // types 58577a984708SDavid Chisnall typedef _IntType result_type; 58587a984708SDavid Chisnall 5859aed8d94eSDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 58607a984708SDavid Chisnall { 58617a984708SDavid Chisnall vector<double> __p_; 58627a984708SDavid Chisnall public: 58637a984708SDavid Chisnall typedef discrete_distribution distribution_type; 58647a984708SDavid Chisnall 58657a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 58667a984708SDavid Chisnall param_type() {} 58677a984708SDavid Chisnall template<class _InputIterator> 58687a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 58697a984708SDavid Chisnall param_type(_InputIterator __f, _InputIterator __l) 58707a984708SDavid Chisnall : __p_(__f, __l) {__init();} 5871540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 58727a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 58737a984708SDavid Chisnall param_type(initializer_list<double> __wl) 58747a984708SDavid Chisnall : __p_(__wl.begin(), __wl.end()) {__init();} 5875540d2a8bSDimitry Andric#endif // _LIBCPP_CXX03_LANG 58767a984708SDavid Chisnall template<class _UnaryOperation> 58777a984708SDavid Chisnall param_type(size_t __nw, double __xmin, double __xmax, 58787a984708SDavid Chisnall _UnaryOperation __fw); 58797a984708SDavid Chisnall 58807a984708SDavid Chisnall vector<double> probabilities() const; 58817a984708SDavid Chisnall 58827a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 58837a984708SDavid Chisnall bool operator==(const param_type& __x, const param_type& __y) 58847a984708SDavid Chisnall {return __x.__p_ == __y.__p_;} 58857a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 58867a984708SDavid Chisnall bool operator!=(const param_type& __x, const param_type& __y) 58877a984708SDavid Chisnall {return !(__x == __y);} 58887a984708SDavid Chisnall 58897a984708SDavid Chisnall private: 58907a984708SDavid Chisnall void __init(); 58917a984708SDavid Chisnall 58927a984708SDavid Chisnall friend class discrete_distribution; 58937a984708SDavid Chisnall 58947a984708SDavid Chisnall template <class _CharT, class _Traits, class _IT> 58957a984708SDavid Chisnall friend 58967a984708SDavid Chisnall basic_ostream<_CharT, _Traits>& 58977a984708SDavid Chisnall operator<<(basic_ostream<_CharT, _Traits>& __os, 58987a984708SDavid Chisnall const discrete_distribution<_IT>& __x); 58997a984708SDavid Chisnall 59007a984708SDavid Chisnall template <class _CharT, class _Traits, class _IT> 59017a984708SDavid Chisnall friend 59027a984708SDavid Chisnall basic_istream<_CharT, _Traits>& 59037a984708SDavid Chisnall operator>>(basic_istream<_CharT, _Traits>& __is, 59047a984708SDavid Chisnall discrete_distribution<_IT>& __x); 59057a984708SDavid Chisnall }; 59067a984708SDavid Chisnall 59077a984708SDavid Chisnallprivate: 59087a984708SDavid Chisnall param_type __p_; 59097a984708SDavid Chisnall 59107a984708SDavid Chisnallpublic: 59117a984708SDavid Chisnall // constructor and reset functions 59127a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 59137a984708SDavid Chisnall discrete_distribution() {} 59147a984708SDavid Chisnall template<class _InputIterator> 59157a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 59167a984708SDavid Chisnall discrete_distribution(_InputIterator __f, _InputIterator __l) 59177a984708SDavid Chisnall : __p_(__f, __l) {} 5918540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 59197a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 59207a984708SDavid Chisnall discrete_distribution(initializer_list<double> __wl) 59217a984708SDavid Chisnall : __p_(__wl) {} 5922540d2a8bSDimitry Andric#endif // _LIBCPP_CXX03_LANG 59237a984708SDavid Chisnall template<class _UnaryOperation> 59247a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 59257a984708SDavid Chisnall discrete_distribution(size_t __nw, double __xmin, double __xmax, 59267a984708SDavid Chisnall _UnaryOperation __fw) 59277a984708SDavid Chisnall : __p_(__nw, __xmin, __xmax, __fw) {} 59287a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 59294f7ab58eSDimitry Andric explicit discrete_distribution(const param_type& __p) 59307a984708SDavid Chisnall : __p_(__p) {} 59317a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 59327a984708SDavid Chisnall void reset() {} 59337a984708SDavid Chisnall 59347a984708SDavid Chisnall // generating functions 59357a984708SDavid Chisnall template<class _URNG> 59367a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 59377a984708SDavid Chisnall result_type operator()(_URNG& __g) 59387a984708SDavid Chisnall {return (*this)(__g, __p_);} 59397a984708SDavid Chisnall template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 59407a984708SDavid Chisnall 59417a984708SDavid Chisnall // property functions 59427a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 59437a984708SDavid Chisnall vector<double> probabilities() const {return __p_.probabilities();} 59447a984708SDavid Chisnall 59457a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 59467a984708SDavid Chisnall param_type param() const {return __p_;} 59477a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 59487a984708SDavid Chisnall void param(const param_type& __p) {__p_ = __p;} 59497a984708SDavid Chisnall 59507a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 59517a984708SDavid Chisnall result_type min() const {return 0;} 59527a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 59537a984708SDavid Chisnall result_type max() const {return __p_.__p_.size();} 59547a984708SDavid Chisnall 59557a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 59567a984708SDavid Chisnall bool operator==(const discrete_distribution& __x, 59577a984708SDavid Chisnall const discrete_distribution& __y) 59587a984708SDavid Chisnall {return __x.__p_ == __y.__p_;} 59597a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 59607a984708SDavid Chisnall bool operator!=(const discrete_distribution& __x, 59617a984708SDavid Chisnall const discrete_distribution& __y) 59627a984708SDavid Chisnall {return !(__x == __y);} 59637a984708SDavid Chisnall 59647a984708SDavid Chisnall template <class _CharT, class _Traits, class _IT> 59657a984708SDavid Chisnall friend 59667a984708SDavid Chisnall basic_ostream<_CharT, _Traits>& 59677a984708SDavid Chisnall operator<<(basic_ostream<_CharT, _Traits>& __os, 59687a984708SDavid Chisnall const discrete_distribution<_IT>& __x); 59697a984708SDavid Chisnall 59707a984708SDavid Chisnall template <class _CharT, class _Traits, class _IT> 59717a984708SDavid Chisnall friend 59727a984708SDavid Chisnall basic_istream<_CharT, _Traits>& 59737a984708SDavid Chisnall operator>>(basic_istream<_CharT, _Traits>& __is, 59747a984708SDavid Chisnall discrete_distribution<_IT>& __x); 59757a984708SDavid Chisnall}; 59767a984708SDavid Chisnall 59777a984708SDavid Chisnalltemplate<class _IntType> 59787a984708SDavid Chisnalltemplate<class _UnaryOperation> 59797a984708SDavid Chisnalldiscrete_distribution<_IntType>::param_type::param_type(size_t __nw, 59807a984708SDavid Chisnall double __xmin, 59817a984708SDavid Chisnall double __xmax, 59827a984708SDavid Chisnall _UnaryOperation __fw) 59837a984708SDavid Chisnall{ 59847a984708SDavid Chisnall if (__nw > 1) 59857a984708SDavid Chisnall { 59867a984708SDavid Chisnall __p_.reserve(__nw - 1); 59877a984708SDavid Chisnall double __d = (__xmax - __xmin) / __nw; 59887a984708SDavid Chisnall double __d2 = __d / 2; 59897a984708SDavid Chisnall for (size_t __k = 0; __k < __nw; ++__k) 59907a984708SDavid Chisnall __p_.push_back(__fw(__xmin + __k * __d + __d2)); 59917a984708SDavid Chisnall __init(); 59927a984708SDavid Chisnall } 59937a984708SDavid Chisnall} 59947a984708SDavid Chisnall 59957a984708SDavid Chisnalltemplate<class _IntType> 59967a984708SDavid Chisnallvoid 59977a984708SDavid Chisnalldiscrete_distribution<_IntType>::param_type::__init() 59987a984708SDavid Chisnall{ 59997a984708SDavid Chisnall if (!__p_.empty()) 60007a984708SDavid Chisnall { 60017a984708SDavid Chisnall if (__p_.size() > 1) 60027a984708SDavid Chisnall { 60037a984708SDavid Chisnall double __s = _VSTD::accumulate(__p_.begin(), __p_.end(), 0.0); 60047a984708SDavid Chisnall for (_VSTD::vector<double>::iterator __i = __p_.begin(), __e = __p_.end(); 60057a984708SDavid Chisnall __i < __e; ++__i) 60067a984708SDavid Chisnall *__i /= __s; 60077a984708SDavid Chisnall vector<double> __t(__p_.size() - 1); 60087a984708SDavid Chisnall _VSTD::partial_sum(__p_.begin(), __p_.end() - 1, __t.begin()); 60097a984708SDavid Chisnall swap(__p_, __t); 60107a984708SDavid Chisnall } 60117a984708SDavid Chisnall else 60127a984708SDavid Chisnall { 60137a984708SDavid Chisnall __p_.clear(); 60147a984708SDavid Chisnall __p_.shrink_to_fit(); 60157a984708SDavid Chisnall } 60167a984708SDavid Chisnall } 60177a984708SDavid Chisnall} 60187a984708SDavid Chisnall 60197a984708SDavid Chisnalltemplate<class _IntType> 60207a984708SDavid Chisnallvector<double> 60217a984708SDavid Chisnalldiscrete_distribution<_IntType>::param_type::probabilities() const 60227a984708SDavid Chisnall{ 60237a984708SDavid Chisnall size_t __n = __p_.size(); 60247a984708SDavid Chisnall _VSTD::vector<double> __p(__n+1); 60257a984708SDavid Chisnall _VSTD::adjacent_difference(__p_.begin(), __p_.end(), __p.begin()); 60267a984708SDavid Chisnall if (__n > 0) 60277a984708SDavid Chisnall __p[__n] = 1 - __p_[__n-1]; 60287a984708SDavid Chisnall else 60297a984708SDavid Chisnall __p[0] = 1; 60307a984708SDavid Chisnall return __p; 60317a984708SDavid Chisnall} 60327a984708SDavid Chisnall 60337a984708SDavid Chisnalltemplate<class _IntType> 60347a984708SDavid Chisnalltemplate<class _URNG> 60357a984708SDavid Chisnall_IntType 60367a984708SDavid Chisnalldiscrete_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p) 60377a984708SDavid Chisnall{ 60387a984708SDavid Chisnall uniform_real_distribution<double> __gen; 60397a984708SDavid Chisnall return static_cast<_IntType>( 60407a984708SDavid Chisnall _VSTD::upper_bound(__p.__p_.begin(), __p.__p_.end(), __gen(__g)) - 60417a984708SDavid Chisnall __p.__p_.begin()); 60427a984708SDavid Chisnall} 60437a984708SDavid Chisnall 60447a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _IT> 60457a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 60467a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 60477a984708SDavid Chisnall const discrete_distribution<_IT>& __x) 60487a984708SDavid Chisnall{ 60491e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__os); 60507a984708SDavid Chisnall __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 60517a984708SDavid Chisnall ios_base::scientific); 60527a984708SDavid Chisnall _CharT __sp = __os.widen(' '); 60537a984708SDavid Chisnall __os.fill(__sp); 60547a984708SDavid Chisnall size_t __n = __x.__p_.__p_.size(); 60557a984708SDavid Chisnall __os << __n; 60567a984708SDavid Chisnall for (size_t __i = 0; __i < __n; ++__i) 60577a984708SDavid Chisnall __os << __sp << __x.__p_.__p_[__i]; 60587a984708SDavid Chisnall return __os; 60597a984708SDavid Chisnall} 60607a984708SDavid Chisnall 60617a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _IT> 60627a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 60637a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 60647a984708SDavid Chisnall discrete_distribution<_IT>& __x) 60657a984708SDavid Chisnall{ 60661e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__is); 60677a984708SDavid Chisnall __is.flags(ios_base::dec | ios_base::skipws); 60687a984708SDavid Chisnall size_t __n; 60697a984708SDavid Chisnall __is >> __n; 60707a984708SDavid Chisnall vector<double> __p(__n); 60717a984708SDavid Chisnall for (size_t __i = 0; __i < __n; ++__i) 60727a984708SDavid Chisnall __is >> __p[__i]; 60737a984708SDavid Chisnall if (!__is.fail()) 60747a984708SDavid Chisnall swap(__x.__p_.__p_, __p); 60757a984708SDavid Chisnall return __is; 60767a984708SDavid Chisnall} 60777a984708SDavid Chisnall 60787a984708SDavid Chisnall// piecewise_constant_distribution 60797a984708SDavid Chisnall 60807a984708SDavid Chisnalltemplate<class _RealType = double> 6081aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS piecewise_constant_distribution 60827a984708SDavid Chisnall{ 60837a984708SDavid Chisnallpublic: 60847a984708SDavid Chisnall // types 60857a984708SDavid Chisnall typedef _RealType result_type; 60867a984708SDavid Chisnall 6087aed8d94eSDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 60887a984708SDavid Chisnall { 60897a984708SDavid Chisnall vector<result_type> __b_; 60907a984708SDavid Chisnall vector<result_type> __densities_; 60917a984708SDavid Chisnall vector<result_type> __areas_; 60927a984708SDavid Chisnall public: 60937a984708SDavid Chisnall typedef piecewise_constant_distribution distribution_type; 60947a984708SDavid Chisnall 60957a984708SDavid Chisnall param_type(); 60967a984708SDavid Chisnall template<class _InputIteratorB, class _InputIteratorW> 60977a984708SDavid Chisnall param_type(_InputIteratorB __fB, _InputIteratorB __lB, 60987a984708SDavid Chisnall _InputIteratorW __fW); 6099540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 61007a984708SDavid Chisnall template<class _UnaryOperation> 61017a984708SDavid Chisnall param_type(initializer_list<result_type> __bl, _UnaryOperation __fw); 6102540d2a8bSDimitry Andric#endif // _LIBCPP_CXX03_LANG 61037a984708SDavid Chisnall template<class _UnaryOperation> 61047a984708SDavid Chisnall param_type(size_t __nw, result_type __xmin, result_type __xmax, 61057a984708SDavid Chisnall _UnaryOperation __fw); 61067a984708SDavid Chisnall param_type & operator=(const param_type& __rhs); 61077a984708SDavid Chisnall 61087a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 61097a984708SDavid Chisnall vector<result_type> intervals() const {return __b_;} 61107a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 61117a984708SDavid Chisnall vector<result_type> densities() const {return __densities_;} 61127a984708SDavid Chisnall 61137a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 61147a984708SDavid Chisnall bool operator==(const param_type& __x, const param_type& __y) 61157a984708SDavid Chisnall {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;} 61167a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 61177a984708SDavid Chisnall bool operator!=(const param_type& __x, const param_type& __y) 61187a984708SDavid Chisnall {return !(__x == __y);} 61197a984708SDavid Chisnall 61207a984708SDavid Chisnall private: 61217a984708SDavid Chisnall void __init(); 61227a984708SDavid Chisnall 61237a984708SDavid Chisnall friend class piecewise_constant_distribution; 61247a984708SDavid Chisnall 61257a984708SDavid Chisnall template <class _CharT, class _Traits, class _RT> 61267a984708SDavid Chisnall friend 61277a984708SDavid Chisnall basic_ostream<_CharT, _Traits>& 61287a984708SDavid Chisnall operator<<(basic_ostream<_CharT, _Traits>& __os, 61297a984708SDavid Chisnall const piecewise_constant_distribution<_RT>& __x); 61307a984708SDavid Chisnall 61317a984708SDavid Chisnall template <class _CharT, class _Traits, class _RT> 61327a984708SDavid Chisnall friend 61337a984708SDavid Chisnall basic_istream<_CharT, _Traits>& 61347a984708SDavid Chisnall operator>>(basic_istream<_CharT, _Traits>& __is, 61357a984708SDavid Chisnall piecewise_constant_distribution<_RT>& __x); 61367a984708SDavid Chisnall }; 61377a984708SDavid Chisnall 61387a984708SDavid Chisnallprivate: 61397a984708SDavid Chisnall param_type __p_; 61407a984708SDavid Chisnall 61417a984708SDavid Chisnallpublic: 61427a984708SDavid Chisnall // constructor and reset functions 61437a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 61447a984708SDavid Chisnall piecewise_constant_distribution() {} 61457a984708SDavid Chisnall template<class _InputIteratorB, class _InputIteratorW> 61467a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 61477a984708SDavid Chisnall piecewise_constant_distribution(_InputIteratorB __fB, 61487a984708SDavid Chisnall _InputIteratorB __lB, 61497a984708SDavid Chisnall _InputIteratorW __fW) 61507a984708SDavid Chisnall : __p_(__fB, __lB, __fW) {} 61517a984708SDavid Chisnall 6152540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 61537a984708SDavid Chisnall template<class _UnaryOperation> 61547a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 61557a984708SDavid Chisnall piecewise_constant_distribution(initializer_list<result_type> __bl, 61567a984708SDavid Chisnall _UnaryOperation __fw) 61577a984708SDavid Chisnall : __p_(__bl, __fw) {} 6158540d2a8bSDimitry Andric#endif // _LIBCPP_CXX03_LANG 61597a984708SDavid Chisnall 61607a984708SDavid Chisnall template<class _UnaryOperation> 61617a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 61627a984708SDavid Chisnall piecewise_constant_distribution(size_t __nw, result_type __xmin, 61637a984708SDavid Chisnall result_type __xmax, _UnaryOperation __fw) 61647a984708SDavid Chisnall : __p_(__nw, __xmin, __xmax, __fw) {} 61657a984708SDavid Chisnall 61667a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 61677a984708SDavid Chisnall explicit piecewise_constant_distribution(const param_type& __p) 61687a984708SDavid Chisnall : __p_(__p) {} 61697a984708SDavid Chisnall 61707a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 61717a984708SDavid Chisnall void reset() {} 61727a984708SDavid Chisnall 61737a984708SDavid Chisnall // generating functions 61747a984708SDavid Chisnall template<class _URNG> 61757a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 61767a984708SDavid Chisnall result_type operator()(_URNG& __g) 61777a984708SDavid Chisnall {return (*this)(__g, __p_);} 61787a984708SDavid Chisnall template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 61797a984708SDavid Chisnall 61807a984708SDavid Chisnall // property functions 61817a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 61827a984708SDavid Chisnall vector<result_type> intervals() const {return __p_.intervals();} 61837a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 61847a984708SDavid Chisnall vector<result_type> densities() const {return __p_.densities();} 61857a984708SDavid Chisnall 61867a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 61877a984708SDavid Chisnall param_type param() const {return __p_;} 61887a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 61897a984708SDavid Chisnall void param(const param_type& __p) {__p_ = __p;} 61907a984708SDavid Chisnall 61917a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 61927a984708SDavid Chisnall result_type min() const {return __p_.__b_.front();} 61937a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 61947a984708SDavid Chisnall result_type max() const {return __p_.__b_.back();} 61957a984708SDavid Chisnall 61967a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 61977a984708SDavid Chisnall bool operator==(const piecewise_constant_distribution& __x, 61987a984708SDavid Chisnall const piecewise_constant_distribution& __y) 61997a984708SDavid Chisnall {return __x.__p_ == __y.__p_;} 62007a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 62017a984708SDavid Chisnall bool operator!=(const piecewise_constant_distribution& __x, 62027a984708SDavid Chisnall const piecewise_constant_distribution& __y) 62037a984708SDavid Chisnall {return !(__x == __y);} 62047a984708SDavid Chisnall 62057a984708SDavid Chisnall template <class _CharT, class _Traits, class _RT> 62067a984708SDavid Chisnall friend 62077a984708SDavid Chisnall basic_ostream<_CharT, _Traits>& 62087a984708SDavid Chisnall operator<<(basic_ostream<_CharT, _Traits>& __os, 62097a984708SDavid Chisnall const piecewise_constant_distribution<_RT>& __x); 62107a984708SDavid Chisnall 62117a984708SDavid Chisnall template <class _CharT, class _Traits, class _RT> 62127a984708SDavid Chisnall friend 62137a984708SDavid Chisnall basic_istream<_CharT, _Traits>& 62147a984708SDavid Chisnall operator>>(basic_istream<_CharT, _Traits>& __is, 62157a984708SDavid Chisnall piecewise_constant_distribution<_RT>& __x); 62167a984708SDavid Chisnall}; 62177a984708SDavid Chisnall 62187a984708SDavid Chisnalltemplate<class _RealType> 62197a984708SDavid Chisnalltypename piecewise_constant_distribution<_RealType>::param_type & 62207a984708SDavid Chisnallpiecewise_constant_distribution<_RealType>::param_type::operator= 62217a984708SDavid Chisnall (const param_type& __rhs) 62227a984708SDavid Chisnall{ 62237a984708SDavid Chisnall// These can throw 62247a984708SDavid Chisnall __b_.reserve (__rhs.__b_.size ()); 62257a984708SDavid Chisnall __densities_.reserve(__rhs.__densities_.size()); 62267a984708SDavid Chisnall __areas_.reserve (__rhs.__areas_.size()); 62277a984708SDavid Chisnall 62287a984708SDavid Chisnall// These can not throw 62297a984708SDavid Chisnall __b_ = __rhs.__b_; 62307a984708SDavid Chisnall __densities_ = __rhs.__densities_; 62317a984708SDavid Chisnall __areas_ = __rhs.__areas_; 62327a984708SDavid Chisnall return *this; 62337a984708SDavid Chisnall} 62347a984708SDavid Chisnall 62357a984708SDavid Chisnalltemplate<class _RealType> 62367a984708SDavid Chisnallvoid 62377a984708SDavid Chisnallpiecewise_constant_distribution<_RealType>::param_type::__init() 62387a984708SDavid Chisnall{ 62397a984708SDavid Chisnall // __densities_ contains non-normalized areas 62407a984708SDavid Chisnall result_type __total_area = _VSTD::accumulate(__densities_.begin(), 62417a984708SDavid Chisnall __densities_.end(), 62427a984708SDavid Chisnall result_type()); 62437a984708SDavid Chisnall for (size_t __i = 0; __i < __densities_.size(); ++__i) 62447a984708SDavid Chisnall __densities_[__i] /= __total_area; 62457a984708SDavid Chisnall // __densities_ contains normalized areas 62467a984708SDavid Chisnall __areas_.assign(__densities_.size(), result_type()); 62477a984708SDavid Chisnall _VSTD::partial_sum(__densities_.begin(), __densities_.end() - 1, 62487a984708SDavid Chisnall __areas_.begin() + 1); 62497a984708SDavid Chisnall // __areas_ contains partial sums of normalized areas: [0, __densities_ - 1] 62507a984708SDavid Chisnall __densities_.back() = 1 - __areas_.back(); // correct round off error 62517a984708SDavid Chisnall for (size_t __i = 0; __i < __densities_.size(); ++__i) 62527a984708SDavid Chisnall __densities_[__i] /= (__b_[__i+1] - __b_[__i]); 62537a984708SDavid Chisnall // __densities_ now contains __densities_ 62547a984708SDavid Chisnall} 62557a984708SDavid Chisnall 62567a984708SDavid Chisnalltemplate<class _RealType> 62577a984708SDavid Chisnallpiecewise_constant_distribution<_RealType>::param_type::param_type() 62587a984708SDavid Chisnall : __b_(2), 62597a984708SDavid Chisnall __densities_(1, 1.0), 62607a984708SDavid Chisnall __areas_(1, 0.0) 62617a984708SDavid Chisnall{ 62627a984708SDavid Chisnall __b_[1] = 1; 62637a984708SDavid Chisnall} 62647a984708SDavid Chisnall 62657a984708SDavid Chisnalltemplate<class _RealType> 62667a984708SDavid Chisnalltemplate<class _InputIteratorB, class _InputIteratorW> 62677a984708SDavid Chisnallpiecewise_constant_distribution<_RealType>::param_type::param_type( 62687a984708SDavid Chisnall _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW) 62697a984708SDavid Chisnall : __b_(__fB, __lB) 62707a984708SDavid Chisnall{ 62717a984708SDavid Chisnall if (__b_.size() < 2) 62727a984708SDavid Chisnall { 62737a984708SDavid Chisnall __b_.resize(2); 62747a984708SDavid Chisnall __b_[0] = 0; 62757a984708SDavid Chisnall __b_[1] = 1; 62767a984708SDavid Chisnall __densities_.assign(1, 1.0); 62777a984708SDavid Chisnall __areas_.assign(1, 0.0); 62787a984708SDavid Chisnall } 62797a984708SDavid Chisnall else 62807a984708SDavid Chisnall { 62817a984708SDavid Chisnall __densities_.reserve(__b_.size() - 1); 62827a984708SDavid Chisnall for (size_t __i = 0; __i < __b_.size() - 1; ++__i, ++__fW) 62837a984708SDavid Chisnall __densities_.push_back(*__fW); 62847a984708SDavid Chisnall __init(); 62857a984708SDavid Chisnall } 62867a984708SDavid Chisnall} 62877a984708SDavid Chisnall 6288540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 62897a984708SDavid Chisnall 62907a984708SDavid Chisnalltemplate<class _RealType> 62917a984708SDavid Chisnalltemplate<class _UnaryOperation> 62927a984708SDavid Chisnallpiecewise_constant_distribution<_RealType>::param_type::param_type( 62937a984708SDavid Chisnall initializer_list<result_type> __bl, _UnaryOperation __fw) 62947a984708SDavid Chisnall : __b_(__bl.begin(), __bl.end()) 62957a984708SDavid Chisnall{ 62967a984708SDavid Chisnall if (__b_.size() < 2) 62977a984708SDavid Chisnall { 62987a984708SDavid Chisnall __b_.resize(2); 62997a984708SDavid Chisnall __b_[0] = 0; 63007a984708SDavid Chisnall __b_[1] = 1; 63017a984708SDavid Chisnall __densities_.assign(1, 1.0); 63027a984708SDavid Chisnall __areas_.assign(1, 0.0); 63037a984708SDavid Chisnall } 63047a984708SDavid Chisnall else 63057a984708SDavid Chisnall { 63067a984708SDavid Chisnall __densities_.reserve(__b_.size() - 1); 63077a984708SDavid Chisnall for (size_t __i = 0; __i < __b_.size() - 1; ++__i) 63087a984708SDavid Chisnall __densities_.push_back(__fw((__b_[__i+1] + __b_[__i])*.5)); 63097a984708SDavid Chisnall __init(); 63107a984708SDavid Chisnall } 63117a984708SDavid Chisnall} 63127a984708SDavid Chisnall 6313540d2a8bSDimitry Andric#endif // _LIBCPP_CXX03_LANG 63147a984708SDavid Chisnall 63157a984708SDavid Chisnalltemplate<class _RealType> 63167a984708SDavid Chisnalltemplate<class _UnaryOperation> 63177a984708SDavid Chisnallpiecewise_constant_distribution<_RealType>::param_type::param_type( 63187a984708SDavid Chisnall size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw) 63197a984708SDavid Chisnall : __b_(__nw == 0 ? 2 : __nw + 1) 63207a984708SDavid Chisnall{ 63217a984708SDavid Chisnall size_t __n = __b_.size() - 1; 63227a984708SDavid Chisnall result_type __d = (__xmax - __xmin) / __n; 63237a984708SDavid Chisnall __densities_.reserve(__n); 63247a984708SDavid Chisnall for (size_t __i = 0; __i < __n; ++__i) 63257a984708SDavid Chisnall { 63267a984708SDavid Chisnall __b_[__i] = __xmin + __i * __d; 63277a984708SDavid Chisnall __densities_.push_back(__fw(__b_[__i] + __d*.5)); 63287a984708SDavid Chisnall } 63297a984708SDavid Chisnall __b_[__n] = __xmax; 63307a984708SDavid Chisnall __init(); 63317a984708SDavid Chisnall} 63327a984708SDavid Chisnall 63337a984708SDavid Chisnalltemplate<class _RealType> 63347a984708SDavid Chisnalltemplate<class _URNG> 63357a984708SDavid Chisnall_RealType 63367a984708SDavid Chisnallpiecewise_constant_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 63377a984708SDavid Chisnall{ 63387a984708SDavid Chisnall typedef uniform_real_distribution<result_type> _Gen; 63397a984708SDavid Chisnall result_type __u = _Gen()(__g); 63407a984708SDavid Chisnall ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(), 63417a984708SDavid Chisnall __u) - __p.__areas_.begin() - 1; 63427a984708SDavid Chisnall return (__u - __p.__areas_[__k]) / __p.__densities_[__k] + __p.__b_[__k]; 63437a984708SDavid Chisnall} 63447a984708SDavid Chisnall 63457a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _RT> 63467a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 63477a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 63487a984708SDavid Chisnall const piecewise_constant_distribution<_RT>& __x) 63497a984708SDavid Chisnall{ 63501e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__os); 63517a984708SDavid Chisnall __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 63527a984708SDavid Chisnall ios_base::scientific); 63537a984708SDavid Chisnall _CharT __sp = __os.widen(' '); 63547a984708SDavid Chisnall __os.fill(__sp); 63557a984708SDavid Chisnall size_t __n = __x.__p_.__b_.size(); 63567a984708SDavid Chisnall __os << __n; 63577a984708SDavid Chisnall for (size_t __i = 0; __i < __n; ++__i) 63587a984708SDavid Chisnall __os << __sp << __x.__p_.__b_[__i]; 63597a984708SDavid Chisnall __n = __x.__p_.__densities_.size(); 63607a984708SDavid Chisnall __os << __sp << __n; 63617a984708SDavid Chisnall for (size_t __i = 0; __i < __n; ++__i) 63627a984708SDavid Chisnall __os << __sp << __x.__p_.__densities_[__i]; 63637a984708SDavid Chisnall __n = __x.__p_.__areas_.size(); 63647a984708SDavid Chisnall __os << __sp << __n; 63657a984708SDavid Chisnall for (size_t __i = 0; __i < __n; ++__i) 63667a984708SDavid Chisnall __os << __sp << __x.__p_.__areas_[__i]; 63677a984708SDavid Chisnall return __os; 63687a984708SDavid Chisnall} 63697a984708SDavid Chisnall 63707a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _RT> 63717a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 63727a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 63737a984708SDavid Chisnall piecewise_constant_distribution<_RT>& __x) 63747a984708SDavid Chisnall{ 63757a984708SDavid Chisnall typedef piecewise_constant_distribution<_RT> _Eng; 63767a984708SDavid Chisnall typedef typename _Eng::result_type result_type; 63771e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__is); 63787a984708SDavid Chisnall __is.flags(ios_base::dec | ios_base::skipws); 63797a984708SDavid Chisnall size_t __n; 63807a984708SDavid Chisnall __is >> __n; 63817a984708SDavid Chisnall vector<result_type> __b(__n); 63827a984708SDavid Chisnall for (size_t __i = 0; __i < __n; ++__i) 63837a984708SDavid Chisnall __is >> __b[__i]; 63847a984708SDavid Chisnall __is >> __n; 63857a984708SDavid Chisnall vector<result_type> __densities(__n); 63867a984708SDavid Chisnall for (size_t __i = 0; __i < __n; ++__i) 63877a984708SDavid Chisnall __is >> __densities[__i]; 63887a984708SDavid Chisnall __is >> __n; 63897a984708SDavid Chisnall vector<result_type> __areas(__n); 63907a984708SDavid Chisnall for (size_t __i = 0; __i < __n; ++__i) 63917a984708SDavid Chisnall __is >> __areas[__i]; 63927a984708SDavid Chisnall if (!__is.fail()) 63937a984708SDavid Chisnall { 63947a984708SDavid Chisnall swap(__x.__p_.__b_, __b); 63957a984708SDavid Chisnall swap(__x.__p_.__densities_, __densities); 63967a984708SDavid Chisnall swap(__x.__p_.__areas_, __areas); 63977a984708SDavid Chisnall } 63987a984708SDavid Chisnall return __is; 63997a984708SDavid Chisnall} 64007a984708SDavid Chisnall 64017a984708SDavid Chisnall// piecewise_linear_distribution 64027a984708SDavid Chisnall 64037a984708SDavid Chisnalltemplate<class _RealType = double> 6404aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS piecewise_linear_distribution 64057a984708SDavid Chisnall{ 64067a984708SDavid Chisnallpublic: 64077a984708SDavid Chisnall // types 64087a984708SDavid Chisnall typedef _RealType result_type; 64097a984708SDavid Chisnall 6410aed8d94eSDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 64117a984708SDavid Chisnall { 64127a984708SDavid Chisnall vector<result_type> __b_; 64137a984708SDavid Chisnall vector<result_type> __densities_; 64147a984708SDavid Chisnall vector<result_type> __areas_; 64157a984708SDavid Chisnall public: 64167a984708SDavid Chisnall typedef piecewise_linear_distribution distribution_type; 64177a984708SDavid Chisnall 64187a984708SDavid Chisnall param_type(); 64197a984708SDavid Chisnall template<class _InputIteratorB, class _InputIteratorW> 64207a984708SDavid Chisnall param_type(_InputIteratorB __fB, _InputIteratorB __lB, 64217a984708SDavid Chisnall _InputIteratorW __fW); 6422540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 64237a984708SDavid Chisnall template<class _UnaryOperation> 64247a984708SDavid Chisnall param_type(initializer_list<result_type> __bl, _UnaryOperation __fw); 6425540d2a8bSDimitry Andric#endif // _LIBCPP_CXX03_LANG 64267a984708SDavid Chisnall template<class _UnaryOperation> 64277a984708SDavid Chisnall param_type(size_t __nw, result_type __xmin, result_type __xmax, 64287a984708SDavid Chisnall _UnaryOperation __fw); 64297a984708SDavid Chisnall param_type & operator=(const param_type& __rhs); 64307a984708SDavid Chisnall 64317a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 64327a984708SDavid Chisnall vector<result_type> intervals() const {return __b_;} 64337a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 64347a984708SDavid Chisnall vector<result_type> densities() const {return __densities_;} 64357a984708SDavid Chisnall 64367a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 64377a984708SDavid Chisnall bool operator==(const param_type& __x, const param_type& __y) 64387a984708SDavid Chisnall {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;} 64397a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 64407a984708SDavid Chisnall bool operator!=(const param_type& __x, const param_type& __y) 64417a984708SDavid Chisnall {return !(__x == __y);} 64427a984708SDavid Chisnall 64437a984708SDavid Chisnall private: 64447a984708SDavid Chisnall void __init(); 64457a984708SDavid Chisnall 64467a984708SDavid Chisnall friend class piecewise_linear_distribution; 64477a984708SDavid Chisnall 64487a984708SDavid Chisnall template <class _CharT, class _Traits, class _RT> 64497a984708SDavid Chisnall friend 64507a984708SDavid Chisnall basic_ostream<_CharT, _Traits>& 64517a984708SDavid Chisnall operator<<(basic_ostream<_CharT, _Traits>& __os, 64527a984708SDavid Chisnall const piecewise_linear_distribution<_RT>& __x); 64537a984708SDavid Chisnall 64547a984708SDavid Chisnall template <class _CharT, class _Traits, class _RT> 64557a984708SDavid Chisnall friend 64567a984708SDavid Chisnall basic_istream<_CharT, _Traits>& 64577a984708SDavid Chisnall operator>>(basic_istream<_CharT, _Traits>& __is, 64587a984708SDavid Chisnall piecewise_linear_distribution<_RT>& __x); 64597a984708SDavid Chisnall }; 64607a984708SDavid Chisnall 64617a984708SDavid Chisnallprivate: 64627a984708SDavid Chisnall param_type __p_; 64637a984708SDavid Chisnall 64647a984708SDavid Chisnallpublic: 64657a984708SDavid Chisnall // constructor and reset functions 64667a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 64677a984708SDavid Chisnall piecewise_linear_distribution() {} 64687a984708SDavid Chisnall template<class _InputIteratorB, class _InputIteratorW> 64697a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 64707a984708SDavid Chisnall piecewise_linear_distribution(_InputIteratorB __fB, 64717a984708SDavid Chisnall _InputIteratorB __lB, 64727a984708SDavid Chisnall _InputIteratorW __fW) 64737a984708SDavid Chisnall : __p_(__fB, __lB, __fW) {} 64747a984708SDavid Chisnall 6475540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 64767a984708SDavid Chisnall template<class _UnaryOperation> 64777a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 64787a984708SDavid Chisnall piecewise_linear_distribution(initializer_list<result_type> __bl, 64797a984708SDavid Chisnall _UnaryOperation __fw) 64807a984708SDavid Chisnall : __p_(__bl, __fw) {} 6481540d2a8bSDimitry Andric#endif // _LIBCPP_CXX03_LANG 64827a984708SDavid Chisnall 64837a984708SDavid Chisnall template<class _UnaryOperation> 64847a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 64857a984708SDavid Chisnall piecewise_linear_distribution(size_t __nw, result_type __xmin, 64867a984708SDavid Chisnall result_type __xmax, _UnaryOperation __fw) 64877a984708SDavid Chisnall : __p_(__nw, __xmin, __xmax, __fw) {} 64887a984708SDavid Chisnall 64897a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 64907a984708SDavid Chisnall explicit piecewise_linear_distribution(const param_type& __p) 64917a984708SDavid Chisnall : __p_(__p) {} 64927a984708SDavid Chisnall 64937a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 64947a984708SDavid Chisnall void reset() {} 64957a984708SDavid Chisnall 64967a984708SDavid Chisnall // generating functions 64977a984708SDavid Chisnall template<class _URNG> 64987a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 64997a984708SDavid Chisnall result_type operator()(_URNG& __g) 65007a984708SDavid Chisnall {return (*this)(__g, __p_);} 65017a984708SDavid Chisnall template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 65027a984708SDavid Chisnall 65037a984708SDavid Chisnall // property functions 65047a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 65057a984708SDavid Chisnall vector<result_type> intervals() const {return __p_.intervals();} 65067a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 65077a984708SDavid Chisnall vector<result_type> densities() const {return __p_.densities();} 65087a984708SDavid Chisnall 65097a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 65107a984708SDavid Chisnall param_type param() const {return __p_;} 65117a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 65127a984708SDavid Chisnall void param(const param_type& __p) {__p_ = __p;} 65137a984708SDavid Chisnall 65147a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 65157a984708SDavid Chisnall result_type min() const {return __p_.__b_.front();} 65167a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 65177a984708SDavid Chisnall result_type max() const {return __p_.__b_.back();} 65187a984708SDavid Chisnall 65197a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 65207a984708SDavid Chisnall bool operator==(const piecewise_linear_distribution& __x, 65217a984708SDavid Chisnall const piecewise_linear_distribution& __y) 65227a984708SDavid Chisnall {return __x.__p_ == __y.__p_;} 65237a984708SDavid Chisnall friend _LIBCPP_INLINE_VISIBILITY 65247a984708SDavid Chisnall bool operator!=(const piecewise_linear_distribution& __x, 65257a984708SDavid Chisnall const piecewise_linear_distribution& __y) 65267a984708SDavid Chisnall {return !(__x == __y);} 65277a984708SDavid Chisnall 65287a984708SDavid Chisnall template <class _CharT, class _Traits, class _RT> 65297a984708SDavid Chisnall friend 65307a984708SDavid Chisnall basic_ostream<_CharT, _Traits>& 65317a984708SDavid Chisnall operator<<(basic_ostream<_CharT, _Traits>& __os, 65327a984708SDavid Chisnall const piecewise_linear_distribution<_RT>& __x); 65337a984708SDavid Chisnall 65347a984708SDavid Chisnall template <class _CharT, class _Traits, class _RT> 65357a984708SDavid Chisnall friend 65367a984708SDavid Chisnall basic_istream<_CharT, _Traits>& 65377a984708SDavid Chisnall operator>>(basic_istream<_CharT, _Traits>& __is, 65387a984708SDavid Chisnall piecewise_linear_distribution<_RT>& __x); 65397a984708SDavid Chisnall}; 65407a984708SDavid Chisnall 65417a984708SDavid Chisnalltemplate<class _RealType> 65427a984708SDavid Chisnalltypename piecewise_linear_distribution<_RealType>::param_type & 65437a984708SDavid Chisnallpiecewise_linear_distribution<_RealType>::param_type::operator= 65447a984708SDavid Chisnall (const param_type& __rhs) 65457a984708SDavid Chisnall{ 65467a984708SDavid Chisnall// These can throw 65477a984708SDavid Chisnall __b_.reserve (__rhs.__b_.size ()); 65487a984708SDavid Chisnall __densities_.reserve(__rhs.__densities_.size()); 65497a984708SDavid Chisnall __areas_.reserve (__rhs.__areas_.size()); 65507a984708SDavid Chisnall 65517a984708SDavid Chisnall// These can not throw 65527a984708SDavid Chisnall __b_ = __rhs.__b_; 65537a984708SDavid Chisnall __densities_ = __rhs.__densities_; 65547a984708SDavid Chisnall __areas_ = __rhs.__areas_; 65557a984708SDavid Chisnall return *this; 65567a984708SDavid Chisnall} 65577a984708SDavid Chisnall 65587a984708SDavid Chisnall 65597a984708SDavid Chisnalltemplate<class _RealType> 65607a984708SDavid Chisnallvoid 65617a984708SDavid Chisnallpiecewise_linear_distribution<_RealType>::param_type::__init() 65627a984708SDavid Chisnall{ 65637a984708SDavid Chisnall __areas_.assign(__densities_.size() - 1, result_type()); 656494e3ee44SDavid Chisnall result_type _Sp = 0; 65657a984708SDavid Chisnall for (size_t __i = 0; __i < __areas_.size(); ++__i) 65667a984708SDavid Chisnall { 65677a984708SDavid Chisnall __areas_[__i] = (__densities_[__i+1] + __densities_[__i]) * 65687a984708SDavid Chisnall (__b_[__i+1] - __b_[__i]) * .5; 656994e3ee44SDavid Chisnall _Sp += __areas_[__i]; 65707a984708SDavid Chisnall } 65717a984708SDavid Chisnall for (size_t __i = __areas_.size(); __i > 1;) 65727a984708SDavid Chisnall { 65737a984708SDavid Chisnall --__i; 657494e3ee44SDavid Chisnall __areas_[__i] = __areas_[__i-1] / _Sp; 65757a984708SDavid Chisnall } 65767a984708SDavid Chisnall __areas_[0] = 0; 65777a984708SDavid Chisnall for (size_t __i = 1; __i < __areas_.size(); ++__i) 65787a984708SDavid Chisnall __areas_[__i] += __areas_[__i-1]; 65797a984708SDavid Chisnall for (size_t __i = 0; __i < __densities_.size(); ++__i) 658094e3ee44SDavid Chisnall __densities_[__i] /= _Sp; 65817a984708SDavid Chisnall} 65827a984708SDavid Chisnall 65837a984708SDavid Chisnalltemplate<class _RealType> 65847a984708SDavid Chisnallpiecewise_linear_distribution<_RealType>::param_type::param_type() 65857a984708SDavid Chisnall : __b_(2), 65867a984708SDavid Chisnall __densities_(2, 1.0), 65877a984708SDavid Chisnall __areas_(1, 0.0) 65887a984708SDavid Chisnall{ 65897a984708SDavid Chisnall __b_[1] = 1; 65907a984708SDavid Chisnall} 65917a984708SDavid Chisnall 65927a984708SDavid Chisnalltemplate<class _RealType> 65937a984708SDavid Chisnalltemplate<class _InputIteratorB, class _InputIteratorW> 65947a984708SDavid Chisnallpiecewise_linear_distribution<_RealType>::param_type::param_type( 65957a984708SDavid Chisnall _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW) 65967a984708SDavid Chisnall : __b_(__fB, __lB) 65977a984708SDavid Chisnall{ 65987a984708SDavid Chisnall if (__b_.size() < 2) 65997a984708SDavid Chisnall { 66007a984708SDavid Chisnall __b_.resize(2); 66017a984708SDavid Chisnall __b_[0] = 0; 66027a984708SDavid Chisnall __b_[1] = 1; 66037a984708SDavid Chisnall __densities_.assign(2, 1.0); 66047a984708SDavid Chisnall __areas_.assign(1, 0.0); 66057a984708SDavid Chisnall } 66067a984708SDavid Chisnall else 66077a984708SDavid Chisnall { 66087a984708SDavid Chisnall __densities_.reserve(__b_.size()); 66097a984708SDavid Chisnall for (size_t __i = 0; __i < __b_.size(); ++__i, ++__fW) 66107a984708SDavid Chisnall __densities_.push_back(*__fW); 66117a984708SDavid Chisnall __init(); 66127a984708SDavid Chisnall } 66137a984708SDavid Chisnall} 66147a984708SDavid Chisnall 6615540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 66167a984708SDavid Chisnall 66177a984708SDavid Chisnalltemplate<class _RealType> 66187a984708SDavid Chisnalltemplate<class _UnaryOperation> 66197a984708SDavid Chisnallpiecewise_linear_distribution<_RealType>::param_type::param_type( 66207a984708SDavid Chisnall initializer_list<result_type> __bl, _UnaryOperation __fw) 66217a984708SDavid Chisnall : __b_(__bl.begin(), __bl.end()) 66227a984708SDavid Chisnall{ 66237a984708SDavid Chisnall if (__b_.size() < 2) 66247a984708SDavid Chisnall { 66257a984708SDavid Chisnall __b_.resize(2); 66267a984708SDavid Chisnall __b_[0] = 0; 66277a984708SDavid Chisnall __b_[1] = 1; 66287a984708SDavid Chisnall __densities_.assign(2, 1.0); 66297a984708SDavid Chisnall __areas_.assign(1, 0.0); 66307a984708SDavid Chisnall } 66317a984708SDavid Chisnall else 66327a984708SDavid Chisnall { 66337a984708SDavid Chisnall __densities_.reserve(__b_.size()); 66347a984708SDavid Chisnall for (size_t __i = 0; __i < __b_.size(); ++__i) 66357a984708SDavid Chisnall __densities_.push_back(__fw(__b_[__i])); 66367a984708SDavid Chisnall __init(); 66377a984708SDavid Chisnall } 66387a984708SDavid Chisnall} 66397a984708SDavid Chisnall 6640540d2a8bSDimitry Andric#endif // _LIBCPP_CXX03_LANG 66417a984708SDavid Chisnall 66427a984708SDavid Chisnalltemplate<class _RealType> 66437a984708SDavid Chisnalltemplate<class _UnaryOperation> 66447a984708SDavid Chisnallpiecewise_linear_distribution<_RealType>::param_type::param_type( 66457a984708SDavid Chisnall size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw) 66467a984708SDavid Chisnall : __b_(__nw == 0 ? 2 : __nw + 1) 66477a984708SDavid Chisnall{ 66487a984708SDavid Chisnall size_t __n = __b_.size() - 1; 66497a984708SDavid Chisnall result_type __d = (__xmax - __xmin) / __n; 66507a984708SDavid Chisnall __densities_.reserve(__b_.size()); 66517a984708SDavid Chisnall for (size_t __i = 0; __i < __n; ++__i) 66527a984708SDavid Chisnall { 66537a984708SDavid Chisnall __b_[__i] = __xmin + __i * __d; 66547a984708SDavid Chisnall __densities_.push_back(__fw(__b_[__i])); 66557a984708SDavid Chisnall } 66567a984708SDavid Chisnall __b_[__n] = __xmax; 66577a984708SDavid Chisnall __densities_.push_back(__fw(__b_[__n])); 66587a984708SDavid Chisnall __init(); 66597a984708SDavid Chisnall} 66607a984708SDavid Chisnall 66617a984708SDavid Chisnalltemplate<class _RealType> 66627a984708SDavid Chisnalltemplate<class _URNG> 66637a984708SDavid Chisnall_RealType 66647a984708SDavid Chisnallpiecewise_linear_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 66657a984708SDavid Chisnall{ 66667a984708SDavid Chisnall typedef uniform_real_distribution<result_type> _Gen; 66677a984708SDavid Chisnall result_type __u = _Gen()(__g); 66687a984708SDavid Chisnall ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(), 66697a984708SDavid Chisnall __u) - __p.__areas_.begin() - 1; 66707a984708SDavid Chisnall __u -= __p.__areas_[__k]; 66717a984708SDavid Chisnall const result_type __dk = __p.__densities_[__k]; 66727a984708SDavid Chisnall const result_type __dk1 = __p.__densities_[__k+1]; 66737a984708SDavid Chisnall const result_type __deltad = __dk1 - __dk; 66747a984708SDavid Chisnall const result_type __bk = __p.__b_[__k]; 66757a984708SDavid Chisnall if (__deltad == 0) 66767a984708SDavid Chisnall return __u / __dk + __bk; 66777a984708SDavid Chisnall const result_type __bk1 = __p.__b_[__k+1]; 66787a984708SDavid Chisnall const result_type __deltab = __bk1 - __bk; 66797a984708SDavid Chisnall return (__bk * __dk1 - __bk1 * __dk + 66807a984708SDavid Chisnall _VSTD::sqrt(__deltab * (__deltab * __dk * __dk + 2 * __deltad * __u))) / 66817a984708SDavid Chisnall __deltad; 66827a984708SDavid Chisnall} 66837a984708SDavid Chisnall 66847a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _RT> 66857a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>& 66867a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, 66877a984708SDavid Chisnall const piecewise_linear_distribution<_RT>& __x) 66887a984708SDavid Chisnall{ 66891e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__os); 66907a984708SDavid Chisnall __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 66917a984708SDavid Chisnall ios_base::scientific); 66927a984708SDavid Chisnall _CharT __sp = __os.widen(' '); 66937a984708SDavid Chisnall __os.fill(__sp); 66947a984708SDavid Chisnall size_t __n = __x.__p_.__b_.size(); 66957a984708SDavid Chisnall __os << __n; 66967a984708SDavid Chisnall for (size_t __i = 0; __i < __n; ++__i) 66977a984708SDavid Chisnall __os << __sp << __x.__p_.__b_[__i]; 66987a984708SDavid Chisnall __n = __x.__p_.__densities_.size(); 66997a984708SDavid Chisnall __os << __sp << __n; 67007a984708SDavid Chisnall for (size_t __i = 0; __i < __n; ++__i) 67017a984708SDavid Chisnall __os << __sp << __x.__p_.__densities_[__i]; 67027a984708SDavid Chisnall __n = __x.__p_.__areas_.size(); 67037a984708SDavid Chisnall __os << __sp << __n; 67047a984708SDavid Chisnall for (size_t __i = 0; __i < __n; ++__i) 67057a984708SDavid Chisnall __os << __sp << __x.__p_.__areas_[__i]; 67067a984708SDavid Chisnall return __os; 67077a984708SDavid Chisnall} 67087a984708SDavid Chisnall 67097a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _RT> 67107a984708SDavid Chisnallbasic_istream<_CharT, _Traits>& 67117a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, 67127a984708SDavid Chisnall piecewise_linear_distribution<_RT>& __x) 67137a984708SDavid Chisnall{ 67147a984708SDavid Chisnall typedef piecewise_linear_distribution<_RT> _Eng; 67157a984708SDavid Chisnall typedef typename _Eng::result_type result_type; 67161e0896acSDavid Chisnall __save_flags<_CharT, _Traits> __lx(__is); 67177a984708SDavid Chisnall __is.flags(ios_base::dec | ios_base::skipws); 67187a984708SDavid Chisnall size_t __n; 67197a984708SDavid Chisnall __is >> __n; 67207a984708SDavid Chisnall vector<result_type> __b(__n); 67217a984708SDavid Chisnall for (size_t __i = 0; __i < __n; ++__i) 67227a984708SDavid Chisnall __is >> __b[__i]; 67237a984708SDavid Chisnall __is >> __n; 67247a984708SDavid Chisnall vector<result_type> __densities(__n); 67257a984708SDavid Chisnall for (size_t __i = 0; __i < __n; ++__i) 67267a984708SDavid Chisnall __is >> __densities[__i]; 67277a984708SDavid Chisnall __is >> __n; 67287a984708SDavid Chisnall vector<result_type> __areas(__n); 67297a984708SDavid Chisnall for (size_t __i = 0; __i < __n; ++__i) 67307a984708SDavid Chisnall __is >> __areas[__i]; 67317a984708SDavid Chisnall if (!__is.fail()) 67327a984708SDavid Chisnall { 67337a984708SDavid Chisnall swap(__x.__p_.__b_, __b); 67347a984708SDavid Chisnall swap(__x.__p_.__densities_, __densities); 67357a984708SDavid Chisnall swap(__x.__p_.__areas_, __areas); 67367a984708SDavid Chisnall } 67377a984708SDavid Chisnall return __is; 67387a984708SDavid Chisnall} 67397a984708SDavid Chisnall 67407a984708SDavid Chisnall_LIBCPP_END_NAMESPACE_STD 67417a984708SDavid Chisnall 6742f9448bf3SDimitry Andric_LIBCPP_POP_MACROS 6743f9448bf3SDimitry Andric 67447a984708SDavid Chisnall#endif // _LIBCPP_RANDOM 6745