14684ddb6SLionel Sambuc// -*- C++ -*- 24684ddb6SLionel Sambuc//===--------------------------- random -----------------------------------===// 34684ddb6SLionel Sambuc// 44684ddb6SLionel Sambuc// The LLVM Compiler Infrastructure 54684ddb6SLionel Sambuc// 64684ddb6SLionel Sambuc// This file is dual licensed under the MIT and the University of Illinois Open 74684ddb6SLionel Sambuc// Source Licenses. See LICENSE.TXT for details. 84684ddb6SLionel Sambuc// 94684ddb6SLionel Sambuc//===----------------------------------------------------------------------===// 104684ddb6SLionel Sambuc 114684ddb6SLionel Sambuc#ifndef _LIBCPP_RANDOM 124684ddb6SLionel Sambuc#define _LIBCPP_RANDOM 134684ddb6SLionel Sambuc 144684ddb6SLionel Sambuc/* 154684ddb6SLionel Sambuc random synopsis 164684ddb6SLionel Sambuc 174684ddb6SLionel Sambuc#include <initializer_list> 184684ddb6SLionel Sambuc 194684ddb6SLionel Sambucnamespace std 204684ddb6SLionel Sambuc{ 214684ddb6SLionel Sambuc 224684ddb6SLionel Sambuc// Engines 234684ddb6SLionel Sambuc 244684ddb6SLionel Sambuctemplate <class UIntType, UIntType a, UIntType c, UIntType m> 254684ddb6SLionel Sambucclass linear_congruential_engine 264684ddb6SLionel Sambuc{ 274684ddb6SLionel Sambucpublic: 284684ddb6SLionel Sambuc // types 294684ddb6SLionel Sambuc typedef UIntType result_type; 304684ddb6SLionel Sambuc 314684ddb6SLionel Sambuc // engine characteristics 324684ddb6SLionel Sambuc static constexpr result_type multiplier = a; 334684ddb6SLionel Sambuc static constexpr result_type increment = c; 344684ddb6SLionel Sambuc static constexpr result_type modulus = m; 354684ddb6SLionel Sambuc static constexpr result_type min() { return c == 0u ? 1u: 0u;} 364684ddb6SLionel Sambuc static constexpr result_type max() { return m - 1u;} 374684ddb6SLionel Sambuc static constexpr result_type default_seed = 1u; 384684ddb6SLionel Sambuc 394684ddb6SLionel Sambuc // constructors and seeding functions 404684ddb6SLionel Sambuc explicit linear_congruential_engine(result_type s = default_seed); 414684ddb6SLionel Sambuc template<class Sseq> explicit linear_congruential_engine(Sseq& q); 424684ddb6SLionel Sambuc void seed(result_type s = default_seed); 434684ddb6SLionel Sambuc template<class Sseq> void seed(Sseq& q); 444684ddb6SLionel Sambuc 454684ddb6SLionel Sambuc // generating functions 464684ddb6SLionel Sambuc result_type operator()(); 474684ddb6SLionel Sambuc void discard(unsigned long long z); 484684ddb6SLionel Sambuc}; 494684ddb6SLionel Sambuc 504684ddb6SLionel Sambuctemplate <class UIntType, UIntType a, UIntType c, UIntType m> 514684ddb6SLionel Sambucbool 524684ddb6SLionel Sambucoperator==(const linear_congruential_engine<UIntType, a, c, m>& x, 534684ddb6SLionel Sambuc const linear_congruential_engine<UIntType, a, c, m>& y); 544684ddb6SLionel Sambuc 554684ddb6SLionel Sambuctemplate <class UIntType, UIntType a, UIntType c, UIntType m> 564684ddb6SLionel Sambucbool 574684ddb6SLionel Sambucoperator!=(const linear_congruential_engine<UIntType, a, c, m>& x, 584684ddb6SLionel Sambuc const linear_congruential_engine<UIntType, a, c, m>& y); 594684ddb6SLionel Sambuc 604684ddb6SLionel Sambuctemplate <class charT, class traits, 614684ddb6SLionel Sambuc class UIntType, UIntType a, UIntType c, UIntType m> 624684ddb6SLionel Sambucbasic_ostream<charT, traits>& 634684ddb6SLionel Sambucoperator<<(basic_ostream<charT, traits>& os, 644684ddb6SLionel Sambuc const linear_congruential_engine<UIntType, a, c, m>& x); 654684ddb6SLionel Sambuc 664684ddb6SLionel Sambuctemplate <class charT, class traits, 674684ddb6SLionel Sambuc class UIntType, UIntType a, UIntType c, UIntType m> 684684ddb6SLionel Sambucbasic_istream<charT, traits>& 694684ddb6SLionel Sambucoperator>>(basic_istream<charT, traits>& is, 704684ddb6SLionel Sambuc linear_congruential_engine<UIntType, a, c, m>& x); 714684ddb6SLionel Sambuc 724684ddb6SLionel Sambuctemplate <class UIntType, size_t w, size_t n, size_t m, size_t r, 734684ddb6SLionel Sambuc UIntType a, size_t u, UIntType d, size_t s, 744684ddb6SLionel Sambuc UIntType b, size_t t, UIntType c, size_t l, UIntType f> 754684ddb6SLionel Sambucclass mersenne_twister_engine 764684ddb6SLionel Sambuc{ 774684ddb6SLionel Sambucpublic: 784684ddb6SLionel Sambuc // types 794684ddb6SLionel Sambuc typedef UIntType result_type; 804684ddb6SLionel Sambuc 814684ddb6SLionel Sambuc // engine characteristics 824684ddb6SLionel Sambuc static constexpr size_t word_size = w; 834684ddb6SLionel Sambuc static constexpr size_t state_size = n; 844684ddb6SLionel Sambuc static constexpr size_t shift_size = m; 854684ddb6SLionel Sambuc static constexpr size_t mask_bits = r; 864684ddb6SLionel Sambuc static constexpr result_type xor_mask = a; 874684ddb6SLionel Sambuc static constexpr size_t tempering_u = u; 884684ddb6SLionel Sambuc static constexpr result_type tempering_d = d; 894684ddb6SLionel Sambuc static constexpr size_t tempering_s = s; 904684ddb6SLionel Sambuc static constexpr result_type tempering_b = b; 914684ddb6SLionel Sambuc static constexpr size_t tempering_t = t; 924684ddb6SLionel Sambuc static constexpr result_type tempering_c = c; 934684ddb6SLionel Sambuc static constexpr size_t tempering_l = l; 944684ddb6SLionel Sambuc static constexpr result_type initialization_multiplier = f; 954684ddb6SLionel Sambuc static constexpr result_type min () { return 0; } 964684ddb6SLionel Sambuc static constexpr result_type max() { return 2^w - 1; } 974684ddb6SLionel Sambuc static constexpr result_type default_seed = 5489u; 984684ddb6SLionel Sambuc 994684ddb6SLionel Sambuc // constructors and seeding functions 1004684ddb6SLionel Sambuc explicit mersenne_twister_engine(result_type value = default_seed); 1014684ddb6SLionel Sambuc template<class Sseq> explicit mersenne_twister_engine(Sseq& q); 1024684ddb6SLionel Sambuc void seed(result_type value = default_seed); 1034684ddb6SLionel Sambuc template<class Sseq> void seed(Sseq& q); 1044684ddb6SLionel Sambuc 1054684ddb6SLionel Sambuc // generating functions 1064684ddb6SLionel Sambuc result_type operator()(); 1074684ddb6SLionel Sambuc void discard(unsigned long long z); 1084684ddb6SLionel Sambuc}; 1094684ddb6SLionel Sambuc 1104684ddb6SLionel Sambuctemplate <class UIntType, size_t w, size_t n, size_t m, size_t r, 1114684ddb6SLionel Sambuc UIntType a, size_t u, UIntType d, size_t s, 1124684ddb6SLionel Sambuc UIntType b, size_t t, UIntType c, size_t l, UIntType f> 1134684ddb6SLionel Sambucbool 1144684ddb6SLionel Sambucoperator==( 1154684ddb6SLionel Sambuc const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x, 1164684ddb6SLionel Sambuc const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& y); 1174684ddb6SLionel Sambuc 1184684ddb6SLionel Sambuctemplate <class UIntType, size_t w, size_t n, size_t m, size_t r, 1194684ddb6SLionel Sambuc UIntType a, size_t u, UIntType d, size_t s, 1204684ddb6SLionel Sambuc UIntType b, size_t t, UIntType c, size_t l, UIntType f> 1214684ddb6SLionel Sambucbool 1224684ddb6SLionel Sambucoperator!=( 1234684ddb6SLionel Sambuc const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x, 1244684ddb6SLionel Sambuc const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& y); 1254684ddb6SLionel Sambuc 1264684ddb6SLionel Sambuctemplate <class charT, class traits, 1274684ddb6SLionel Sambuc class UIntType, size_t w, size_t n, size_t m, size_t r, 1284684ddb6SLionel Sambuc UIntType a, size_t u, UIntType d, size_t s, 1294684ddb6SLionel Sambuc UIntType b, size_t t, UIntType c, size_t l, UIntType f> 1304684ddb6SLionel Sambucbasic_ostream<charT, traits>& 1314684ddb6SLionel Sambucoperator<<(basic_ostream<charT, traits>& os, 1324684ddb6SLionel Sambuc const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x); 1334684ddb6SLionel Sambuc 1344684ddb6SLionel Sambuctemplate <class charT, class traits, 1354684ddb6SLionel Sambuc class UIntType, size_t w, size_t n, size_t m, size_t r, 1364684ddb6SLionel Sambuc UIntType a, size_t u, UIntType d, size_t s, 1374684ddb6SLionel Sambuc UIntType b, size_t t, UIntType c, size_t l, UIntType f> 1384684ddb6SLionel Sambucbasic_istream<charT, traits>& 1394684ddb6SLionel Sambucoperator>>(basic_istream<charT, traits>& is, 1404684ddb6SLionel Sambuc mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x); 1414684ddb6SLionel Sambuc 1424684ddb6SLionel Sambuctemplate<class UIntType, size_t w, size_t s, size_t r> 1434684ddb6SLionel Sambucclass subtract_with_carry_engine 1444684ddb6SLionel Sambuc{ 1454684ddb6SLionel Sambucpublic: 1464684ddb6SLionel Sambuc // types 1474684ddb6SLionel Sambuc typedef UIntType result_type; 1484684ddb6SLionel Sambuc 1494684ddb6SLionel Sambuc // engine characteristics 1504684ddb6SLionel Sambuc static constexpr size_t word_size = w; 1514684ddb6SLionel Sambuc static constexpr size_t short_lag = s; 1524684ddb6SLionel Sambuc static constexpr size_t long_lag = r; 1534684ddb6SLionel Sambuc static constexpr result_type min() { return 0; } 1544684ddb6SLionel Sambuc static constexpr result_type max() { return m-1; } 1554684ddb6SLionel Sambuc static constexpr result_type default_seed = 19780503u; 1564684ddb6SLionel Sambuc 1574684ddb6SLionel Sambuc // constructors and seeding functions 1584684ddb6SLionel Sambuc explicit subtract_with_carry_engine(result_type value = default_seed); 1594684ddb6SLionel Sambuc template<class Sseq> explicit subtract_with_carry_engine(Sseq& q); 1604684ddb6SLionel Sambuc void seed(result_type value = default_seed); 1614684ddb6SLionel Sambuc template<class Sseq> void seed(Sseq& q); 1624684ddb6SLionel Sambuc 1634684ddb6SLionel Sambuc // generating functions 1644684ddb6SLionel Sambuc result_type operator()(); 1654684ddb6SLionel Sambuc void discard(unsigned long long z); 1664684ddb6SLionel Sambuc}; 1674684ddb6SLionel Sambuc 1684684ddb6SLionel Sambuctemplate<class UIntType, size_t w, size_t s, size_t r> 1694684ddb6SLionel Sambucbool 1704684ddb6SLionel Sambucoperator==( 1714684ddb6SLionel Sambuc const subtract_with_carry_engine<UIntType, w, s, r>& x, 1724684ddb6SLionel Sambuc const subtract_with_carry_engine<UIntType, w, s, r>& y); 1734684ddb6SLionel Sambuc 1744684ddb6SLionel Sambuctemplate<class UIntType, size_t w, size_t s, size_t r> 1754684ddb6SLionel Sambucbool 1764684ddb6SLionel Sambucoperator!=( 1774684ddb6SLionel Sambuc const subtract_with_carry_engine<UIntType, w, s, r>& x, 1784684ddb6SLionel Sambuc const subtract_with_carry_engine<UIntType, w, s, r>& y); 1794684ddb6SLionel Sambuc 1804684ddb6SLionel Sambuctemplate <class charT, class traits, 1814684ddb6SLionel Sambuc class UIntType, size_t w, size_t s, size_t r> 1824684ddb6SLionel Sambucbasic_ostream<charT, traits>& 1834684ddb6SLionel Sambucoperator<<(basic_ostream<charT, traits>& os, 1844684ddb6SLionel Sambuc const subtract_with_carry_engine<UIntType, w, s, r>& x); 1854684ddb6SLionel Sambuc 1864684ddb6SLionel Sambuctemplate <class charT, class traits, 1874684ddb6SLionel Sambuc class UIntType, size_t w, size_t s, size_t r> 1884684ddb6SLionel Sambucbasic_istream<charT, traits>& 1894684ddb6SLionel Sambucoperator>>(basic_istream<charT, traits>& is, 1904684ddb6SLionel Sambuc subtract_with_carry_engine<UIntType, w, s, r>& x); 1914684ddb6SLionel Sambuc 1924684ddb6SLionel Sambuctemplate<class Engine, size_t p, size_t r> 1934684ddb6SLionel Sambucclass discard_block_engine 1944684ddb6SLionel Sambuc{ 1954684ddb6SLionel Sambucpublic: 1964684ddb6SLionel Sambuc // types 1974684ddb6SLionel Sambuc typedef typename Engine::result_type result_type; 1984684ddb6SLionel Sambuc 1994684ddb6SLionel Sambuc // engine characteristics 2004684ddb6SLionel Sambuc static constexpr size_t block_size = p; 2014684ddb6SLionel Sambuc static constexpr size_t used_block = r; 2024684ddb6SLionel Sambuc static constexpr result_type min() { return Engine::min(); } 2034684ddb6SLionel Sambuc static constexpr result_type max() { return Engine::max(); } 2044684ddb6SLionel Sambuc 2054684ddb6SLionel Sambuc // constructors and seeding functions 2064684ddb6SLionel Sambuc discard_block_engine(); 2074684ddb6SLionel Sambuc explicit discard_block_engine(const Engine& e); 2084684ddb6SLionel Sambuc explicit discard_block_engine(Engine&& e); 2094684ddb6SLionel Sambuc explicit discard_block_engine(result_type s); 2104684ddb6SLionel Sambuc template<class Sseq> explicit discard_block_engine(Sseq& q); 2114684ddb6SLionel Sambuc void seed(); 2124684ddb6SLionel Sambuc void seed(result_type s); 2134684ddb6SLionel Sambuc template<class Sseq> void seed(Sseq& q); 2144684ddb6SLionel Sambuc 2154684ddb6SLionel Sambuc // generating functions 2164684ddb6SLionel Sambuc result_type operator()(); 2174684ddb6SLionel Sambuc void discard(unsigned long long z); 2184684ddb6SLionel Sambuc 2194684ddb6SLionel Sambuc // property functions 2204684ddb6SLionel Sambuc const Engine& base() const noexcept; 2214684ddb6SLionel Sambuc}; 2224684ddb6SLionel Sambuc 2234684ddb6SLionel Sambuctemplate<class Engine, size_t p, size_t r> 2244684ddb6SLionel Sambucbool 2254684ddb6SLionel Sambucoperator==( 2264684ddb6SLionel Sambuc const discard_block_engine<Engine, p, r>& x, 2274684ddb6SLionel Sambuc const discard_block_engine<Engine, p, r>& y); 2284684ddb6SLionel Sambuc 2294684ddb6SLionel Sambuctemplate<class Engine, size_t p, size_t r> 2304684ddb6SLionel Sambucbool 2314684ddb6SLionel Sambucoperator!=( 2324684ddb6SLionel Sambuc const discard_block_engine<Engine, p, r>& x, 2334684ddb6SLionel Sambuc const discard_block_engine<Engine, p, r>& y); 2344684ddb6SLionel Sambuc 2354684ddb6SLionel Sambuctemplate <class charT, class traits, 2364684ddb6SLionel Sambuc class Engine, size_t p, size_t r> 2374684ddb6SLionel Sambucbasic_ostream<charT, traits>& 2384684ddb6SLionel Sambucoperator<<(basic_ostream<charT, traits>& os, 2394684ddb6SLionel Sambuc const discard_block_engine<Engine, p, r>& x); 2404684ddb6SLionel Sambuc 2414684ddb6SLionel Sambuctemplate <class charT, class traits, 2424684ddb6SLionel Sambuc class Engine, size_t p, size_t r> 2434684ddb6SLionel Sambucbasic_istream<charT, traits>& 2444684ddb6SLionel Sambucoperator>>(basic_istream<charT, traits>& is, 2454684ddb6SLionel Sambuc discard_block_engine<Engine, p, r>& x); 2464684ddb6SLionel Sambuc 2474684ddb6SLionel Sambuctemplate<class Engine, size_t w, class UIntType> 2484684ddb6SLionel Sambucclass independent_bits_engine 2494684ddb6SLionel Sambuc{ 2504684ddb6SLionel Sambucpublic: 2514684ddb6SLionel Sambuc // types 2524684ddb6SLionel Sambuc typedef UIntType result_type; 2534684ddb6SLionel Sambuc 2544684ddb6SLionel Sambuc // engine characteristics 2554684ddb6SLionel Sambuc static constexpr result_type min() { return 0; } 2564684ddb6SLionel Sambuc static constexpr result_type max() { return 2^w - 1; } 2574684ddb6SLionel Sambuc 2584684ddb6SLionel Sambuc // constructors and seeding functions 2594684ddb6SLionel Sambuc independent_bits_engine(); 2604684ddb6SLionel Sambuc explicit independent_bits_engine(const Engine& e); 2614684ddb6SLionel Sambuc explicit independent_bits_engine(Engine&& e); 2624684ddb6SLionel Sambuc explicit independent_bits_engine(result_type s); 2634684ddb6SLionel Sambuc template<class Sseq> explicit independent_bits_engine(Sseq& q); 2644684ddb6SLionel Sambuc void seed(); 2654684ddb6SLionel Sambuc void seed(result_type s); 2664684ddb6SLionel Sambuc template<class Sseq> void seed(Sseq& q); 2674684ddb6SLionel Sambuc 2684684ddb6SLionel Sambuc // generating functions 2694684ddb6SLionel Sambuc result_type operator()(); void discard(unsigned long long z); 2704684ddb6SLionel Sambuc 2714684ddb6SLionel Sambuc // property functions 2724684ddb6SLionel Sambuc const Engine& base() const noexcept; 2734684ddb6SLionel Sambuc}; 2744684ddb6SLionel Sambuc 2754684ddb6SLionel Sambuctemplate<class Engine, size_t w, class UIntType> 2764684ddb6SLionel Sambucbool 2774684ddb6SLionel Sambucoperator==( 2784684ddb6SLionel Sambuc const independent_bits_engine<Engine, w, UIntType>& x, 2794684ddb6SLionel Sambuc const independent_bits_engine<Engine, w, UIntType>& y); 2804684ddb6SLionel Sambuc 2814684ddb6SLionel Sambuctemplate<class Engine, size_t w, class UIntType> 2824684ddb6SLionel Sambucbool 2834684ddb6SLionel Sambucoperator!=( 2844684ddb6SLionel Sambuc const independent_bits_engine<Engine, w, UIntType>& x, 2854684ddb6SLionel Sambuc const independent_bits_engine<Engine, w, UIntType>& y); 2864684ddb6SLionel Sambuc 2874684ddb6SLionel Sambuctemplate <class charT, class traits, 2884684ddb6SLionel Sambuc class Engine, size_t w, class UIntType> 2894684ddb6SLionel Sambucbasic_ostream<charT, traits>& 2904684ddb6SLionel Sambucoperator<<(basic_ostream<charT, traits>& os, 2914684ddb6SLionel Sambuc const independent_bits_engine<Engine, w, UIntType>& x); 2924684ddb6SLionel Sambuc 2934684ddb6SLionel Sambuctemplate <class charT, class traits, 2944684ddb6SLionel Sambuc class Engine, size_t w, class UIntType> 2954684ddb6SLionel Sambucbasic_istream<charT, traits>& 2964684ddb6SLionel Sambucoperator>>(basic_istream<charT, traits>& is, 2974684ddb6SLionel Sambuc independent_bits_engine<Engine, w, UIntType>& x); 2984684ddb6SLionel Sambuc 2994684ddb6SLionel Sambuctemplate<class Engine, size_t k> 3004684ddb6SLionel Sambucclass shuffle_order_engine 3014684ddb6SLionel Sambuc{ 3024684ddb6SLionel Sambucpublic: 3034684ddb6SLionel Sambuc // types 3044684ddb6SLionel Sambuc typedef typename Engine::result_type result_type; 3054684ddb6SLionel Sambuc 3064684ddb6SLionel Sambuc // engine characteristics 3074684ddb6SLionel Sambuc static constexpr size_t table_size = k; 3084684ddb6SLionel Sambuc static constexpr result_type min() { return Engine::min; } 3094684ddb6SLionel Sambuc static constexpr result_type max() { return Engine::max; } 3104684ddb6SLionel Sambuc 3114684ddb6SLionel Sambuc // constructors and seeding functions 3124684ddb6SLionel Sambuc shuffle_order_engine(); 3134684ddb6SLionel Sambuc explicit shuffle_order_engine(const Engine& e); 3144684ddb6SLionel Sambuc explicit shuffle_order_engine(Engine&& e); 3154684ddb6SLionel Sambuc explicit shuffle_order_engine(result_type s); 3164684ddb6SLionel Sambuc template<class Sseq> explicit shuffle_order_engine(Sseq& q); 3174684ddb6SLionel Sambuc void seed(); 3184684ddb6SLionel Sambuc void seed(result_type s); 3194684ddb6SLionel Sambuc template<class Sseq> void seed(Sseq& q); 3204684ddb6SLionel Sambuc 3214684ddb6SLionel Sambuc // generating functions 3224684ddb6SLionel Sambuc result_type operator()(); 3234684ddb6SLionel Sambuc void discard(unsigned long long z); 3244684ddb6SLionel Sambuc 3254684ddb6SLionel Sambuc // property functions 3264684ddb6SLionel Sambuc const Engine& base() const noexcept; 3274684ddb6SLionel Sambuc}; 3284684ddb6SLionel Sambuc 3294684ddb6SLionel Sambuctemplate<class Engine, size_t k> 3304684ddb6SLionel Sambucbool 3314684ddb6SLionel Sambucoperator==( 3324684ddb6SLionel Sambuc const shuffle_order_engine<Engine, k>& x, 3334684ddb6SLionel Sambuc const shuffle_order_engine<Engine, k>& y); 3344684ddb6SLionel Sambuc 3354684ddb6SLionel Sambuctemplate<class Engine, size_t k> 3364684ddb6SLionel Sambucbool 3374684ddb6SLionel Sambucoperator!=( 3384684ddb6SLionel Sambuc const shuffle_order_engine<Engine, k>& x, 3394684ddb6SLionel Sambuc const shuffle_order_engine<Engine, k>& y); 3404684ddb6SLionel Sambuc 3414684ddb6SLionel Sambuctemplate <class charT, class traits, 3424684ddb6SLionel Sambuc class Engine, size_t k> 3434684ddb6SLionel Sambucbasic_ostream<charT, traits>& 3444684ddb6SLionel Sambucoperator<<(basic_ostream<charT, traits>& os, 3454684ddb6SLionel Sambuc const shuffle_order_engine<Engine, k>& x); 3464684ddb6SLionel Sambuc 3474684ddb6SLionel Sambuctemplate <class charT, class traits, 3484684ddb6SLionel Sambuc class Engine, size_t k> 3494684ddb6SLionel Sambucbasic_istream<charT, traits>& 3504684ddb6SLionel Sambucoperator>>(basic_istream<charT, traits>& is, 3514684ddb6SLionel Sambuc shuffle_order_engine<Engine, k>& x); 3524684ddb6SLionel Sambuc 3534684ddb6SLionel Sambuctypedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647> 3544684ddb6SLionel Sambuc minstd_rand0; 3554684ddb6SLionel Sambuctypedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647> 3564684ddb6SLionel Sambuc minstd_rand; 3574684ddb6SLionel Sambuctypedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31, 3584684ddb6SLionel Sambuc 0x9908b0df, 3594684ddb6SLionel Sambuc 11, 0xffffffff, 3604684ddb6SLionel Sambuc 7, 0x9d2c5680, 3614684ddb6SLionel Sambuc 15, 0xefc60000, 3624684ddb6SLionel Sambuc 18, 1812433253> mt19937; 3634684ddb6SLionel Sambuctypedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31, 3644684ddb6SLionel Sambuc 0xb5026f5aa96619e9, 3654684ddb6SLionel Sambuc 29, 0x5555555555555555, 3664684ddb6SLionel Sambuc 17, 0x71d67fffeda60000, 3674684ddb6SLionel Sambuc 37, 0xfff7eee000000000, 3684684ddb6SLionel Sambuc 43, 6364136223846793005> mt19937_64; 3694684ddb6SLionel Sambuctypedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> ranlux24_base; 3704684ddb6SLionel Sambuctypedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> ranlux48_base; 3714684ddb6SLionel Sambuctypedef discard_block_engine<ranlux24_base, 223, 23> ranlux24; 3724684ddb6SLionel Sambuctypedef discard_block_engine<ranlux48_base, 389, 11> ranlux48; 3734684ddb6SLionel Sambuctypedef shuffle_order_engine<minstd_rand0, 256> knuth_b; 3744684ddb6SLionel Sambuctypedef minstd_rand default_random_engine; 3754684ddb6SLionel Sambuc 3764684ddb6SLionel Sambuc// Generators 3774684ddb6SLionel Sambuc 3784684ddb6SLionel Sambucclass random_device 3794684ddb6SLionel Sambuc{ 3804684ddb6SLionel Sambucpublic: 3814684ddb6SLionel Sambuc // types 3824684ddb6SLionel Sambuc typedef unsigned int result_type; 3834684ddb6SLionel Sambuc 3844684ddb6SLionel Sambuc // generator characteristics 3854684ddb6SLionel Sambuc static constexpr result_type min() { return numeric_limits<result_type>::min(); } 3864684ddb6SLionel Sambuc static constexpr result_type max() { return numeric_limits<result_type>::max(); } 3874684ddb6SLionel Sambuc 3884684ddb6SLionel Sambuc // constructors 3894684ddb6SLionel Sambuc explicit random_device(const string& token = "/dev/urandom"); 3904684ddb6SLionel Sambuc 3914684ddb6SLionel Sambuc // generating functions 3924684ddb6SLionel Sambuc result_type operator()(); 3934684ddb6SLionel Sambuc 3944684ddb6SLionel Sambuc // property functions 3954684ddb6SLionel Sambuc double entropy() const noexcept; 3964684ddb6SLionel Sambuc 3974684ddb6SLionel Sambuc // no copy functions 3984684ddb6SLionel Sambuc random_device(const random_device& ) = delete; 3994684ddb6SLionel Sambuc void operator=(const random_device& ) = delete; 4004684ddb6SLionel Sambuc}; 4014684ddb6SLionel Sambuc 4024684ddb6SLionel Sambuc// Utilities 4034684ddb6SLionel Sambuc 4044684ddb6SLionel Sambucclass seed_seq 4054684ddb6SLionel Sambuc{ 4064684ddb6SLionel Sambucpublic: 4074684ddb6SLionel Sambuc // types 4084684ddb6SLionel Sambuc typedef uint_least32_t result_type; 4094684ddb6SLionel Sambuc 4104684ddb6SLionel Sambuc // constructors 4114684ddb6SLionel Sambuc seed_seq(); 4124684ddb6SLionel Sambuc template<class T> 4134684ddb6SLionel Sambuc seed_seq(initializer_list<T> il); 4144684ddb6SLionel Sambuc template<class InputIterator> 4154684ddb6SLionel Sambuc seed_seq(InputIterator begin, InputIterator end); 4164684ddb6SLionel Sambuc 4174684ddb6SLionel Sambuc // generating functions 4184684ddb6SLionel Sambuc template<class RandomAccessIterator> 4194684ddb6SLionel Sambuc void generate(RandomAccessIterator begin, RandomAccessIterator end); 4204684ddb6SLionel Sambuc 4214684ddb6SLionel Sambuc // property functions 4224684ddb6SLionel Sambuc size_t size() const; 4234684ddb6SLionel Sambuc template<class OutputIterator> 4244684ddb6SLionel Sambuc void param(OutputIterator dest) const; 4254684ddb6SLionel Sambuc 4264684ddb6SLionel Sambuc // no copy functions 4274684ddb6SLionel Sambuc seed_seq(const seed_seq&) = delete; 4284684ddb6SLionel Sambuc void operator=(const seed_seq& ) = delete; 4294684ddb6SLionel Sambuc}; 4304684ddb6SLionel Sambuc 4314684ddb6SLionel Sambuctemplate<class RealType, size_t bits, class URNG> 4324684ddb6SLionel Sambuc RealType generate_canonical(URNG& g); 4334684ddb6SLionel Sambuc 4344684ddb6SLionel Sambuc// Distributions 4354684ddb6SLionel Sambuc 4364684ddb6SLionel Sambuctemplate<class IntType = int> 4374684ddb6SLionel Sambucclass uniform_int_distribution 4384684ddb6SLionel Sambuc{ 4394684ddb6SLionel Sambucpublic: 4404684ddb6SLionel Sambuc // types 4414684ddb6SLionel Sambuc typedef IntType result_type; 4424684ddb6SLionel Sambuc 4434684ddb6SLionel Sambuc class param_type 4444684ddb6SLionel Sambuc { 4454684ddb6SLionel Sambuc public: 4464684ddb6SLionel Sambuc typedef uniform_int_distribution distribution_type; 4474684ddb6SLionel Sambuc 4484684ddb6SLionel Sambuc explicit param_type(IntType a = 0, 4494684ddb6SLionel Sambuc IntType b = numeric_limits<IntType>::max()); 4504684ddb6SLionel Sambuc 4514684ddb6SLionel Sambuc result_type a() const; 4524684ddb6SLionel Sambuc result_type b() const; 4534684ddb6SLionel Sambuc 4544684ddb6SLionel Sambuc friend bool operator==(const param_type& x, const param_type& y); 4554684ddb6SLionel Sambuc friend bool operator!=(const param_type& x, const param_type& y); 4564684ddb6SLionel Sambuc }; 4574684ddb6SLionel Sambuc 4584684ddb6SLionel Sambuc // constructors and reset functions 4594684ddb6SLionel Sambuc explicit uniform_int_distribution(IntType a = 0, 4604684ddb6SLionel Sambuc IntType b = numeric_limits<IntType>::max()); 4614684ddb6SLionel Sambuc explicit uniform_int_distribution(const param_type& parm); 4624684ddb6SLionel Sambuc void reset(); 4634684ddb6SLionel Sambuc 4644684ddb6SLionel Sambuc // generating functions 4654684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g); 4664684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g, const param_type& parm); 4674684ddb6SLionel Sambuc 4684684ddb6SLionel Sambuc // property functions 4694684ddb6SLionel Sambuc result_type a() const; 4704684ddb6SLionel Sambuc result_type b() const; 4714684ddb6SLionel Sambuc 4724684ddb6SLionel Sambuc param_type param() const; 4734684ddb6SLionel Sambuc void param(const param_type& parm); 4744684ddb6SLionel Sambuc 4754684ddb6SLionel Sambuc result_type min() const; 4764684ddb6SLionel Sambuc result_type max() const; 4774684ddb6SLionel Sambuc 4784684ddb6SLionel Sambuc friend bool operator==(const uniform_int_distribution& x, 4794684ddb6SLionel Sambuc const uniform_int_distribution& y); 4804684ddb6SLionel Sambuc friend bool operator!=(const uniform_int_distribution& x, 4814684ddb6SLionel Sambuc const uniform_int_distribution& y); 4824684ddb6SLionel Sambuc 4834684ddb6SLionel Sambuc template <class charT, class traits> 4844684ddb6SLionel Sambuc friend 4854684ddb6SLionel Sambuc basic_ostream<charT, traits>& 4864684ddb6SLionel Sambuc operator<<(basic_ostream<charT, traits>& os, 4874684ddb6SLionel Sambuc const uniform_int_distribution& x); 4884684ddb6SLionel Sambuc 4894684ddb6SLionel Sambuc template <class charT, class traits> 4904684ddb6SLionel Sambuc friend 4914684ddb6SLionel Sambuc basic_istream<charT, traits>& 4924684ddb6SLionel Sambuc operator>>(basic_istream<charT, traits>& is, 4934684ddb6SLionel Sambuc uniform_int_distribution& x); 4944684ddb6SLionel Sambuc}; 4954684ddb6SLionel Sambuc 4964684ddb6SLionel Sambuctemplate<class RealType = double> 4974684ddb6SLionel Sambucclass uniform_real_distribution 4984684ddb6SLionel Sambuc{ 4994684ddb6SLionel Sambucpublic: 5004684ddb6SLionel Sambuc // types 5014684ddb6SLionel Sambuc typedef RealType result_type; 5024684ddb6SLionel Sambuc 5034684ddb6SLionel Sambuc class param_type 5044684ddb6SLionel Sambuc { 5054684ddb6SLionel Sambuc public: 5064684ddb6SLionel Sambuc typedef uniform_real_distribution distribution_type; 5074684ddb6SLionel Sambuc 5084684ddb6SLionel Sambuc explicit param_type(RealType a = 0, 5094684ddb6SLionel Sambuc RealType b = 1); 5104684ddb6SLionel Sambuc 5114684ddb6SLionel Sambuc result_type a() const; 5124684ddb6SLionel Sambuc result_type b() const; 5134684ddb6SLionel Sambuc 5144684ddb6SLionel Sambuc friend bool operator==(const param_type& x, const param_type& y); 5154684ddb6SLionel Sambuc friend bool operator!=(const param_type& x, const param_type& y); 5164684ddb6SLionel Sambuc }; 5174684ddb6SLionel Sambuc 5184684ddb6SLionel Sambuc // constructors and reset functions 5194684ddb6SLionel Sambuc explicit uniform_real_distribution(RealType a = 0.0, RealType b = 1.0); 5204684ddb6SLionel Sambuc explicit uniform_real_distribution(const param_type& parm); 5214684ddb6SLionel Sambuc void reset(); 5224684ddb6SLionel Sambuc 5234684ddb6SLionel Sambuc // generating functions 5244684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g); 5254684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g, const param_type& parm); 5264684ddb6SLionel Sambuc 5274684ddb6SLionel Sambuc // property functions 5284684ddb6SLionel Sambuc result_type a() const; 5294684ddb6SLionel Sambuc result_type b() const; 5304684ddb6SLionel Sambuc 5314684ddb6SLionel Sambuc param_type param() const; 5324684ddb6SLionel Sambuc void param(const param_type& parm); 5334684ddb6SLionel Sambuc 5344684ddb6SLionel Sambuc result_type min() const; 5354684ddb6SLionel Sambuc result_type max() const; 5364684ddb6SLionel Sambuc 5374684ddb6SLionel Sambuc friend bool operator==(const uniform_real_distribution& x, 5384684ddb6SLionel Sambuc const uniform_real_distribution& y); 5394684ddb6SLionel Sambuc friend bool operator!=(const uniform_real_distribution& x, 5404684ddb6SLionel Sambuc const uniform_real_distribution& y); 5414684ddb6SLionel Sambuc 5424684ddb6SLionel Sambuc template <class charT, class traits> 5434684ddb6SLionel Sambuc friend 5444684ddb6SLionel Sambuc basic_ostream<charT, traits>& 5454684ddb6SLionel Sambuc operator<<(basic_ostream<charT, traits>& os, 5464684ddb6SLionel Sambuc const uniform_real_distribution& x); 5474684ddb6SLionel Sambuc 5484684ddb6SLionel Sambuc template <class charT, class traits> 5494684ddb6SLionel Sambuc friend 5504684ddb6SLionel Sambuc basic_istream<charT, traits>& 5514684ddb6SLionel Sambuc operator>>(basic_istream<charT, traits>& is, 5524684ddb6SLionel Sambuc uniform_real_distribution& x); 5534684ddb6SLionel Sambuc}; 5544684ddb6SLionel Sambuc 5554684ddb6SLionel Sambucclass bernoulli_distribution 5564684ddb6SLionel Sambuc{ 5574684ddb6SLionel Sambucpublic: 5584684ddb6SLionel Sambuc // types 5594684ddb6SLionel Sambuc typedef bool result_type; 5604684ddb6SLionel Sambuc 5614684ddb6SLionel Sambuc class param_type 5624684ddb6SLionel Sambuc { 5634684ddb6SLionel Sambuc public: 5644684ddb6SLionel Sambuc typedef bernoulli_distribution distribution_type; 5654684ddb6SLionel Sambuc 5664684ddb6SLionel Sambuc explicit param_type(double p = 0.5); 5674684ddb6SLionel Sambuc 5684684ddb6SLionel Sambuc double p() const; 5694684ddb6SLionel Sambuc 5704684ddb6SLionel Sambuc friend bool operator==(const param_type& x, const param_type& y); 5714684ddb6SLionel Sambuc friend bool operator!=(const param_type& x, const param_type& y); 5724684ddb6SLionel Sambuc }; 5734684ddb6SLionel Sambuc 5744684ddb6SLionel Sambuc // constructors and reset functions 5754684ddb6SLionel Sambuc explicit bernoulli_distribution(double p = 0.5); 5764684ddb6SLionel Sambuc explicit bernoulli_distribution(const param_type& parm); 5774684ddb6SLionel Sambuc void reset(); 5784684ddb6SLionel Sambuc 5794684ddb6SLionel Sambuc // generating functions 5804684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g); 5814684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g, const param_type& parm); 5824684ddb6SLionel Sambuc 5834684ddb6SLionel Sambuc // property functions 5844684ddb6SLionel Sambuc double p() const; 5854684ddb6SLionel Sambuc 5864684ddb6SLionel Sambuc param_type param() const; 5874684ddb6SLionel Sambuc void param(const param_type& parm); 5884684ddb6SLionel Sambuc 5894684ddb6SLionel Sambuc result_type min() const; 5904684ddb6SLionel Sambuc result_type max() const; 5914684ddb6SLionel Sambuc 5924684ddb6SLionel Sambuc friend bool operator==(const bernoulli_distribution& x, 5934684ddb6SLionel Sambuc const bernoulli_distribution& y); 5944684ddb6SLionel Sambuc friend bool operator!=(const bernoulli_distribution& x, 5954684ddb6SLionel Sambuc const bernoulli_distribution& y); 5964684ddb6SLionel Sambuc 5974684ddb6SLionel Sambuc template <class charT, class traits> 5984684ddb6SLionel Sambuc friend 5994684ddb6SLionel Sambuc basic_ostream<charT, traits>& 6004684ddb6SLionel Sambuc operator<<(basic_ostream<charT, traits>& os, 6014684ddb6SLionel Sambuc const bernoulli_distribution& x); 6024684ddb6SLionel Sambuc 6034684ddb6SLionel Sambuc template <class charT, class traits> 6044684ddb6SLionel Sambuc friend 6054684ddb6SLionel Sambuc basic_istream<charT, traits>& 6064684ddb6SLionel Sambuc operator>>(basic_istream<charT, traits>& is, 6074684ddb6SLionel Sambuc bernoulli_distribution& x); 6084684ddb6SLionel Sambuc}; 6094684ddb6SLionel Sambuc 6104684ddb6SLionel Sambuctemplate<class IntType = int> 6114684ddb6SLionel Sambucclass binomial_distribution 6124684ddb6SLionel Sambuc{ 6134684ddb6SLionel Sambucpublic: 6144684ddb6SLionel Sambuc // types 6154684ddb6SLionel Sambuc typedef IntType result_type; 6164684ddb6SLionel Sambuc 6174684ddb6SLionel Sambuc class param_type 6184684ddb6SLionel Sambuc { 6194684ddb6SLionel Sambuc public: 6204684ddb6SLionel Sambuc typedef binomial_distribution distribution_type; 6214684ddb6SLionel Sambuc 6224684ddb6SLionel Sambuc explicit param_type(IntType t = 1, double p = 0.5); 6234684ddb6SLionel Sambuc 6244684ddb6SLionel Sambuc IntType t() const; 6254684ddb6SLionel Sambuc double p() const; 6264684ddb6SLionel Sambuc 6274684ddb6SLionel Sambuc friend bool operator==(const param_type& x, const param_type& y); 6284684ddb6SLionel Sambuc friend bool operator!=(const param_type& x, const param_type& y); 6294684ddb6SLionel Sambuc }; 6304684ddb6SLionel Sambuc 6314684ddb6SLionel Sambuc // constructors and reset functions 6324684ddb6SLionel Sambuc explicit binomial_distribution(IntType t = 1, double p = 0.5); 6334684ddb6SLionel Sambuc explicit binomial_distribution(const param_type& parm); 6344684ddb6SLionel Sambuc void reset(); 6354684ddb6SLionel Sambuc 6364684ddb6SLionel Sambuc // generating functions 6374684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g); 6384684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g, const param_type& parm); 6394684ddb6SLionel Sambuc 6404684ddb6SLionel Sambuc // property functions 6414684ddb6SLionel Sambuc IntType t() const; 6424684ddb6SLionel Sambuc double p() const; 6434684ddb6SLionel Sambuc 6444684ddb6SLionel Sambuc param_type param() const; 6454684ddb6SLionel Sambuc void param(const param_type& parm); 6464684ddb6SLionel Sambuc 6474684ddb6SLionel Sambuc result_type min() const; 6484684ddb6SLionel Sambuc result_type max() const; 6494684ddb6SLionel Sambuc 6504684ddb6SLionel Sambuc friend bool operator==(const binomial_distribution& x, 6514684ddb6SLionel Sambuc const binomial_distribution& y); 6524684ddb6SLionel Sambuc friend bool operator!=(const binomial_distribution& x, 6534684ddb6SLionel Sambuc const binomial_distribution& y); 6544684ddb6SLionel Sambuc 6554684ddb6SLionel Sambuc template <class charT, class traits> 6564684ddb6SLionel Sambuc friend 6574684ddb6SLionel Sambuc basic_ostream<charT, traits>& 6584684ddb6SLionel Sambuc operator<<(basic_ostream<charT, traits>& os, 6594684ddb6SLionel Sambuc const binomial_distribution& x); 6604684ddb6SLionel Sambuc 6614684ddb6SLionel Sambuc template <class charT, class traits> 6624684ddb6SLionel Sambuc friend 6634684ddb6SLionel Sambuc basic_istream<charT, traits>& 6644684ddb6SLionel Sambuc operator>>(basic_istream<charT, traits>& is, 6654684ddb6SLionel Sambuc binomial_distribution& x); 6664684ddb6SLionel Sambuc}; 6674684ddb6SLionel Sambuc 6684684ddb6SLionel Sambuctemplate<class IntType = int> 6694684ddb6SLionel Sambucclass geometric_distribution 6704684ddb6SLionel Sambuc{ 6714684ddb6SLionel Sambucpublic: 6724684ddb6SLionel Sambuc // types 6734684ddb6SLionel Sambuc typedef IntType result_type; 6744684ddb6SLionel Sambuc 6754684ddb6SLionel Sambuc class param_type 6764684ddb6SLionel Sambuc { 6774684ddb6SLionel Sambuc public: 6784684ddb6SLionel Sambuc typedef geometric_distribution distribution_type; 6794684ddb6SLionel Sambuc 6804684ddb6SLionel Sambuc explicit param_type(double p = 0.5); 6814684ddb6SLionel Sambuc 6824684ddb6SLionel Sambuc double p() const; 6834684ddb6SLionel Sambuc 6844684ddb6SLionel Sambuc friend bool operator==(const param_type& x, const param_type& y); 6854684ddb6SLionel Sambuc friend bool operator!=(const param_type& x, const param_type& y); 6864684ddb6SLionel Sambuc }; 6874684ddb6SLionel Sambuc 6884684ddb6SLionel Sambuc // constructors and reset functions 6894684ddb6SLionel Sambuc explicit geometric_distribution(double p = 0.5); 6904684ddb6SLionel Sambuc explicit geometric_distribution(const param_type& parm); 6914684ddb6SLionel Sambuc void reset(); 6924684ddb6SLionel Sambuc 6934684ddb6SLionel Sambuc // generating functions 6944684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g); 6954684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g, const param_type& parm); 6964684ddb6SLionel Sambuc 6974684ddb6SLionel Sambuc // property functions 6984684ddb6SLionel Sambuc double p() const; 6994684ddb6SLionel Sambuc 7004684ddb6SLionel Sambuc param_type param() const; 7014684ddb6SLionel Sambuc void param(const param_type& parm); 7024684ddb6SLionel Sambuc 7034684ddb6SLionel Sambuc result_type min() const; 7044684ddb6SLionel Sambuc result_type max() const; 7054684ddb6SLionel Sambuc 7064684ddb6SLionel Sambuc friend bool operator==(const geometric_distribution& x, 7074684ddb6SLionel Sambuc const geometric_distribution& y); 7084684ddb6SLionel Sambuc friend bool operator!=(const geometric_distribution& x, 7094684ddb6SLionel Sambuc const geometric_distribution& y); 7104684ddb6SLionel Sambuc 7114684ddb6SLionel Sambuc template <class charT, class traits> 7124684ddb6SLionel Sambuc friend 7134684ddb6SLionel Sambuc basic_ostream<charT, traits>& 7144684ddb6SLionel Sambuc operator<<(basic_ostream<charT, traits>& os, 7154684ddb6SLionel Sambuc const geometric_distribution& x); 7164684ddb6SLionel Sambuc 7174684ddb6SLionel Sambuc template <class charT, class traits> 7184684ddb6SLionel Sambuc friend 7194684ddb6SLionel Sambuc basic_istream<charT, traits>& 7204684ddb6SLionel Sambuc operator>>(basic_istream<charT, traits>& is, 7214684ddb6SLionel Sambuc geometric_distribution& x); 7224684ddb6SLionel Sambuc}; 7234684ddb6SLionel Sambuc 7244684ddb6SLionel Sambuctemplate<class IntType = int> 7254684ddb6SLionel Sambucclass negative_binomial_distribution 7264684ddb6SLionel Sambuc{ 7274684ddb6SLionel Sambucpublic: 7284684ddb6SLionel Sambuc // types 7294684ddb6SLionel Sambuc typedef IntType result_type; 7304684ddb6SLionel Sambuc 7314684ddb6SLionel Sambuc class param_type 7324684ddb6SLionel Sambuc { 7334684ddb6SLionel Sambuc public: 7344684ddb6SLionel Sambuc typedef negative_binomial_distribution distribution_type; 7354684ddb6SLionel Sambuc 7364684ddb6SLionel Sambuc explicit param_type(result_type k = 1, double p = 0.5); 7374684ddb6SLionel Sambuc 7384684ddb6SLionel Sambuc result_type k() const; 7394684ddb6SLionel Sambuc double p() const; 7404684ddb6SLionel Sambuc 7414684ddb6SLionel Sambuc friend bool operator==(const param_type& x, const param_type& y); 7424684ddb6SLionel Sambuc friend bool operator!=(const param_type& x, const param_type& y); 7434684ddb6SLionel Sambuc }; 7444684ddb6SLionel Sambuc 7454684ddb6SLionel Sambuc // constructor and reset functions 7464684ddb6SLionel Sambuc explicit negative_binomial_distribution(result_type k = 1, double p = 0.5); 7474684ddb6SLionel Sambuc explicit negative_binomial_distribution(const param_type& parm); 7484684ddb6SLionel Sambuc void reset(); 7494684ddb6SLionel Sambuc 7504684ddb6SLionel Sambuc // generating functions 7514684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g); 7524684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g, const param_type& parm); 7534684ddb6SLionel Sambuc 7544684ddb6SLionel Sambuc // property functions 7554684ddb6SLionel Sambuc result_type k() const; 7564684ddb6SLionel Sambuc double p() const; 7574684ddb6SLionel Sambuc 7584684ddb6SLionel Sambuc param_type param() const; 7594684ddb6SLionel Sambuc void param(const param_type& parm); 7604684ddb6SLionel Sambuc 7614684ddb6SLionel Sambuc result_type min() const; 7624684ddb6SLionel Sambuc result_type max() const; 7634684ddb6SLionel Sambuc 7644684ddb6SLionel Sambuc friend bool operator==(const negative_binomial_distribution& x, 7654684ddb6SLionel Sambuc const negative_binomial_distribution& y); 7664684ddb6SLionel Sambuc friend bool operator!=(const negative_binomial_distribution& x, 7674684ddb6SLionel Sambuc const negative_binomial_distribution& y); 7684684ddb6SLionel Sambuc 7694684ddb6SLionel Sambuc template <class charT, class traits> 7704684ddb6SLionel Sambuc friend 7714684ddb6SLionel Sambuc basic_ostream<charT, traits>& 7724684ddb6SLionel Sambuc operator<<(basic_ostream<charT, traits>& os, 7734684ddb6SLionel Sambuc const negative_binomial_distribution& x); 7744684ddb6SLionel Sambuc 7754684ddb6SLionel Sambuc template <class charT, class traits> 7764684ddb6SLionel Sambuc friend 7774684ddb6SLionel Sambuc basic_istream<charT, traits>& 7784684ddb6SLionel Sambuc operator>>(basic_istream<charT, traits>& is, 7794684ddb6SLionel Sambuc negative_binomial_distribution& x); 7804684ddb6SLionel Sambuc}; 7814684ddb6SLionel Sambuc 7824684ddb6SLionel Sambuctemplate<class IntType = int> 7834684ddb6SLionel Sambucclass poisson_distribution 7844684ddb6SLionel Sambuc{ 7854684ddb6SLionel Sambucpublic: 7864684ddb6SLionel Sambuc // types 7874684ddb6SLionel Sambuc typedef IntType result_type; 7884684ddb6SLionel Sambuc 7894684ddb6SLionel Sambuc class param_type 7904684ddb6SLionel Sambuc { 7914684ddb6SLionel Sambuc public: 7924684ddb6SLionel Sambuc typedef poisson_distribution distribution_type; 7934684ddb6SLionel Sambuc 7944684ddb6SLionel Sambuc explicit param_type(double mean = 1.0); 7954684ddb6SLionel Sambuc 7964684ddb6SLionel Sambuc double mean() const; 7974684ddb6SLionel Sambuc 7984684ddb6SLionel Sambuc friend bool operator==(const param_type& x, const param_type& y); 7994684ddb6SLionel Sambuc friend bool operator!=(const param_type& x, const param_type& y); 8004684ddb6SLionel Sambuc }; 8014684ddb6SLionel Sambuc 8024684ddb6SLionel Sambuc // constructors and reset functions 8034684ddb6SLionel Sambuc explicit poisson_distribution(double mean = 1.0); 8044684ddb6SLionel Sambuc explicit poisson_distribution(const param_type& parm); 8054684ddb6SLionel Sambuc void reset(); 8064684ddb6SLionel Sambuc 8074684ddb6SLionel Sambuc // generating functions 8084684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g); 8094684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g, const param_type& parm); 8104684ddb6SLionel Sambuc 8114684ddb6SLionel Sambuc // property functions 8124684ddb6SLionel Sambuc double mean() const; 8134684ddb6SLionel Sambuc 8144684ddb6SLionel Sambuc param_type param() const; 8154684ddb6SLionel Sambuc void param(const param_type& parm); 8164684ddb6SLionel Sambuc 8174684ddb6SLionel Sambuc result_type min() const; 8184684ddb6SLionel Sambuc result_type max() const; 8194684ddb6SLionel Sambuc 8204684ddb6SLionel Sambuc friend bool operator==(const poisson_distribution& x, 8214684ddb6SLionel Sambuc const poisson_distribution& y); 8224684ddb6SLionel Sambuc friend bool operator!=(const poisson_distribution& x, 8234684ddb6SLionel Sambuc const poisson_distribution& y); 8244684ddb6SLionel Sambuc 8254684ddb6SLionel Sambuc template <class charT, class traits> 8264684ddb6SLionel Sambuc friend 8274684ddb6SLionel Sambuc basic_ostream<charT, traits>& 8284684ddb6SLionel Sambuc operator<<(basic_ostream<charT, traits>& os, 8294684ddb6SLionel Sambuc const poisson_distribution& x); 8304684ddb6SLionel Sambuc 8314684ddb6SLionel Sambuc template <class charT, class traits> 8324684ddb6SLionel Sambuc friend 8334684ddb6SLionel Sambuc basic_istream<charT, traits>& 8344684ddb6SLionel Sambuc operator>>(basic_istream<charT, traits>& is, 8354684ddb6SLionel Sambuc poisson_distribution& x); 8364684ddb6SLionel Sambuc}; 8374684ddb6SLionel Sambuc 8384684ddb6SLionel Sambuctemplate<class RealType = double> 8394684ddb6SLionel Sambucclass exponential_distribution 8404684ddb6SLionel Sambuc{ 8414684ddb6SLionel Sambucpublic: 8424684ddb6SLionel Sambuc // types 8434684ddb6SLionel Sambuc typedef RealType result_type; 8444684ddb6SLionel Sambuc 8454684ddb6SLionel Sambuc class param_type 8464684ddb6SLionel Sambuc { 8474684ddb6SLionel Sambuc public: 8484684ddb6SLionel Sambuc typedef exponential_distribution distribution_type; 8494684ddb6SLionel Sambuc 8504684ddb6SLionel Sambuc explicit param_type(result_type lambda = 1.0); 8514684ddb6SLionel Sambuc 8524684ddb6SLionel Sambuc result_type lambda() const; 8534684ddb6SLionel Sambuc 8544684ddb6SLionel Sambuc friend bool operator==(const param_type& x, const param_type& y); 8554684ddb6SLionel Sambuc friend bool operator!=(const param_type& x, const param_type& y); 8564684ddb6SLionel Sambuc }; 8574684ddb6SLionel Sambuc 8584684ddb6SLionel Sambuc // constructors and reset functions 8594684ddb6SLionel Sambuc explicit exponential_distribution(result_type lambda = 1.0); 8604684ddb6SLionel Sambuc explicit exponential_distribution(const param_type& parm); 8614684ddb6SLionel Sambuc void reset(); 8624684ddb6SLionel Sambuc 8634684ddb6SLionel Sambuc // generating functions 8644684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g); 8654684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g, const param_type& parm); 8664684ddb6SLionel Sambuc 8674684ddb6SLionel Sambuc // property functions 8684684ddb6SLionel Sambuc result_type lambda() const; 8694684ddb6SLionel Sambuc 8704684ddb6SLionel Sambuc param_type param() const; 8714684ddb6SLionel Sambuc void param(const param_type& parm); 8724684ddb6SLionel Sambuc 8734684ddb6SLionel Sambuc result_type min() const; 8744684ddb6SLionel Sambuc result_type max() const; 8754684ddb6SLionel Sambuc 8764684ddb6SLionel Sambuc friend bool operator==(const exponential_distribution& x, 8774684ddb6SLionel Sambuc const exponential_distribution& y); 8784684ddb6SLionel Sambuc friend bool operator!=(const exponential_distribution& x, 8794684ddb6SLionel Sambuc const exponential_distribution& y); 8804684ddb6SLionel Sambuc 8814684ddb6SLionel Sambuc template <class charT, class traits> 8824684ddb6SLionel Sambuc friend 8834684ddb6SLionel Sambuc basic_ostream<charT, traits>& 8844684ddb6SLionel Sambuc operator<<(basic_ostream<charT, traits>& os, 8854684ddb6SLionel Sambuc const exponential_distribution& x); 8864684ddb6SLionel Sambuc 8874684ddb6SLionel Sambuc template <class charT, class traits> 8884684ddb6SLionel Sambuc friend 8894684ddb6SLionel Sambuc basic_istream<charT, traits>& 8904684ddb6SLionel Sambuc operator>>(basic_istream<charT, traits>& is, 8914684ddb6SLionel Sambuc exponential_distribution& x); 8924684ddb6SLionel Sambuc}; 8934684ddb6SLionel Sambuc 8944684ddb6SLionel Sambuctemplate<class RealType = double> 8954684ddb6SLionel Sambucclass gamma_distribution 8964684ddb6SLionel Sambuc{ 8974684ddb6SLionel Sambucpublic: 8984684ddb6SLionel Sambuc // types 8994684ddb6SLionel Sambuc typedef RealType result_type; 9004684ddb6SLionel Sambuc 9014684ddb6SLionel Sambuc class param_type 9024684ddb6SLionel Sambuc { 9034684ddb6SLionel Sambuc public: 9044684ddb6SLionel Sambuc typedef gamma_distribution distribution_type; 9054684ddb6SLionel Sambuc 9064684ddb6SLionel Sambuc explicit param_type(result_type alpha = 1, result_type beta = 1); 9074684ddb6SLionel Sambuc 9084684ddb6SLionel Sambuc result_type alpha() const; 9094684ddb6SLionel Sambuc result_type beta() const; 9104684ddb6SLionel Sambuc 9114684ddb6SLionel Sambuc friend bool operator==(const param_type& x, const param_type& y); 9124684ddb6SLionel Sambuc friend bool operator!=(const param_type& x, const param_type& y); 9134684ddb6SLionel Sambuc }; 9144684ddb6SLionel Sambuc 9154684ddb6SLionel Sambuc // constructors and reset functions 9164684ddb6SLionel Sambuc explicit gamma_distribution(result_type alpha = 1, result_type beta = 1); 9174684ddb6SLionel Sambuc explicit gamma_distribution(const param_type& parm); 9184684ddb6SLionel Sambuc void reset(); 9194684ddb6SLionel Sambuc 9204684ddb6SLionel Sambuc // generating functions 9214684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g); 9224684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g, const param_type& parm); 9234684ddb6SLionel Sambuc 9244684ddb6SLionel Sambuc // property functions 9254684ddb6SLionel Sambuc result_type alpha() const; 9264684ddb6SLionel Sambuc result_type beta() const; 9274684ddb6SLionel Sambuc 9284684ddb6SLionel Sambuc param_type param() const; 9294684ddb6SLionel Sambuc void param(const param_type& parm); 9304684ddb6SLionel Sambuc 9314684ddb6SLionel Sambuc result_type min() const; 9324684ddb6SLionel Sambuc result_type max() const; 9334684ddb6SLionel Sambuc 9344684ddb6SLionel Sambuc friend bool operator==(const gamma_distribution& x, 9354684ddb6SLionel Sambuc const gamma_distribution& y); 9364684ddb6SLionel Sambuc friend bool operator!=(const gamma_distribution& x, 9374684ddb6SLionel Sambuc const gamma_distribution& y); 9384684ddb6SLionel Sambuc 9394684ddb6SLionel Sambuc template <class charT, class traits> 9404684ddb6SLionel Sambuc friend 9414684ddb6SLionel Sambuc basic_ostream<charT, traits>& 9424684ddb6SLionel Sambuc operator<<(basic_ostream<charT, traits>& os, 9434684ddb6SLionel Sambuc const gamma_distribution& x); 9444684ddb6SLionel Sambuc 9454684ddb6SLionel Sambuc template <class charT, class traits> 9464684ddb6SLionel Sambuc friend 9474684ddb6SLionel Sambuc basic_istream<charT, traits>& 9484684ddb6SLionel Sambuc operator>>(basic_istream<charT, traits>& is, 9494684ddb6SLionel Sambuc gamma_distribution& x); 9504684ddb6SLionel Sambuc}; 9514684ddb6SLionel Sambuc 9524684ddb6SLionel Sambuctemplate<class RealType = double> 9534684ddb6SLionel Sambucclass weibull_distribution 9544684ddb6SLionel Sambuc{ 9554684ddb6SLionel Sambucpublic: 9564684ddb6SLionel Sambuc // types 9574684ddb6SLionel Sambuc typedef RealType result_type; 9584684ddb6SLionel Sambuc 9594684ddb6SLionel Sambuc class param_type 9604684ddb6SLionel Sambuc { 9614684ddb6SLionel Sambuc public: 9624684ddb6SLionel Sambuc typedef weibull_distribution distribution_type; 9634684ddb6SLionel Sambuc 9644684ddb6SLionel Sambuc explicit param_type(result_type alpha = 1, result_type beta = 1); 9654684ddb6SLionel Sambuc 9664684ddb6SLionel Sambuc result_type a() const; 9674684ddb6SLionel Sambuc result_type b() const; 9684684ddb6SLionel Sambuc 9694684ddb6SLionel Sambuc friend bool operator==(const param_type& x, const param_type& y); 9704684ddb6SLionel Sambuc friend bool operator!=(const param_type& x, const param_type& y); 9714684ddb6SLionel Sambuc }; 9724684ddb6SLionel Sambuc 9734684ddb6SLionel Sambuc // constructor and reset functions 9744684ddb6SLionel Sambuc explicit weibull_distribution(result_type a = 1, result_type b = 1); 9754684ddb6SLionel Sambuc explicit weibull_distribution(const param_type& parm); 9764684ddb6SLionel Sambuc void reset(); 9774684ddb6SLionel Sambuc 9784684ddb6SLionel Sambuc // generating functions 9794684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g); 9804684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g, const param_type& parm); 9814684ddb6SLionel Sambuc 9824684ddb6SLionel Sambuc // property functions 9834684ddb6SLionel Sambuc result_type a() const; 9844684ddb6SLionel Sambuc result_type b() const; 9854684ddb6SLionel Sambuc 9864684ddb6SLionel Sambuc param_type param() const; 9874684ddb6SLionel Sambuc void param(const param_type& parm); 9884684ddb6SLionel Sambuc 9894684ddb6SLionel Sambuc result_type min() const; 9904684ddb6SLionel Sambuc result_type max() const; 9914684ddb6SLionel Sambuc 9924684ddb6SLionel Sambuc friend bool operator==(const weibull_distribution& x, 9934684ddb6SLionel Sambuc const weibull_distribution& y); 9944684ddb6SLionel Sambuc friend bool operator!=(const weibull_distribution& x, 9954684ddb6SLionel Sambuc const weibull_distribution& y); 9964684ddb6SLionel Sambuc 9974684ddb6SLionel Sambuc template <class charT, class traits> 9984684ddb6SLionel Sambuc friend 9994684ddb6SLionel Sambuc basic_ostream<charT, traits>& 10004684ddb6SLionel Sambuc operator<<(basic_ostream<charT, traits>& os, 10014684ddb6SLionel Sambuc const weibull_distribution& x); 10024684ddb6SLionel Sambuc 10034684ddb6SLionel Sambuc template <class charT, class traits> 10044684ddb6SLionel Sambuc friend 10054684ddb6SLionel Sambuc basic_istream<charT, traits>& 10064684ddb6SLionel Sambuc operator>>(basic_istream<charT, traits>& is, 10074684ddb6SLionel Sambuc weibull_distribution& x); 10084684ddb6SLionel Sambuc}; 10094684ddb6SLionel Sambuc 10104684ddb6SLionel Sambuctemplate<class RealType = double> 10114684ddb6SLionel Sambucclass extreme_value_distribution 10124684ddb6SLionel Sambuc{ 10134684ddb6SLionel Sambucpublic: 10144684ddb6SLionel Sambuc // types 10154684ddb6SLionel Sambuc typedef RealType result_type; 10164684ddb6SLionel Sambuc 10174684ddb6SLionel Sambuc class param_type 10184684ddb6SLionel Sambuc { 10194684ddb6SLionel Sambuc public: 10204684ddb6SLionel Sambuc typedef extreme_value_distribution distribution_type; 10214684ddb6SLionel Sambuc 10224684ddb6SLionel Sambuc explicit param_type(result_type a = 0, result_type b = 1); 10234684ddb6SLionel Sambuc 10244684ddb6SLionel Sambuc result_type a() const; 10254684ddb6SLionel Sambuc result_type b() const; 10264684ddb6SLionel Sambuc 10274684ddb6SLionel Sambuc friend bool operator==(const param_type& x, const param_type& y); 10284684ddb6SLionel Sambuc friend bool operator!=(const param_type& x, const param_type& y); 10294684ddb6SLionel Sambuc }; 10304684ddb6SLionel Sambuc 10314684ddb6SLionel Sambuc // constructor and reset functions 10324684ddb6SLionel Sambuc explicit extreme_value_distribution(result_type a = 0, result_type b = 1); 10334684ddb6SLionel Sambuc explicit extreme_value_distribution(const param_type& parm); 10344684ddb6SLionel Sambuc void reset(); 10354684ddb6SLionel Sambuc 10364684ddb6SLionel Sambuc // generating functions 10374684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g); 10384684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g, const param_type& parm); 10394684ddb6SLionel Sambuc 10404684ddb6SLionel Sambuc // property functions 10414684ddb6SLionel Sambuc result_type a() const; 10424684ddb6SLionel Sambuc result_type b() const; 10434684ddb6SLionel Sambuc 10444684ddb6SLionel Sambuc param_type param() const; 10454684ddb6SLionel Sambuc void param(const param_type& parm); 10464684ddb6SLionel Sambuc 10474684ddb6SLionel Sambuc result_type min() const; 10484684ddb6SLionel Sambuc result_type max() const; 10494684ddb6SLionel Sambuc 10504684ddb6SLionel Sambuc friend bool operator==(const extreme_value_distribution& x, 10514684ddb6SLionel Sambuc const extreme_value_distribution& y); 10524684ddb6SLionel Sambuc friend bool operator!=(const extreme_value_distribution& x, 10534684ddb6SLionel Sambuc const extreme_value_distribution& y); 10544684ddb6SLionel Sambuc 10554684ddb6SLionel Sambuc template <class charT, class traits> 10564684ddb6SLionel Sambuc friend 10574684ddb6SLionel Sambuc basic_ostream<charT, traits>& 10584684ddb6SLionel Sambuc operator<<(basic_ostream<charT, traits>& os, 10594684ddb6SLionel Sambuc const extreme_value_distribution& x); 10604684ddb6SLionel Sambuc 10614684ddb6SLionel Sambuc template <class charT, class traits> 10624684ddb6SLionel Sambuc friend 10634684ddb6SLionel Sambuc basic_istream<charT, traits>& 10644684ddb6SLionel Sambuc operator>>(basic_istream<charT, traits>& is, 10654684ddb6SLionel Sambuc extreme_value_distribution& x); 10664684ddb6SLionel Sambuc}; 10674684ddb6SLionel Sambuc 10684684ddb6SLionel Sambuctemplate<class RealType = double> 10694684ddb6SLionel Sambucclass normal_distribution 10704684ddb6SLionel Sambuc{ 10714684ddb6SLionel Sambucpublic: 10724684ddb6SLionel Sambuc // types 10734684ddb6SLionel Sambuc typedef RealType result_type; 10744684ddb6SLionel Sambuc 10754684ddb6SLionel Sambuc class param_type 10764684ddb6SLionel Sambuc { 10774684ddb6SLionel Sambuc public: 10784684ddb6SLionel Sambuc typedef normal_distribution distribution_type; 10794684ddb6SLionel Sambuc 10804684ddb6SLionel Sambuc explicit param_type(result_type mean = 0, result_type stddev = 1); 10814684ddb6SLionel Sambuc 10824684ddb6SLionel Sambuc result_type mean() const; 10834684ddb6SLionel Sambuc result_type stddev() const; 10844684ddb6SLionel Sambuc 10854684ddb6SLionel Sambuc friend bool operator==(const param_type& x, const param_type& y); 10864684ddb6SLionel Sambuc friend bool operator!=(const param_type& x, const param_type& y); 10874684ddb6SLionel Sambuc }; 10884684ddb6SLionel Sambuc 10894684ddb6SLionel Sambuc // constructors and reset functions 10904684ddb6SLionel Sambuc explicit normal_distribution(result_type mean = 0, result_type stddev = 1); 10914684ddb6SLionel Sambuc explicit normal_distribution(const param_type& parm); 10924684ddb6SLionel Sambuc void reset(); 10934684ddb6SLionel Sambuc 10944684ddb6SLionel Sambuc // generating functions 10954684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g); 10964684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g, const param_type& parm); 10974684ddb6SLionel Sambuc 10984684ddb6SLionel Sambuc // property functions 10994684ddb6SLionel Sambuc result_type mean() const; 11004684ddb6SLionel Sambuc result_type stddev() const; 11014684ddb6SLionel Sambuc 11024684ddb6SLionel Sambuc param_type param() const; 11034684ddb6SLionel Sambuc void param(const param_type& parm); 11044684ddb6SLionel Sambuc 11054684ddb6SLionel Sambuc result_type min() const; 11064684ddb6SLionel Sambuc result_type max() const; 11074684ddb6SLionel Sambuc 11084684ddb6SLionel Sambuc friend bool operator==(const normal_distribution& x, 11094684ddb6SLionel Sambuc const normal_distribution& y); 11104684ddb6SLionel Sambuc friend bool operator!=(const normal_distribution& x, 11114684ddb6SLionel Sambuc const normal_distribution& y); 11124684ddb6SLionel Sambuc 11134684ddb6SLionel Sambuc template <class charT, class traits> 11144684ddb6SLionel Sambuc friend 11154684ddb6SLionel Sambuc basic_ostream<charT, traits>& 11164684ddb6SLionel Sambuc operator<<(basic_ostream<charT, traits>& os, 11174684ddb6SLionel Sambuc const normal_distribution& x); 11184684ddb6SLionel Sambuc 11194684ddb6SLionel Sambuc template <class charT, class traits> 11204684ddb6SLionel Sambuc friend 11214684ddb6SLionel Sambuc basic_istream<charT, traits>& 11224684ddb6SLionel Sambuc operator>>(basic_istream<charT, traits>& is, 11234684ddb6SLionel Sambuc normal_distribution& x); 11244684ddb6SLionel Sambuc}; 11254684ddb6SLionel Sambuc 11264684ddb6SLionel Sambuctemplate<class RealType = double> 11274684ddb6SLionel Sambucclass lognormal_distribution 11284684ddb6SLionel Sambuc{ 11294684ddb6SLionel Sambucpublic: 11304684ddb6SLionel Sambuc // types 11314684ddb6SLionel Sambuc typedef RealType result_type; 11324684ddb6SLionel Sambuc 11334684ddb6SLionel Sambuc class param_type 11344684ddb6SLionel Sambuc { 11354684ddb6SLionel Sambuc public: 11364684ddb6SLionel Sambuc typedef lognormal_distribution distribution_type; 11374684ddb6SLionel Sambuc 11384684ddb6SLionel Sambuc explicit param_type(result_type m = 0, result_type s = 1); 11394684ddb6SLionel Sambuc 11404684ddb6SLionel Sambuc result_type m() const; 11414684ddb6SLionel Sambuc result_type s() const; 11424684ddb6SLionel Sambuc 11434684ddb6SLionel Sambuc friend bool operator==(const param_type& x, const param_type& y); 11444684ddb6SLionel Sambuc friend bool operator!=(const param_type& x, const param_type& y); 11454684ddb6SLionel Sambuc }; 11464684ddb6SLionel Sambuc 11474684ddb6SLionel Sambuc // constructor and reset functions 11484684ddb6SLionel Sambuc explicit lognormal_distribution(result_type m = 0, result_type s = 1); 11494684ddb6SLionel Sambuc explicit lognormal_distribution(const param_type& parm); 11504684ddb6SLionel Sambuc void reset(); 11514684ddb6SLionel Sambuc 11524684ddb6SLionel Sambuc // generating functions 11534684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g); 11544684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g, const param_type& parm); 11554684ddb6SLionel Sambuc 11564684ddb6SLionel Sambuc // property functions 11574684ddb6SLionel Sambuc result_type m() const; 11584684ddb6SLionel Sambuc result_type s() const; 11594684ddb6SLionel Sambuc 11604684ddb6SLionel Sambuc param_type param() const; 11614684ddb6SLionel Sambuc void param(const param_type& parm); 11624684ddb6SLionel Sambuc 11634684ddb6SLionel Sambuc result_type min() const; 11644684ddb6SLionel Sambuc result_type max() const; 11654684ddb6SLionel Sambuc 11664684ddb6SLionel Sambuc friend bool operator==(const lognormal_distribution& x, 11674684ddb6SLionel Sambuc const lognormal_distribution& y); 11684684ddb6SLionel Sambuc friend bool operator!=(const lognormal_distribution& x, 11694684ddb6SLionel Sambuc const lognormal_distribution& y); 11704684ddb6SLionel Sambuc 11714684ddb6SLionel Sambuc template <class charT, class traits> 11724684ddb6SLionel Sambuc friend 11734684ddb6SLionel Sambuc basic_ostream<charT, traits>& 11744684ddb6SLionel Sambuc operator<<(basic_ostream<charT, traits>& os, 11754684ddb6SLionel Sambuc const lognormal_distribution& x); 11764684ddb6SLionel Sambuc 11774684ddb6SLionel Sambuc template <class charT, class traits> 11784684ddb6SLionel Sambuc friend 11794684ddb6SLionel Sambuc basic_istream<charT, traits>& 11804684ddb6SLionel Sambuc operator>>(basic_istream<charT, traits>& is, 11814684ddb6SLionel Sambuc lognormal_distribution& x); 11824684ddb6SLionel Sambuc}; 11834684ddb6SLionel Sambuc 11844684ddb6SLionel Sambuctemplate<class RealType = double> 11854684ddb6SLionel Sambucclass chi_squared_distribution 11864684ddb6SLionel Sambuc{ 11874684ddb6SLionel Sambucpublic: 11884684ddb6SLionel Sambuc // types 11894684ddb6SLionel Sambuc typedef RealType result_type; 11904684ddb6SLionel Sambuc 11914684ddb6SLionel Sambuc class param_type 11924684ddb6SLionel Sambuc { 11934684ddb6SLionel Sambuc public: 11944684ddb6SLionel Sambuc typedef chi_squared_distribution distribution_type; 11954684ddb6SLionel Sambuc 11964684ddb6SLionel Sambuc explicit param_type(result_type n = 1); 11974684ddb6SLionel Sambuc 11984684ddb6SLionel Sambuc result_type n() const; 11994684ddb6SLionel Sambuc 12004684ddb6SLionel Sambuc friend bool operator==(const param_type& x, const param_type& y); 12014684ddb6SLionel Sambuc friend bool operator!=(const param_type& x, const param_type& y); 12024684ddb6SLionel Sambuc }; 12034684ddb6SLionel Sambuc 12044684ddb6SLionel Sambuc // constructor and reset functions 12054684ddb6SLionel Sambuc explicit chi_squared_distribution(result_type n = 1); 12064684ddb6SLionel Sambuc explicit chi_squared_distribution(const param_type& parm); 12074684ddb6SLionel Sambuc void reset(); 12084684ddb6SLionel Sambuc 12094684ddb6SLionel Sambuc // generating functions 12104684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g); 12114684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g, const param_type& parm); 12124684ddb6SLionel Sambuc 12134684ddb6SLionel Sambuc // property functions 12144684ddb6SLionel Sambuc result_type n() const; 12154684ddb6SLionel Sambuc 12164684ddb6SLionel Sambuc param_type param() const; 12174684ddb6SLionel Sambuc void param(const param_type& parm); 12184684ddb6SLionel Sambuc 12194684ddb6SLionel Sambuc result_type min() const; 12204684ddb6SLionel Sambuc result_type max() const; 12214684ddb6SLionel Sambuc 12224684ddb6SLionel Sambuc friend bool operator==(const chi_squared_distribution& x, 12234684ddb6SLionel Sambuc const chi_squared_distribution& y); 12244684ddb6SLionel Sambuc friend bool operator!=(const chi_squared_distribution& x, 12254684ddb6SLionel Sambuc const chi_squared_distribution& y); 12264684ddb6SLionel Sambuc 12274684ddb6SLionel Sambuc template <class charT, class traits> 12284684ddb6SLionel Sambuc friend 12294684ddb6SLionel Sambuc basic_ostream<charT, traits>& 12304684ddb6SLionel Sambuc operator<<(basic_ostream<charT, traits>& os, 12314684ddb6SLionel Sambuc const chi_squared_distribution& x); 12324684ddb6SLionel Sambuc 12334684ddb6SLionel Sambuc template <class charT, class traits> 12344684ddb6SLionel Sambuc friend 12354684ddb6SLionel Sambuc basic_istream<charT, traits>& 12364684ddb6SLionel Sambuc operator>>(basic_istream<charT, traits>& is, 12374684ddb6SLionel Sambuc chi_squared_distribution& x); 12384684ddb6SLionel Sambuc}; 12394684ddb6SLionel Sambuc 12404684ddb6SLionel Sambuctemplate<class RealType = double> 12414684ddb6SLionel Sambucclass cauchy_distribution 12424684ddb6SLionel Sambuc{ 12434684ddb6SLionel Sambucpublic: 12444684ddb6SLionel Sambuc // types 12454684ddb6SLionel Sambuc typedef RealType result_type; 12464684ddb6SLionel Sambuc 12474684ddb6SLionel Sambuc class param_type 12484684ddb6SLionel Sambuc { 12494684ddb6SLionel Sambuc public: 12504684ddb6SLionel Sambuc typedef cauchy_distribution distribution_type; 12514684ddb6SLionel Sambuc 12524684ddb6SLionel Sambuc explicit param_type(result_type a = 0, result_type b = 1); 12534684ddb6SLionel Sambuc 12544684ddb6SLionel Sambuc result_type a() const; 12554684ddb6SLionel Sambuc result_type b() const; 12564684ddb6SLionel Sambuc 12574684ddb6SLionel Sambuc friend bool operator==(const param_type& x, const param_type& y); 12584684ddb6SLionel Sambuc friend bool operator!=(const param_type& x, const param_type& y); 12594684ddb6SLionel Sambuc }; 12604684ddb6SLionel Sambuc 12614684ddb6SLionel Sambuc // constructor and reset functions 12624684ddb6SLionel Sambuc explicit cauchy_distribution(result_type a = 0, result_type b = 1); 12634684ddb6SLionel Sambuc explicit cauchy_distribution(const param_type& parm); 12644684ddb6SLionel Sambuc void reset(); 12654684ddb6SLionel Sambuc 12664684ddb6SLionel Sambuc // generating functions 12674684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g); 12684684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g, const param_type& parm); 12694684ddb6SLionel Sambuc 12704684ddb6SLionel Sambuc // property functions 12714684ddb6SLionel Sambuc result_type a() const; 12724684ddb6SLionel Sambuc result_type b() const; 12734684ddb6SLionel Sambuc 12744684ddb6SLionel Sambuc param_type param() const; 12754684ddb6SLionel Sambuc void param(const param_type& parm); 12764684ddb6SLionel Sambuc 12774684ddb6SLionel Sambuc result_type min() const; 12784684ddb6SLionel Sambuc result_type max() const; 12794684ddb6SLionel Sambuc 12804684ddb6SLionel Sambuc friend bool operator==(const cauchy_distribution& x, 12814684ddb6SLionel Sambuc const cauchy_distribution& y); 12824684ddb6SLionel Sambuc friend bool operator!=(const cauchy_distribution& x, 12834684ddb6SLionel Sambuc const cauchy_distribution& y); 12844684ddb6SLionel Sambuc 12854684ddb6SLionel Sambuc template <class charT, class traits> 12864684ddb6SLionel Sambuc friend 12874684ddb6SLionel Sambuc basic_ostream<charT, traits>& 12884684ddb6SLionel Sambuc operator<<(basic_ostream<charT, traits>& os, 12894684ddb6SLionel Sambuc const cauchy_distribution& x); 12904684ddb6SLionel Sambuc 12914684ddb6SLionel Sambuc template <class charT, class traits> 12924684ddb6SLionel Sambuc friend 12934684ddb6SLionel Sambuc basic_istream<charT, traits>& 12944684ddb6SLionel Sambuc operator>>(basic_istream<charT, traits>& is, 12954684ddb6SLionel Sambuc cauchy_distribution& x); 12964684ddb6SLionel Sambuc}; 12974684ddb6SLionel Sambuc 12984684ddb6SLionel Sambuctemplate<class RealType = double> 12994684ddb6SLionel Sambucclass fisher_f_distribution 13004684ddb6SLionel Sambuc{ 13014684ddb6SLionel Sambucpublic: 13024684ddb6SLionel Sambuc // types 13034684ddb6SLionel Sambuc typedef RealType result_type; 13044684ddb6SLionel Sambuc 13054684ddb6SLionel Sambuc class param_type 13064684ddb6SLionel Sambuc { 13074684ddb6SLionel Sambuc public: 13084684ddb6SLionel Sambuc typedef fisher_f_distribution distribution_type; 13094684ddb6SLionel Sambuc 13104684ddb6SLionel Sambuc explicit param_type(result_type m = 1, result_type n = 1); 13114684ddb6SLionel Sambuc 13124684ddb6SLionel Sambuc result_type m() const; 13134684ddb6SLionel Sambuc result_type n() const; 13144684ddb6SLionel Sambuc 13154684ddb6SLionel Sambuc friend bool operator==(const param_type& x, const param_type& y); 13164684ddb6SLionel Sambuc friend bool operator!=(const param_type& x, const param_type& y); 13174684ddb6SLionel Sambuc }; 13184684ddb6SLionel Sambuc 13194684ddb6SLionel Sambuc // constructor and reset functions 13204684ddb6SLionel Sambuc explicit fisher_f_distribution(result_type m = 1, result_type n = 1); 13214684ddb6SLionel Sambuc explicit fisher_f_distribution(const param_type& parm); 13224684ddb6SLionel Sambuc void reset(); 13234684ddb6SLionel Sambuc 13244684ddb6SLionel Sambuc // generating functions 13254684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g); 13264684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g, const param_type& parm); 13274684ddb6SLionel Sambuc 13284684ddb6SLionel Sambuc // property functions 13294684ddb6SLionel Sambuc result_type m() const; 13304684ddb6SLionel Sambuc result_type n() const; 13314684ddb6SLionel Sambuc 13324684ddb6SLionel Sambuc param_type param() const; 13334684ddb6SLionel Sambuc void param(const param_type& parm); 13344684ddb6SLionel Sambuc 13354684ddb6SLionel Sambuc result_type min() const; 13364684ddb6SLionel Sambuc result_type max() const; 13374684ddb6SLionel Sambuc 13384684ddb6SLionel Sambuc friend bool operator==(const fisher_f_distribution& x, 13394684ddb6SLionel Sambuc const fisher_f_distribution& y); 13404684ddb6SLionel Sambuc friend bool operator!=(const fisher_f_distribution& x, 13414684ddb6SLionel Sambuc const fisher_f_distribution& y); 13424684ddb6SLionel Sambuc 13434684ddb6SLionel Sambuc template <class charT, class traits> 13444684ddb6SLionel Sambuc friend 13454684ddb6SLionel Sambuc basic_ostream<charT, traits>& 13464684ddb6SLionel Sambuc operator<<(basic_ostream<charT, traits>& os, 13474684ddb6SLionel Sambuc const fisher_f_distribution& x); 13484684ddb6SLionel Sambuc 13494684ddb6SLionel Sambuc template <class charT, class traits> 13504684ddb6SLionel Sambuc friend 13514684ddb6SLionel Sambuc basic_istream<charT, traits>& 13524684ddb6SLionel Sambuc operator>>(basic_istream<charT, traits>& is, 13534684ddb6SLionel Sambuc fisher_f_distribution& x); 13544684ddb6SLionel Sambuc}; 13554684ddb6SLionel Sambuc 13564684ddb6SLionel Sambuctemplate<class RealType = double> 13574684ddb6SLionel Sambucclass student_t_distribution 13584684ddb6SLionel Sambuc{ 13594684ddb6SLionel Sambucpublic: 13604684ddb6SLionel Sambuc // types 13614684ddb6SLionel Sambuc typedef RealType result_type; 13624684ddb6SLionel Sambuc 13634684ddb6SLionel Sambuc class param_type 13644684ddb6SLionel Sambuc { 13654684ddb6SLionel Sambuc public: 13664684ddb6SLionel Sambuc typedef student_t_distribution distribution_type; 13674684ddb6SLionel Sambuc 13684684ddb6SLionel Sambuc explicit param_type(result_type n = 1); 13694684ddb6SLionel Sambuc 13704684ddb6SLionel Sambuc result_type n() const; 13714684ddb6SLionel Sambuc 13724684ddb6SLionel Sambuc friend bool operator==(const param_type& x, const param_type& y); 13734684ddb6SLionel Sambuc friend bool operator!=(const param_type& x, const param_type& y); 13744684ddb6SLionel Sambuc }; 13754684ddb6SLionel Sambuc 13764684ddb6SLionel Sambuc // constructor and reset functions 13774684ddb6SLionel Sambuc explicit student_t_distribution(result_type n = 1); 13784684ddb6SLionel Sambuc explicit student_t_distribution(const param_type& parm); 13794684ddb6SLionel Sambuc void reset(); 13804684ddb6SLionel Sambuc 13814684ddb6SLionel Sambuc // generating functions 13824684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g); 13834684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g, const param_type& parm); 13844684ddb6SLionel Sambuc 13854684ddb6SLionel Sambuc // property functions 13864684ddb6SLionel Sambuc result_type n() const; 13874684ddb6SLionel Sambuc 13884684ddb6SLionel Sambuc param_type param() const; 13894684ddb6SLionel Sambuc void param(const param_type& parm); 13904684ddb6SLionel Sambuc 13914684ddb6SLionel Sambuc result_type min() const; 13924684ddb6SLionel Sambuc result_type max() const; 13934684ddb6SLionel Sambuc 13944684ddb6SLionel Sambuc friend bool operator==(const student_t_distribution& x, 13954684ddb6SLionel Sambuc const student_t_distribution& y); 13964684ddb6SLionel Sambuc friend bool operator!=(const student_t_distribution& x, 13974684ddb6SLionel Sambuc const student_t_distribution& y); 13984684ddb6SLionel Sambuc 13994684ddb6SLionel Sambuc template <class charT, class traits> 14004684ddb6SLionel Sambuc friend 14014684ddb6SLionel Sambuc basic_ostream<charT, traits>& 14024684ddb6SLionel Sambuc operator<<(basic_ostream<charT, traits>& os, 14034684ddb6SLionel Sambuc const student_t_distribution& x); 14044684ddb6SLionel Sambuc 14054684ddb6SLionel Sambuc template <class charT, class traits> 14064684ddb6SLionel Sambuc friend 14074684ddb6SLionel Sambuc basic_istream<charT, traits>& 14084684ddb6SLionel Sambuc operator>>(basic_istream<charT, traits>& is, 14094684ddb6SLionel Sambuc student_t_distribution& x); 14104684ddb6SLionel Sambuc}; 14114684ddb6SLionel Sambuc 14124684ddb6SLionel Sambuctemplate<class IntType = int> 14134684ddb6SLionel Sambucclass discrete_distribution 14144684ddb6SLionel Sambuc{ 14154684ddb6SLionel Sambucpublic: 14164684ddb6SLionel Sambuc // types 14174684ddb6SLionel Sambuc typedef IntType result_type; 14184684ddb6SLionel Sambuc 14194684ddb6SLionel Sambuc class param_type 14204684ddb6SLionel Sambuc { 14214684ddb6SLionel Sambuc public: 14224684ddb6SLionel Sambuc typedef discrete_distribution distribution_type; 14234684ddb6SLionel Sambuc 14244684ddb6SLionel Sambuc param_type(); 14254684ddb6SLionel Sambuc template<class InputIterator> 14264684ddb6SLionel Sambuc param_type(InputIterator firstW, InputIterator lastW); 14274684ddb6SLionel Sambuc param_type(initializer_list<double> wl); 14284684ddb6SLionel Sambuc template<class UnaryOperation> 14294684ddb6SLionel Sambuc param_type(size_t nw, double xmin, double xmax, UnaryOperation fw); 14304684ddb6SLionel Sambuc 14314684ddb6SLionel Sambuc vector<double> probabilities() const; 14324684ddb6SLionel Sambuc 14334684ddb6SLionel Sambuc friend bool operator==(const param_type& x, const param_type& y); 14344684ddb6SLionel Sambuc friend bool operator!=(const param_type& x, const param_type& y); 14354684ddb6SLionel Sambuc }; 14364684ddb6SLionel Sambuc 14374684ddb6SLionel Sambuc // constructor and reset functions 14384684ddb6SLionel Sambuc discrete_distribution(); 14394684ddb6SLionel Sambuc template<class InputIterator> 14404684ddb6SLionel Sambuc discrete_distribution(InputIterator firstW, InputIterator lastW); 14414684ddb6SLionel Sambuc discrete_distribution(initializer_list<double> wl); 14424684ddb6SLionel Sambuc template<class UnaryOperation> 14434684ddb6SLionel Sambuc discrete_distribution(size_t nw, double xmin, double xmax, 14444684ddb6SLionel Sambuc UnaryOperation fw); 14454684ddb6SLionel Sambuc explicit discrete_distribution(const param_type& parm); 14464684ddb6SLionel Sambuc void reset(); 14474684ddb6SLionel Sambuc 14484684ddb6SLionel Sambuc // generating functions 14494684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g); 14504684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g, const param_type& parm); 14514684ddb6SLionel Sambuc 14524684ddb6SLionel Sambuc // property functions 14534684ddb6SLionel Sambuc vector<double> probabilities() const; 14544684ddb6SLionel Sambuc 14554684ddb6SLionel Sambuc param_type param() const; 14564684ddb6SLionel Sambuc void param(const param_type& parm); 14574684ddb6SLionel Sambuc 14584684ddb6SLionel Sambuc result_type min() const; 14594684ddb6SLionel Sambuc result_type max() const; 14604684ddb6SLionel Sambuc 14614684ddb6SLionel Sambuc friend bool operator==(const discrete_distribution& x, 14624684ddb6SLionel Sambuc const discrete_distribution& y); 14634684ddb6SLionel Sambuc friend bool operator!=(const discrete_distribution& x, 14644684ddb6SLionel Sambuc const discrete_distribution& y); 14654684ddb6SLionel Sambuc 14664684ddb6SLionel Sambuc template <class charT, class traits> 14674684ddb6SLionel Sambuc friend 14684684ddb6SLionel Sambuc basic_ostream<charT, traits>& 14694684ddb6SLionel Sambuc operator<<(basic_ostream<charT, traits>& os, 14704684ddb6SLionel Sambuc const discrete_distribution& x); 14714684ddb6SLionel Sambuc 14724684ddb6SLionel Sambuc template <class charT, class traits> 14734684ddb6SLionel Sambuc friend 14744684ddb6SLionel Sambuc basic_istream<charT, traits>& 14754684ddb6SLionel Sambuc operator>>(basic_istream<charT, traits>& is, 14764684ddb6SLionel Sambuc discrete_distribution& x); 14774684ddb6SLionel Sambuc}; 14784684ddb6SLionel Sambuc 14794684ddb6SLionel Sambuctemplate<class RealType = double> 14804684ddb6SLionel Sambucclass piecewise_constant_distribution 14814684ddb6SLionel Sambuc{ 14824684ddb6SLionel Sambuc // types 14834684ddb6SLionel Sambuc typedef RealType result_type; 14844684ddb6SLionel Sambuc 14854684ddb6SLionel Sambuc class param_type 14864684ddb6SLionel Sambuc { 14874684ddb6SLionel Sambuc public: 14884684ddb6SLionel Sambuc typedef piecewise_constant_distribution distribution_type; 14894684ddb6SLionel Sambuc 14904684ddb6SLionel Sambuc param_type(); 14914684ddb6SLionel Sambuc template<class InputIteratorB, class InputIteratorW> 14924684ddb6SLionel Sambuc param_type(InputIteratorB firstB, InputIteratorB lastB, 14934684ddb6SLionel Sambuc InputIteratorW firstW); 14944684ddb6SLionel Sambuc template<class UnaryOperation> 14954684ddb6SLionel Sambuc param_type(initializer_list<result_type> bl, UnaryOperation fw); 14964684ddb6SLionel Sambuc template<class UnaryOperation> 14974684ddb6SLionel Sambuc param_type(size_t nw, result_type xmin, result_type xmax, 14984684ddb6SLionel Sambuc UnaryOperation fw); 14994684ddb6SLionel Sambuc 15004684ddb6SLionel Sambuc vector<result_type> intervals() const; 15014684ddb6SLionel Sambuc vector<result_type> densities() const; 15024684ddb6SLionel Sambuc 15034684ddb6SLionel Sambuc friend bool operator==(const param_type& x, const param_type& y); 15044684ddb6SLionel Sambuc friend bool operator!=(const param_type& x, const param_type& y); 15054684ddb6SLionel Sambuc }; 15064684ddb6SLionel Sambuc 15074684ddb6SLionel Sambuc // constructor and reset functions 15084684ddb6SLionel Sambuc piecewise_constant_distribution(); 15094684ddb6SLionel Sambuc template<class InputIteratorB, class InputIteratorW> 15104684ddb6SLionel Sambuc piecewise_constant_distribution(InputIteratorB firstB, 15114684ddb6SLionel Sambuc InputIteratorB lastB, 15124684ddb6SLionel Sambuc InputIteratorW firstW); 15134684ddb6SLionel Sambuc template<class UnaryOperation> 15144684ddb6SLionel Sambuc piecewise_constant_distribution(initializer_list<result_type> bl, 15154684ddb6SLionel Sambuc UnaryOperation fw); 15164684ddb6SLionel Sambuc template<class UnaryOperation> 15174684ddb6SLionel Sambuc piecewise_constant_distribution(size_t nw, result_type xmin, 15184684ddb6SLionel Sambuc result_type xmax, UnaryOperation fw); 15194684ddb6SLionel Sambuc explicit piecewise_constant_distribution(const param_type& parm); 15204684ddb6SLionel Sambuc void reset(); 15214684ddb6SLionel Sambuc 15224684ddb6SLionel Sambuc // generating functions 15234684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g); 15244684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g, const param_type& parm); 15254684ddb6SLionel Sambuc 15264684ddb6SLionel Sambuc // property functions 15274684ddb6SLionel Sambuc vector<result_type> intervals() const; 15284684ddb6SLionel Sambuc vector<result_type> densities() const; 15294684ddb6SLionel Sambuc 15304684ddb6SLionel Sambuc param_type param() const; 15314684ddb6SLionel Sambuc void param(const param_type& parm); 15324684ddb6SLionel Sambuc 15334684ddb6SLionel Sambuc result_type min() const; 15344684ddb6SLionel Sambuc result_type max() const; 15354684ddb6SLionel Sambuc 15364684ddb6SLionel Sambuc friend bool operator==(const piecewise_constant_distribution& x, 15374684ddb6SLionel Sambuc const piecewise_constant_distribution& y); 15384684ddb6SLionel Sambuc friend bool operator!=(const piecewise_constant_distribution& x, 15394684ddb6SLionel Sambuc const piecewise_constant_distribution& y); 15404684ddb6SLionel Sambuc 15414684ddb6SLionel Sambuc template <class charT, class traits> 15424684ddb6SLionel Sambuc friend 15434684ddb6SLionel Sambuc basic_ostream<charT, traits>& 15444684ddb6SLionel Sambuc operator<<(basic_ostream<charT, traits>& os, 15454684ddb6SLionel Sambuc const piecewise_constant_distribution& x); 15464684ddb6SLionel Sambuc 15474684ddb6SLionel Sambuc template <class charT, class traits> 15484684ddb6SLionel Sambuc friend 15494684ddb6SLionel Sambuc basic_istream<charT, traits>& 15504684ddb6SLionel Sambuc operator>>(basic_istream<charT, traits>& is, 15514684ddb6SLionel Sambuc piecewise_constant_distribution& x); 15524684ddb6SLionel Sambuc}; 15534684ddb6SLionel Sambuc 15544684ddb6SLionel Sambuctemplate<class RealType = double> 15554684ddb6SLionel Sambucclass piecewise_linear_distribution 15564684ddb6SLionel Sambuc{ 15574684ddb6SLionel Sambuc // types 15584684ddb6SLionel Sambuc typedef RealType result_type; 15594684ddb6SLionel Sambuc 15604684ddb6SLionel Sambuc class param_type 15614684ddb6SLionel Sambuc { 15624684ddb6SLionel Sambuc public: 15634684ddb6SLionel Sambuc typedef piecewise_linear_distribution distribution_type; 15644684ddb6SLionel Sambuc 15654684ddb6SLionel Sambuc param_type(); 15664684ddb6SLionel Sambuc template<class InputIteratorB, class InputIteratorW> 15674684ddb6SLionel Sambuc param_type(InputIteratorB firstB, InputIteratorB lastB, 15684684ddb6SLionel Sambuc InputIteratorW firstW); 15694684ddb6SLionel Sambuc template<class UnaryOperation> 15704684ddb6SLionel Sambuc param_type(initializer_list<result_type> bl, UnaryOperation fw); 15714684ddb6SLionel Sambuc template<class UnaryOperation> 15724684ddb6SLionel Sambuc param_type(size_t nw, result_type xmin, result_type xmax, 15734684ddb6SLionel Sambuc UnaryOperation fw); 15744684ddb6SLionel Sambuc 15754684ddb6SLionel Sambuc vector<result_type> intervals() const; 15764684ddb6SLionel Sambuc vector<result_type> densities() const; 15774684ddb6SLionel Sambuc 15784684ddb6SLionel Sambuc friend bool operator==(const param_type& x, const param_type& y); 15794684ddb6SLionel Sambuc friend bool operator!=(const param_type& x, const param_type& y); 15804684ddb6SLionel Sambuc }; 15814684ddb6SLionel Sambuc 15824684ddb6SLionel Sambuc // constructor and reset functions 15834684ddb6SLionel Sambuc piecewise_linear_distribution(); 15844684ddb6SLionel Sambuc template<class InputIteratorB, class InputIteratorW> 15854684ddb6SLionel Sambuc piecewise_linear_distribution(InputIteratorB firstB, 15864684ddb6SLionel Sambuc InputIteratorB lastB, 15874684ddb6SLionel Sambuc InputIteratorW firstW); 15884684ddb6SLionel Sambuc 15894684ddb6SLionel Sambuc template<class UnaryOperation> 15904684ddb6SLionel Sambuc piecewise_linear_distribution(initializer_list<result_type> bl, 15914684ddb6SLionel Sambuc UnaryOperation fw); 15924684ddb6SLionel Sambuc 15934684ddb6SLionel Sambuc template<class UnaryOperation> 15944684ddb6SLionel Sambuc piecewise_linear_distribution(size_t nw, result_type xmin, 15954684ddb6SLionel Sambuc result_type xmax, UnaryOperation fw); 15964684ddb6SLionel Sambuc 15974684ddb6SLionel Sambuc explicit piecewise_linear_distribution(const param_type& parm); 15984684ddb6SLionel Sambuc void reset(); 15994684ddb6SLionel Sambuc 16004684ddb6SLionel Sambuc // generating functions 16014684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g); 16024684ddb6SLionel Sambuc template<class URNG> result_type operator()(URNG& g, const param_type& parm); 16034684ddb6SLionel Sambuc 16044684ddb6SLionel Sambuc // property functions 16054684ddb6SLionel Sambuc vector<result_type> intervals() const; 16064684ddb6SLionel Sambuc vector<result_type> densities() const; 16074684ddb6SLionel Sambuc 16084684ddb6SLionel Sambuc param_type param() const; 16094684ddb6SLionel Sambuc void param(const param_type& parm); 16104684ddb6SLionel Sambuc 16114684ddb6SLionel Sambuc result_type min() const; 16124684ddb6SLionel Sambuc result_type max() const; 16134684ddb6SLionel Sambuc 16144684ddb6SLionel Sambuc friend bool operator==(const piecewise_linear_distribution& x, 16154684ddb6SLionel Sambuc const piecewise_linear_distribution& y); 16164684ddb6SLionel Sambuc friend bool operator!=(const piecewise_linear_distribution& x, 16174684ddb6SLionel Sambuc const piecewise_linear_distribution& y); 16184684ddb6SLionel Sambuc 16194684ddb6SLionel Sambuc template <class charT, class traits> 16204684ddb6SLionel Sambuc friend 16214684ddb6SLionel Sambuc basic_ostream<charT, traits>& 16224684ddb6SLionel Sambuc operator<<(basic_ostream<charT, traits>& os, 16234684ddb6SLionel Sambuc const piecewise_linear_distribution& x); 16244684ddb6SLionel Sambuc 16254684ddb6SLionel Sambuc template <class charT, class traits> 16264684ddb6SLionel Sambuc friend 16274684ddb6SLionel Sambuc basic_istream<charT, traits>& 16284684ddb6SLionel Sambuc operator>>(basic_istream<charT, traits>& is, 16294684ddb6SLionel Sambuc piecewise_linear_distribution& x); 16304684ddb6SLionel Sambuc}; 16314684ddb6SLionel Sambuc 16324684ddb6SLionel Sambuc} // std 16334684ddb6SLionel Sambuc*/ 16344684ddb6SLionel Sambuc 16354684ddb6SLionel Sambuc#include <__config> 16364684ddb6SLionel Sambuc#include <cstddef> 1637*0a6a1f1dSLionel Sambuc#include <cstdint> 1638*0a6a1f1dSLionel Sambuc#include <cmath> 16394684ddb6SLionel Sambuc#include <type_traits> 16404684ddb6SLionel Sambuc#include <initializer_list> 16414684ddb6SLionel Sambuc#include <limits> 16424684ddb6SLionel Sambuc#include <algorithm> 16434684ddb6SLionel Sambuc#include <numeric> 16444684ddb6SLionel Sambuc#include <vector> 16454684ddb6SLionel Sambuc#include <string> 16464684ddb6SLionel Sambuc#include <istream> 16474684ddb6SLionel Sambuc#include <ostream> 16484684ddb6SLionel Sambuc 16494684ddb6SLionel Sambuc#include <__undef_min_max> 16504684ddb6SLionel Sambuc 16514684ddb6SLionel Sambuc#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 16524684ddb6SLionel Sambuc#pragma GCC system_header 16534684ddb6SLionel Sambuc#endif 16544684ddb6SLionel Sambuc 16554684ddb6SLionel Sambuc_LIBCPP_BEGIN_NAMESPACE_STD 16564684ddb6SLionel Sambuc 16574684ddb6SLionel Sambuc// __is_seed_sequence 16584684ddb6SLionel Sambuc 16594684ddb6SLionel Sambuctemplate <class _Sseq, class _Engine> 16604684ddb6SLionel Sambucstruct __is_seed_sequence 16614684ddb6SLionel Sambuc{ 16624684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const bool value = 16634684ddb6SLionel Sambuc !is_convertible<_Sseq, typename _Engine::result_type>::value && 16644684ddb6SLionel Sambuc !is_same<typename remove_cv<_Sseq>::type, _Engine>::value; 16654684ddb6SLionel Sambuc}; 16664684ddb6SLionel Sambuc 16674684ddb6SLionel Sambuc// linear_congruential_engine 16684684ddb6SLionel Sambuc 16694684ddb6SLionel Sambuctemplate <unsigned long long __a, unsigned long long __c, 16704684ddb6SLionel Sambuc unsigned long long __m, unsigned long long _Mp, 16714684ddb6SLionel Sambuc bool _MightOverflow = (__a != 0 && __m != 0 && __m-1 > (_Mp-__c)/__a)> 16724684ddb6SLionel Sambucstruct __lce_ta; 16734684ddb6SLionel Sambuc 16744684ddb6SLionel Sambuc// 64 16754684ddb6SLionel Sambuc 16764684ddb6SLionel Sambuctemplate <unsigned long long __a, unsigned long long __c, unsigned long long __m> 16774684ddb6SLionel Sambucstruct __lce_ta<__a, __c, __m, (unsigned long long)(~0), true> 16784684ddb6SLionel Sambuc{ 16794684ddb6SLionel Sambuc typedef unsigned long long result_type; 16804684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 16814684ddb6SLionel Sambuc static result_type next(result_type __x) 16824684ddb6SLionel Sambuc { 16834684ddb6SLionel Sambuc // Schrage's algorithm 16844684ddb6SLionel Sambuc const result_type __q = __m / __a; 16854684ddb6SLionel Sambuc const result_type __r = __m % __a; 16864684ddb6SLionel Sambuc const result_type __t0 = __a * (__x % __q); 16874684ddb6SLionel Sambuc const result_type __t1 = __r * (__x / __q); 16884684ddb6SLionel Sambuc __x = __t0 + (__t0 < __t1) * __m - __t1; 16894684ddb6SLionel Sambuc __x += __c - (__x >= __m - __c) * __m; 16904684ddb6SLionel Sambuc return __x; 16914684ddb6SLionel Sambuc } 16924684ddb6SLionel Sambuc}; 16934684ddb6SLionel Sambuc 16944684ddb6SLionel Sambuctemplate <unsigned long long __a, unsigned long long __m> 16954684ddb6SLionel Sambucstruct __lce_ta<__a, 0, __m, (unsigned long long)(~0), true> 16964684ddb6SLionel Sambuc{ 16974684ddb6SLionel Sambuc typedef unsigned long long result_type; 16984684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 16994684ddb6SLionel Sambuc static result_type next(result_type __x) 17004684ddb6SLionel Sambuc { 17014684ddb6SLionel Sambuc // Schrage's algorithm 17024684ddb6SLionel Sambuc const result_type __q = __m / __a; 17034684ddb6SLionel Sambuc const result_type __r = __m % __a; 17044684ddb6SLionel Sambuc const result_type __t0 = __a * (__x % __q); 17054684ddb6SLionel Sambuc const result_type __t1 = __r * (__x / __q); 17064684ddb6SLionel Sambuc __x = __t0 + (__t0 < __t1) * __m - __t1; 17074684ddb6SLionel Sambuc return __x; 17084684ddb6SLionel Sambuc } 17094684ddb6SLionel Sambuc}; 17104684ddb6SLionel Sambuc 17114684ddb6SLionel Sambuctemplate <unsigned long long __a, unsigned long long __c, unsigned long long __m> 17124684ddb6SLionel Sambucstruct __lce_ta<__a, __c, __m, (unsigned long long)(~0), false> 17134684ddb6SLionel Sambuc{ 17144684ddb6SLionel Sambuc typedef unsigned long long result_type; 17154684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 17164684ddb6SLionel Sambuc static result_type next(result_type __x) 17174684ddb6SLionel Sambuc { 17184684ddb6SLionel Sambuc return (__a * __x + __c) % __m; 17194684ddb6SLionel Sambuc } 17204684ddb6SLionel Sambuc}; 17214684ddb6SLionel Sambuc 17224684ddb6SLionel Sambuctemplate <unsigned long long __a, unsigned long long __c> 17234684ddb6SLionel Sambucstruct __lce_ta<__a, __c, 0, (unsigned long long)(~0), false> 17244684ddb6SLionel Sambuc{ 17254684ddb6SLionel Sambuc typedef unsigned long long result_type; 17264684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 17274684ddb6SLionel Sambuc static result_type next(result_type __x) 17284684ddb6SLionel Sambuc { 17294684ddb6SLionel Sambuc return __a * __x + __c; 17304684ddb6SLionel Sambuc } 17314684ddb6SLionel Sambuc}; 17324684ddb6SLionel Sambuc 17334684ddb6SLionel Sambuc// 32 17344684ddb6SLionel Sambuc 17354684ddb6SLionel Sambuctemplate <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp> 17364684ddb6SLionel Sambucstruct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), true> 17374684ddb6SLionel Sambuc{ 17384684ddb6SLionel Sambuc typedef unsigned result_type; 17394684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 17404684ddb6SLionel Sambuc static result_type next(result_type __x) 17414684ddb6SLionel Sambuc { 17424684ddb6SLionel Sambuc const result_type __a = static_cast<result_type>(_Ap); 17434684ddb6SLionel Sambuc const result_type __c = static_cast<result_type>(_Cp); 17444684ddb6SLionel Sambuc const result_type __m = static_cast<result_type>(_Mp); 17454684ddb6SLionel Sambuc // Schrage's algorithm 17464684ddb6SLionel Sambuc const result_type __q = __m / __a; 17474684ddb6SLionel Sambuc const result_type __r = __m % __a; 17484684ddb6SLionel Sambuc const result_type __t0 = __a * (__x % __q); 17494684ddb6SLionel Sambuc const result_type __t1 = __r * (__x / __q); 17504684ddb6SLionel Sambuc __x = __t0 + (__t0 < __t1) * __m - __t1; 17514684ddb6SLionel Sambuc __x += __c - (__x >= __m - __c) * __m; 17524684ddb6SLionel Sambuc return __x; 17534684ddb6SLionel Sambuc } 17544684ddb6SLionel Sambuc}; 17554684ddb6SLionel Sambuc 17564684ddb6SLionel Sambuctemplate <unsigned long long _Ap, unsigned long long _Mp> 17574684ddb6SLionel Sambucstruct __lce_ta<_Ap, 0, _Mp, unsigned(~0), true> 17584684ddb6SLionel Sambuc{ 17594684ddb6SLionel Sambuc typedef unsigned result_type; 17604684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 17614684ddb6SLionel Sambuc static result_type next(result_type __x) 17624684ddb6SLionel Sambuc { 17634684ddb6SLionel Sambuc const result_type __a = static_cast<result_type>(_Ap); 17644684ddb6SLionel Sambuc const result_type __m = static_cast<result_type>(_Mp); 17654684ddb6SLionel Sambuc // Schrage's algorithm 17664684ddb6SLionel Sambuc const result_type __q = __m / __a; 17674684ddb6SLionel Sambuc const result_type __r = __m % __a; 17684684ddb6SLionel Sambuc const result_type __t0 = __a * (__x % __q); 17694684ddb6SLionel Sambuc const result_type __t1 = __r * (__x / __q); 17704684ddb6SLionel Sambuc __x = __t0 + (__t0 < __t1) * __m - __t1; 17714684ddb6SLionel Sambuc return __x; 17724684ddb6SLionel Sambuc } 17734684ddb6SLionel Sambuc}; 17744684ddb6SLionel Sambuc 17754684ddb6SLionel Sambuctemplate <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp> 17764684ddb6SLionel Sambucstruct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), false> 17774684ddb6SLionel Sambuc{ 17784684ddb6SLionel Sambuc typedef unsigned result_type; 17794684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 17804684ddb6SLionel Sambuc static result_type next(result_type __x) 17814684ddb6SLionel Sambuc { 17824684ddb6SLionel Sambuc const result_type __a = static_cast<result_type>(_Ap); 17834684ddb6SLionel Sambuc const result_type __c = static_cast<result_type>(_Cp); 17844684ddb6SLionel Sambuc const result_type __m = static_cast<result_type>(_Mp); 17854684ddb6SLionel Sambuc return (__a * __x + __c) % __m; 17864684ddb6SLionel Sambuc } 17874684ddb6SLionel Sambuc}; 17884684ddb6SLionel Sambuc 17894684ddb6SLionel Sambuctemplate <unsigned long long _Ap, unsigned long long _Cp> 17904684ddb6SLionel Sambucstruct __lce_ta<_Ap, _Cp, 0, unsigned(~0), false> 17914684ddb6SLionel Sambuc{ 17924684ddb6SLionel Sambuc typedef unsigned result_type; 17934684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 17944684ddb6SLionel Sambuc static result_type next(result_type __x) 17954684ddb6SLionel Sambuc { 17964684ddb6SLionel Sambuc const result_type __a = static_cast<result_type>(_Ap); 17974684ddb6SLionel Sambuc const result_type __c = static_cast<result_type>(_Cp); 17984684ddb6SLionel Sambuc return __a * __x + __c; 17994684ddb6SLionel Sambuc } 18004684ddb6SLionel Sambuc}; 18014684ddb6SLionel Sambuc 18024684ddb6SLionel Sambuc// 16 18034684ddb6SLionel Sambuc 18044684ddb6SLionel Sambuctemplate <unsigned long long __a, unsigned long long __c, unsigned long long __m, bool __b> 18054684ddb6SLionel Sambucstruct __lce_ta<__a, __c, __m, (unsigned short)(~0), __b> 18064684ddb6SLionel Sambuc{ 18074684ddb6SLionel Sambuc typedef unsigned short result_type; 18084684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 18094684ddb6SLionel Sambuc static result_type next(result_type __x) 18104684ddb6SLionel Sambuc { 18114684ddb6SLionel Sambuc return static_cast<result_type>(__lce_ta<__a, __c, __m, unsigned(~0)>::next(__x)); 18124684ddb6SLionel Sambuc } 18134684ddb6SLionel Sambuc}; 18144684ddb6SLionel Sambuc 18154684ddb6SLionel Sambuctemplate <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 18164684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY linear_congruential_engine; 18174684ddb6SLionel Sambuc 18184684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, 18194684ddb6SLionel Sambuc class _Up, _Up _Ap, _Up _Cp, _Up _Np> 18204684ddb6SLionel Sambuc_LIBCPP_INLINE_VISIBILITY 18214684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 18224684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 18234684ddb6SLionel Sambuc const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&); 18244684ddb6SLionel Sambuc 18254684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, 18264684ddb6SLionel Sambuc class _Up, _Up _Ap, _Up _Cp, _Up _Np> 18274684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 18284684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 18294684ddb6SLionel Sambuc linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x); 18304684ddb6SLionel Sambuc 18314684ddb6SLionel Sambuctemplate <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 18324684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY linear_congruential_engine 18334684ddb6SLionel Sambuc{ 18344684ddb6SLionel Sambucpublic: 18354684ddb6SLionel Sambuc // types 18364684ddb6SLionel Sambuc typedef _UIntType result_type; 18374684ddb6SLionel Sambuc 18384684ddb6SLionel Sambucprivate: 18394684ddb6SLionel Sambuc result_type __x_; 18404684ddb6SLionel Sambuc 18414684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type _Mp = result_type(~0); 18424684ddb6SLionel Sambuc 18434684ddb6SLionel Sambuc static_assert(__m == 0 || __a < __m, "linear_congruential_engine invalid parameters"); 18444684ddb6SLionel Sambuc static_assert(__m == 0 || __c < __m, "linear_congruential_engine invalid parameters"); 18454684ddb6SLionel Sambucpublic: 18464684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type _Min = __c == 0u ? 1u: 0u; 18474684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type _Max = __m - 1u; 18484684ddb6SLionel Sambuc static_assert(_Min < _Max, "linear_congruential_engine invalid parameters"); 18494684ddb6SLionel Sambuc 18504684ddb6SLionel Sambuc // engine characteristics 18514684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type multiplier = __a; 18524684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type increment = __c; 18534684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type modulus = __m; 18544684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 18554684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR result_type min() {return _Min;} 18564684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 18574684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR result_type max() {return _Max;} 18584684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type default_seed = 1u; 18594684ddb6SLionel Sambuc 18604684ddb6SLionel Sambuc // constructors and seeding functions 18614684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 18624684ddb6SLionel Sambuc explicit linear_congruential_engine(result_type __s = default_seed) 18634684ddb6SLionel Sambuc {seed(__s);} 18644684ddb6SLionel Sambuc template<class _Sseq> 18654684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 18664684ddb6SLionel Sambuc explicit linear_congruential_engine(_Sseq& __q, 18674684ddb6SLionel Sambuc typename enable_if<__is_seed_sequence<_Sseq, linear_congruential_engine>::value>::type* = 0) 18684684ddb6SLionel Sambuc {seed(__q);} 18694684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 18704684ddb6SLionel Sambuc void seed(result_type __s = default_seed) 18714684ddb6SLionel Sambuc {seed(integral_constant<bool, __m == 0>(), 18724684ddb6SLionel Sambuc integral_constant<bool, __c == 0>(), __s);} 18734684ddb6SLionel Sambuc template<class _Sseq> 18744684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 18754684ddb6SLionel Sambuc typename enable_if 18764684ddb6SLionel Sambuc < 18774684ddb6SLionel Sambuc __is_seed_sequence<_Sseq, linear_congruential_engine>::value, 18784684ddb6SLionel Sambuc void 18794684ddb6SLionel Sambuc >::type 18804684ddb6SLionel Sambuc seed(_Sseq& __q) 18814684ddb6SLionel Sambuc {__seed(__q, integral_constant<unsigned, 18824684ddb6SLionel Sambuc 1 + (__m == 0 ? (sizeof(result_type) * __CHAR_BIT__ - 1)/32 18834684ddb6SLionel Sambuc : (__m > 0x100000000ull))>());} 18844684ddb6SLionel Sambuc 18854684ddb6SLionel Sambuc // generating functions 18864684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 18874684ddb6SLionel Sambuc result_type operator()() 18884684ddb6SLionel Sambuc {return __x_ = static_cast<result_type>(__lce_ta<__a, __c, __m, _Mp>::next(__x_));} 18894684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 18904684ddb6SLionel Sambuc void discard(unsigned long long __z) {for (; __z; --__z) operator()();} 18914684ddb6SLionel Sambuc 18924684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 18934684ddb6SLionel Sambuc bool operator==(const linear_congruential_engine& __x, 18944684ddb6SLionel Sambuc const linear_congruential_engine& __y) 18954684ddb6SLionel Sambuc {return __x.__x_ == __y.__x_;} 18964684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 18974684ddb6SLionel Sambuc bool operator!=(const linear_congruential_engine& __x, 18984684ddb6SLionel Sambuc const linear_congruential_engine& __y) 18994684ddb6SLionel Sambuc {return !(__x == __y);} 19004684ddb6SLionel Sambuc 19014684ddb6SLionel Sambucprivate: 19024684ddb6SLionel Sambuc 19034684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 19044684ddb6SLionel Sambuc void seed(true_type, true_type, result_type __s) {__x_ = __s == 0 ? 1 : __s;} 19054684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 19064684ddb6SLionel Sambuc void seed(true_type, false_type, result_type __s) {__x_ = __s;} 19074684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 19084684ddb6SLionel Sambuc void seed(false_type, true_type, result_type __s) {__x_ = __s % __m == 0 ? 19094684ddb6SLionel Sambuc 1 : __s % __m;} 19104684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 19114684ddb6SLionel Sambuc void seed(false_type, false_type, result_type __s) {__x_ = __s % __m;} 19124684ddb6SLionel Sambuc 19134684ddb6SLionel Sambuc template<class _Sseq> 19144684ddb6SLionel Sambuc void __seed(_Sseq& __q, integral_constant<unsigned, 1>); 19154684ddb6SLionel Sambuc template<class _Sseq> 19164684ddb6SLionel Sambuc void __seed(_Sseq& __q, integral_constant<unsigned, 2>); 19174684ddb6SLionel Sambuc 19184684ddb6SLionel Sambuc template <class _CharT, class _Traits, 19194684ddb6SLionel Sambuc class _Up, _Up _Ap, _Up _Cp, _Up _Np> 19204684ddb6SLionel Sambuc friend 19214684ddb6SLionel Sambuc basic_ostream<_CharT, _Traits>& 19224684ddb6SLionel Sambuc operator<<(basic_ostream<_CharT, _Traits>& __os, 19234684ddb6SLionel Sambuc const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&); 19244684ddb6SLionel Sambuc 19254684ddb6SLionel Sambuc template <class _CharT, class _Traits, 19264684ddb6SLionel Sambuc class _Up, _Up _Ap, _Up _Cp, _Up _Np> 19274684ddb6SLionel Sambuc friend 19284684ddb6SLionel Sambuc basic_istream<_CharT, _Traits>& 19294684ddb6SLionel Sambuc operator>>(basic_istream<_CharT, _Traits>& __is, 19304684ddb6SLionel Sambuc linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x); 19314684ddb6SLionel Sambuc}; 19324684ddb6SLionel Sambuc 19334684ddb6SLionel Sambuctemplate <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 19344684ddb6SLionel Sambuc _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type 19354684ddb6SLionel Sambuc linear_congruential_engine<_UIntType, __a, __c, __m>::multiplier; 19364684ddb6SLionel Sambuc 19374684ddb6SLionel Sambuctemplate <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 19384684ddb6SLionel Sambuc _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type 19394684ddb6SLionel Sambuc linear_congruential_engine<_UIntType, __a, __c, __m>::increment; 19404684ddb6SLionel Sambuc 19414684ddb6SLionel Sambuctemplate <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 19424684ddb6SLionel Sambuc _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type 19434684ddb6SLionel Sambuc linear_congruential_engine<_UIntType, __a, __c, __m>::modulus; 19444684ddb6SLionel Sambuc 19454684ddb6SLionel Sambuctemplate <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 19464684ddb6SLionel Sambuc _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type 19474684ddb6SLionel Sambuc linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed; 19484684ddb6SLionel Sambuc 19494684ddb6SLionel Sambuctemplate <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 19504684ddb6SLionel Sambuctemplate<class _Sseq> 19514684ddb6SLionel Sambucvoid 19524684ddb6SLionel Sambuclinear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, 19534684ddb6SLionel Sambuc integral_constant<unsigned, 1>) 19544684ddb6SLionel Sambuc{ 19554684ddb6SLionel Sambuc const unsigned __k = 1; 19564684ddb6SLionel Sambuc uint32_t __ar[__k+3]; 19574684ddb6SLionel Sambuc __q.generate(__ar, __ar + __k + 3); 19584684ddb6SLionel Sambuc result_type __s = static_cast<result_type>(__ar[3] % __m); 19594684ddb6SLionel Sambuc __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; 19604684ddb6SLionel Sambuc} 19614684ddb6SLionel Sambuc 19624684ddb6SLionel Sambuctemplate <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 19634684ddb6SLionel Sambuctemplate<class _Sseq> 19644684ddb6SLionel Sambucvoid 19654684ddb6SLionel Sambuclinear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, 19664684ddb6SLionel Sambuc integral_constant<unsigned, 2>) 19674684ddb6SLionel Sambuc{ 19684684ddb6SLionel Sambuc const unsigned __k = 2; 19694684ddb6SLionel Sambuc uint32_t __ar[__k+3]; 19704684ddb6SLionel Sambuc __q.generate(__ar, __ar + __k + 3); 19714684ddb6SLionel Sambuc result_type __s = static_cast<result_type>((__ar[3] + 19724684ddb6SLionel Sambuc ((uint64_t)__ar[4] << 32)) % __m); 19734684ddb6SLionel Sambuc __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; 19744684ddb6SLionel Sambuc} 19754684ddb6SLionel Sambuc 19764684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, 19774684ddb6SLionel Sambuc class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 19784684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 19794684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 19804684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 19814684ddb6SLionel Sambuc const linear_congruential_engine<_UIntType, __a, __c, __m>& __x) 19824684ddb6SLionel Sambuc{ 19834684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__os); 19844684ddb6SLionel Sambuc __os.flags(ios_base::dec | ios_base::left); 19854684ddb6SLionel Sambuc __os.fill(__os.widen(' ')); 19864684ddb6SLionel Sambuc return __os << __x.__x_; 19874684ddb6SLionel Sambuc} 19884684ddb6SLionel Sambuc 19894684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, 19904684ddb6SLionel Sambuc class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 19914684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 19924684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 19934684ddb6SLionel Sambuc linear_congruential_engine<_UIntType, __a, __c, __m>& __x) 19944684ddb6SLionel Sambuc{ 19954684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__is); 19964684ddb6SLionel Sambuc __is.flags(ios_base::dec | ios_base::skipws); 19974684ddb6SLionel Sambuc _UIntType __t; 19984684ddb6SLionel Sambuc __is >> __t; 19994684ddb6SLionel Sambuc if (!__is.fail()) 20004684ddb6SLionel Sambuc __x.__x_ = __t; 20014684ddb6SLionel Sambuc return __is; 20024684ddb6SLionel Sambuc} 20034684ddb6SLionel Sambuc 20044684ddb6SLionel Sambuctypedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647> 20054684ddb6SLionel Sambuc minstd_rand0; 20064684ddb6SLionel Sambuctypedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647> 20074684ddb6SLionel Sambuc minstd_rand; 20084684ddb6SLionel Sambuctypedef minstd_rand default_random_engine; 20094684ddb6SLionel Sambuc// mersenne_twister_engine 20104684ddb6SLionel Sambuc 20114684ddb6SLionel Sambuctemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 20124684ddb6SLionel Sambuc _UIntType __a, size_t __u, _UIntType __d, size_t __s, 20134684ddb6SLionel Sambuc _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 20144684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY mersenne_twister_engine; 20154684ddb6SLionel Sambuc 20164684ddb6SLionel Sambuctemplate <class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 20174684ddb6SLionel Sambuc _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp, 20184684ddb6SLionel Sambuc _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp> 20194684ddb6SLionel Sambucbool 20204684ddb6SLionel Sambucoperator==(const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 20214684ddb6SLionel Sambuc _Bp, _Tp, _Cp, _Lp, _Fp>& __x, 20224684ddb6SLionel Sambuc const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 20234684ddb6SLionel Sambuc _Bp, _Tp, _Cp, _Lp, _Fp>& __y); 20244684ddb6SLionel Sambuc 20254684ddb6SLionel Sambuctemplate <class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 20264684ddb6SLionel Sambuc _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp, 20274684ddb6SLionel Sambuc _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp> 20284684ddb6SLionel Sambuc_LIBCPP_INLINE_VISIBILITY 20294684ddb6SLionel Sambucbool 20304684ddb6SLionel Sambucoperator!=(const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 20314684ddb6SLionel Sambuc _Bp, _Tp, _Cp, _Lp, _Fp>& __x, 20324684ddb6SLionel Sambuc const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 20334684ddb6SLionel Sambuc _Bp, _Tp, _Cp, _Lp, _Fp>& __y); 20344684ddb6SLionel Sambuc 20354684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, 20364684ddb6SLionel Sambuc class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 20374684ddb6SLionel Sambuc _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp, 20384684ddb6SLionel Sambuc _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp> 20394684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 20404684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 20414684ddb6SLionel Sambuc const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 20424684ddb6SLionel Sambuc _Bp, _Tp, _Cp, _Lp, _Fp>& __x); 20434684ddb6SLionel Sambuc 20444684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, 20454684ddb6SLionel Sambuc class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 20464684ddb6SLionel Sambuc _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp, 20474684ddb6SLionel Sambuc _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp> 20484684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 20494684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 20504684ddb6SLionel Sambuc mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 20514684ddb6SLionel Sambuc _Bp, _Tp, _Cp, _Lp, _Fp>& __x); 20524684ddb6SLionel Sambuc 20534684ddb6SLionel Sambuctemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 20544684ddb6SLionel Sambuc _UIntType __a, size_t __u, _UIntType __d, size_t __s, 20554684ddb6SLionel Sambuc _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 20564684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY mersenne_twister_engine 20574684ddb6SLionel Sambuc{ 20584684ddb6SLionel Sambucpublic: 20594684ddb6SLionel Sambuc // types 20604684ddb6SLionel Sambuc typedef _UIntType result_type; 20614684ddb6SLionel Sambuc 20624684ddb6SLionel Sambucprivate: 20634684ddb6SLionel Sambuc result_type __x_[__n]; 20644684ddb6SLionel Sambuc size_t __i_; 20654684ddb6SLionel Sambuc 20664684ddb6SLionel Sambuc static_assert( 0 < __m, "mersenne_twister_engine invalid parameters"); 20674684ddb6SLionel Sambuc static_assert(__m <= __n, "mersenne_twister_engine invalid parameters"); 20684684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; 20694684ddb6SLionel Sambuc static_assert(__w <= _Dt, "mersenne_twister_engine invalid parameters"); 20704684ddb6SLionel Sambuc static_assert( 2 <= __w, "mersenne_twister_engine invalid parameters"); 20714684ddb6SLionel Sambuc static_assert(__r <= __w, "mersenne_twister_engine invalid parameters"); 20724684ddb6SLionel Sambuc static_assert(__u <= __w, "mersenne_twister_engine invalid parameters"); 20734684ddb6SLionel Sambuc static_assert(__s <= __w, "mersenne_twister_engine invalid parameters"); 20744684ddb6SLionel Sambuc static_assert(__t <= __w, "mersenne_twister_engine invalid parameters"); 20754684ddb6SLionel Sambuc static_assert(__l <= __w, "mersenne_twister_engine invalid parameters"); 20764684ddb6SLionel Sambucpublic: 20774684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type _Min = 0; 20784684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : 20794684ddb6SLionel Sambuc (result_type(1) << __w) - result_type(1); 20804684ddb6SLionel Sambuc static_assert(_Min < _Max, "mersenne_twister_engine invalid parameters"); 20814684ddb6SLionel Sambuc static_assert(__a <= _Max, "mersenne_twister_engine invalid parameters"); 20824684ddb6SLionel Sambuc static_assert(__b <= _Max, "mersenne_twister_engine invalid parameters"); 20834684ddb6SLionel Sambuc static_assert(__c <= _Max, "mersenne_twister_engine invalid parameters"); 20844684ddb6SLionel Sambuc static_assert(__d <= _Max, "mersenne_twister_engine invalid parameters"); 20854684ddb6SLionel Sambuc static_assert(__f <= _Max, "mersenne_twister_engine invalid parameters"); 20864684ddb6SLionel Sambuc 20874684ddb6SLionel Sambuc // engine characteristics 20884684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const size_t word_size = __w; 20894684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const size_t state_size = __n; 20904684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const size_t shift_size = __m; 20914684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const size_t mask_bits = __r; 20924684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type xor_mask = __a; 20934684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const size_t tempering_u = __u; 20944684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type tempering_d = __d; 20954684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const size_t tempering_s = __s; 20964684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type tempering_b = __b; 20974684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const size_t tempering_t = __t; 20984684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type tempering_c = __c; 20994684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const size_t tempering_l = __l; 21004684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type initialization_multiplier = __f; 21014684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 21024684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR result_type min() { return _Min; } 21034684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 21044684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR result_type max() { return _Max; } 21054684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type default_seed = 5489u; 21064684ddb6SLionel Sambuc 21074684ddb6SLionel Sambuc // constructors and seeding functions 21084684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 21094684ddb6SLionel Sambuc explicit mersenne_twister_engine(result_type __sd = default_seed) 21104684ddb6SLionel Sambuc {seed(__sd);} 21114684ddb6SLionel Sambuc template<class _Sseq> 21124684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 21134684ddb6SLionel Sambuc explicit mersenne_twister_engine(_Sseq& __q, 21144684ddb6SLionel Sambuc typename enable_if<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value>::type* = 0) 21154684ddb6SLionel Sambuc {seed(__q);} 21164684ddb6SLionel Sambuc void seed(result_type __sd = default_seed); 21174684ddb6SLionel Sambuc template<class _Sseq> 21184684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 21194684ddb6SLionel Sambuc typename enable_if 21204684ddb6SLionel Sambuc < 21214684ddb6SLionel Sambuc __is_seed_sequence<_Sseq, mersenne_twister_engine>::value, 21224684ddb6SLionel Sambuc void 21234684ddb6SLionel Sambuc >::type 21244684ddb6SLionel Sambuc seed(_Sseq& __q) 21254684ddb6SLionel Sambuc {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());} 21264684ddb6SLionel Sambuc 21274684ddb6SLionel Sambuc // generating functions 21284684ddb6SLionel Sambuc result_type operator()(); 21294684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 21304684ddb6SLionel Sambuc void discard(unsigned long long __z) {for (; __z; --__z) operator()();} 21314684ddb6SLionel Sambuc 21324684ddb6SLionel Sambuc template <class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 21334684ddb6SLionel Sambuc _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp, 21344684ddb6SLionel Sambuc _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp> 21354684ddb6SLionel Sambuc friend 21364684ddb6SLionel Sambuc bool 21374684ddb6SLionel Sambuc operator==(const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 21384684ddb6SLionel Sambuc _Bp, _Tp, _Cp, _Lp, _Fp>& __x, 21394684ddb6SLionel Sambuc const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 21404684ddb6SLionel Sambuc _Bp, _Tp, _Cp, _Lp, _Fp>& __y); 21414684ddb6SLionel Sambuc 21424684ddb6SLionel Sambuc template <class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 21434684ddb6SLionel Sambuc _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp, 21444684ddb6SLionel Sambuc _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp> 21454684ddb6SLionel Sambuc friend 21464684ddb6SLionel Sambuc bool 21474684ddb6SLionel Sambuc operator!=(const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 21484684ddb6SLionel Sambuc _Bp, _Tp, _Cp, _Lp, _Fp>& __x, 21494684ddb6SLionel Sambuc const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 21504684ddb6SLionel Sambuc _Bp, _Tp, _Cp, _Lp, _Fp>& __y); 21514684ddb6SLionel Sambuc 21524684ddb6SLionel Sambuc template <class _CharT, class _Traits, 21534684ddb6SLionel Sambuc class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 21544684ddb6SLionel Sambuc _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp, 21554684ddb6SLionel Sambuc _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp> 21564684ddb6SLionel Sambuc friend 21574684ddb6SLionel Sambuc basic_ostream<_CharT, _Traits>& 21584684ddb6SLionel Sambuc operator<<(basic_ostream<_CharT, _Traits>& __os, 21594684ddb6SLionel Sambuc const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 21604684ddb6SLionel Sambuc _Bp, _Tp, _Cp, _Lp, _Fp>& __x); 21614684ddb6SLionel Sambuc 21624684ddb6SLionel Sambuc template <class _CharT, class _Traits, 21634684ddb6SLionel Sambuc class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 21644684ddb6SLionel Sambuc _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp, 21654684ddb6SLionel Sambuc _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp> 21664684ddb6SLionel Sambuc friend 21674684ddb6SLionel Sambuc basic_istream<_CharT, _Traits>& 21684684ddb6SLionel Sambuc operator>>(basic_istream<_CharT, _Traits>& __is, 21694684ddb6SLionel Sambuc mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 21704684ddb6SLionel Sambuc _Bp, _Tp, _Cp, _Lp, _Fp>& __x); 21714684ddb6SLionel Sambucprivate: 21724684ddb6SLionel Sambuc 21734684ddb6SLionel Sambuc template<class _Sseq> 21744684ddb6SLionel Sambuc void __seed(_Sseq& __q, integral_constant<unsigned, 1>); 21754684ddb6SLionel Sambuc template<class _Sseq> 21764684ddb6SLionel Sambuc void __seed(_Sseq& __q, integral_constant<unsigned, 2>); 21774684ddb6SLionel Sambuc 21784684ddb6SLionel Sambuc template <size_t __count> 21794684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 21804684ddb6SLionel Sambuc static 21814684ddb6SLionel Sambuc typename enable_if 21824684ddb6SLionel Sambuc < 21834684ddb6SLionel Sambuc __count < __w, 21844684ddb6SLionel Sambuc result_type 21854684ddb6SLionel Sambuc >::type 21864684ddb6SLionel Sambuc __lshift(result_type __x) {return (__x << __count) & _Max;} 21874684ddb6SLionel Sambuc 21884684ddb6SLionel Sambuc template <size_t __count> 21894684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 21904684ddb6SLionel Sambuc static 21914684ddb6SLionel Sambuc typename enable_if 21924684ddb6SLionel Sambuc < 21934684ddb6SLionel Sambuc (__count >= __w), 21944684ddb6SLionel Sambuc result_type 21954684ddb6SLionel Sambuc >::type 21964684ddb6SLionel Sambuc __lshift(result_type) {return result_type(0);} 21974684ddb6SLionel Sambuc 21984684ddb6SLionel Sambuc template <size_t __count> 21994684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 22004684ddb6SLionel Sambuc static 22014684ddb6SLionel Sambuc typename enable_if 22024684ddb6SLionel Sambuc < 22034684ddb6SLionel Sambuc __count < _Dt, 22044684ddb6SLionel Sambuc result_type 22054684ddb6SLionel Sambuc >::type 22064684ddb6SLionel Sambuc __rshift(result_type __x) {return __x >> __count;} 22074684ddb6SLionel Sambuc 22084684ddb6SLionel Sambuc template <size_t __count> 22094684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 22104684ddb6SLionel Sambuc static 22114684ddb6SLionel Sambuc typename enable_if 22124684ddb6SLionel Sambuc < 22134684ddb6SLionel Sambuc (__count >= _Dt), 22144684ddb6SLionel Sambuc result_type 22154684ddb6SLionel Sambuc >::type 22164684ddb6SLionel Sambuc __rshift(result_type) {return result_type(0);} 22174684ddb6SLionel Sambuc}; 22184684ddb6SLionel Sambuc 22194684ddb6SLionel Sambuctemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 22204684ddb6SLionel Sambuc _UIntType __a, size_t __u, _UIntType __d, size_t __s, 22214684ddb6SLionel Sambuc _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 22224684ddb6SLionel Sambuc _LIBCPP_CONSTEXPR const size_t 22234684ddb6SLionel Sambuc mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::word_size; 22244684ddb6SLionel Sambuc 22254684ddb6SLionel Sambuctemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 22264684ddb6SLionel Sambuc _UIntType __a, size_t __u, _UIntType __d, size_t __s, 22274684ddb6SLionel Sambuc _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 22284684ddb6SLionel Sambuc _LIBCPP_CONSTEXPR const size_t 22294684ddb6SLionel Sambuc mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::state_size; 22304684ddb6SLionel Sambuc 22314684ddb6SLionel Sambuctemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 22324684ddb6SLionel Sambuc _UIntType __a, size_t __u, _UIntType __d, size_t __s, 22334684ddb6SLionel Sambuc _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 22344684ddb6SLionel Sambuc _LIBCPP_CONSTEXPR const size_t 22354684ddb6SLionel Sambuc mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::shift_size; 22364684ddb6SLionel Sambuc 22374684ddb6SLionel Sambuctemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 22384684ddb6SLionel Sambuc _UIntType __a, size_t __u, _UIntType __d, size_t __s, 22394684ddb6SLionel Sambuc _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 22404684ddb6SLionel Sambuc _LIBCPP_CONSTEXPR const size_t 22414684ddb6SLionel Sambuc mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mask_bits; 22424684ddb6SLionel Sambuc 22434684ddb6SLionel Sambuctemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 22444684ddb6SLionel Sambuc _UIntType __a, size_t __u, _UIntType __d, size_t __s, 22454684ddb6SLionel Sambuc _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 22464684ddb6SLionel Sambuc _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type 22474684ddb6SLionel Sambuc mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::xor_mask; 22484684ddb6SLionel Sambuc 22494684ddb6SLionel Sambuctemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 22504684ddb6SLionel Sambuc _UIntType __a, size_t __u, _UIntType __d, size_t __s, 22514684ddb6SLionel Sambuc _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 22524684ddb6SLionel Sambuc _LIBCPP_CONSTEXPR const size_t 22534684ddb6SLionel Sambuc mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_u; 22544684ddb6SLionel Sambuc 22554684ddb6SLionel Sambuctemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 22564684ddb6SLionel Sambuc _UIntType __a, size_t __u, _UIntType __d, size_t __s, 22574684ddb6SLionel Sambuc _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 22584684ddb6SLionel Sambuc _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type 22594684ddb6SLionel Sambuc mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_d; 22604684ddb6SLionel Sambuc 22614684ddb6SLionel Sambuctemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 22624684ddb6SLionel Sambuc _UIntType __a, size_t __u, _UIntType __d, size_t __s, 22634684ddb6SLionel Sambuc _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 22644684ddb6SLionel Sambuc _LIBCPP_CONSTEXPR const size_t 22654684ddb6SLionel Sambuc mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_s; 22664684ddb6SLionel Sambuc 22674684ddb6SLionel Sambuctemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 22684684ddb6SLionel Sambuc _UIntType __a, size_t __u, _UIntType __d, size_t __s, 22694684ddb6SLionel Sambuc _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 22704684ddb6SLionel Sambuc _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type 22714684ddb6SLionel Sambuc mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_b; 22724684ddb6SLionel Sambuc 22734684ddb6SLionel Sambuctemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 22744684ddb6SLionel Sambuc _UIntType __a, size_t __u, _UIntType __d, size_t __s, 22754684ddb6SLionel Sambuc _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 22764684ddb6SLionel Sambuc _LIBCPP_CONSTEXPR const size_t 22774684ddb6SLionel Sambuc mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_t; 22784684ddb6SLionel Sambuc 22794684ddb6SLionel Sambuctemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 22804684ddb6SLionel Sambuc _UIntType __a, size_t __u, _UIntType __d, size_t __s, 22814684ddb6SLionel Sambuc _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 22824684ddb6SLionel Sambuc _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type 22834684ddb6SLionel Sambuc mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_c; 22844684ddb6SLionel Sambuc 22854684ddb6SLionel Sambuctemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 22864684ddb6SLionel Sambuc _UIntType __a, size_t __u, _UIntType __d, size_t __s, 22874684ddb6SLionel Sambuc _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 22884684ddb6SLionel Sambuc _LIBCPP_CONSTEXPR const size_t 22894684ddb6SLionel Sambuc mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_l; 22904684ddb6SLionel Sambuc 22914684ddb6SLionel Sambuctemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 22924684ddb6SLionel Sambuc _UIntType __a, size_t __u, _UIntType __d, size_t __s, 22934684ddb6SLionel Sambuc _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 22944684ddb6SLionel Sambuc _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type 22954684ddb6SLionel Sambuc mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::initialization_multiplier; 22964684ddb6SLionel Sambuc 22974684ddb6SLionel Sambuctemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 22984684ddb6SLionel Sambuc _UIntType __a, size_t __u, _UIntType __d, size_t __s, 22994684ddb6SLionel Sambuc _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 23004684ddb6SLionel Sambuc _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type 23014684ddb6SLionel Sambuc mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::default_seed; 23024684ddb6SLionel Sambuc 23034684ddb6SLionel Sambuctemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 23044684ddb6SLionel Sambuc _UIntType __a, size_t __u, _UIntType __d, size_t __s, 23054684ddb6SLionel Sambuc _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 23064684ddb6SLionel Sambucvoid 23074684ddb6SLionel Sambucmersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, 23084684ddb6SLionel Sambuc __t, __c, __l, __f>::seed(result_type __sd) 23094684ddb6SLionel Sambuc{ // __w >= 2 23104684ddb6SLionel Sambuc __x_[0] = __sd & _Max; 23114684ddb6SLionel Sambuc for (size_t __i = 1; __i < __n; ++__i) 23124684ddb6SLionel Sambuc __x_[__i] = (__f * (__x_[__i-1] ^ __rshift<__w - 2>(__x_[__i-1])) + __i) & _Max; 23134684ddb6SLionel Sambuc __i_ = 0; 23144684ddb6SLionel Sambuc} 23154684ddb6SLionel Sambuc 23164684ddb6SLionel Sambuctemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 23174684ddb6SLionel Sambuc _UIntType __a, size_t __u, _UIntType __d, size_t __s, 23184684ddb6SLionel Sambuc _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 23194684ddb6SLionel Sambuctemplate<class _Sseq> 23204684ddb6SLionel Sambucvoid 23214684ddb6SLionel Sambucmersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, 23224684ddb6SLionel Sambuc __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 1>) 23234684ddb6SLionel Sambuc{ 23244684ddb6SLionel Sambuc const unsigned __k = 1; 23254684ddb6SLionel Sambuc uint32_t __ar[__n * __k]; 23264684ddb6SLionel Sambuc __q.generate(__ar, __ar + __n * __k); 23274684ddb6SLionel Sambuc for (size_t __i = 0; __i < __n; ++__i) 23284684ddb6SLionel Sambuc __x_[__i] = static_cast<result_type>(__ar[__i] & _Max); 23294684ddb6SLionel Sambuc const result_type __mask = __r == _Dt ? result_type(~0) : 23304684ddb6SLionel Sambuc (result_type(1) << __r) - result_type(1); 23314684ddb6SLionel Sambuc __i_ = 0; 23324684ddb6SLionel Sambuc if ((__x_[0] & ~__mask) == 0) 23334684ddb6SLionel Sambuc { 23344684ddb6SLionel Sambuc for (size_t __i = 1; __i < __n; ++__i) 23354684ddb6SLionel Sambuc if (__x_[__i] != 0) 23364684ddb6SLionel Sambuc return; 23374684ddb6SLionel Sambuc __x_[0] = _Max; 23384684ddb6SLionel Sambuc } 23394684ddb6SLionel Sambuc} 23404684ddb6SLionel Sambuc 23414684ddb6SLionel Sambuctemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 23424684ddb6SLionel Sambuc _UIntType __a, size_t __u, _UIntType __d, size_t __s, 23434684ddb6SLionel Sambuc _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 23444684ddb6SLionel Sambuctemplate<class _Sseq> 23454684ddb6SLionel Sambucvoid 23464684ddb6SLionel Sambucmersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, 23474684ddb6SLionel Sambuc __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 2>) 23484684ddb6SLionel Sambuc{ 23494684ddb6SLionel Sambuc const unsigned __k = 2; 23504684ddb6SLionel Sambuc uint32_t __ar[__n * __k]; 23514684ddb6SLionel Sambuc __q.generate(__ar, __ar + __n * __k); 23524684ddb6SLionel Sambuc for (size_t __i = 0; __i < __n; ++__i) 23534684ddb6SLionel Sambuc __x_[__i] = static_cast<result_type>( 23544684ddb6SLionel Sambuc (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); 23554684ddb6SLionel Sambuc const result_type __mask = __r == _Dt ? result_type(~0) : 23564684ddb6SLionel Sambuc (result_type(1) << __r) - result_type(1); 23574684ddb6SLionel Sambuc __i_ = 0; 23584684ddb6SLionel Sambuc if ((__x_[0] & ~__mask) == 0) 23594684ddb6SLionel Sambuc { 23604684ddb6SLionel Sambuc for (size_t __i = 1; __i < __n; ++__i) 23614684ddb6SLionel Sambuc if (__x_[__i] != 0) 23624684ddb6SLionel Sambuc return; 23634684ddb6SLionel Sambuc __x_[0] = _Max; 23644684ddb6SLionel Sambuc } 23654684ddb6SLionel Sambuc} 23664684ddb6SLionel Sambuc 23674684ddb6SLionel Sambuctemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 23684684ddb6SLionel Sambuc _UIntType __a, size_t __u, _UIntType __d, size_t __s, 23694684ddb6SLionel Sambuc _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 23704684ddb6SLionel Sambuc_UIntType 23714684ddb6SLionel Sambucmersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, 23724684ddb6SLionel Sambuc __t, __c, __l, __f>::operator()() 23734684ddb6SLionel Sambuc{ 23744684ddb6SLionel Sambuc const size_t __j = (__i_ + 1) % __n; 23754684ddb6SLionel Sambuc const result_type __mask = __r == _Dt ? result_type(~0) : 23764684ddb6SLionel Sambuc (result_type(1) << __r) - result_type(1); 23774684ddb6SLionel Sambuc const result_type _Yp = (__x_[__i_] & ~__mask) | (__x_[__j] & __mask); 23784684ddb6SLionel Sambuc const size_t __k = (__i_ + __m) % __n; 23794684ddb6SLionel Sambuc __x_[__i_] = __x_[__k] ^ __rshift<1>(_Yp) ^ (__a * (_Yp & 1)); 23804684ddb6SLionel Sambuc result_type __z = __x_[__i_] ^ (__rshift<__u>(__x_[__i_]) & __d); 23814684ddb6SLionel Sambuc __i_ = __j; 23824684ddb6SLionel Sambuc __z ^= __lshift<__s>(__z) & __b; 23834684ddb6SLionel Sambuc __z ^= __lshift<__t>(__z) & __c; 23844684ddb6SLionel Sambuc return __z ^ __rshift<__l>(__z); 23854684ddb6SLionel Sambuc} 23864684ddb6SLionel Sambuc 23874684ddb6SLionel Sambuctemplate <class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 23884684ddb6SLionel Sambuc _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp, 23894684ddb6SLionel Sambuc _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp> 23904684ddb6SLionel Sambucbool 23914684ddb6SLionel Sambucoperator==(const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 23924684ddb6SLionel Sambuc _Bp, _Tp, _Cp, _Lp, _Fp>& __x, 23934684ddb6SLionel Sambuc const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 23944684ddb6SLionel Sambuc _Bp, _Tp, _Cp, _Lp, _Fp>& __y) 23954684ddb6SLionel Sambuc{ 23964684ddb6SLionel Sambuc if (__x.__i_ == __y.__i_) 23974684ddb6SLionel Sambuc return _VSTD::equal(__x.__x_, __x.__x_ + _Np, __y.__x_); 23984684ddb6SLionel Sambuc if (__x.__i_ == 0 || __y.__i_ == 0) 23994684ddb6SLionel Sambuc { 24004684ddb6SLionel Sambuc size_t __j = _VSTD::min(_Np - __x.__i_, _Np - __y.__i_); 24014684ddb6SLionel Sambuc if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, 24024684ddb6SLionel Sambuc __y.__x_ + __y.__i_)) 24034684ddb6SLionel Sambuc return false; 24044684ddb6SLionel Sambuc if (__x.__i_ == 0) 24054684ddb6SLionel Sambuc return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Np, __y.__x_); 24064684ddb6SLionel Sambuc return _VSTD::equal(__x.__x_, __x.__x_ + (_Np - __j), __y.__x_ + __j); 24074684ddb6SLionel Sambuc } 24084684ddb6SLionel Sambuc if (__x.__i_ < __y.__i_) 24094684ddb6SLionel Sambuc { 24104684ddb6SLionel Sambuc size_t __j = _Np - __y.__i_; 24114684ddb6SLionel Sambuc if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), 24124684ddb6SLionel Sambuc __y.__x_ + __y.__i_)) 24134684ddb6SLionel Sambuc return false; 24144684ddb6SLionel Sambuc if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Np, 24154684ddb6SLionel Sambuc __y.__x_)) 24164684ddb6SLionel Sambuc return false; 24174684ddb6SLionel Sambuc return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_, 24184684ddb6SLionel Sambuc __y.__x_ + (_Np - (__x.__i_ + __j))); 24194684ddb6SLionel Sambuc } 24204684ddb6SLionel Sambuc size_t __j = _Np - __x.__i_; 24214684ddb6SLionel Sambuc if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), 24224684ddb6SLionel Sambuc __x.__x_ + __x.__i_)) 24234684ddb6SLionel Sambuc return false; 24244684ddb6SLionel Sambuc if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Np, 24254684ddb6SLionel Sambuc __x.__x_)) 24264684ddb6SLionel Sambuc return false; 24274684ddb6SLionel Sambuc return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_, 24284684ddb6SLionel Sambuc __x.__x_ + (_Np - (__y.__i_ + __j))); 24294684ddb6SLionel Sambuc} 24304684ddb6SLionel Sambuc 24314684ddb6SLionel Sambuctemplate <class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 24324684ddb6SLionel Sambuc _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp, 24334684ddb6SLionel Sambuc _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp> 24344684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 24354684ddb6SLionel Sambucbool 24364684ddb6SLionel Sambucoperator!=(const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 24374684ddb6SLionel Sambuc _Bp, _Tp, _Cp, _Lp, _Fp>& __x, 24384684ddb6SLionel Sambuc const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 24394684ddb6SLionel Sambuc _Bp, _Tp, _Cp, _Lp, _Fp>& __y) 24404684ddb6SLionel Sambuc{ 24414684ddb6SLionel Sambuc return !(__x == __y); 24424684ddb6SLionel Sambuc} 24434684ddb6SLionel Sambuc 24444684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, 24454684ddb6SLionel Sambuc class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 24464684ddb6SLionel Sambuc _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp, 24474684ddb6SLionel Sambuc _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp> 24484684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 24494684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 24504684ddb6SLionel Sambuc const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 24514684ddb6SLionel Sambuc _Bp, _Tp, _Cp, _Lp, _Fp>& __x) 24524684ddb6SLionel Sambuc{ 24534684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__os); 24544684ddb6SLionel Sambuc __os.flags(ios_base::dec | ios_base::left); 24554684ddb6SLionel Sambuc _CharT __sp = __os.widen(' '); 24564684ddb6SLionel Sambuc __os.fill(__sp); 24574684ddb6SLionel Sambuc __os << __x.__x_[__x.__i_]; 24584684ddb6SLionel Sambuc for (size_t __j = __x.__i_ + 1; __j < _Np; ++__j) 24594684ddb6SLionel Sambuc __os << __sp << __x.__x_[__j]; 24604684ddb6SLionel Sambuc for (size_t __j = 0; __j < __x.__i_; ++__j) 24614684ddb6SLionel Sambuc __os << __sp << __x.__x_[__j]; 24624684ddb6SLionel Sambuc return __os; 24634684ddb6SLionel Sambuc} 24644684ddb6SLionel Sambuc 24654684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, 24664684ddb6SLionel Sambuc class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 24674684ddb6SLionel Sambuc _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp, 24684684ddb6SLionel Sambuc _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp> 24694684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 24704684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 24714684ddb6SLionel Sambuc mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 24724684ddb6SLionel Sambuc _Bp, _Tp, _Cp, _Lp, _Fp>& __x) 24734684ddb6SLionel Sambuc{ 24744684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__is); 24754684ddb6SLionel Sambuc __is.flags(ios_base::dec | ios_base::skipws); 24764684ddb6SLionel Sambuc _UI __t[_Np]; 24774684ddb6SLionel Sambuc for (size_t __i = 0; __i < _Np; ++__i) 24784684ddb6SLionel Sambuc __is >> __t[__i]; 24794684ddb6SLionel Sambuc if (!__is.fail()) 24804684ddb6SLionel Sambuc { 24814684ddb6SLionel Sambuc for (size_t __i = 0; __i < _Np; ++__i) 24824684ddb6SLionel Sambuc __x.__x_[__i] = __t[__i]; 24834684ddb6SLionel Sambuc __x.__i_ = 0; 24844684ddb6SLionel Sambuc } 24854684ddb6SLionel Sambuc return __is; 24864684ddb6SLionel Sambuc} 24874684ddb6SLionel Sambuc 24884684ddb6SLionel Sambuctypedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31, 24894684ddb6SLionel Sambuc 0x9908b0df, 11, 0xffffffff, 24904684ddb6SLionel Sambuc 7, 0x9d2c5680, 24914684ddb6SLionel Sambuc 15, 0xefc60000, 24924684ddb6SLionel Sambuc 18, 1812433253> mt19937; 24934684ddb6SLionel Sambuctypedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31, 24944684ddb6SLionel Sambuc 0xb5026f5aa96619e9ULL, 29, 0x5555555555555555ULL, 24954684ddb6SLionel Sambuc 17, 0x71d67fffeda60000ULL, 24964684ddb6SLionel Sambuc 37, 0xfff7eee000000000ULL, 24974684ddb6SLionel Sambuc 43, 6364136223846793005ULL> mt19937_64; 24984684ddb6SLionel Sambuc 24994684ddb6SLionel Sambuc// subtract_with_carry_engine 25004684ddb6SLionel Sambuc 25014684ddb6SLionel Sambuctemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 25024684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY subtract_with_carry_engine; 25034684ddb6SLionel Sambuc 25044684ddb6SLionel Sambuctemplate<class _UI, size_t _Wp, size_t _Sp, size_t _Rp> 25054684ddb6SLionel Sambucbool 25064684ddb6SLionel Sambucoperator==( 25074684ddb6SLionel Sambuc const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x, 25084684ddb6SLionel Sambuc const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __y); 25094684ddb6SLionel Sambuc 25104684ddb6SLionel Sambuctemplate<class _UI, size_t _Wp, size_t _Sp, size_t _Rp> 25114684ddb6SLionel Sambuc_LIBCPP_INLINE_VISIBILITY 25124684ddb6SLionel Sambucbool 25134684ddb6SLionel Sambucoperator!=( 25144684ddb6SLionel Sambuc const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x, 25154684ddb6SLionel Sambuc const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __y); 25164684ddb6SLionel Sambuc 25174684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, 25184684ddb6SLionel Sambuc class _UI, size_t _Wp, size_t _Sp, size_t _Rp> 25194684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 25204684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 25214684ddb6SLionel Sambuc const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x); 25224684ddb6SLionel Sambuc 25234684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, 25244684ddb6SLionel Sambuc class _UI, size_t _Wp, size_t _Sp, size_t _Rp> 25254684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 25264684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 25274684ddb6SLionel Sambuc subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x); 25284684ddb6SLionel Sambuc 25294684ddb6SLionel Sambuctemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 25304684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY subtract_with_carry_engine 25314684ddb6SLionel Sambuc{ 25324684ddb6SLionel Sambucpublic: 25334684ddb6SLionel Sambuc // types 25344684ddb6SLionel Sambuc typedef _UIntType result_type; 25354684ddb6SLionel Sambuc 25364684ddb6SLionel Sambucprivate: 25374684ddb6SLionel Sambuc result_type __x_[__r]; 25384684ddb6SLionel Sambuc result_type __c_; 25394684ddb6SLionel Sambuc size_t __i_; 25404684ddb6SLionel Sambuc 25414684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; 25424684ddb6SLionel Sambuc static_assert( 0 < __w, "subtract_with_carry_engine invalid parameters"); 25434684ddb6SLionel Sambuc static_assert(__w <= _Dt, "subtract_with_carry_engine invalid parameters"); 25444684ddb6SLionel Sambuc static_assert( 0 < __s, "subtract_with_carry_engine invalid parameters"); 25454684ddb6SLionel Sambuc static_assert(__s < __r, "subtract_with_carry_engine invalid parameters"); 25464684ddb6SLionel Sambucpublic: 25474684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type _Min = 0; 25484684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : 25494684ddb6SLionel Sambuc (result_type(1) << __w) - result_type(1); 25504684ddb6SLionel Sambuc static_assert(_Min < _Max, "subtract_with_carry_engine invalid parameters"); 25514684ddb6SLionel Sambuc 25524684ddb6SLionel Sambuc // engine characteristics 25534684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const size_t word_size = __w; 25544684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const size_t short_lag = __s; 25554684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const size_t long_lag = __r; 25564684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25574684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR result_type min() { return _Min; } 25584684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25594684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR result_type max() { return _Max; } 25604684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type default_seed = 19780503u; 25614684ddb6SLionel Sambuc 25624684ddb6SLionel Sambuc // constructors and seeding functions 25634684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25644684ddb6SLionel Sambuc explicit subtract_with_carry_engine(result_type __sd = default_seed) 25654684ddb6SLionel Sambuc {seed(__sd);} 25664684ddb6SLionel Sambuc template<class _Sseq> 25674684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25684684ddb6SLionel Sambuc explicit subtract_with_carry_engine(_Sseq& __q, 25694684ddb6SLionel Sambuc typename enable_if<__is_seed_sequence<_Sseq, subtract_with_carry_engine>::value>::type* = 0) 25704684ddb6SLionel Sambuc {seed(__q);} 25714684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25724684ddb6SLionel Sambuc void seed(result_type __sd = default_seed) 25734684ddb6SLionel Sambuc {seed(__sd, integral_constant<unsigned, 1 + (__w - 1) / 32>());} 25744684ddb6SLionel Sambuc template<class _Sseq> 25754684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25764684ddb6SLionel Sambuc typename enable_if 25774684ddb6SLionel Sambuc < 25784684ddb6SLionel Sambuc __is_seed_sequence<_Sseq, subtract_with_carry_engine>::value, 25794684ddb6SLionel Sambuc void 25804684ddb6SLionel Sambuc >::type 25814684ddb6SLionel Sambuc seed(_Sseq& __q) 25824684ddb6SLionel Sambuc {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());} 25834684ddb6SLionel Sambuc 25844684ddb6SLionel Sambuc // generating functions 25854684ddb6SLionel Sambuc result_type operator()(); 25864684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25874684ddb6SLionel Sambuc void discard(unsigned long long __z) {for (; __z; --__z) operator()();} 25884684ddb6SLionel Sambuc 25894684ddb6SLionel Sambuc template<class _UI, size_t _Wp, size_t _Sp, size_t _Rp> 25904684ddb6SLionel Sambuc friend 25914684ddb6SLionel Sambuc bool 25924684ddb6SLionel Sambuc operator==( 25934684ddb6SLionel Sambuc const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x, 25944684ddb6SLionel Sambuc const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __y); 25954684ddb6SLionel Sambuc 25964684ddb6SLionel Sambuc template<class _UI, size_t _Wp, size_t _Sp, size_t _Rp> 25974684ddb6SLionel Sambuc friend 25984684ddb6SLionel Sambuc bool 25994684ddb6SLionel Sambuc operator!=( 26004684ddb6SLionel Sambuc const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x, 26014684ddb6SLionel Sambuc const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __y); 26024684ddb6SLionel Sambuc 26034684ddb6SLionel Sambuc template <class _CharT, class _Traits, 26044684ddb6SLionel Sambuc class _UI, size_t _Wp, size_t _Sp, size_t _Rp> 26054684ddb6SLionel Sambuc friend 26064684ddb6SLionel Sambuc basic_ostream<_CharT, _Traits>& 26074684ddb6SLionel Sambuc operator<<(basic_ostream<_CharT, _Traits>& __os, 26084684ddb6SLionel Sambuc const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x); 26094684ddb6SLionel Sambuc 26104684ddb6SLionel Sambuc template <class _CharT, class _Traits, 26114684ddb6SLionel Sambuc class _UI, size_t _Wp, size_t _Sp, size_t _Rp> 26124684ddb6SLionel Sambuc friend 26134684ddb6SLionel Sambuc basic_istream<_CharT, _Traits>& 26144684ddb6SLionel Sambuc operator>>(basic_istream<_CharT, _Traits>& __is, 26154684ddb6SLionel Sambuc subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x); 26164684ddb6SLionel Sambuc 26174684ddb6SLionel Sambucprivate: 26184684ddb6SLionel Sambuc 26194684ddb6SLionel Sambuc void seed(result_type __sd, integral_constant<unsigned, 1>); 26204684ddb6SLionel Sambuc void seed(result_type __sd, integral_constant<unsigned, 2>); 26214684ddb6SLionel Sambuc template<class _Sseq> 26224684ddb6SLionel Sambuc void __seed(_Sseq& __q, integral_constant<unsigned, 1>); 26234684ddb6SLionel Sambuc template<class _Sseq> 26244684ddb6SLionel Sambuc void __seed(_Sseq& __q, integral_constant<unsigned, 2>); 26254684ddb6SLionel Sambuc}; 26264684ddb6SLionel Sambuc 26274684ddb6SLionel Sambuctemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 26284684ddb6SLionel Sambuc _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size; 26294684ddb6SLionel Sambuc 26304684ddb6SLionel Sambuctemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 26314684ddb6SLionel Sambuc _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::short_lag; 26324684ddb6SLionel Sambuc 26334684ddb6SLionel Sambuctemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 26344684ddb6SLionel Sambuc _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag; 26354684ddb6SLionel Sambuc 26364684ddb6SLionel Sambuctemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 26374684ddb6SLionel Sambuc _LIBCPP_CONSTEXPR const typename subtract_with_carry_engine<_UIntType, __w, __s, __r>::result_type 26384684ddb6SLionel Sambuc subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed; 26394684ddb6SLionel Sambuc 26404684ddb6SLionel Sambuctemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 26414684ddb6SLionel Sambucvoid 26424684ddb6SLionel Sambucsubtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, 26434684ddb6SLionel Sambuc integral_constant<unsigned, 1>) 26444684ddb6SLionel Sambuc{ 26454684ddb6SLionel Sambuc linear_congruential_engine<result_type, 40014u, 0u, 2147483563u> 26464684ddb6SLionel Sambuc __e(__sd == 0u ? default_seed : __sd); 26474684ddb6SLionel Sambuc for (size_t __i = 0; __i < __r; ++__i) 26484684ddb6SLionel Sambuc __x_[__i] = static_cast<result_type>(__e() & _Max); 26494684ddb6SLionel Sambuc __c_ = __x_[__r-1] == 0; 26504684ddb6SLionel Sambuc __i_ = 0; 26514684ddb6SLionel Sambuc} 26524684ddb6SLionel Sambuc 26534684ddb6SLionel Sambuctemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 26544684ddb6SLionel Sambucvoid 26554684ddb6SLionel Sambucsubtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, 26564684ddb6SLionel Sambuc integral_constant<unsigned, 2>) 26574684ddb6SLionel Sambuc{ 26584684ddb6SLionel Sambuc linear_congruential_engine<result_type, 40014u, 0u, 2147483563u> 26594684ddb6SLionel Sambuc __e(__sd == 0u ? default_seed : __sd); 26604684ddb6SLionel Sambuc for (size_t __i = 0; __i < __r; ++__i) 26614684ddb6SLionel Sambuc { 26624684ddb6SLionel Sambuc result_type __e0 = __e(); 26634684ddb6SLionel Sambuc __x_[__i] = static_cast<result_type>( 26644684ddb6SLionel Sambuc (__e0 + ((uint64_t)__e() << 32)) & _Max); 26654684ddb6SLionel Sambuc } 26664684ddb6SLionel Sambuc __c_ = __x_[__r-1] == 0; 26674684ddb6SLionel Sambuc __i_ = 0; 26684684ddb6SLionel Sambuc} 26694684ddb6SLionel Sambuc 26704684ddb6SLionel Sambuctemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 26714684ddb6SLionel Sambuctemplate<class _Sseq> 26724684ddb6SLionel Sambucvoid 26734684ddb6SLionel Sambucsubtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q, 26744684ddb6SLionel Sambuc integral_constant<unsigned, 1>) 26754684ddb6SLionel Sambuc{ 26764684ddb6SLionel Sambuc const unsigned __k = 1; 26774684ddb6SLionel Sambuc uint32_t __ar[__r * __k]; 26784684ddb6SLionel Sambuc __q.generate(__ar, __ar + __r * __k); 26794684ddb6SLionel Sambuc for (size_t __i = 0; __i < __r; ++__i) 26804684ddb6SLionel Sambuc __x_[__i] = static_cast<result_type>(__ar[__i] & _Max); 26814684ddb6SLionel Sambuc __c_ = __x_[__r-1] == 0; 26824684ddb6SLionel Sambuc __i_ = 0; 26834684ddb6SLionel Sambuc} 26844684ddb6SLionel Sambuc 26854684ddb6SLionel Sambuctemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 26864684ddb6SLionel Sambuctemplate<class _Sseq> 26874684ddb6SLionel Sambucvoid 26884684ddb6SLionel Sambucsubtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q, 26894684ddb6SLionel Sambuc integral_constant<unsigned, 2>) 26904684ddb6SLionel Sambuc{ 26914684ddb6SLionel Sambuc const unsigned __k = 2; 26924684ddb6SLionel Sambuc uint32_t __ar[__r * __k]; 26934684ddb6SLionel Sambuc __q.generate(__ar, __ar + __r * __k); 26944684ddb6SLionel Sambuc for (size_t __i = 0; __i < __r; ++__i) 26954684ddb6SLionel Sambuc __x_[__i] = static_cast<result_type>( 26964684ddb6SLionel Sambuc (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); 26974684ddb6SLionel Sambuc __c_ = __x_[__r-1] == 0; 26984684ddb6SLionel Sambuc __i_ = 0; 26994684ddb6SLionel Sambuc} 27004684ddb6SLionel Sambuc 27014684ddb6SLionel Sambuctemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 27024684ddb6SLionel Sambuc_UIntType 27034684ddb6SLionel Sambucsubtract_with_carry_engine<_UIntType, __w, __s, __r>::operator()() 27044684ddb6SLionel Sambuc{ 27054684ddb6SLionel Sambuc const result_type& __xs = __x_[(__i_ + (__r - __s)) % __r]; 27064684ddb6SLionel Sambuc result_type& __xr = __x_[__i_]; 27074684ddb6SLionel Sambuc result_type __new_c = __c_ == 0 ? __xs < __xr : __xs != 0 ? __xs <= __xr : 1; 27084684ddb6SLionel Sambuc __xr = (__xs - __xr - __c_) & _Max; 27094684ddb6SLionel Sambuc __c_ = __new_c; 27104684ddb6SLionel Sambuc __i_ = (__i_ + 1) % __r; 27114684ddb6SLionel Sambuc return __xr; 27124684ddb6SLionel Sambuc} 27134684ddb6SLionel Sambuc 27144684ddb6SLionel Sambuctemplate<class _UI, size_t _Wp, size_t _Sp, size_t _Rp> 27154684ddb6SLionel Sambucbool 27164684ddb6SLionel Sambucoperator==( 27174684ddb6SLionel Sambuc const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x, 27184684ddb6SLionel Sambuc const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __y) 27194684ddb6SLionel Sambuc{ 27204684ddb6SLionel Sambuc if (__x.__c_ != __y.__c_) 27214684ddb6SLionel Sambuc return false; 27224684ddb6SLionel Sambuc if (__x.__i_ == __y.__i_) 27234684ddb6SLionel Sambuc return _VSTD::equal(__x.__x_, __x.__x_ + _Rp, __y.__x_); 27244684ddb6SLionel Sambuc if (__x.__i_ == 0 || __y.__i_ == 0) 27254684ddb6SLionel Sambuc { 27264684ddb6SLionel Sambuc size_t __j = _VSTD::min(_Rp - __x.__i_, _Rp - __y.__i_); 27274684ddb6SLionel Sambuc if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, 27284684ddb6SLionel Sambuc __y.__x_ + __y.__i_)) 27294684ddb6SLionel Sambuc return false; 27304684ddb6SLionel Sambuc if (__x.__i_ == 0) 27314684ddb6SLionel Sambuc return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Rp, __y.__x_); 27324684ddb6SLionel Sambuc return _VSTD::equal(__x.__x_, __x.__x_ + (_Rp - __j), __y.__x_ + __j); 27334684ddb6SLionel Sambuc } 27344684ddb6SLionel Sambuc if (__x.__i_ < __y.__i_) 27354684ddb6SLionel Sambuc { 27364684ddb6SLionel Sambuc size_t __j = _Rp - __y.__i_; 27374684ddb6SLionel Sambuc if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), 27384684ddb6SLionel Sambuc __y.__x_ + __y.__i_)) 27394684ddb6SLionel Sambuc return false; 27404684ddb6SLionel Sambuc if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Rp, 27414684ddb6SLionel Sambuc __y.__x_)) 27424684ddb6SLionel Sambuc return false; 27434684ddb6SLionel Sambuc return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_, 27444684ddb6SLionel Sambuc __y.__x_ + (_Rp - (__x.__i_ + __j))); 27454684ddb6SLionel Sambuc } 27464684ddb6SLionel Sambuc size_t __j = _Rp - __x.__i_; 27474684ddb6SLionel Sambuc if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), 27484684ddb6SLionel Sambuc __x.__x_ + __x.__i_)) 27494684ddb6SLionel Sambuc return false; 27504684ddb6SLionel Sambuc if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Rp, 27514684ddb6SLionel Sambuc __x.__x_)) 27524684ddb6SLionel Sambuc return false; 27534684ddb6SLionel Sambuc return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_, 27544684ddb6SLionel Sambuc __x.__x_ + (_Rp - (__y.__i_ + __j))); 27554684ddb6SLionel Sambuc} 27564684ddb6SLionel Sambuc 27574684ddb6SLionel Sambuctemplate<class _UI, size_t _Wp, size_t _Sp, size_t _Rp> 27584684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 27594684ddb6SLionel Sambucbool 27604684ddb6SLionel Sambucoperator!=( 27614684ddb6SLionel Sambuc const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x, 27624684ddb6SLionel Sambuc const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __y) 27634684ddb6SLionel Sambuc{ 27644684ddb6SLionel Sambuc return !(__x == __y); 27654684ddb6SLionel Sambuc} 27664684ddb6SLionel Sambuc 27674684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, 27684684ddb6SLionel Sambuc class _UI, size_t _Wp, size_t _Sp, size_t _Rp> 27694684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 27704684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 27714684ddb6SLionel Sambuc const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x) 27724684ddb6SLionel Sambuc{ 27734684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__os); 27744684ddb6SLionel Sambuc __os.flags(ios_base::dec | ios_base::left); 27754684ddb6SLionel Sambuc _CharT __sp = __os.widen(' '); 27764684ddb6SLionel Sambuc __os.fill(__sp); 27774684ddb6SLionel Sambuc __os << __x.__x_[__x.__i_]; 27784684ddb6SLionel Sambuc for (size_t __j = __x.__i_ + 1; __j < _Rp; ++__j) 27794684ddb6SLionel Sambuc __os << __sp << __x.__x_[__j]; 27804684ddb6SLionel Sambuc for (size_t __j = 0; __j < __x.__i_; ++__j) 27814684ddb6SLionel Sambuc __os << __sp << __x.__x_[__j]; 27824684ddb6SLionel Sambuc __os << __sp << __x.__c_; 27834684ddb6SLionel Sambuc return __os; 27844684ddb6SLionel Sambuc} 27854684ddb6SLionel Sambuc 27864684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, 27874684ddb6SLionel Sambuc class _UI, size_t _Wp, size_t _Sp, size_t _Rp> 27884684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 27894684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 27904684ddb6SLionel Sambuc subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x) 27914684ddb6SLionel Sambuc{ 27924684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__is); 27934684ddb6SLionel Sambuc __is.flags(ios_base::dec | ios_base::skipws); 27944684ddb6SLionel Sambuc _UI __t[_Rp+1]; 27954684ddb6SLionel Sambuc for (size_t __i = 0; __i < _Rp+1; ++__i) 27964684ddb6SLionel Sambuc __is >> __t[__i]; 27974684ddb6SLionel Sambuc if (!__is.fail()) 27984684ddb6SLionel Sambuc { 27994684ddb6SLionel Sambuc for (size_t __i = 0; __i < _Rp; ++__i) 28004684ddb6SLionel Sambuc __x.__x_[__i] = __t[__i]; 28014684ddb6SLionel Sambuc __x.__c_ = __t[_Rp]; 28024684ddb6SLionel Sambuc __x.__i_ = 0; 28034684ddb6SLionel Sambuc } 28044684ddb6SLionel Sambuc return __is; 28054684ddb6SLionel Sambuc} 28064684ddb6SLionel Sambuc 28074684ddb6SLionel Sambuctypedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> ranlux24_base; 28084684ddb6SLionel Sambuctypedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> ranlux48_base; 28094684ddb6SLionel Sambuc 28104684ddb6SLionel Sambuc// discard_block_engine 28114684ddb6SLionel Sambuc 28124684ddb6SLionel Sambuctemplate<class _Engine, size_t __p, size_t __r> 28134684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY discard_block_engine 28144684ddb6SLionel Sambuc{ 28154684ddb6SLionel Sambuc _Engine __e_; 28164684ddb6SLionel Sambuc int __n_; 28174684ddb6SLionel Sambuc 28184684ddb6SLionel Sambuc static_assert( 0 < __r, "discard_block_engine invalid parameters"); 28194684ddb6SLionel Sambuc static_assert(__r <= __p, "discard_block_engine invalid parameters"); 28204684ddb6SLionel Sambucpublic: 28214684ddb6SLionel Sambuc // types 28224684ddb6SLionel Sambuc typedef typename _Engine::result_type result_type; 28234684ddb6SLionel Sambuc 28244684ddb6SLionel Sambuc // engine characteristics 28254684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const size_t block_size = __p; 28264684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const size_t used_block = __r; 28274684ddb6SLionel Sambuc 28284684ddb6SLionel Sambuc#ifdef _LIBCPP_HAS_NO_CONSTEXPR 28294684ddb6SLionel Sambuc static const result_type _Min = _Engine::_Min; 28304684ddb6SLionel Sambuc static const result_type _Max = _Engine::_Max; 28314684ddb6SLionel Sambuc#else 28324684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min(); 28334684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max(); 28344684ddb6SLionel Sambuc#endif 28354684ddb6SLionel Sambuc 28364684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 28374684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR result_type min() { return _Engine::min(); } 28384684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 28394684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR result_type max() { return _Engine::max(); } 28404684ddb6SLionel Sambuc 28414684ddb6SLionel Sambuc // constructors and seeding functions 28424684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 28434684ddb6SLionel Sambuc discard_block_engine() : __n_(0) {} 28444684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 28454684ddb6SLionel Sambuc explicit discard_block_engine(const _Engine& __e) 28464684ddb6SLionel Sambuc : __e_(__e), __n_(0) {} 28474684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 28484684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 28494684ddb6SLionel Sambuc explicit discard_block_engine(_Engine&& __e) 28504684ddb6SLionel Sambuc : __e_(_VSTD::move(__e)), __n_(0) {} 28514684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 28524684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 28534684ddb6SLionel Sambuc explicit discard_block_engine(result_type __sd) : __e_(__sd), __n_(0) {} 28544684ddb6SLionel Sambuc template<class _Sseq> 28554684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 28564684ddb6SLionel Sambuc explicit discard_block_engine(_Sseq& __q, 28574684ddb6SLionel Sambuc typename enable_if<__is_seed_sequence<_Sseq, discard_block_engine>::value && 28584684ddb6SLionel Sambuc !is_convertible<_Sseq, _Engine>::value>::type* = 0) 28594684ddb6SLionel Sambuc : __e_(__q), __n_(0) {} 28604684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 28614684ddb6SLionel Sambuc void seed() {__e_.seed(); __n_ = 0;} 28624684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 28634684ddb6SLionel Sambuc void seed(result_type __sd) {__e_.seed(__sd); __n_ = 0;} 28644684ddb6SLionel Sambuc template<class _Sseq> 28654684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 28664684ddb6SLionel Sambuc typename enable_if 28674684ddb6SLionel Sambuc < 28684684ddb6SLionel Sambuc __is_seed_sequence<_Sseq, discard_block_engine>::value, 28694684ddb6SLionel Sambuc void 28704684ddb6SLionel Sambuc >::type 28714684ddb6SLionel Sambuc seed(_Sseq& __q) {__e_.seed(__q); __n_ = 0;} 28724684ddb6SLionel Sambuc 28734684ddb6SLionel Sambuc // generating functions 28744684ddb6SLionel Sambuc result_type operator()(); 28754684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 28764684ddb6SLionel Sambuc void discard(unsigned long long __z) {for (; __z; --__z) operator()();} 28774684ddb6SLionel Sambuc 28784684ddb6SLionel Sambuc // property functions 28794684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 28804684ddb6SLionel Sambuc const _Engine& base() const _NOEXCEPT {return __e_;} 28814684ddb6SLionel Sambuc 28824684ddb6SLionel Sambuc template<class _Eng, size_t _Pp, size_t _Rp> 28834684ddb6SLionel Sambuc friend 28844684ddb6SLionel Sambuc bool 28854684ddb6SLionel Sambuc operator==( 28864684ddb6SLionel Sambuc const discard_block_engine<_Eng, _Pp, _Rp>& __x, 28874684ddb6SLionel Sambuc const discard_block_engine<_Eng, _Pp, _Rp>& __y); 28884684ddb6SLionel Sambuc 28894684ddb6SLionel Sambuc template<class _Eng, size_t _Pp, size_t _Rp> 28904684ddb6SLionel Sambuc friend 28914684ddb6SLionel Sambuc bool 28924684ddb6SLionel Sambuc operator!=( 28934684ddb6SLionel Sambuc const discard_block_engine<_Eng, _Pp, _Rp>& __x, 28944684ddb6SLionel Sambuc const discard_block_engine<_Eng, _Pp, _Rp>& __y); 28954684ddb6SLionel Sambuc 28964684ddb6SLionel Sambuc template <class _CharT, class _Traits, 28974684ddb6SLionel Sambuc class _Eng, size_t _Pp, size_t _Rp> 28984684ddb6SLionel Sambuc friend 28994684ddb6SLionel Sambuc basic_ostream<_CharT, _Traits>& 29004684ddb6SLionel Sambuc operator<<(basic_ostream<_CharT, _Traits>& __os, 29014684ddb6SLionel Sambuc const discard_block_engine<_Eng, _Pp, _Rp>& __x); 29024684ddb6SLionel Sambuc 29034684ddb6SLionel Sambuc template <class _CharT, class _Traits, 29044684ddb6SLionel Sambuc class _Eng, size_t _Pp, size_t _Rp> 29054684ddb6SLionel Sambuc friend 29064684ddb6SLionel Sambuc basic_istream<_CharT, _Traits>& 29074684ddb6SLionel Sambuc operator>>(basic_istream<_CharT, _Traits>& __is, 29084684ddb6SLionel Sambuc discard_block_engine<_Eng, _Pp, _Rp>& __x); 29094684ddb6SLionel Sambuc}; 29104684ddb6SLionel Sambuc 29114684ddb6SLionel Sambuctemplate<class _Engine, size_t __p, size_t __r> 29124684ddb6SLionel Sambuc _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::block_size; 29134684ddb6SLionel Sambuc 29144684ddb6SLionel Sambuctemplate<class _Engine, size_t __p, size_t __r> 29154684ddb6SLionel Sambuc _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::used_block; 29164684ddb6SLionel Sambuc 29174684ddb6SLionel Sambuctemplate<class _Engine, size_t __p, size_t __r> 29184684ddb6SLionel Sambuctypename discard_block_engine<_Engine, __p, __r>::result_type 29194684ddb6SLionel Sambucdiscard_block_engine<_Engine, __p, __r>::operator()() 29204684ddb6SLionel Sambuc{ 29214684ddb6SLionel Sambuc if (__n_ >= __r) 29224684ddb6SLionel Sambuc { 29234684ddb6SLionel Sambuc __e_.discard(__p - __r); 29244684ddb6SLionel Sambuc __n_ = 0; 29254684ddb6SLionel Sambuc } 29264684ddb6SLionel Sambuc ++__n_; 29274684ddb6SLionel Sambuc return __e_(); 29284684ddb6SLionel Sambuc} 29294684ddb6SLionel Sambuc 29304684ddb6SLionel Sambuctemplate<class _Eng, size_t _Pp, size_t _Rp> 29314684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 29324684ddb6SLionel Sambucbool 29334684ddb6SLionel Sambucoperator==(const discard_block_engine<_Eng, _Pp, _Rp>& __x, 29344684ddb6SLionel Sambuc const discard_block_engine<_Eng, _Pp, _Rp>& __y) 29354684ddb6SLionel Sambuc{ 29364684ddb6SLionel Sambuc return __x.__n_ == __y.__n_ && __x.__e_ == __y.__e_; 29374684ddb6SLionel Sambuc} 29384684ddb6SLionel Sambuc 29394684ddb6SLionel Sambuctemplate<class _Eng, size_t _Pp, size_t _Rp> 29404684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 29414684ddb6SLionel Sambucbool 29424684ddb6SLionel Sambucoperator!=(const discard_block_engine<_Eng, _Pp, _Rp>& __x, 29434684ddb6SLionel Sambuc const discard_block_engine<_Eng, _Pp, _Rp>& __y) 29444684ddb6SLionel Sambuc{ 29454684ddb6SLionel Sambuc return !(__x == __y); 29464684ddb6SLionel Sambuc} 29474684ddb6SLionel Sambuc 29484684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, 29494684ddb6SLionel Sambuc class _Eng, size_t _Pp, size_t _Rp> 29504684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 29514684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 29524684ddb6SLionel Sambuc const discard_block_engine<_Eng, _Pp, _Rp>& __x) 29534684ddb6SLionel Sambuc{ 29544684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__os); 29554684ddb6SLionel Sambuc __os.flags(ios_base::dec | ios_base::left); 29564684ddb6SLionel Sambuc _CharT __sp = __os.widen(' '); 29574684ddb6SLionel Sambuc __os.fill(__sp); 29584684ddb6SLionel Sambuc return __os << __x.__e_ << __sp << __x.__n_; 29594684ddb6SLionel Sambuc} 29604684ddb6SLionel Sambuc 29614684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, 29624684ddb6SLionel Sambuc class _Eng, size_t _Pp, size_t _Rp> 29634684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 29644684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 29654684ddb6SLionel Sambuc discard_block_engine<_Eng, _Pp, _Rp>& __x) 29664684ddb6SLionel Sambuc{ 29674684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__is); 29684684ddb6SLionel Sambuc __is.flags(ios_base::dec | ios_base::skipws); 29694684ddb6SLionel Sambuc _Eng __e; 29704684ddb6SLionel Sambuc int __n; 29714684ddb6SLionel Sambuc __is >> __e >> __n; 29724684ddb6SLionel Sambuc if (!__is.fail()) 29734684ddb6SLionel Sambuc { 29744684ddb6SLionel Sambuc __x.__e_ = __e; 29754684ddb6SLionel Sambuc __x.__n_ = __n; 29764684ddb6SLionel Sambuc } 29774684ddb6SLionel Sambuc return __is; 29784684ddb6SLionel Sambuc} 29794684ddb6SLionel Sambuc 29804684ddb6SLionel Sambuctypedef discard_block_engine<ranlux24_base, 223, 23> ranlux24; 29814684ddb6SLionel Sambuctypedef discard_block_engine<ranlux48_base, 389, 11> ranlux48; 29824684ddb6SLionel Sambuc 29834684ddb6SLionel Sambuc// independent_bits_engine 29844684ddb6SLionel Sambuc 29854684ddb6SLionel Sambuctemplate<class _Engine, size_t __w, class _UIntType> 29864684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY independent_bits_engine 29874684ddb6SLionel Sambuc{ 29884684ddb6SLionel Sambuc template <class _UI, _UI _R0, size_t _Wp, size_t _Mp> 29894684ddb6SLionel Sambuc class __get_n 29904684ddb6SLionel Sambuc { 29914684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const size_t _Dt = numeric_limits<_UI>::digits; 29924684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const size_t _Np = _Wp / _Mp + (_Wp % _Mp != 0); 29934684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const size_t _W0 = _Wp / _Np; 29944684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const _UI _Y0 = _W0 >= _Dt ? 0 : (_R0 >> _W0) << _W0; 29954684ddb6SLionel Sambuc public: 29964684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const size_t value = _R0 - _Y0 > _Y0 / _Np ? _Np + 1 : _Np; 29974684ddb6SLionel Sambuc }; 29984684ddb6SLionel Sambucpublic: 29994684ddb6SLionel Sambuc // types 30004684ddb6SLionel Sambuc typedef _UIntType result_type; 30014684ddb6SLionel Sambuc 30024684ddb6SLionel Sambucprivate: 30034684ddb6SLionel Sambuc _Engine __e_; 30044684ddb6SLionel Sambuc 30054684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; 30064684ddb6SLionel Sambuc static_assert( 0 < __w, "independent_bits_engine invalid parameters"); 30074684ddb6SLionel Sambuc static_assert(__w <= _Dt, "independent_bits_engine invalid parameters"); 30084684ddb6SLionel Sambuc 30094684ddb6SLionel Sambuc typedef typename _Engine::result_type _Engine_result_type; 30104684ddb6SLionel Sambuc typedef typename conditional 30114684ddb6SLionel Sambuc < 30124684ddb6SLionel Sambuc sizeof(_Engine_result_type) <= sizeof(result_type), 30134684ddb6SLionel Sambuc result_type, 30144684ddb6SLionel Sambuc _Engine_result_type 30154684ddb6SLionel Sambuc >::type _Working_result_type; 30164684ddb6SLionel Sambuc#ifdef _LIBCPP_HAS_NO_CONSTEXPR 30174684ddb6SLionel Sambuc static const _Working_result_type _Rp = _Engine::_Max - _Engine::_Min 30184684ddb6SLionel Sambuc + _Working_result_type(1); 30194684ddb6SLionel Sambuc#else 30204684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const _Working_result_type _Rp = _Engine::max() - _Engine::min() 30214684ddb6SLionel Sambuc + _Working_result_type(1); 30224684ddb6SLionel Sambuc#endif 30234684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const size_t __m = __log2<_Working_result_type, _Rp>::value; 30244684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const size_t __n = __get_n<_Working_result_type, _Rp, __w, __m>::value; 30254684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const size_t __w0 = __w / __n; 30264684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const size_t __n0 = __n - __w % __n; 30274684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const size_t _WDt = numeric_limits<_Working_result_type>::digits; 30284684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const size_t _EDt = numeric_limits<_Engine_result_type>::digits; 30294684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const _Working_result_type __y0 = __w0 >= _WDt ? 0 : 30304684ddb6SLionel Sambuc (_Rp >> __w0) << __w0; 30314684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const _Working_result_type __y1 = __w0 >= _WDt - 1 ? 0 : 30324684ddb6SLionel Sambuc (_Rp >> (__w0+1)) << (__w0+1); 30334684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const _Engine_result_type __mask0 = __w0 > 0 ? 30344684ddb6SLionel Sambuc _Engine_result_type(~0) >> (_EDt - __w0) : 30354684ddb6SLionel Sambuc _Engine_result_type(0); 30364684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const _Engine_result_type __mask1 = __w0 < _EDt - 1 ? 30374684ddb6SLionel Sambuc _Engine_result_type(~0) >> (_EDt - (__w0 + 1)) : 30384684ddb6SLionel Sambuc _Engine_result_type(~0); 30394684ddb6SLionel Sambucpublic: 30404684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type _Min = 0; 30414684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : 30424684ddb6SLionel Sambuc (result_type(1) << __w) - result_type(1); 30434684ddb6SLionel Sambuc static_assert(_Min < _Max, "independent_bits_engine invalid parameters"); 30444684ddb6SLionel Sambuc 30454684ddb6SLionel Sambuc // engine characteristics 30464684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 30474684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR result_type min() { return _Min; } 30484684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 30494684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR result_type max() { return _Max; } 30504684ddb6SLionel Sambuc 30514684ddb6SLionel Sambuc // constructors and seeding functions 30524684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 30534684ddb6SLionel Sambuc independent_bits_engine() {} 30544684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 30554684ddb6SLionel Sambuc explicit independent_bits_engine(const _Engine& __e) 30564684ddb6SLionel Sambuc : __e_(__e) {} 30574684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 30584684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 30594684ddb6SLionel Sambuc explicit independent_bits_engine(_Engine&& __e) 30604684ddb6SLionel Sambuc : __e_(_VSTD::move(__e)) {} 30614684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 30624684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 30634684ddb6SLionel Sambuc explicit independent_bits_engine(result_type __sd) : __e_(__sd) {} 30644684ddb6SLionel Sambuc template<class _Sseq> 30654684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 30664684ddb6SLionel Sambuc explicit independent_bits_engine(_Sseq& __q, 30674684ddb6SLionel Sambuc typename enable_if<__is_seed_sequence<_Sseq, independent_bits_engine>::value && 30684684ddb6SLionel Sambuc !is_convertible<_Sseq, _Engine>::value>::type* = 0) 30694684ddb6SLionel Sambuc : __e_(__q) {} 30704684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 30714684ddb6SLionel Sambuc void seed() {__e_.seed();} 30724684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 30734684ddb6SLionel Sambuc void seed(result_type __sd) {__e_.seed(__sd);} 30744684ddb6SLionel Sambuc template<class _Sseq> 30754684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 30764684ddb6SLionel Sambuc typename enable_if 30774684ddb6SLionel Sambuc < 30784684ddb6SLionel Sambuc __is_seed_sequence<_Sseq, independent_bits_engine>::value, 30794684ddb6SLionel Sambuc void 30804684ddb6SLionel Sambuc >::type 30814684ddb6SLionel Sambuc seed(_Sseq& __q) {__e_.seed(__q);} 30824684ddb6SLionel Sambuc 30834684ddb6SLionel Sambuc // generating functions 30844684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 30854684ddb6SLionel Sambuc result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());} 30864684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 30874684ddb6SLionel Sambuc void discard(unsigned long long __z) {for (; __z; --__z) operator()();} 30884684ddb6SLionel Sambuc 30894684ddb6SLionel Sambuc // property functions 30904684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 30914684ddb6SLionel Sambuc const _Engine& base() const _NOEXCEPT {return __e_;} 30924684ddb6SLionel Sambuc 30934684ddb6SLionel Sambuc template<class _Eng, size_t _Wp, class _UI> 30944684ddb6SLionel Sambuc friend 30954684ddb6SLionel Sambuc bool 30964684ddb6SLionel Sambuc operator==( 30974684ddb6SLionel Sambuc const independent_bits_engine<_Eng, _Wp, _UI>& __x, 30984684ddb6SLionel Sambuc const independent_bits_engine<_Eng, _Wp, _UI>& __y); 30994684ddb6SLionel Sambuc 31004684ddb6SLionel Sambuc template<class _Eng, size_t _Wp, class _UI> 31014684ddb6SLionel Sambuc friend 31024684ddb6SLionel Sambuc bool 31034684ddb6SLionel Sambuc operator!=( 31044684ddb6SLionel Sambuc const independent_bits_engine<_Eng, _Wp, _UI>& __x, 31054684ddb6SLionel Sambuc const independent_bits_engine<_Eng, _Wp, _UI>& __y); 31064684ddb6SLionel Sambuc 31074684ddb6SLionel Sambuc template <class _CharT, class _Traits, 31084684ddb6SLionel Sambuc class _Eng, size_t _Wp, class _UI> 31094684ddb6SLionel Sambuc friend 31104684ddb6SLionel Sambuc basic_ostream<_CharT, _Traits>& 31114684ddb6SLionel Sambuc operator<<(basic_ostream<_CharT, _Traits>& __os, 31124684ddb6SLionel Sambuc const independent_bits_engine<_Eng, _Wp, _UI>& __x); 31134684ddb6SLionel Sambuc 31144684ddb6SLionel Sambuc template <class _CharT, class _Traits, 31154684ddb6SLionel Sambuc class _Eng, size_t _Wp, class _UI> 31164684ddb6SLionel Sambuc friend 31174684ddb6SLionel Sambuc basic_istream<_CharT, _Traits>& 31184684ddb6SLionel Sambuc operator>>(basic_istream<_CharT, _Traits>& __is, 31194684ddb6SLionel Sambuc independent_bits_engine<_Eng, _Wp, _UI>& __x); 31204684ddb6SLionel Sambuc 31214684ddb6SLionel Sambucprivate: 31224684ddb6SLionel Sambuc result_type __eval(false_type); 31234684ddb6SLionel Sambuc result_type __eval(true_type); 31244684ddb6SLionel Sambuc 31254684ddb6SLionel Sambuc template <size_t __count> 31264684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 31274684ddb6SLionel Sambuc static 31284684ddb6SLionel Sambuc typename enable_if 31294684ddb6SLionel Sambuc < 31304684ddb6SLionel Sambuc __count < _Dt, 31314684ddb6SLionel Sambuc result_type 31324684ddb6SLionel Sambuc >::type 31334684ddb6SLionel Sambuc __lshift(result_type __x) {return __x << __count;} 31344684ddb6SLionel Sambuc 31354684ddb6SLionel Sambuc template <size_t __count> 31364684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 31374684ddb6SLionel Sambuc static 31384684ddb6SLionel Sambuc typename enable_if 31394684ddb6SLionel Sambuc < 31404684ddb6SLionel Sambuc (__count >= _Dt), 31414684ddb6SLionel Sambuc result_type 31424684ddb6SLionel Sambuc >::type 31434684ddb6SLionel Sambuc __lshift(result_type) {return result_type(0);} 31444684ddb6SLionel Sambuc}; 31454684ddb6SLionel Sambuc 31464684ddb6SLionel Sambuctemplate<class _Engine, size_t __w, class _UIntType> 31474684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 31484684ddb6SLionel Sambuc_UIntType 31494684ddb6SLionel Sambucindependent_bits_engine<_Engine, __w, _UIntType>::__eval(false_type) 31504684ddb6SLionel Sambuc{ 31514684ddb6SLionel Sambuc return static_cast<result_type>(__e_() & __mask0); 31524684ddb6SLionel Sambuc} 31534684ddb6SLionel Sambuc 31544684ddb6SLionel Sambuctemplate<class _Engine, size_t __w, class _UIntType> 31554684ddb6SLionel Sambuc_UIntType 31564684ddb6SLionel Sambucindependent_bits_engine<_Engine, __w, _UIntType>::__eval(true_type) 31574684ddb6SLionel Sambuc{ 31584684ddb6SLionel Sambuc result_type _Sp = 0; 31594684ddb6SLionel Sambuc for (size_t __k = 0; __k < __n0; ++__k) 31604684ddb6SLionel Sambuc { 31614684ddb6SLionel Sambuc _Engine_result_type __u; 31624684ddb6SLionel Sambuc do 31634684ddb6SLionel Sambuc { 31644684ddb6SLionel Sambuc __u = __e_() - _Engine::min(); 31654684ddb6SLionel Sambuc } while (__u >= __y0); 31664684ddb6SLionel Sambuc _Sp = static_cast<result_type>(__lshift<__w0>(_Sp) + (__u & __mask0)); 31674684ddb6SLionel Sambuc } 31684684ddb6SLionel Sambuc for (size_t __k = __n0; __k < __n; ++__k) 31694684ddb6SLionel Sambuc { 31704684ddb6SLionel Sambuc _Engine_result_type __u; 31714684ddb6SLionel Sambuc do 31724684ddb6SLionel Sambuc { 31734684ddb6SLionel Sambuc __u = __e_() - _Engine::min(); 31744684ddb6SLionel Sambuc } while (__u >= __y1); 31754684ddb6SLionel Sambuc _Sp = static_cast<result_type>(__lshift<__w0+1>(_Sp) + (__u & __mask1)); 31764684ddb6SLionel Sambuc } 31774684ddb6SLionel Sambuc return _Sp; 31784684ddb6SLionel Sambuc} 31794684ddb6SLionel Sambuc 31804684ddb6SLionel Sambuctemplate<class _Eng, size_t _Wp, class _UI> 31814684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 31824684ddb6SLionel Sambucbool 31834684ddb6SLionel Sambucoperator==( 31844684ddb6SLionel Sambuc const independent_bits_engine<_Eng, _Wp, _UI>& __x, 31854684ddb6SLionel Sambuc const independent_bits_engine<_Eng, _Wp, _UI>& __y) 31864684ddb6SLionel Sambuc{ 31874684ddb6SLionel Sambuc return __x.base() == __y.base(); 31884684ddb6SLionel Sambuc} 31894684ddb6SLionel Sambuc 31904684ddb6SLionel Sambuctemplate<class _Eng, size_t _Wp, class _UI> 31914684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 31924684ddb6SLionel Sambucbool 31934684ddb6SLionel Sambucoperator!=( 31944684ddb6SLionel Sambuc const independent_bits_engine<_Eng, _Wp, _UI>& __x, 31954684ddb6SLionel Sambuc const independent_bits_engine<_Eng, _Wp, _UI>& __y) 31964684ddb6SLionel Sambuc{ 31974684ddb6SLionel Sambuc return !(__x == __y); 31984684ddb6SLionel Sambuc} 31994684ddb6SLionel Sambuc 32004684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, 32014684ddb6SLionel Sambuc class _Eng, size_t _Wp, class _UI> 32024684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 32034684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 32044684ddb6SLionel Sambuc const independent_bits_engine<_Eng, _Wp, _UI>& __x) 32054684ddb6SLionel Sambuc{ 32064684ddb6SLionel Sambuc return __os << __x.base(); 32074684ddb6SLionel Sambuc} 32084684ddb6SLionel Sambuc 32094684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, 32104684ddb6SLionel Sambuc class _Eng, size_t _Wp, class _UI> 32114684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 32124684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 32134684ddb6SLionel Sambuc independent_bits_engine<_Eng, _Wp, _UI>& __x) 32144684ddb6SLionel Sambuc{ 32154684ddb6SLionel Sambuc _Eng __e; 32164684ddb6SLionel Sambuc __is >> __e; 32174684ddb6SLionel Sambuc if (!__is.fail()) 32184684ddb6SLionel Sambuc __x.__e_ = __e; 32194684ddb6SLionel Sambuc return __is; 32204684ddb6SLionel Sambuc} 32214684ddb6SLionel Sambuc 32224684ddb6SLionel Sambuc// shuffle_order_engine 32234684ddb6SLionel Sambuc 32244684ddb6SLionel Sambuctemplate <uint64_t _Xp, uint64_t _Yp> 32254684ddb6SLionel Sambucstruct __ugcd 32264684ddb6SLionel Sambuc{ 32274684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const uint64_t value = __ugcd<_Yp, _Xp % _Yp>::value; 32284684ddb6SLionel Sambuc}; 32294684ddb6SLionel Sambuc 32304684ddb6SLionel Sambuctemplate <uint64_t _Xp> 32314684ddb6SLionel Sambucstruct __ugcd<_Xp, 0> 32324684ddb6SLionel Sambuc{ 32334684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const uint64_t value = _Xp; 32344684ddb6SLionel Sambuc}; 32354684ddb6SLionel Sambuc 32364684ddb6SLionel Sambuctemplate <uint64_t _Np, uint64_t _Dp> 32374684ddb6SLionel Sambucclass __uratio 32384684ddb6SLionel Sambuc{ 32394684ddb6SLionel Sambuc static_assert(_Dp != 0, "__uratio divide by 0"); 32404684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const uint64_t __gcd = __ugcd<_Np, _Dp>::value; 32414684ddb6SLionel Sambucpublic: 32424684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const uint64_t num = _Np / __gcd; 32434684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const uint64_t den = _Dp / __gcd; 32444684ddb6SLionel Sambuc 32454684ddb6SLionel Sambuc typedef __uratio<num, den> type; 32464684ddb6SLionel Sambuc}; 32474684ddb6SLionel Sambuc 32484684ddb6SLionel Sambuctemplate<class _Engine, size_t __k> 32494684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY shuffle_order_engine 32504684ddb6SLionel Sambuc{ 32514684ddb6SLionel Sambuc static_assert(0 < __k, "shuffle_order_engine invalid parameters"); 32524684ddb6SLionel Sambucpublic: 32534684ddb6SLionel Sambuc // types 32544684ddb6SLionel Sambuc typedef typename _Engine::result_type result_type; 32554684ddb6SLionel Sambuc 32564684ddb6SLionel Sambucprivate: 32574684ddb6SLionel Sambuc _Engine __e_; 32584684ddb6SLionel Sambuc result_type _V_[__k]; 32594684ddb6SLionel Sambuc result_type _Y_; 32604684ddb6SLionel Sambuc 32614684ddb6SLionel Sambucpublic: 32624684ddb6SLionel Sambuc // engine characteristics 32634684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const size_t table_size = __k; 32644684ddb6SLionel Sambuc 32654684ddb6SLionel Sambuc#ifdef _LIBCPP_HAS_NO_CONSTEXPR 32664684ddb6SLionel Sambuc static const result_type _Min = _Engine::_Min; 32674684ddb6SLionel Sambuc static const result_type _Max = _Engine::_Max; 32684684ddb6SLionel Sambuc#else 32694684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min(); 32704684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max(); 32714684ddb6SLionel Sambuc#endif 32724684ddb6SLionel Sambuc static_assert(_Min < _Max, "shuffle_order_engine invalid parameters"); 32734684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 32744684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR result_type min() { return _Min; } 32754684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 32764684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR result_type max() { return _Max; } 32774684ddb6SLionel Sambuc 32784684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const unsigned long long _Rp = _Max - _Min + 1ull; 32794684ddb6SLionel Sambuc 32804684ddb6SLionel Sambuc // constructors and seeding functions 32814684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 32824684ddb6SLionel Sambuc shuffle_order_engine() {__init();} 32834684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 32844684ddb6SLionel Sambuc explicit shuffle_order_engine(const _Engine& __e) 32854684ddb6SLionel Sambuc : __e_(__e) {__init();} 32864684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 32874684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 32884684ddb6SLionel Sambuc explicit shuffle_order_engine(_Engine&& __e) 32894684ddb6SLionel Sambuc : __e_(_VSTD::move(__e)) {__init();} 32904684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 32914684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 32924684ddb6SLionel Sambuc explicit shuffle_order_engine(result_type __sd) : __e_(__sd) {__init();} 32934684ddb6SLionel Sambuc template<class _Sseq> 32944684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 32954684ddb6SLionel Sambuc explicit shuffle_order_engine(_Sseq& __q, 32964684ddb6SLionel Sambuc typename enable_if<__is_seed_sequence<_Sseq, shuffle_order_engine>::value && 32974684ddb6SLionel Sambuc !is_convertible<_Sseq, _Engine>::value>::type* = 0) 32984684ddb6SLionel Sambuc : __e_(__q) {__init();} 32994684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 33004684ddb6SLionel Sambuc void seed() {__e_.seed(); __init();} 33014684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 33024684ddb6SLionel Sambuc void seed(result_type __sd) {__e_.seed(__sd); __init();} 33034684ddb6SLionel Sambuc template<class _Sseq> 33044684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 33054684ddb6SLionel Sambuc typename enable_if 33064684ddb6SLionel Sambuc < 33074684ddb6SLionel Sambuc __is_seed_sequence<_Sseq, shuffle_order_engine>::value, 33084684ddb6SLionel Sambuc void 33094684ddb6SLionel Sambuc >::type 33104684ddb6SLionel Sambuc seed(_Sseq& __q) {__e_.seed(__q); __init();} 33114684ddb6SLionel Sambuc 33124684ddb6SLionel Sambuc // generating functions 33134684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 33144684ddb6SLionel Sambuc result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());} 33154684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 33164684ddb6SLionel Sambuc void discard(unsigned long long __z) {for (; __z; --__z) operator()();} 33174684ddb6SLionel Sambuc 33184684ddb6SLionel Sambuc // property functions 33194684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 33204684ddb6SLionel Sambuc const _Engine& base() const _NOEXCEPT {return __e_;} 33214684ddb6SLionel Sambuc 33224684ddb6SLionel Sambucprivate: 33234684ddb6SLionel Sambuc template<class _Eng, size_t _Kp> 33244684ddb6SLionel Sambuc friend 33254684ddb6SLionel Sambuc bool 33264684ddb6SLionel Sambuc operator==( 33274684ddb6SLionel Sambuc const shuffle_order_engine<_Eng, _Kp>& __x, 33284684ddb6SLionel Sambuc const shuffle_order_engine<_Eng, _Kp>& __y); 33294684ddb6SLionel Sambuc 33304684ddb6SLionel Sambuc template<class _Eng, size_t _Kp> 33314684ddb6SLionel Sambuc friend 33324684ddb6SLionel Sambuc bool 33334684ddb6SLionel Sambuc operator!=( 33344684ddb6SLionel Sambuc const shuffle_order_engine<_Eng, _Kp>& __x, 33354684ddb6SLionel Sambuc const shuffle_order_engine<_Eng, _Kp>& __y); 33364684ddb6SLionel Sambuc 33374684ddb6SLionel Sambuc template <class _CharT, class _Traits, 33384684ddb6SLionel Sambuc class _Eng, size_t _Kp> 33394684ddb6SLionel Sambuc friend 33404684ddb6SLionel Sambuc basic_ostream<_CharT, _Traits>& 33414684ddb6SLionel Sambuc operator<<(basic_ostream<_CharT, _Traits>& __os, 33424684ddb6SLionel Sambuc const shuffle_order_engine<_Eng, _Kp>& __x); 33434684ddb6SLionel Sambuc 33444684ddb6SLionel Sambuc template <class _CharT, class _Traits, 33454684ddb6SLionel Sambuc class _Eng, size_t _Kp> 33464684ddb6SLionel Sambuc friend 33474684ddb6SLionel Sambuc basic_istream<_CharT, _Traits>& 33484684ddb6SLionel Sambuc operator>>(basic_istream<_CharT, _Traits>& __is, 33494684ddb6SLionel Sambuc shuffle_order_engine<_Eng, _Kp>& __x); 33504684ddb6SLionel Sambuc 33514684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 33524684ddb6SLionel Sambuc void __init() 33534684ddb6SLionel Sambuc { 33544684ddb6SLionel Sambuc for (size_t __i = 0; __i < __k; ++__i) 33554684ddb6SLionel Sambuc _V_[__i] = __e_(); 33564684ddb6SLionel Sambuc _Y_ = __e_(); 33574684ddb6SLionel Sambuc } 33584684ddb6SLionel Sambuc 33594684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 33604684ddb6SLionel Sambuc result_type __eval(false_type) {return __eval2(integral_constant<bool, __k & 1>());} 33614684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 33624684ddb6SLionel Sambuc result_type __eval(true_type) {return __eval(__uratio<__k, _Rp>());} 33634684ddb6SLionel Sambuc 33644684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 33654684ddb6SLionel Sambuc result_type __eval2(false_type) {return __eval(__uratio<__k/2, 0x8000000000000000ull>());} 33664684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 33674684ddb6SLionel Sambuc result_type __eval2(true_type) {return __evalf<__k, 0>();} 33684684ddb6SLionel Sambuc 33694684ddb6SLionel Sambuc template <uint64_t _Np, uint64_t _Dp> 33704684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 33714684ddb6SLionel Sambuc typename enable_if 33724684ddb6SLionel Sambuc < 33734684ddb6SLionel Sambuc (__uratio<_Np, _Dp>::num > 0xFFFFFFFFFFFFFFFFull / (_Max - _Min)), 33744684ddb6SLionel Sambuc result_type 33754684ddb6SLionel Sambuc >::type 33764684ddb6SLionel Sambuc __eval(__uratio<_Np, _Dp>) 33774684ddb6SLionel Sambuc {return __evalf<__uratio<_Np, _Dp>::num, __uratio<_Np, _Dp>::den>();} 33784684ddb6SLionel Sambuc 33794684ddb6SLionel Sambuc template <uint64_t _Np, uint64_t _Dp> 33804684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 33814684ddb6SLionel Sambuc typename enable_if 33824684ddb6SLionel Sambuc < 33834684ddb6SLionel Sambuc __uratio<_Np, _Dp>::num <= 0xFFFFFFFFFFFFFFFFull / (_Max - _Min), 33844684ddb6SLionel Sambuc result_type 33854684ddb6SLionel Sambuc >::type 33864684ddb6SLionel Sambuc __eval(__uratio<_Np, _Dp>) 33874684ddb6SLionel Sambuc { 33884684ddb6SLionel Sambuc const size_t __j = static_cast<size_t>(__uratio<_Np, _Dp>::num * (_Y_ - _Min) 33894684ddb6SLionel Sambuc / __uratio<_Np, _Dp>::den); 33904684ddb6SLionel Sambuc _Y_ = _V_[__j]; 33914684ddb6SLionel Sambuc _V_[__j] = __e_(); 33924684ddb6SLionel Sambuc return _Y_; 33934684ddb6SLionel Sambuc } 33944684ddb6SLionel Sambuc 33954684ddb6SLionel Sambuc template <uint64_t __n, uint64_t __d> 33964684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 33974684ddb6SLionel Sambuc result_type __evalf() 33984684ddb6SLionel Sambuc { 33994684ddb6SLionel Sambuc const double _Fp = __d == 0 ? 34004684ddb6SLionel Sambuc __n / (2. * 0x8000000000000000ull) : 34014684ddb6SLionel Sambuc __n / (double)__d; 34024684ddb6SLionel Sambuc const size_t __j = static_cast<size_t>(_Fp * (_Y_ - _Min)); 34034684ddb6SLionel Sambuc _Y_ = _V_[__j]; 34044684ddb6SLionel Sambuc _V_[__j] = __e_(); 34054684ddb6SLionel Sambuc return _Y_; 34064684ddb6SLionel Sambuc } 34074684ddb6SLionel Sambuc}; 34084684ddb6SLionel Sambuc 34094684ddb6SLionel Sambuctemplate<class _Engine, size_t __k> 34104684ddb6SLionel Sambuc _LIBCPP_CONSTEXPR const size_t shuffle_order_engine<_Engine, __k>::table_size; 34114684ddb6SLionel Sambuc 34124684ddb6SLionel Sambuctemplate<class _Eng, size_t _Kp> 34134684ddb6SLionel Sambucbool 34144684ddb6SLionel Sambucoperator==( 34154684ddb6SLionel Sambuc const shuffle_order_engine<_Eng, _Kp>& __x, 34164684ddb6SLionel Sambuc const shuffle_order_engine<_Eng, _Kp>& __y) 34174684ddb6SLionel Sambuc{ 34184684ddb6SLionel Sambuc return __x._Y_ == __y._Y_ && _VSTD::equal(__x._V_, __x._V_ + _Kp, __y._V_) && 34194684ddb6SLionel Sambuc __x.__e_ == __y.__e_; 34204684ddb6SLionel Sambuc} 34214684ddb6SLionel Sambuc 34224684ddb6SLionel Sambuctemplate<class _Eng, size_t _Kp> 34234684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 34244684ddb6SLionel Sambucbool 34254684ddb6SLionel Sambucoperator!=( 34264684ddb6SLionel Sambuc const shuffle_order_engine<_Eng, _Kp>& __x, 34274684ddb6SLionel Sambuc const shuffle_order_engine<_Eng, _Kp>& __y) 34284684ddb6SLionel Sambuc{ 34294684ddb6SLionel Sambuc return !(__x == __y); 34304684ddb6SLionel Sambuc} 34314684ddb6SLionel Sambuc 34324684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, 34334684ddb6SLionel Sambuc class _Eng, size_t _Kp> 34344684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 34354684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 34364684ddb6SLionel Sambuc const shuffle_order_engine<_Eng, _Kp>& __x) 34374684ddb6SLionel Sambuc{ 34384684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__os); 34394684ddb6SLionel Sambuc __os.flags(ios_base::dec | ios_base::left); 34404684ddb6SLionel Sambuc _CharT __sp = __os.widen(' '); 34414684ddb6SLionel Sambuc __os.fill(__sp); 34424684ddb6SLionel Sambuc __os << __x.__e_ << __sp << __x._V_[0]; 34434684ddb6SLionel Sambuc for (size_t __i = 1; __i < _Kp; ++__i) 34444684ddb6SLionel Sambuc __os << __sp << __x._V_[__i]; 34454684ddb6SLionel Sambuc return __os << __sp << __x._Y_; 34464684ddb6SLionel Sambuc} 34474684ddb6SLionel Sambuc 34484684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, 34494684ddb6SLionel Sambuc class _Eng, size_t _Kp> 34504684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 34514684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 34524684ddb6SLionel Sambuc shuffle_order_engine<_Eng, _Kp>& __x) 34534684ddb6SLionel Sambuc{ 34544684ddb6SLionel Sambuc typedef typename shuffle_order_engine<_Eng, _Kp>::result_type result_type; 34554684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__is); 34564684ddb6SLionel Sambuc __is.flags(ios_base::dec | ios_base::skipws); 34574684ddb6SLionel Sambuc _Eng __e; 34584684ddb6SLionel Sambuc result_type _Vp[_Kp+1]; 34594684ddb6SLionel Sambuc __is >> __e; 34604684ddb6SLionel Sambuc for (size_t __i = 0; __i < _Kp+1; ++__i) 34614684ddb6SLionel Sambuc __is >> _Vp[__i]; 34624684ddb6SLionel Sambuc if (!__is.fail()) 34634684ddb6SLionel Sambuc { 34644684ddb6SLionel Sambuc __x.__e_ = __e; 34654684ddb6SLionel Sambuc for (size_t __i = 0; __i < _Kp; ++__i) 34664684ddb6SLionel Sambuc __x._V_[__i] = _Vp[__i]; 34674684ddb6SLionel Sambuc __x._Y_ = _Vp[_Kp]; 34684684ddb6SLionel Sambuc } 34694684ddb6SLionel Sambuc return __is; 34704684ddb6SLionel Sambuc} 34714684ddb6SLionel Sambuc 34724684ddb6SLionel Sambuctypedef shuffle_order_engine<minstd_rand0, 256> knuth_b; 34734684ddb6SLionel Sambuc 34744684ddb6SLionel Sambuc// random_device 34754684ddb6SLionel Sambuc 34764684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS random_device 34774684ddb6SLionel Sambuc{ 3478*0a6a1f1dSLionel Sambuc#ifdef _LIBCPP_USING_DEV_RANDOM 34794684ddb6SLionel Sambuc int __f_; 3480*0a6a1f1dSLionel Sambuc#endif // defined(_LIBCPP_USING_DEV_RANDOM) 34814684ddb6SLionel Sambucpublic: 34824684ddb6SLionel Sambuc // types 34834684ddb6SLionel Sambuc typedef unsigned result_type; 34844684ddb6SLionel Sambuc 34854684ddb6SLionel Sambuc // generator characteristics 34864684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type _Min = 0; 34874684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR const result_type _Max = 0xFFFFFFFFu; 34884684ddb6SLionel Sambuc 34894684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 34904684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR result_type min() { return _Min;} 34914684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 34924684ddb6SLionel Sambuc static _LIBCPP_CONSTEXPR result_type max() { return _Max;} 34934684ddb6SLionel Sambuc 34944684ddb6SLionel Sambuc // constructors 34954684ddb6SLionel Sambuc explicit random_device(const string& __token = "/dev/urandom"); 34964684ddb6SLionel Sambuc ~random_device(); 34974684ddb6SLionel Sambuc 34984684ddb6SLionel Sambuc // generating functions 34994684ddb6SLionel Sambuc result_type operator()(); 35004684ddb6SLionel Sambuc 35014684ddb6SLionel Sambuc // property functions 35024684ddb6SLionel Sambuc double entropy() const _NOEXCEPT; 35034684ddb6SLionel Sambuc 35044684ddb6SLionel Sambucprivate: 35054684ddb6SLionel Sambuc // no copy functions 35064684ddb6SLionel Sambuc random_device(const random_device&); // = delete; 35074684ddb6SLionel Sambuc random_device& operator=(const random_device&); // = delete; 35084684ddb6SLionel Sambuc}; 35094684ddb6SLionel Sambuc 35104684ddb6SLionel Sambuc// seed_seq 35114684ddb6SLionel Sambuc 35124684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY seed_seq 35134684ddb6SLionel Sambuc{ 35144684ddb6SLionel Sambucpublic: 35154684ddb6SLionel Sambuc // types 35164684ddb6SLionel Sambuc typedef uint32_t result_type; 35174684ddb6SLionel Sambuc 35184684ddb6SLionel Sambucprivate: 35194684ddb6SLionel Sambuc vector<result_type> __v_; 35204684ddb6SLionel Sambuc 35214684ddb6SLionel Sambuc template<class _InputIterator> 35224684ddb6SLionel Sambuc void init(_InputIterator __first, _InputIterator __last); 35234684ddb6SLionel Sambucpublic: 35244684ddb6SLionel Sambuc // constructors 35254684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 35264684ddb6SLionel Sambuc seed_seq() _NOEXCEPT {} 35274684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 35284684ddb6SLionel Sambuc template<class _Tp> 35294684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 35304684ddb6SLionel Sambuc seed_seq(initializer_list<_Tp> __il) {init(__il.begin(), __il.end());} 35314684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 35324684ddb6SLionel Sambuc 35334684ddb6SLionel Sambuc template<class _InputIterator> 35344684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 35354684ddb6SLionel Sambuc seed_seq(_InputIterator __first, _InputIterator __last) 35364684ddb6SLionel Sambuc {init(__first, __last);} 35374684ddb6SLionel Sambuc 35384684ddb6SLionel Sambuc // generating functions 35394684ddb6SLionel Sambuc template<class _RandomAccessIterator> 35404684ddb6SLionel Sambuc void generate(_RandomAccessIterator __first, _RandomAccessIterator __last); 35414684ddb6SLionel Sambuc 35424684ddb6SLionel Sambuc // property functions 35434684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 35444684ddb6SLionel Sambuc size_t size() const _NOEXCEPT {return __v_.size();} 35454684ddb6SLionel Sambuc template<class _OutputIterator> 35464684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 35474684ddb6SLionel Sambuc void param(_OutputIterator __dest) const 35484684ddb6SLionel Sambuc {_VSTD::copy(__v_.begin(), __v_.end(), __dest);} 35494684ddb6SLionel Sambuc 35504684ddb6SLionel Sambucprivate: 35514684ddb6SLionel Sambuc // no copy functions 35524684ddb6SLionel Sambuc seed_seq(const seed_seq&); // = delete; 35534684ddb6SLionel Sambuc void operator=(const seed_seq&); // = delete; 35544684ddb6SLionel Sambuc 35554684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 35564684ddb6SLionel Sambuc static result_type _Tp(result_type __x) {return __x ^ (__x >> 27);} 35574684ddb6SLionel Sambuc}; 35584684ddb6SLionel Sambuc 35594684ddb6SLionel Sambuctemplate<class _InputIterator> 35604684ddb6SLionel Sambucvoid 35614684ddb6SLionel Sambucseed_seq::init(_InputIterator __first, _InputIterator __last) 35624684ddb6SLionel Sambuc{ 35634684ddb6SLionel Sambuc for (_InputIterator __s = __first; __s != __last; ++__s) 35644684ddb6SLionel Sambuc __v_.push_back(*__s & 0xFFFFFFFF); 35654684ddb6SLionel Sambuc} 35664684ddb6SLionel Sambuc 35674684ddb6SLionel Sambuctemplate<class _RandomAccessIterator> 35684684ddb6SLionel Sambucvoid 35694684ddb6SLionel Sambucseed_seq::generate(_RandomAccessIterator __first, _RandomAccessIterator __last) 35704684ddb6SLionel Sambuc{ 35714684ddb6SLionel Sambuc if (__first != __last) 35724684ddb6SLionel Sambuc { 35734684ddb6SLionel Sambuc _VSTD::fill(__first, __last, 0x8b8b8b8b); 35744684ddb6SLionel Sambuc const size_t __n = static_cast<size_t>(__last - __first); 35754684ddb6SLionel Sambuc const size_t __s = __v_.size(); 35764684ddb6SLionel Sambuc const size_t __t = (__n >= 623) ? 11 35774684ddb6SLionel Sambuc : (__n >= 68) ? 7 35784684ddb6SLionel Sambuc : (__n >= 39) ? 5 35794684ddb6SLionel Sambuc : (__n >= 7) ? 3 35804684ddb6SLionel Sambuc : (__n - 1) / 2; 35814684ddb6SLionel Sambuc const size_t __p = (__n - __t) / 2; 35824684ddb6SLionel Sambuc const size_t __q = __p + __t; 35834684ddb6SLionel Sambuc const size_t __m = _VSTD::max(__s + 1, __n); 35844684ddb6SLionel Sambuc // __k = 0; 35854684ddb6SLionel Sambuc { 35864684ddb6SLionel Sambuc result_type __r = 1664525 * _Tp(__first[0] ^ __first[__p] 35874684ddb6SLionel Sambuc ^ __first[__n - 1]); 35884684ddb6SLionel Sambuc __first[__p] += __r; 35894684ddb6SLionel Sambuc __r += __s; 35904684ddb6SLionel Sambuc __first[__q] += __r; 35914684ddb6SLionel Sambuc __first[0] = __r; 35924684ddb6SLionel Sambuc } 35934684ddb6SLionel Sambuc for (size_t __k = 1; __k <= __s; ++__k) 35944684ddb6SLionel Sambuc { 35954684ddb6SLionel Sambuc const size_t __kmodn = __k % __n; 35964684ddb6SLionel Sambuc const size_t __kpmodn = (__k + __p) % __n; 35974684ddb6SLionel Sambuc result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn] 35984684ddb6SLionel Sambuc ^ __first[(__k - 1) % __n]); 35994684ddb6SLionel Sambuc __first[__kpmodn] += __r; 36004684ddb6SLionel Sambuc __r += __kmodn + __v_[__k-1]; 36014684ddb6SLionel Sambuc __first[(__k + __q) % __n] += __r; 36024684ddb6SLionel Sambuc __first[__kmodn] = __r; 36034684ddb6SLionel Sambuc } 36044684ddb6SLionel Sambuc for (size_t __k = __s + 1; __k < __m; ++__k) 36054684ddb6SLionel Sambuc { 36064684ddb6SLionel Sambuc const size_t __kmodn = __k % __n; 36074684ddb6SLionel Sambuc const size_t __kpmodn = (__k + __p) % __n; 36084684ddb6SLionel Sambuc result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn] 36094684ddb6SLionel Sambuc ^ __first[(__k - 1) % __n]); 36104684ddb6SLionel Sambuc __first[__kpmodn] += __r; 36114684ddb6SLionel Sambuc __r += __kmodn; 36124684ddb6SLionel Sambuc __first[(__k + __q) % __n] += __r; 36134684ddb6SLionel Sambuc __first[__kmodn] = __r; 36144684ddb6SLionel Sambuc } 36154684ddb6SLionel Sambuc for (size_t __k = __m; __k < __m + __n; ++__k) 36164684ddb6SLionel Sambuc { 36174684ddb6SLionel Sambuc const size_t __kmodn = __k % __n; 36184684ddb6SLionel Sambuc const size_t __kpmodn = (__k + __p) % __n; 36194684ddb6SLionel Sambuc result_type __r = 1566083941 * _Tp(__first[__kmodn] + 36204684ddb6SLionel Sambuc __first[__kpmodn] + 36214684ddb6SLionel Sambuc __first[(__k - 1) % __n]); 36224684ddb6SLionel Sambuc __first[__kpmodn] ^= __r; 36234684ddb6SLionel Sambuc __r -= __kmodn; 36244684ddb6SLionel Sambuc __first[(__k + __q) % __n] ^= __r; 36254684ddb6SLionel Sambuc __first[__kmodn] = __r; 36264684ddb6SLionel Sambuc } 36274684ddb6SLionel Sambuc } 36284684ddb6SLionel Sambuc} 36294684ddb6SLionel Sambuc 36304684ddb6SLionel Sambuc// generate_canonical 36314684ddb6SLionel Sambuc 36324684ddb6SLionel Sambuctemplate<class _RealType, size_t __bits, class _URNG> 36334684ddb6SLionel Sambuc_RealType 36344684ddb6SLionel Sambucgenerate_canonical(_URNG& __g) 36354684ddb6SLionel Sambuc{ 36364684ddb6SLionel Sambuc const size_t _Dt = numeric_limits<_RealType>::digits; 36374684ddb6SLionel Sambuc const size_t __b = _Dt < __bits ? _Dt : __bits; 36384684ddb6SLionel Sambuc#ifdef _LIBCPP_HAS_NO_CONSTEXPR 36394684ddb6SLionel Sambuc const size_t __logR = __log2<uint64_t, _URNG::_Max - _URNG::_Min + uint64_t(1)>::value; 36404684ddb6SLionel Sambuc#else 36414684ddb6SLionel Sambuc const size_t __logR = __log2<uint64_t, _URNG::max() - _URNG::min() + uint64_t(1)>::value; 36424684ddb6SLionel Sambuc#endif 36434684ddb6SLionel Sambuc const size_t __k = __b / __logR + (__b % __logR != 0) + (__b == 0); 36444684ddb6SLionel Sambuc const _RealType _Rp = _URNG::max() - _URNG::min() + _RealType(1); 36454684ddb6SLionel Sambuc _RealType __base = _Rp; 36464684ddb6SLionel Sambuc _RealType _Sp = __g() - _URNG::min(); 36474684ddb6SLionel Sambuc for (size_t __i = 1; __i < __k; ++__i, __base *= _Rp) 36484684ddb6SLionel Sambuc _Sp += (__g() - _URNG::min()) * __base; 36494684ddb6SLionel Sambuc return _Sp / __base; 36504684ddb6SLionel Sambuc} 36514684ddb6SLionel Sambuc 36524684ddb6SLionel Sambuc// uniform_int_distribution 36534684ddb6SLionel Sambuc 36544684ddb6SLionel Sambuc// in <algorithm> 36554684ddb6SLionel Sambuc 36564684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _IT> 36574684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 36584684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 36594684ddb6SLionel Sambuc const uniform_int_distribution<_IT>& __x) 36604684ddb6SLionel Sambuc{ 36614684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__os); 36624684ddb6SLionel Sambuc __os.flags(ios_base::dec | ios_base::left); 36634684ddb6SLionel Sambuc _CharT __sp = __os.widen(' '); 36644684ddb6SLionel Sambuc __os.fill(__sp); 36654684ddb6SLionel Sambuc return __os << __x.a() << __sp << __x.b(); 36664684ddb6SLionel Sambuc} 36674684ddb6SLionel Sambuc 36684684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _IT> 36694684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 36704684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 36714684ddb6SLionel Sambuc uniform_int_distribution<_IT>& __x) 36724684ddb6SLionel Sambuc{ 36734684ddb6SLionel Sambuc typedef uniform_int_distribution<_IT> _Eng; 36744684ddb6SLionel Sambuc typedef typename _Eng::result_type result_type; 36754684ddb6SLionel Sambuc typedef typename _Eng::param_type param_type; 36764684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__is); 36774684ddb6SLionel Sambuc __is.flags(ios_base::dec | ios_base::skipws); 36784684ddb6SLionel Sambuc result_type __a; 36794684ddb6SLionel Sambuc result_type __b; 36804684ddb6SLionel Sambuc __is >> __a >> __b; 36814684ddb6SLionel Sambuc if (!__is.fail()) 36824684ddb6SLionel Sambuc __x.param(param_type(__a, __b)); 36834684ddb6SLionel Sambuc return __is; 36844684ddb6SLionel Sambuc} 36854684ddb6SLionel Sambuc 36864684ddb6SLionel Sambuc// uniform_real_distribution 36874684ddb6SLionel Sambuc 36884684ddb6SLionel Sambuctemplate<class _RealType = double> 36894684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY uniform_real_distribution 36904684ddb6SLionel Sambuc{ 36914684ddb6SLionel Sambucpublic: 36924684ddb6SLionel Sambuc // types 36934684ddb6SLionel Sambuc typedef _RealType result_type; 36944684ddb6SLionel Sambuc 36954684ddb6SLionel Sambuc class _LIBCPP_TYPE_VIS_ONLY param_type 36964684ddb6SLionel Sambuc { 36974684ddb6SLionel Sambuc result_type __a_; 36984684ddb6SLionel Sambuc result_type __b_; 36994684ddb6SLionel Sambuc public: 37004684ddb6SLionel Sambuc typedef uniform_real_distribution distribution_type; 37014684ddb6SLionel Sambuc 37024684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 37034684ddb6SLionel Sambuc explicit param_type(result_type __a = 0, 37044684ddb6SLionel Sambuc result_type __b = 1) 37054684ddb6SLionel Sambuc : __a_(__a), __b_(__b) {} 37064684ddb6SLionel Sambuc 37074684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 37084684ddb6SLionel Sambuc result_type a() const {return __a_;} 37094684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 37104684ddb6SLionel Sambuc result_type b() const {return __b_;} 37114684ddb6SLionel Sambuc 37124684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 37134684ddb6SLionel Sambuc bool operator==(const param_type& __x, const param_type& __y) 37144684ddb6SLionel Sambuc {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} 37154684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 37164684ddb6SLionel Sambuc bool operator!=(const param_type& __x, const param_type& __y) 37174684ddb6SLionel Sambuc {return !(__x == __y);} 37184684ddb6SLionel Sambuc }; 37194684ddb6SLionel Sambuc 37204684ddb6SLionel Sambucprivate: 37214684ddb6SLionel Sambuc param_type __p_; 37224684ddb6SLionel Sambuc 37234684ddb6SLionel Sambucpublic: 37244684ddb6SLionel Sambuc // constructors and reset functions 37254684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 37264684ddb6SLionel Sambuc explicit uniform_real_distribution(result_type __a = 0, result_type __b = 1) 37274684ddb6SLionel Sambuc : __p_(param_type(__a, __b)) {} 37284684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 37294684ddb6SLionel Sambuc explicit uniform_real_distribution(const param_type& __p) : __p_(__p) {} 37304684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 37314684ddb6SLionel Sambuc void reset() {} 37324684ddb6SLionel Sambuc 37334684ddb6SLionel Sambuc // generating functions 37344684ddb6SLionel Sambuc template<class _URNG> 37354684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 37364684ddb6SLionel Sambuc result_type operator()(_URNG& __g) 37374684ddb6SLionel Sambuc {return (*this)(__g, __p_);} 37384684ddb6SLionel Sambuc template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 37394684ddb6SLionel Sambuc 37404684ddb6SLionel Sambuc // property functions 37414684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 37424684ddb6SLionel Sambuc result_type a() const {return __p_.a();} 37434684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 37444684ddb6SLionel Sambuc result_type b() const {return __p_.b();} 37454684ddb6SLionel Sambuc 37464684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 37474684ddb6SLionel Sambuc param_type param() const {return __p_;} 37484684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 37494684ddb6SLionel Sambuc void param(const param_type& __p) {__p_ = __p;} 37504684ddb6SLionel Sambuc 37514684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 37524684ddb6SLionel Sambuc result_type min() const {return a();} 37534684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 37544684ddb6SLionel Sambuc result_type max() const {return b();} 37554684ddb6SLionel Sambuc 37564684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 37574684ddb6SLionel Sambuc bool operator==(const uniform_real_distribution& __x, 37584684ddb6SLionel Sambuc const uniform_real_distribution& __y) 37594684ddb6SLionel Sambuc {return __x.__p_ == __y.__p_;} 37604684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 37614684ddb6SLionel Sambuc bool operator!=(const uniform_real_distribution& __x, 37624684ddb6SLionel Sambuc const uniform_real_distribution& __y) 37634684ddb6SLionel Sambuc {return !(__x == __y);} 37644684ddb6SLionel Sambuc}; 37654684ddb6SLionel Sambuc 37664684ddb6SLionel Sambuctemplate<class _RealType> 37674684ddb6SLionel Sambuctemplate<class _URNG> 37684684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 37694684ddb6SLionel Sambuctypename uniform_real_distribution<_RealType>::result_type 37704684ddb6SLionel Sambucuniform_real_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 37714684ddb6SLionel Sambuc{ 37724684ddb6SLionel Sambuc return (__p.b() - __p.a()) 37734684ddb6SLionel Sambuc * _VSTD::generate_canonical<_RealType, numeric_limits<_RealType>::digits>(__g) 37744684ddb6SLionel Sambuc + __p.a(); 37754684ddb6SLionel Sambuc} 37764684ddb6SLionel Sambuc 37774684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _RT> 37784684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 37794684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 37804684ddb6SLionel Sambuc const uniform_real_distribution<_RT>& __x) 37814684ddb6SLionel Sambuc{ 37824684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__os); 37834684ddb6SLionel Sambuc __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 37844684ddb6SLionel Sambuc ios_base::scientific); 37854684ddb6SLionel Sambuc _CharT __sp = __os.widen(' '); 37864684ddb6SLionel Sambuc __os.fill(__sp); 37874684ddb6SLionel Sambuc return __os << __x.a() << __sp << __x.b(); 37884684ddb6SLionel Sambuc} 37894684ddb6SLionel Sambuc 37904684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _RT> 37914684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 37924684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 37934684ddb6SLionel Sambuc uniform_real_distribution<_RT>& __x) 37944684ddb6SLionel Sambuc{ 37954684ddb6SLionel Sambuc typedef uniform_real_distribution<_RT> _Eng; 37964684ddb6SLionel Sambuc typedef typename _Eng::result_type result_type; 37974684ddb6SLionel Sambuc typedef typename _Eng::param_type param_type; 37984684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__is); 37994684ddb6SLionel Sambuc __is.flags(ios_base::dec | ios_base::skipws); 38004684ddb6SLionel Sambuc result_type __a; 38014684ddb6SLionel Sambuc result_type __b; 38024684ddb6SLionel Sambuc __is >> __a >> __b; 38034684ddb6SLionel Sambuc if (!__is.fail()) 38044684ddb6SLionel Sambuc __x.param(param_type(__a, __b)); 38054684ddb6SLionel Sambuc return __is; 38064684ddb6SLionel Sambuc} 38074684ddb6SLionel Sambuc 38084684ddb6SLionel Sambuc// bernoulli_distribution 38094684ddb6SLionel Sambuc 38104684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY bernoulli_distribution 38114684ddb6SLionel Sambuc{ 38124684ddb6SLionel Sambucpublic: 38134684ddb6SLionel Sambuc // types 38144684ddb6SLionel Sambuc typedef bool result_type; 38154684ddb6SLionel Sambuc 38164684ddb6SLionel Sambuc class _LIBCPP_TYPE_VIS_ONLY param_type 38174684ddb6SLionel Sambuc { 38184684ddb6SLionel Sambuc double __p_; 38194684ddb6SLionel Sambuc public: 38204684ddb6SLionel Sambuc typedef bernoulli_distribution distribution_type; 38214684ddb6SLionel Sambuc 38224684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 38234684ddb6SLionel Sambuc explicit param_type(double __p = 0.5) : __p_(__p) {} 38244684ddb6SLionel Sambuc 38254684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 38264684ddb6SLionel Sambuc double p() const {return __p_;} 38274684ddb6SLionel Sambuc 38284684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 38294684ddb6SLionel Sambuc bool operator==(const param_type& __x, const param_type& __y) 38304684ddb6SLionel Sambuc {return __x.__p_ == __y.__p_;} 38314684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 38324684ddb6SLionel Sambuc bool operator!=(const param_type& __x, const param_type& __y) 38334684ddb6SLionel Sambuc {return !(__x == __y);} 38344684ddb6SLionel Sambuc }; 38354684ddb6SLionel Sambuc 38364684ddb6SLionel Sambucprivate: 38374684ddb6SLionel Sambuc param_type __p_; 38384684ddb6SLionel Sambuc 38394684ddb6SLionel Sambucpublic: 38404684ddb6SLionel Sambuc // constructors and reset functions 38414684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 38424684ddb6SLionel Sambuc explicit bernoulli_distribution(double __p = 0.5) 38434684ddb6SLionel Sambuc : __p_(param_type(__p)) {} 38444684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 38454684ddb6SLionel Sambuc explicit bernoulli_distribution(const param_type& __p) : __p_(__p) {} 38464684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 38474684ddb6SLionel Sambuc void reset() {} 38484684ddb6SLionel Sambuc 38494684ddb6SLionel Sambuc // generating functions 38504684ddb6SLionel Sambuc template<class _URNG> 38514684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 38524684ddb6SLionel Sambuc result_type operator()(_URNG& __g) 38534684ddb6SLionel Sambuc {return (*this)(__g, __p_);} 38544684ddb6SLionel Sambuc template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 38554684ddb6SLionel Sambuc 38564684ddb6SLionel Sambuc // property functions 38574684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 38584684ddb6SLionel Sambuc double p() const {return __p_.p();} 38594684ddb6SLionel Sambuc 38604684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 38614684ddb6SLionel Sambuc param_type param() const {return __p_;} 38624684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 38634684ddb6SLionel Sambuc void param(const param_type& __p) {__p_ = __p;} 38644684ddb6SLionel Sambuc 38654684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 38664684ddb6SLionel Sambuc result_type min() const {return false;} 38674684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 38684684ddb6SLionel Sambuc result_type max() const {return true;} 38694684ddb6SLionel Sambuc 38704684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 38714684ddb6SLionel Sambuc bool operator==(const bernoulli_distribution& __x, 38724684ddb6SLionel Sambuc const bernoulli_distribution& __y) 38734684ddb6SLionel Sambuc {return __x.__p_ == __y.__p_;} 38744684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 38754684ddb6SLionel Sambuc bool operator!=(const bernoulli_distribution& __x, 38764684ddb6SLionel Sambuc const bernoulli_distribution& __y) 38774684ddb6SLionel Sambuc {return !(__x == __y);} 38784684ddb6SLionel Sambuc}; 38794684ddb6SLionel Sambuc 38804684ddb6SLionel Sambuctemplate<class _URNG> 38814684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 38824684ddb6SLionel Sambucbernoulli_distribution::result_type 38834684ddb6SLionel Sambucbernoulli_distribution::operator()(_URNG& __g, const param_type& __p) 38844684ddb6SLionel Sambuc{ 38854684ddb6SLionel Sambuc uniform_real_distribution<double> __gen; 38864684ddb6SLionel Sambuc return __gen(__g) < __p.p(); 38874684ddb6SLionel Sambuc} 38884684ddb6SLionel Sambuc 38894684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 38904684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 38914684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, const bernoulli_distribution& __x) 38924684ddb6SLionel Sambuc{ 38934684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__os); 38944684ddb6SLionel Sambuc __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 38954684ddb6SLionel Sambuc ios_base::scientific); 38964684ddb6SLionel Sambuc _CharT __sp = __os.widen(' '); 38974684ddb6SLionel Sambuc __os.fill(__sp); 38984684ddb6SLionel Sambuc return __os << __x.p(); 38994684ddb6SLionel Sambuc} 39004684ddb6SLionel Sambuc 39014684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 39024684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 39034684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, bernoulli_distribution& __x) 39044684ddb6SLionel Sambuc{ 39054684ddb6SLionel Sambuc typedef bernoulli_distribution _Eng; 39064684ddb6SLionel Sambuc typedef typename _Eng::param_type param_type; 39074684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__is); 39084684ddb6SLionel Sambuc __is.flags(ios_base::dec | ios_base::skipws); 39094684ddb6SLionel Sambuc double __p; 39104684ddb6SLionel Sambuc __is >> __p; 39114684ddb6SLionel Sambuc if (!__is.fail()) 39124684ddb6SLionel Sambuc __x.param(param_type(__p)); 39134684ddb6SLionel Sambuc return __is; 39144684ddb6SLionel Sambuc} 39154684ddb6SLionel Sambuc 39164684ddb6SLionel Sambuc// binomial_distribution 39174684ddb6SLionel Sambuc 39184684ddb6SLionel Sambuctemplate<class _IntType = int> 39194684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY binomial_distribution 39204684ddb6SLionel Sambuc{ 39214684ddb6SLionel Sambucpublic: 39224684ddb6SLionel Sambuc // types 39234684ddb6SLionel Sambuc typedef _IntType result_type; 39244684ddb6SLionel Sambuc 39254684ddb6SLionel Sambuc class _LIBCPP_TYPE_VIS_ONLY param_type 39264684ddb6SLionel Sambuc { 39274684ddb6SLionel Sambuc result_type __t_; 39284684ddb6SLionel Sambuc double __p_; 39294684ddb6SLionel Sambuc double __pr_; 39304684ddb6SLionel Sambuc double __odds_ratio_; 39314684ddb6SLionel Sambuc result_type __r0_; 39324684ddb6SLionel Sambuc public: 39334684ddb6SLionel Sambuc typedef binomial_distribution distribution_type; 39344684ddb6SLionel Sambuc 39354684ddb6SLionel Sambuc explicit param_type(result_type __t = 1, double __p = 0.5); 39364684ddb6SLionel Sambuc 39374684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 39384684ddb6SLionel Sambuc result_type t() const {return __t_;} 39394684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 39404684ddb6SLionel Sambuc double p() const {return __p_;} 39414684ddb6SLionel Sambuc 39424684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 39434684ddb6SLionel Sambuc bool operator==(const param_type& __x, const param_type& __y) 39444684ddb6SLionel Sambuc {return __x.__t_ == __y.__t_ && __x.__p_ == __y.__p_;} 39454684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 39464684ddb6SLionel Sambuc bool operator!=(const param_type& __x, const param_type& __y) 39474684ddb6SLionel Sambuc {return !(__x == __y);} 39484684ddb6SLionel Sambuc 39494684ddb6SLionel Sambuc friend class binomial_distribution; 39504684ddb6SLionel Sambuc }; 39514684ddb6SLionel Sambuc 39524684ddb6SLionel Sambucprivate: 39534684ddb6SLionel Sambuc param_type __p_; 39544684ddb6SLionel Sambuc 39554684ddb6SLionel Sambucpublic: 39564684ddb6SLionel Sambuc // constructors and reset functions 39574684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 39584684ddb6SLionel Sambuc explicit binomial_distribution(result_type __t = 1, double __p = 0.5) 39594684ddb6SLionel Sambuc : __p_(param_type(__t, __p)) {} 39604684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 39614684ddb6SLionel Sambuc explicit binomial_distribution(const param_type& __p) : __p_(__p) {} 39624684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 39634684ddb6SLionel Sambuc void reset() {} 39644684ddb6SLionel Sambuc 39654684ddb6SLionel Sambuc // generating functions 39664684ddb6SLionel Sambuc template<class _URNG> 39674684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 39684684ddb6SLionel Sambuc result_type operator()(_URNG& __g) 39694684ddb6SLionel Sambuc {return (*this)(__g, __p_);} 39704684ddb6SLionel Sambuc template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 39714684ddb6SLionel Sambuc 39724684ddb6SLionel Sambuc // property functions 39734684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 39744684ddb6SLionel Sambuc result_type t() const {return __p_.t();} 39754684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 39764684ddb6SLionel Sambuc double p() const {return __p_.p();} 39774684ddb6SLionel Sambuc 39784684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 39794684ddb6SLionel Sambuc param_type param() const {return __p_;} 39804684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 39814684ddb6SLionel Sambuc void param(const param_type& __p) {__p_ = __p;} 39824684ddb6SLionel Sambuc 39834684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 39844684ddb6SLionel Sambuc result_type min() const {return 0;} 39854684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 39864684ddb6SLionel Sambuc result_type max() const {return t();} 39874684ddb6SLionel Sambuc 39884684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 39894684ddb6SLionel Sambuc bool operator==(const binomial_distribution& __x, 39904684ddb6SLionel Sambuc const binomial_distribution& __y) 39914684ddb6SLionel Sambuc {return __x.__p_ == __y.__p_;} 39924684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 39934684ddb6SLionel Sambuc bool operator!=(const binomial_distribution& __x, 39944684ddb6SLionel Sambuc const binomial_distribution& __y) 39954684ddb6SLionel Sambuc {return !(__x == __y);} 39964684ddb6SLionel Sambuc}; 39974684ddb6SLionel Sambuc 39984684ddb6SLionel Sambuctemplate<class _IntType> 39994684ddb6SLionel Sambucbinomial_distribution<_IntType>::param_type::param_type(result_type __t, double __p) 40004684ddb6SLionel Sambuc : __t_(__t), __p_(__p) 40014684ddb6SLionel Sambuc{ 40024684ddb6SLionel Sambuc if (0 < __p_ && __p_ < 1) 40034684ddb6SLionel Sambuc { 40044684ddb6SLionel Sambuc __r0_ = static_cast<result_type>((__t_ + 1) * __p_); 40054684ddb6SLionel Sambuc __pr_ = _VSTD::exp(_VSTD::lgamma(__t_ + 1.) - _VSTD::lgamma(__r0_ + 1.) - 40064684ddb6SLionel Sambuc _VSTD::lgamma(__t_ - __r0_ + 1.) + __r0_ * _VSTD::log(__p_) + 40074684ddb6SLionel Sambuc (__t_ - __r0_) * _VSTD::log(1 - __p_)); 40084684ddb6SLionel Sambuc __odds_ratio_ = __p_ / (1 - __p_); 40094684ddb6SLionel Sambuc } 40104684ddb6SLionel Sambuc} 40114684ddb6SLionel Sambuc 4012*0a6a1f1dSLionel Sambuc// Reference: Kemp, C.D. (1986). `A modal method for generating binomial 4013*0a6a1f1dSLionel Sambuc// variables', Commun. Statist. - Theor. Meth. 15(3), 805-813. 40144684ddb6SLionel Sambuctemplate<class _IntType> 40154684ddb6SLionel Sambuctemplate<class _URNG> 40164684ddb6SLionel Sambuc_IntType 40174684ddb6SLionel Sambucbinomial_distribution<_IntType>::operator()(_URNG& __g, const param_type& __pr) 40184684ddb6SLionel Sambuc{ 40194684ddb6SLionel Sambuc if (__pr.__t_ == 0 || __pr.__p_ == 0) 40204684ddb6SLionel Sambuc return 0; 40214684ddb6SLionel Sambuc if (__pr.__p_ == 1) 40224684ddb6SLionel Sambuc return __pr.__t_; 40234684ddb6SLionel Sambuc uniform_real_distribution<double> __gen; 40244684ddb6SLionel Sambuc double __u = __gen(__g) - __pr.__pr_; 40254684ddb6SLionel Sambuc if (__u < 0) 40264684ddb6SLionel Sambuc return __pr.__r0_; 40274684ddb6SLionel Sambuc double __pu = __pr.__pr_; 40284684ddb6SLionel Sambuc double __pd = __pu; 40294684ddb6SLionel Sambuc result_type __ru = __pr.__r0_; 40304684ddb6SLionel Sambuc result_type __rd = __ru; 40314684ddb6SLionel Sambuc while (true) 40324684ddb6SLionel Sambuc { 40334684ddb6SLionel Sambuc if (__rd >= 1) 40344684ddb6SLionel Sambuc { 40354684ddb6SLionel Sambuc __pd *= __rd / (__pr.__odds_ratio_ * (__pr.__t_ - __rd + 1)); 40364684ddb6SLionel Sambuc __u -= __pd; 40374684ddb6SLionel Sambuc if (__u < 0) 40384684ddb6SLionel Sambuc return __rd - 1; 40394684ddb6SLionel Sambuc } 4040*0a6a1f1dSLionel Sambuc if ( __rd != 0 ) 40414684ddb6SLionel Sambuc --__rd; 40424684ddb6SLionel Sambuc ++__ru; 40434684ddb6SLionel Sambuc if (__ru <= __pr.__t_) 40444684ddb6SLionel Sambuc { 40454684ddb6SLionel Sambuc __pu *= (__pr.__t_ - __ru + 1) * __pr.__odds_ratio_ / __ru; 40464684ddb6SLionel Sambuc __u -= __pu; 40474684ddb6SLionel Sambuc if (__u < 0) 40484684ddb6SLionel Sambuc return __ru; 40494684ddb6SLionel Sambuc } 40504684ddb6SLionel Sambuc } 40514684ddb6SLionel Sambuc} 40524684ddb6SLionel Sambuc 40534684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _IntType> 40544684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 40554684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 40564684ddb6SLionel Sambuc const binomial_distribution<_IntType>& __x) 40574684ddb6SLionel Sambuc{ 40584684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__os); 40594684ddb6SLionel Sambuc __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 40604684ddb6SLionel Sambuc ios_base::scientific); 40614684ddb6SLionel Sambuc _CharT __sp = __os.widen(' '); 40624684ddb6SLionel Sambuc __os.fill(__sp); 40634684ddb6SLionel Sambuc return __os << __x.t() << __sp << __x.p(); 40644684ddb6SLionel Sambuc} 40654684ddb6SLionel Sambuc 40664684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _IntType> 40674684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 40684684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 40694684ddb6SLionel Sambuc binomial_distribution<_IntType>& __x) 40704684ddb6SLionel Sambuc{ 40714684ddb6SLionel Sambuc typedef binomial_distribution<_IntType> _Eng; 40724684ddb6SLionel Sambuc typedef typename _Eng::result_type result_type; 40734684ddb6SLionel Sambuc typedef typename _Eng::param_type param_type; 40744684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__is); 40754684ddb6SLionel Sambuc __is.flags(ios_base::dec | ios_base::skipws); 40764684ddb6SLionel Sambuc result_type __t; 40774684ddb6SLionel Sambuc double __p; 40784684ddb6SLionel Sambuc __is >> __t >> __p; 40794684ddb6SLionel Sambuc if (!__is.fail()) 40804684ddb6SLionel Sambuc __x.param(param_type(__t, __p)); 40814684ddb6SLionel Sambuc return __is; 40824684ddb6SLionel Sambuc} 40834684ddb6SLionel Sambuc 40844684ddb6SLionel Sambuc// exponential_distribution 40854684ddb6SLionel Sambuc 40864684ddb6SLionel Sambuctemplate<class _RealType = double> 40874684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY exponential_distribution 40884684ddb6SLionel Sambuc{ 40894684ddb6SLionel Sambucpublic: 40904684ddb6SLionel Sambuc // types 40914684ddb6SLionel Sambuc typedef _RealType result_type; 40924684ddb6SLionel Sambuc 40934684ddb6SLionel Sambuc class _LIBCPP_TYPE_VIS_ONLY param_type 40944684ddb6SLionel Sambuc { 40954684ddb6SLionel Sambuc result_type __lambda_; 40964684ddb6SLionel Sambuc public: 40974684ddb6SLionel Sambuc typedef exponential_distribution distribution_type; 40984684ddb6SLionel Sambuc 40994684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 41004684ddb6SLionel Sambuc explicit param_type(result_type __lambda = 1) : __lambda_(__lambda) {} 41014684ddb6SLionel Sambuc 41024684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 41034684ddb6SLionel Sambuc result_type lambda() const {return __lambda_;} 41044684ddb6SLionel Sambuc 41054684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 41064684ddb6SLionel Sambuc bool operator==(const param_type& __x, const param_type& __y) 41074684ddb6SLionel Sambuc {return __x.__lambda_ == __y.__lambda_;} 41084684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 41094684ddb6SLionel Sambuc bool operator!=(const param_type& __x, const param_type& __y) 41104684ddb6SLionel Sambuc {return !(__x == __y);} 41114684ddb6SLionel Sambuc }; 41124684ddb6SLionel Sambuc 41134684ddb6SLionel Sambucprivate: 41144684ddb6SLionel Sambuc param_type __p_; 41154684ddb6SLionel Sambuc 41164684ddb6SLionel Sambucpublic: 41174684ddb6SLionel Sambuc // constructors and reset functions 41184684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 41194684ddb6SLionel Sambuc explicit exponential_distribution(result_type __lambda = 1) 41204684ddb6SLionel Sambuc : __p_(param_type(__lambda)) {} 41214684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 41224684ddb6SLionel Sambuc explicit exponential_distribution(const param_type& __p) : __p_(__p) {} 41234684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 41244684ddb6SLionel Sambuc void reset() {} 41254684ddb6SLionel Sambuc 41264684ddb6SLionel Sambuc // generating functions 41274684ddb6SLionel Sambuc template<class _URNG> 41284684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 41294684ddb6SLionel Sambuc result_type operator()(_URNG& __g) 41304684ddb6SLionel Sambuc {return (*this)(__g, __p_);} 41314684ddb6SLionel Sambuc template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 41324684ddb6SLionel Sambuc 41334684ddb6SLionel Sambuc // property functions 41344684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 41354684ddb6SLionel Sambuc result_type lambda() const {return __p_.lambda();} 41364684ddb6SLionel Sambuc 41374684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 41384684ddb6SLionel Sambuc param_type param() const {return __p_;} 41394684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 41404684ddb6SLionel Sambuc void param(const param_type& __p) {__p_ = __p;} 41414684ddb6SLionel Sambuc 41424684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 41434684ddb6SLionel Sambuc result_type min() const {return 0;} 41444684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 41454684ddb6SLionel Sambuc result_type max() const {return numeric_limits<result_type>::infinity();} 41464684ddb6SLionel Sambuc 41474684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 41484684ddb6SLionel Sambuc bool operator==(const exponential_distribution& __x, 41494684ddb6SLionel Sambuc const exponential_distribution& __y) 41504684ddb6SLionel Sambuc {return __x.__p_ == __y.__p_;} 41514684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 41524684ddb6SLionel Sambuc bool operator!=(const exponential_distribution& __x, 41534684ddb6SLionel Sambuc const exponential_distribution& __y) 41544684ddb6SLionel Sambuc {return !(__x == __y);} 41554684ddb6SLionel Sambuc}; 41564684ddb6SLionel Sambuc 41574684ddb6SLionel Sambuctemplate <class _RealType> 41584684ddb6SLionel Sambuctemplate<class _URNG> 41594684ddb6SLionel Sambuc_RealType 41604684ddb6SLionel Sambucexponential_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 41614684ddb6SLionel Sambuc{ 41624684ddb6SLionel Sambuc return -_VSTD::log 41634684ddb6SLionel Sambuc ( 41644684ddb6SLionel Sambuc result_type(1) - 41654684ddb6SLionel Sambuc _VSTD::generate_canonical<result_type, 41664684ddb6SLionel Sambuc numeric_limits<result_type>::digits>(__g) 41674684ddb6SLionel Sambuc ) 41684684ddb6SLionel Sambuc / __p.lambda(); 41694684ddb6SLionel Sambuc} 41704684ddb6SLionel Sambuc 41714684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _RealType> 41724684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 41734684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 41744684ddb6SLionel Sambuc const exponential_distribution<_RealType>& __x) 41754684ddb6SLionel Sambuc{ 41764684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__os); 41774684ddb6SLionel Sambuc __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 41784684ddb6SLionel Sambuc ios_base::scientific); 41794684ddb6SLionel Sambuc return __os << __x.lambda(); 41804684ddb6SLionel Sambuc} 41814684ddb6SLionel Sambuc 41824684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _RealType> 41834684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 41844684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 41854684ddb6SLionel Sambuc exponential_distribution<_RealType>& __x) 41864684ddb6SLionel Sambuc{ 41874684ddb6SLionel Sambuc typedef exponential_distribution<_RealType> _Eng; 41884684ddb6SLionel Sambuc typedef typename _Eng::result_type result_type; 41894684ddb6SLionel Sambuc typedef typename _Eng::param_type param_type; 41904684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__is); 41914684ddb6SLionel Sambuc __is.flags(ios_base::dec | ios_base::skipws); 41924684ddb6SLionel Sambuc result_type __lambda; 41934684ddb6SLionel Sambuc __is >> __lambda; 41944684ddb6SLionel Sambuc if (!__is.fail()) 41954684ddb6SLionel Sambuc __x.param(param_type(__lambda)); 41964684ddb6SLionel Sambuc return __is; 41974684ddb6SLionel Sambuc} 41984684ddb6SLionel Sambuc 41994684ddb6SLionel Sambuc// normal_distribution 42004684ddb6SLionel Sambuc 42014684ddb6SLionel Sambuctemplate<class _RealType = double> 42024684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY normal_distribution 42034684ddb6SLionel Sambuc{ 42044684ddb6SLionel Sambucpublic: 42054684ddb6SLionel Sambuc // types 42064684ddb6SLionel Sambuc typedef _RealType result_type; 42074684ddb6SLionel Sambuc 42084684ddb6SLionel Sambuc class _LIBCPP_TYPE_VIS_ONLY param_type 42094684ddb6SLionel Sambuc { 42104684ddb6SLionel Sambuc result_type __mean_; 42114684ddb6SLionel Sambuc result_type __stddev_; 42124684ddb6SLionel Sambuc public: 42134684ddb6SLionel Sambuc typedef normal_distribution distribution_type; 42144684ddb6SLionel Sambuc 42154684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 42164684ddb6SLionel Sambuc explicit param_type(result_type __mean = 0, result_type __stddev = 1) 42174684ddb6SLionel Sambuc : __mean_(__mean), __stddev_(__stddev) {} 42184684ddb6SLionel Sambuc 42194684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 42204684ddb6SLionel Sambuc result_type mean() const {return __mean_;} 42214684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 42224684ddb6SLionel Sambuc result_type stddev() const {return __stddev_;} 42234684ddb6SLionel Sambuc 42244684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 42254684ddb6SLionel Sambuc bool operator==(const param_type& __x, const param_type& __y) 42264684ddb6SLionel Sambuc {return __x.__mean_ == __y.__mean_ && __x.__stddev_ == __y.__stddev_;} 42274684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 42284684ddb6SLionel Sambuc bool operator!=(const param_type& __x, const param_type& __y) 42294684ddb6SLionel Sambuc {return !(__x == __y);} 42304684ddb6SLionel Sambuc }; 42314684ddb6SLionel Sambuc 42324684ddb6SLionel Sambucprivate: 42334684ddb6SLionel Sambuc param_type __p_; 42344684ddb6SLionel Sambuc result_type _V_; 42354684ddb6SLionel Sambuc bool _V_hot_; 42364684ddb6SLionel Sambuc 42374684ddb6SLionel Sambucpublic: 42384684ddb6SLionel Sambuc // constructors and reset functions 42394684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 42404684ddb6SLionel Sambuc explicit normal_distribution(result_type __mean = 0, result_type __stddev = 1) 42414684ddb6SLionel Sambuc : __p_(param_type(__mean, __stddev)), _V_hot_(false) {} 42424684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 42434684ddb6SLionel Sambuc explicit normal_distribution(const param_type& __p) 42444684ddb6SLionel Sambuc : __p_(__p), _V_hot_(false) {} 42454684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 42464684ddb6SLionel Sambuc void reset() {_V_hot_ = false;} 42474684ddb6SLionel Sambuc 42484684ddb6SLionel Sambuc // generating functions 42494684ddb6SLionel Sambuc template<class _URNG> 42504684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 42514684ddb6SLionel Sambuc result_type operator()(_URNG& __g) 42524684ddb6SLionel Sambuc {return (*this)(__g, __p_);} 42534684ddb6SLionel Sambuc template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 42544684ddb6SLionel Sambuc 42554684ddb6SLionel Sambuc // property functions 42564684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 42574684ddb6SLionel Sambuc result_type mean() const {return __p_.mean();} 42584684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 42594684ddb6SLionel Sambuc result_type stddev() const {return __p_.stddev();} 42604684ddb6SLionel Sambuc 42614684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 42624684ddb6SLionel Sambuc param_type param() const {return __p_;} 42634684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 42644684ddb6SLionel Sambuc void param(const param_type& __p) {__p_ = __p;} 42654684ddb6SLionel Sambuc 42664684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 42674684ddb6SLionel Sambuc result_type min() const {return -numeric_limits<result_type>::infinity();} 42684684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 42694684ddb6SLionel Sambuc result_type max() const {return numeric_limits<result_type>::infinity();} 42704684ddb6SLionel Sambuc 42714684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 42724684ddb6SLionel Sambuc bool operator==(const normal_distribution& __x, 42734684ddb6SLionel Sambuc const normal_distribution& __y) 42744684ddb6SLionel Sambuc {return __x.__p_ == __y.__p_ && __x._V_hot_ == __y._V_hot_ && 42754684ddb6SLionel Sambuc (!__x._V_hot_ || __x._V_ == __y._V_);} 42764684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 42774684ddb6SLionel Sambuc bool operator!=(const normal_distribution& __x, 42784684ddb6SLionel Sambuc const normal_distribution& __y) 42794684ddb6SLionel Sambuc {return !(__x == __y);} 42804684ddb6SLionel Sambuc 42814684ddb6SLionel Sambuc template <class _CharT, class _Traits, class _RT> 42824684ddb6SLionel Sambuc friend 42834684ddb6SLionel Sambuc basic_ostream<_CharT, _Traits>& 42844684ddb6SLionel Sambuc operator<<(basic_ostream<_CharT, _Traits>& __os, 42854684ddb6SLionel Sambuc const normal_distribution<_RT>& __x); 42864684ddb6SLionel Sambuc 42874684ddb6SLionel Sambuc template <class _CharT, class _Traits, class _RT> 42884684ddb6SLionel Sambuc friend 42894684ddb6SLionel Sambuc basic_istream<_CharT, _Traits>& 42904684ddb6SLionel Sambuc operator>>(basic_istream<_CharT, _Traits>& __is, 42914684ddb6SLionel Sambuc normal_distribution<_RT>& __x); 42924684ddb6SLionel Sambuc}; 42934684ddb6SLionel Sambuc 42944684ddb6SLionel Sambuctemplate <class _RealType> 42954684ddb6SLionel Sambuctemplate<class _URNG> 42964684ddb6SLionel Sambuc_RealType 42974684ddb6SLionel Sambucnormal_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 42984684ddb6SLionel Sambuc{ 42994684ddb6SLionel Sambuc result_type _Up; 43004684ddb6SLionel Sambuc if (_V_hot_) 43014684ddb6SLionel Sambuc { 43024684ddb6SLionel Sambuc _V_hot_ = false; 43034684ddb6SLionel Sambuc _Up = _V_; 43044684ddb6SLionel Sambuc } 43054684ddb6SLionel Sambuc else 43064684ddb6SLionel Sambuc { 43074684ddb6SLionel Sambuc uniform_real_distribution<result_type> _Uni(-1, 1); 43084684ddb6SLionel Sambuc result_type __u; 43094684ddb6SLionel Sambuc result_type __v; 43104684ddb6SLionel Sambuc result_type __s; 43114684ddb6SLionel Sambuc do 43124684ddb6SLionel Sambuc { 43134684ddb6SLionel Sambuc __u = _Uni(__g); 43144684ddb6SLionel Sambuc __v = _Uni(__g); 43154684ddb6SLionel Sambuc __s = __u * __u + __v * __v; 43164684ddb6SLionel Sambuc } while (__s > 1 || __s == 0); 43174684ddb6SLionel Sambuc result_type _Fp = _VSTD::sqrt(-2 * _VSTD::log(__s) / __s); 43184684ddb6SLionel Sambuc _V_ = __v * _Fp; 43194684ddb6SLionel Sambuc _V_hot_ = true; 43204684ddb6SLionel Sambuc _Up = __u * _Fp; 43214684ddb6SLionel Sambuc } 43224684ddb6SLionel Sambuc return _Up * __p.stddev() + __p.mean(); 43234684ddb6SLionel Sambuc} 43244684ddb6SLionel Sambuc 43254684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _RT> 43264684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 43274684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 43284684ddb6SLionel Sambuc const normal_distribution<_RT>& __x) 43294684ddb6SLionel Sambuc{ 43304684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__os); 43314684ddb6SLionel Sambuc __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 43324684ddb6SLionel Sambuc ios_base::scientific); 43334684ddb6SLionel Sambuc _CharT __sp = __os.widen(' '); 43344684ddb6SLionel Sambuc __os.fill(__sp); 43354684ddb6SLionel Sambuc __os << __x.mean() << __sp << __x.stddev() << __sp << __x._V_hot_; 43364684ddb6SLionel Sambuc if (__x._V_hot_) 43374684ddb6SLionel Sambuc __os << __sp << __x._V_; 43384684ddb6SLionel Sambuc return __os; 43394684ddb6SLionel Sambuc} 43404684ddb6SLionel Sambuc 43414684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _RT> 43424684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 43434684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 43444684ddb6SLionel Sambuc normal_distribution<_RT>& __x) 43454684ddb6SLionel Sambuc{ 43464684ddb6SLionel Sambuc typedef normal_distribution<_RT> _Eng; 43474684ddb6SLionel Sambuc typedef typename _Eng::result_type result_type; 43484684ddb6SLionel Sambuc typedef typename _Eng::param_type param_type; 43494684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__is); 43504684ddb6SLionel Sambuc __is.flags(ios_base::dec | ios_base::skipws); 43514684ddb6SLionel Sambuc result_type __mean; 43524684ddb6SLionel Sambuc result_type __stddev; 43534684ddb6SLionel Sambuc result_type _Vp = 0; 43544684ddb6SLionel Sambuc bool _V_hot = false; 43554684ddb6SLionel Sambuc __is >> __mean >> __stddev >> _V_hot; 43564684ddb6SLionel Sambuc if (_V_hot) 43574684ddb6SLionel Sambuc __is >> _Vp; 43584684ddb6SLionel Sambuc if (!__is.fail()) 43594684ddb6SLionel Sambuc { 43604684ddb6SLionel Sambuc __x.param(param_type(__mean, __stddev)); 43614684ddb6SLionel Sambuc __x._V_hot_ = _V_hot; 43624684ddb6SLionel Sambuc __x._V_ = _Vp; 43634684ddb6SLionel Sambuc } 43644684ddb6SLionel Sambuc return __is; 43654684ddb6SLionel Sambuc} 43664684ddb6SLionel Sambuc 43674684ddb6SLionel Sambuc// lognormal_distribution 43684684ddb6SLionel Sambuc 43694684ddb6SLionel Sambuctemplate<class _RealType = double> 43704684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY lognormal_distribution 43714684ddb6SLionel Sambuc{ 43724684ddb6SLionel Sambucpublic: 43734684ddb6SLionel Sambuc // types 43744684ddb6SLionel Sambuc typedef _RealType result_type; 43754684ddb6SLionel Sambuc 43764684ddb6SLionel Sambuc class _LIBCPP_TYPE_VIS_ONLY param_type 43774684ddb6SLionel Sambuc { 43784684ddb6SLionel Sambuc normal_distribution<result_type> __nd_; 43794684ddb6SLionel Sambuc public: 43804684ddb6SLionel Sambuc typedef lognormal_distribution distribution_type; 43814684ddb6SLionel Sambuc 43824684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 43834684ddb6SLionel Sambuc explicit param_type(result_type __m = 0, result_type __s = 1) 43844684ddb6SLionel Sambuc : __nd_(__m, __s) {} 43854684ddb6SLionel Sambuc 43864684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 43874684ddb6SLionel Sambuc result_type m() const {return __nd_.mean();} 43884684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 43894684ddb6SLionel Sambuc result_type s() const {return __nd_.stddev();} 43904684ddb6SLionel Sambuc 43914684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 43924684ddb6SLionel Sambuc bool operator==(const param_type& __x, const param_type& __y) 43934684ddb6SLionel Sambuc {return __x.__nd_ == __y.__nd_;} 43944684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 43954684ddb6SLionel Sambuc bool operator!=(const param_type& __x, const param_type& __y) 43964684ddb6SLionel Sambuc {return !(__x == __y);} 43974684ddb6SLionel Sambuc friend class lognormal_distribution; 43984684ddb6SLionel Sambuc 43994684ddb6SLionel Sambuc template <class _CharT, class _Traits, class _RT> 44004684ddb6SLionel Sambuc friend 44014684ddb6SLionel Sambuc basic_ostream<_CharT, _Traits>& 44024684ddb6SLionel Sambuc operator<<(basic_ostream<_CharT, _Traits>& __os, 44034684ddb6SLionel Sambuc const lognormal_distribution<_RT>& __x); 44044684ddb6SLionel Sambuc 44054684ddb6SLionel Sambuc template <class _CharT, class _Traits, class _RT> 44064684ddb6SLionel Sambuc friend 44074684ddb6SLionel Sambuc basic_istream<_CharT, _Traits>& 44084684ddb6SLionel Sambuc operator>>(basic_istream<_CharT, _Traits>& __is, 44094684ddb6SLionel Sambuc lognormal_distribution<_RT>& __x); 44104684ddb6SLionel Sambuc }; 44114684ddb6SLionel Sambuc 44124684ddb6SLionel Sambucprivate: 44134684ddb6SLionel Sambuc param_type __p_; 44144684ddb6SLionel Sambuc 44154684ddb6SLionel Sambucpublic: 44164684ddb6SLionel Sambuc // constructor and reset functions 44174684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 44184684ddb6SLionel Sambuc explicit lognormal_distribution(result_type __m = 0, result_type __s = 1) 44194684ddb6SLionel Sambuc : __p_(param_type(__m, __s)) {} 44204684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 44214684ddb6SLionel Sambuc explicit lognormal_distribution(const param_type& __p) 44224684ddb6SLionel Sambuc : __p_(__p) {} 44234684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 44244684ddb6SLionel Sambuc void reset() {__p_.__nd_.reset();} 44254684ddb6SLionel Sambuc 44264684ddb6SLionel Sambuc // generating functions 44274684ddb6SLionel Sambuc template<class _URNG> 44284684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 44294684ddb6SLionel Sambuc result_type operator()(_URNG& __g) 44304684ddb6SLionel Sambuc {return (*this)(__g, __p_);} 44314684ddb6SLionel Sambuc template<class _URNG> 44324684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 44334684ddb6SLionel Sambuc result_type operator()(_URNG& __g, const param_type& __p) 44344684ddb6SLionel Sambuc {return _VSTD::exp(const_cast<normal_distribution<result_type>&>(__p.__nd_)(__g));} 44354684ddb6SLionel Sambuc 44364684ddb6SLionel Sambuc // property functions 44374684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 44384684ddb6SLionel Sambuc result_type m() const {return __p_.m();} 44394684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 44404684ddb6SLionel Sambuc result_type s() const {return __p_.s();} 44414684ddb6SLionel Sambuc 44424684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 44434684ddb6SLionel Sambuc param_type param() const {return __p_;} 44444684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 44454684ddb6SLionel Sambuc void param(const param_type& __p) {__p_ = __p;} 44464684ddb6SLionel Sambuc 44474684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 44484684ddb6SLionel Sambuc result_type min() const {return 0;} 44494684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 44504684ddb6SLionel Sambuc result_type max() const {return numeric_limits<result_type>::infinity();} 44514684ddb6SLionel Sambuc 44524684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 44534684ddb6SLionel Sambuc bool operator==(const lognormal_distribution& __x, 44544684ddb6SLionel Sambuc const lognormal_distribution& __y) 44554684ddb6SLionel Sambuc {return __x.__p_ == __y.__p_;} 44564684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 44574684ddb6SLionel Sambuc bool operator!=(const lognormal_distribution& __x, 44584684ddb6SLionel Sambuc const lognormal_distribution& __y) 44594684ddb6SLionel Sambuc {return !(__x == __y);} 44604684ddb6SLionel Sambuc 44614684ddb6SLionel Sambuc template <class _CharT, class _Traits, class _RT> 44624684ddb6SLionel Sambuc friend 44634684ddb6SLionel Sambuc basic_ostream<_CharT, _Traits>& 44644684ddb6SLionel Sambuc operator<<(basic_ostream<_CharT, _Traits>& __os, 44654684ddb6SLionel Sambuc const lognormal_distribution<_RT>& __x); 44664684ddb6SLionel Sambuc 44674684ddb6SLionel Sambuc template <class _CharT, class _Traits, class _RT> 44684684ddb6SLionel Sambuc friend 44694684ddb6SLionel Sambuc basic_istream<_CharT, _Traits>& 44704684ddb6SLionel Sambuc operator>>(basic_istream<_CharT, _Traits>& __is, 44714684ddb6SLionel Sambuc lognormal_distribution<_RT>& __x); 44724684ddb6SLionel Sambuc}; 44734684ddb6SLionel Sambuc 44744684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _RT> 44754684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 44764684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 44774684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 44784684ddb6SLionel Sambuc const lognormal_distribution<_RT>& __x) 44794684ddb6SLionel Sambuc{ 44804684ddb6SLionel Sambuc return __os << __x.__p_.__nd_; 44814684ddb6SLionel Sambuc} 44824684ddb6SLionel Sambuc 44834684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _RT> 44844684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 44854684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 44864684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 44874684ddb6SLionel Sambuc lognormal_distribution<_RT>& __x) 44884684ddb6SLionel Sambuc{ 44894684ddb6SLionel Sambuc return __is >> __x.__p_.__nd_; 44904684ddb6SLionel Sambuc} 44914684ddb6SLionel Sambuc 44924684ddb6SLionel Sambuc// poisson_distribution 44934684ddb6SLionel Sambuc 44944684ddb6SLionel Sambuctemplate<class _IntType = int> 44954684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY poisson_distribution 44964684ddb6SLionel Sambuc{ 44974684ddb6SLionel Sambucpublic: 44984684ddb6SLionel Sambuc // types 44994684ddb6SLionel Sambuc typedef _IntType result_type; 45004684ddb6SLionel Sambuc 45014684ddb6SLionel Sambuc class _LIBCPP_TYPE_VIS_ONLY param_type 45024684ddb6SLionel Sambuc { 45034684ddb6SLionel Sambuc double __mean_; 45044684ddb6SLionel Sambuc double __s_; 45054684ddb6SLionel Sambuc double __d_; 45064684ddb6SLionel Sambuc double __l_; 45074684ddb6SLionel Sambuc double __omega_; 45084684ddb6SLionel Sambuc double __c0_; 45094684ddb6SLionel Sambuc double __c1_; 45104684ddb6SLionel Sambuc double __c2_; 45114684ddb6SLionel Sambuc double __c3_; 45124684ddb6SLionel Sambuc double __c_; 45134684ddb6SLionel Sambuc 45144684ddb6SLionel Sambuc public: 45154684ddb6SLionel Sambuc typedef poisson_distribution distribution_type; 45164684ddb6SLionel Sambuc 45174684ddb6SLionel Sambuc explicit param_type(double __mean = 1.0); 45184684ddb6SLionel Sambuc 45194684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 45204684ddb6SLionel Sambuc double mean() const {return __mean_;} 45214684ddb6SLionel Sambuc 45224684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 45234684ddb6SLionel Sambuc bool operator==(const param_type& __x, const param_type& __y) 45244684ddb6SLionel Sambuc {return __x.__mean_ == __y.__mean_;} 45254684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 45264684ddb6SLionel Sambuc bool operator!=(const param_type& __x, const param_type& __y) 45274684ddb6SLionel Sambuc {return !(__x == __y);} 45284684ddb6SLionel Sambuc 45294684ddb6SLionel Sambuc friend class poisson_distribution; 45304684ddb6SLionel Sambuc }; 45314684ddb6SLionel Sambuc 45324684ddb6SLionel Sambucprivate: 45334684ddb6SLionel Sambuc param_type __p_; 45344684ddb6SLionel Sambuc 45354684ddb6SLionel Sambucpublic: 45364684ddb6SLionel Sambuc // constructors and reset functions 45374684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 45384684ddb6SLionel Sambuc explicit poisson_distribution(double __mean = 1.0) : __p_(__mean) {} 45394684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 45404684ddb6SLionel Sambuc explicit poisson_distribution(const param_type& __p) : __p_(__p) {} 45414684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 45424684ddb6SLionel Sambuc void reset() {} 45434684ddb6SLionel Sambuc 45444684ddb6SLionel Sambuc // generating functions 45454684ddb6SLionel Sambuc template<class _URNG> 45464684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 45474684ddb6SLionel Sambuc result_type operator()(_URNG& __g) 45484684ddb6SLionel Sambuc {return (*this)(__g, __p_);} 45494684ddb6SLionel Sambuc template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 45504684ddb6SLionel Sambuc 45514684ddb6SLionel Sambuc // property functions 45524684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 45534684ddb6SLionel Sambuc double mean() const {return __p_.mean();} 45544684ddb6SLionel Sambuc 45554684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 45564684ddb6SLionel Sambuc param_type param() const {return __p_;} 45574684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 45584684ddb6SLionel Sambuc void param(const param_type& __p) {__p_ = __p;} 45594684ddb6SLionel Sambuc 45604684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 45614684ddb6SLionel Sambuc result_type min() const {return 0;} 45624684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 45634684ddb6SLionel Sambuc result_type max() const {return numeric_limits<result_type>::max();} 45644684ddb6SLionel Sambuc 45654684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 45664684ddb6SLionel Sambuc bool operator==(const poisson_distribution& __x, 45674684ddb6SLionel Sambuc const poisson_distribution& __y) 45684684ddb6SLionel Sambuc {return __x.__p_ == __y.__p_;} 45694684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 45704684ddb6SLionel Sambuc bool operator!=(const poisson_distribution& __x, 45714684ddb6SLionel Sambuc const poisson_distribution& __y) 45724684ddb6SLionel Sambuc {return !(__x == __y);} 45734684ddb6SLionel Sambuc}; 45744684ddb6SLionel Sambuc 45754684ddb6SLionel Sambuctemplate<class _IntType> 45764684ddb6SLionel Sambucpoisson_distribution<_IntType>::param_type::param_type(double __mean) 45774684ddb6SLionel Sambuc : __mean_(__mean) 45784684ddb6SLionel Sambuc{ 45794684ddb6SLionel Sambuc if (__mean_ < 10) 45804684ddb6SLionel Sambuc { 45814684ddb6SLionel Sambuc __s_ = 0; 45824684ddb6SLionel Sambuc __d_ = 0; 45834684ddb6SLionel Sambuc __l_ = _VSTD::exp(-__mean_); 45844684ddb6SLionel Sambuc __omega_ = 0; 45854684ddb6SLionel Sambuc __c3_ = 0; 45864684ddb6SLionel Sambuc __c2_ = 0; 45874684ddb6SLionel Sambuc __c1_ = 0; 45884684ddb6SLionel Sambuc __c0_ = 0; 45894684ddb6SLionel Sambuc __c_ = 0; 45904684ddb6SLionel Sambuc } 45914684ddb6SLionel Sambuc else 45924684ddb6SLionel Sambuc { 45934684ddb6SLionel Sambuc __s_ = _VSTD::sqrt(__mean_); 45944684ddb6SLionel Sambuc __d_ = 6 * __mean_ * __mean_; 45954684ddb6SLionel Sambuc __l_ = static_cast<result_type>(__mean_ - 1.1484); 45964684ddb6SLionel Sambuc __omega_ = .3989423 / __s_; 45974684ddb6SLionel Sambuc double __b1_ = .4166667E-1 / __mean_; 45984684ddb6SLionel Sambuc double __b2_ = .3 * __b1_ * __b1_; 45994684ddb6SLionel Sambuc __c3_ = .1428571 * __b1_ * __b2_; 46004684ddb6SLionel Sambuc __c2_ = __b2_ - 15. * __c3_; 46014684ddb6SLionel Sambuc __c1_ = __b1_ - 6. * __b2_ + 45. * __c3_; 46024684ddb6SLionel Sambuc __c0_ = 1. - __b1_ + 3. * __b2_ - 15. * __c3_; 46034684ddb6SLionel Sambuc __c_ = .1069 / __mean_; 46044684ddb6SLionel Sambuc } 46054684ddb6SLionel Sambuc} 46064684ddb6SLionel Sambuc 46074684ddb6SLionel Sambuctemplate <class _IntType> 46084684ddb6SLionel Sambuctemplate<class _URNG> 46094684ddb6SLionel Sambuc_IntType 46104684ddb6SLionel Sambucpoisson_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr) 46114684ddb6SLionel Sambuc{ 46124684ddb6SLionel Sambuc result_type __x; 46134684ddb6SLionel Sambuc uniform_real_distribution<double> __urd; 46144684ddb6SLionel Sambuc if (__pr.__mean_ < 10) 46154684ddb6SLionel Sambuc { 46164684ddb6SLionel Sambuc __x = 0; 46174684ddb6SLionel Sambuc for (double __p = __urd(__urng); __p > __pr.__l_; ++__x) 46184684ddb6SLionel Sambuc __p *= __urd(__urng); 46194684ddb6SLionel Sambuc } 46204684ddb6SLionel Sambuc else 46214684ddb6SLionel Sambuc { 46224684ddb6SLionel Sambuc double __difmuk; 46234684ddb6SLionel Sambuc double __g = __pr.__mean_ + __pr.__s_ * normal_distribution<double>()(__urng); 46244684ddb6SLionel Sambuc double __u; 46254684ddb6SLionel Sambuc if (__g > 0) 46264684ddb6SLionel Sambuc { 46274684ddb6SLionel Sambuc __x = static_cast<result_type>(__g); 46284684ddb6SLionel Sambuc if (__x >= __pr.__l_) 46294684ddb6SLionel Sambuc return __x; 46304684ddb6SLionel Sambuc __difmuk = __pr.__mean_ - __x; 46314684ddb6SLionel Sambuc __u = __urd(__urng); 46324684ddb6SLionel Sambuc if (__pr.__d_ * __u >= __difmuk * __difmuk * __difmuk) 46334684ddb6SLionel Sambuc return __x; 46344684ddb6SLionel Sambuc } 46354684ddb6SLionel Sambuc exponential_distribution<double> __edist; 46364684ddb6SLionel Sambuc for (bool __using_exp_dist = false; true; __using_exp_dist = true) 46374684ddb6SLionel Sambuc { 46384684ddb6SLionel Sambuc double __e; 46394684ddb6SLionel Sambuc if (__using_exp_dist || __g < 0) 46404684ddb6SLionel Sambuc { 46414684ddb6SLionel Sambuc double __t; 46424684ddb6SLionel Sambuc do 46434684ddb6SLionel Sambuc { 46444684ddb6SLionel Sambuc __e = __edist(__urng); 46454684ddb6SLionel Sambuc __u = __urd(__urng); 46464684ddb6SLionel Sambuc __u += __u - 1; 46474684ddb6SLionel Sambuc __t = 1.8 + (__u < 0 ? -__e : __e); 46484684ddb6SLionel Sambuc } while (__t <= -.6744); 46494684ddb6SLionel Sambuc __x = __pr.__mean_ + __pr.__s_ * __t; 46504684ddb6SLionel Sambuc __difmuk = __pr.__mean_ - __x; 46514684ddb6SLionel Sambuc __using_exp_dist = true; 46524684ddb6SLionel Sambuc } 46534684ddb6SLionel Sambuc double __px; 46544684ddb6SLionel Sambuc double __py; 46554684ddb6SLionel Sambuc if (__x < 10) 46564684ddb6SLionel Sambuc { 46574684ddb6SLionel Sambuc const result_type __fac[] = {1, 1, 2, 6, 24, 120, 720, 5040, 46584684ddb6SLionel Sambuc 40320, 362880}; 46594684ddb6SLionel Sambuc __px = -__pr.__mean_; 46604684ddb6SLionel Sambuc __py = _VSTD::pow(__pr.__mean_, (double)__x) / __fac[__x]; 46614684ddb6SLionel Sambuc } 46624684ddb6SLionel Sambuc else 46634684ddb6SLionel Sambuc { 46644684ddb6SLionel Sambuc double __del = .8333333E-1 / __x; 46654684ddb6SLionel Sambuc __del -= 4.8 * __del * __del * __del; 46664684ddb6SLionel Sambuc double __v = __difmuk / __x; 46674684ddb6SLionel Sambuc if (_VSTD::abs(__v) > 0.25) 46684684ddb6SLionel Sambuc __px = __x * _VSTD::log(1 + __v) - __difmuk - __del; 46694684ddb6SLionel Sambuc else 46704684ddb6SLionel Sambuc __px = __x * __v * __v * (((((((.1250060 * __v + -.1384794) * 46714684ddb6SLionel Sambuc __v + .1421878) * __v + -.1661269) * __v + .2000118) * 46724684ddb6SLionel Sambuc __v + -.2500068) * __v + .3333333) * __v + -.5) - __del; 46734684ddb6SLionel Sambuc __py = .3989423 / _VSTD::sqrt(__x); 46744684ddb6SLionel Sambuc } 46754684ddb6SLionel Sambuc double __r = (0.5 - __difmuk) / __pr.__s_; 46764684ddb6SLionel Sambuc double __r2 = __r * __r; 46774684ddb6SLionel Sambuc double __fx = -0.5 * __r2; 46784684ddb6SLionel Sambuc double __fy = __pr.__omega_ * (((__pr.__c3_ * __r2 + __pr.__c2_) * 46794684ddb6SLionel Sambuc __r2 + __pr.__c1_) * __r2 + __pr.__c0_); 46804684ddb6SLionel Sambuc if (__using_exp_dist) 46814684ddb6SLionel Sambuc { 46824684ddb6SLionel Sambuc if (__pr.__c_ * _VSTD::abs(__u) <= __py * _VSTD::exp(__px + __e) - 46834684ddb6SLionel Sambuc __fy * _VSTD::exp(__fx + __e)) 46844684ddb6SLionel Sambuc break; 46854684ddb6SLionel Sambuc } 46864684ddb6SLionel Sambuc else 46874684ddb6SLionel Sambuc { 46884684ddb6SLionel Sambuc if (__fy - __u * __fy <= __py * _VSTD::exp(__px - __fx)) 46894684ddb6SLionel Sambuc break; 46904684ddb6SLionel Sambuc } 46914684ddb6SLionel Sambuc } 46924684ddb6SLionel Sambuc } 46934684ddb6SLionel Sambuc return __x; 46944684ddb6SLionel Sambuc} 46954684ddb6SLionel Sambuc 46964684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _IntType> 46974684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 46984684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 46994684ddb6SLionel Sambuc const poisson_distribution<_IntType>& __x) 47004684ddb6SLionel Sambuc{ 47014684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__os); 47024684ddb6SLionel Sambuc __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 47034684ddb6SLionel Sambuc ios_base::scientific); 47044684ddb6SLionel Sambuc return __os << __x.mean(); 47054684ddb6SLionel Sambuc} 47064684ddb6SLionel Sambuc 47074684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _IntType> 47084684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 47094684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 47104684ddb6SLionel Sambuc poisson_distribution<_IntType>& __x) 47114684ddb6SLionel Sambuc{ 47124684ddb6SLionel Sambuc typedef poisson_distribution<_IntType> _Eng; 47134684ddb6SLionel Sambuc typedef typename _Eng::param_type param_type; 47144684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__is); 47154684ddb6SLionel Sambuc __is.flags(ios_base::dec | ios_base::skipws); 47164684ddb6SLionel Sambuc double __mean; 47174684ddb6SLionel Sambuc __is >> __mean; 47184684ddb6SLionel Sambuc if (!__is.fail()) 47194684ddb6SLionel Sambuc __x.param(param_type(__mean)); 47204684ddb6SLionel Sambuc return __is; 47214684ddb6SLionel Sambuc} 47224684ddb6SLionel Sambuc 47234684ddb6SLionel Sambuc// weibull_distribution 47244684ddb6SLionel Sambuc 47254684ddb6SLionel Sambuctemplate<class _RealType = double> 47264684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY weibull_distribution 47274684ddb6SLionel Sambuc{ 47284684ddb6SLionel Sambucpublic: 47294684ddb6SLionel Sambuc // types 47304684ddb6SLionel Sambuc typedef _RealType result_type; 47314684ddb6SLionel Sambuc 47324684ddb6SLionel Sambuc class _LIBCPP_TYPE_VIS_ONLY param_type 47334684ddb6SLionel Sambuc { 47344684ddb6SLionel Sambuc result_type __a_; 47354684ddb6SLionel Sambuc result_type __b_; 47364684ddb6SLionel Sambuc public: 47374684ddb6SLionel Sambuc typedef weibull_distribution distribution_type; 47384684ddb6SLionel Sambuc 47394684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 47404684ddb6SLionel Sambuc explicit param_type(result_type __a = 1, result_type __b = 1) 47414684ddb6SLionel Sambuc : __a_(__a), __b_(__b) {} 47424684ddb6SLionel Sambuc 47434684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 47444684ddb6SLionel Sambuc result_type a() const {return __a_;} 47454684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 47464684ddb6SLionel Sambuc result_type b() const {return __b_;} 47474684ddb6SLionel Sambuc 47484684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 47494684ddb6SLionel Sambuc bool operator==(const param_type& __x, const param_type& __y) 47504684ddb6SLionel Sambuc {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} 47514684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 47524684ddb6SLionel Sambuc bool operator!=(const param_type& __x, const param_type& __y) 47534684ddb6SLionel Sambuc {return !(__x == __y);} 47544684ddb6SLionel Sambuc }; 47554684ddb6SLionel Sambuc 47564684ddb6SLionel Sambucprivate: 47574684ddb6SLionel Sambuc param_type __p_; 47584684ddb6SLionel Sambuc 47594684ddb6SLionel Sambucpublic: 47604684ddb6SLionel Sambuc // constructor and reset functions 47614684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 47624684ddb6SLionel Sambuc explicit weibull_distribution(result_type __a = 1, result_type __b = 1) 47634684ddb6SLionel Sambuc : __p_(param_type(__a, __b)) {} 47644684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 47654684ddb6SLionel Sambuc explicit weibull_distribution(const param_type& __p) 47664684ddb6SLionel Sambuc : __p_(__p) {} 47674684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 47684684ddb6SLionel Sambuc void reset() {} 47694684ddb6SLionel Sambuc 47704684ddb6SLionel Sambuc // generating functions 47714684ddb6SLionel Sambuc template<class _URNG> 47724684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 47734684ddb6SLionel Sambuc result_type operator()(_URNG& __g) 47744684ddb6SLionel Sambuc {return (*this)(__g, __p_);} 47754684ddb6SLionel Sambuc template<class _URNG> 47764684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 47774684ddb6SLionel Sambuc result_type operator()(_URNG& __g, const param_type& __p) 47784684ddb6SLionel Sambuc {return __p.b() * 47794684ddb6SLionel Sambuc _VSTD::pow(exponential_distribution<result_type>()(__g), 1/__p.a());} 47804684ddb6SLionel Sambuc 47814684ddb6SLionel Sambuc // property functions 47824684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 47834684ddb6SLionel Sambuc result_type a() const {return __p_.a();} 47844684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 47854684ddb6SLionel Sambuc result_type b() const {return __p_.b();} 47864684ddb6SLionel Sambuc 47874684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 47884684ddb6SLionel Sambuc param_type param() const {return __p_;} 47894684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 47904684ddb6SLionel Sambuc void param(const param_type& __p) {__p_ = __p;} 47914684ddb6SLionel Sambuc 47924684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 47934684ddb6SLionel Sambuc result_type min() const {return 0;} 47944684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 47954684ddb6SLionel Sambuc result_type max() const {return numeric_limits<result_type>::infinity();} 47964684ddb6SLionel Sambuc 47974684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 47984684ddb6SLionel Sambuc bool operator==(const weibull_distribution& __x, 47994684ddb6SLionel Sambuc const weibull_distribution& __y) 48004684ddb6SLionel Sambuc {return __x.__p_ == __y.__p_;} 48014684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 48024684ddb6SLionel Sambuc bool operator!=(const weibull_distribution& __x, 48034684ddb6SLionel Sambuc const weibull_distribution& __y) 48044684ddb6SLionel Sambuc {return !(__x == __y);} 48054684ddb6SLionel Sambuc}; 48064684ddb6SLionel Sambuc 48074684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _RT> 48084684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 48094684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 48104684ddb6SLionel Sambuc const weibull_distribution<_RT>& __x) 48114684ddb6SLionel Sambuc{ 48124684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__os); 48134684ddb6SLionel Sambuc __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 48144684ddb6SLionel Sambuc ios_base::scientific); 48154684ddb6SLionel Sambuc _CharT __sp = __os.widen(' '); 48164684ddb6SLionel Sambuc __os.fill(__sp); 48174684ddb6SLionel Sambuc __os << __x.a() << __sp << __x.b(); 48184684ddb6SLionel Sambuc return __os; 48194684ddb6SLionel Sambuc} 48204684ddb6SLionel Sambuc 48214684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _RT> 48224684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 48234684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 48244684ddb6SLionel Sambuc weibull_distribution<_RT>& __x) 48254684ddb6SLionel Sambuc{ 48264684ddb6SLionel Sambuc typedef weibull_distribution<_RT> _Eng; 48274684ddb6SLionel Sambuc typedef typename _Eng::result_type result_type; 48284684ddb6SLionel Sambuc typedef typename _Eng::param_type param_type; 48294684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__is); 48304684ddb6SLionel Sambuc __is.flags(ios_base::dec | ios_base::skipws); 48314684ddb6SLionel Sambuc result_type __a; 48324684ddb6SLionel Sambuc result_type __b; 48334684ddb6SLionel Sambuc __is >> __a >> __b; 48344684ddb6SLionel Sambuc if (!__is.fail()) 48354684ddb6SLionel Sambuc __x.param(param_type(__a, __b)); 48364684ddb6SLionel Sambuc return __is; 48374684ddb6SLionel Sambuc} 48384684ddb6SLionel Sambuc 48394684ddb6SLionel Sambuctemplate<class _RealType = double> 48404684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY extreme_value_distribution 48414684ddb6SLionel Sambuc{ 48424684ddb6SLionel Sambucpublic: 48434684ddb6SLionel Sambuc // types 48444684ddb6SLionel Sambuc typedef _RealType result_type; 48454684ddb6SLionel Sambuc 48464684ddb6SLionel Sambuc class _LIBCPP_TYPE_VIS_ONLY param_type 48474684ddb6SLionel Sambuc { 48484684ddb6SLionel Sambuc result_type __a_; 48494684ddb6SLionel Sambuc result_type __b_; 48504684ddb6SLionel Sambuc public: 48514684ddb6SLionel Sambuc typedef extreme_value_distribution distribution_type; 48524684ddb6SLionel Sambuc 48534684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 48544684ddb6SLionel Sambuc explicit param_type(result_type __a = 0, result_type __b = 1) 48554684ddb6SLionel Sambuc : __a_(__a), __b_(__b) {} 48564684ddb6SLionel Sambuc 48574684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 48584684ddb6SLionel Sambuc result_type a() const {return __a_;} 48594684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 48604684ddb6SLionel Sambuc result_type b() const {return __b_;} 48614684ddb6SLionel Sambuc 48624684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 48634684ddb6SLionel Sambuc bool operator==(const param_type& __x, const param_type& __y) 48644684ddb6SLionel Sambuc {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} 48654684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 48664684ddb6SLionel Sambuc bool operator!=(const param_type& __x, const param_type& __y) 48674684ddb6SLionel Sambuc {return !(__x == __y);} 48684684ddb6SLionel Sambuc }; 48694684ddb6SLionel Sambuc 48704684ddb6SLionel Sambucprivate: 48714684ddb6SLionel Sambuc param_type __p_; 48724684ddb6SLionel Sambuc 48734684ddb6SLionel Sambucpublic: 48744684ddb6SLionel Sambuc // constructor and reset functions 48754684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 48764684ddb6SLionel Sambuc explicit extreme_value_distribution(result_type __a = 0, result_type __b = 1) 48774684ddb6SLionel Sambuc : __p_(param_type(__a, __b)) {} 48784684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 48794684ddb6SLionel Sambuc explicit extreme_value_distribution(const param_type& __p) 48804684ddb6SLionel Sambuc : __p_(__p) {} 48814684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 48824684ddb6SLionel Sambuc void reset() {} 48834684ddb6SLionel Sambuc 48844684ddb6SLionel Sambuc // generating functions 48854684ddb6SLionel Sambuc template<class _URNG> 48864684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 48874684ddb6SLionel Sambuc result_type operator()(_URNG& __g) 48884684ddb6SLionel Sambuc {return (*this)(__g, __p_);} 48894684ddb6SLionel Sambuc template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 48904684ddb6SLionel Sambuc 48914684ddb6SLionel Sambuc // property functions 48924684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 48934684ddb6SLionel Sambuc result_type a() const {return __p_.a();} 48944684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 48954684ddb6SLionel Sambuc result_type b() const {return __p_.b();} 48964684ddb6SLionel Sambuc 48974684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 48984684ddb6SLionel Sambuc param_type param() const {return __p_;} 48994684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 49004684ddb6SLionel Sambuc void param(const param_type& __p) {__p_ = __p;} 49014684ddb6SLionel Sambuc 49024684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 49034684ddb6SLionel Sambuc result_type min() const {return -numeric_limits<result_type>::infinity();} 49044684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 49054684ddb6SLionel Sambuc result_type max() const {return numeric_limits<result_type>::infinity();} 49064684ddb6SLionel Sambuc 49074684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 49084684ddb6SLionel Sambuc bool operator==(const extreme_value_distribution& __x, 49094684ddb6SLionel Sambuc const extreme_value_distribution& __y) 49104684ddb6SLionel Sambuc {return __x.__p_ == __y.__p_;} 49114684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 49124684ddb6SLionel Sambuc bool operator!=(const extreme_value_distribution& __x, 49134684ddb6SLionel Sambuc const extreme_value_distribution& __y) 49144684ddb6SLionel Sambuc {return !(__x == __y);} 49154684ddb6SLionel Sambuc}; 49164684ddb6SLionel Sambuc 49174684ddb6SLionel Sambuctemplate<class _RealType> 49184684ddb6SLionel Sambuctemplate<class _URNG> 49194684ddb6SLionel Sambuc_RealType 49204684ddb6SLionel Sambucextreme_value_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 49214684ddb6SLionel Sambuc{ 49224684ddb6SLionel Sambuc return __p.a() - __p.b() * 49234684ddb6SLionel Sambuc _VSTD::log(-_VSTD::log(1-uniform_real_distribution<result_type>()(__g))); 49244684ddb6SLionel Sambuc} 49254684ddb6SLionel Sambuc 49264684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _RT> 49274684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 49284684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 49294684ddb6SLionel Sambuc const extreme_value_distribution<_RT>& __x) 49304684ddb6SLionel Sambuc{ 49314684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__os); 49324684ddb6SLionel Sambuc __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 49334684ddb6SLionel Sambuc ios_base::scientific); 49344684ddb6SLionel Sambuc _CharT __sp = __os.widen(' '); 49354684ddb6SLionel Sambuc __os.fill(__sp); 49364684ddb6SLionel Sambuc __os << __x.a() << __sp << __x.b(); 49374684ddb6SLionel Sambuc return __os; 49384684ddb6SLionel Sambuc} 49394684ddb6SLionel Sambuc 49404684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _RT> 49414684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 49424684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 49434684ddb6SLionel Sambuc extreme_value_distribution<_RT>& __x) 49444684ddb6SLionel Sambuc{ 49454684ddb6SLionel Sambuc typedef extreme_value_distribution<_RT> _Eng; 49464684ddb6SLionel Sambuc typedef typename _Eng::result_type result_type; 49474684ddb6SLionel Sambuc typedef typename _Eng::param_type param_type; 49484684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__is); 49494684ddb6SLionel Sambuc __is.flags(ios_base::dec | ios_base::skipws); 49504684ddb6SLionel Sambuc result_type __a; 49514684ddb6SLionel Sambuc result_type __b; 49524684ddb6SLionel Sambuc __is >> __a >> __b; 49534684ddb6SLionel Sambuc if (!__is.fail()) 49544684ddb6SLionel Sambuc __x.param(param_type(__a, __b)); 49554684ddb6SLionel Sambuc return __is; 49564684ddb6SLionel Sambuc} 49574684ddb6SLionel Sambuc 49584684ddb6SLionel Sambuc// gamma_distribution 49594684ddb6SLionel Sambuc 49604684ddb6SLionel Sambuctemplate<class _RealType = double> 49614684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY gamma_distribution 49624684ddb6SLionel Sambuc{ 49634684ddb6SLionel Sambucpublic: 49644684ddb6SLionel Sambuc // types 49654684ddb6SLionel Sambuc typedef _RealType result_type; 49664684ddb6SLionel Sambuc 49674684ddb6SLionel Sambuc class _LIBCPP_TYPE_VIS_ONLY param_type 49684684ddb6SLionel Sambuc { 49694684ddb6SLionel Sambuc result_type __alpha_; 49704684ddb6SLionel Sambuc result_type __beta_; 49714684ddb6SLionel Sambuc public: 49724684ddb6SLionel Sambuc typedef gamma_distribution distribution_type; 49734684ddb6SLionel Sambuc 49744684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 49754684ddb6SLionel Sambuc explicit param_type(result_type __alpha = 1, result_type __beta = 1) 49764684ddb6SLionel Sambuc : __alpha_(__alpha), __beta_(__beta) {} 49774684ddb6SLionel Sambuc 49784684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 49794684ddb6SLionel Sambuc result_type alpha() const {return __alpha_;} 49804684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 49814684ddb6SLionel Sambuc result_type beta() const {return __beta_;} 49824684ddb6SLionel Sambuc 49834684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 49844684ddb6SLionel Sambuc bool operator==(const param_type& __x, const param_type& __y) 49854684ddb6SLionel Sambuc {return __x.__alpha_ == __y.__alpha_ && __x.__beta_ == __y.__beta_;} 49864684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 49874684ddb6SLionel Sambuc bool operator!=(const param_type& __x, const param_type& __y) 49884684ddb6SLionel Sambuc {return !(__x == __y);} 49894684ddb6SLionel Sambuc }; 49904684ddb6SLionel Sambuc 49914684ddb6SLionel Sambucprivate: 49924684ddb6SLionel Sambuc param_type __p_; 49934684ddb6SLionel Sambuc 49944684ddb6SLionel Sambucpublic: 49954684ddb6SLionel Sambuc // constructors and reset functions 49964684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 49974684ddb6SLionel Sambuc explicit gamma_distribution(result_type __alpha = 1, result_type __beta = 1) 49984684ddb6SLionel Sambuc : __p_(param_type(__alpha, __beta)) {} 49994684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 50004684ddb6SLionel Sambuc explicit gamma_distribution(const param_type& __p) 50014684ddb6SLionel Sambuc : __p_(__p) {} 50024684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 50034684ddb6SLionel Sambuc void reset() {} 50044684ddb6SLionel Sambuc 50054684ddb6SLionel Sambuc // generating functions 50064684ddb6SLionel Sambuc template<class _URNG> 50074684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 50084684ddb6SLionel Sambuc result_type operator()(_URNG& __g) 50094684ddb6SLionel Sambuc {return (*this)(__g, __p_);} 50104684ddb6SLionel Sambuc template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 50114684ddb6SLionel Sambuc 50124684ddb6SLionel Sambuc // property functions 50134684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 50144684ddb6SLionel Sambuc result_type alpha() const {return __p_.alpha();} 50154684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 50164684ddb6SLionel Sambuc result_type beta() const {return __p_.beta();} 50174684ddb6SLionel Sambuc 50184684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 50194684ddb6SLionel Sambuc param_type param() const {return __p_;} 50204684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 50214684ddb6SLionel Sambuc void param(const param_type& __p) {__p_ = __p;} 50224684ddb6SLionel Sambuc 50234684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 50244684ddb6SLionel Sambuc result_type min() const {return 0;} 50254684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 50264684ddb6SLionel Sambuc result_type max() const {return numeric_limits<result_type>::infinity();} 50274684ddb6SLionel Sambuc 50284684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 50294684ddb6SLionel Sambuc bool operator==(const gamma_distribution& __x, 50304684ddb6SLionel Sambuc const gamma_distribution& __y) 50314684ddb6SLionel Sambuc {return __x.__p_ == __y.__p_;} 50324684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 50334684ddb6SLionel Sambuc bool operator!=(const gamma_distribution& __x, 50344684ddb6SLionel Sambuc const gamma_distribution& __y) 50354684ddb6SLionel Sambuc {return !(__x == __y);} 50364684ddb6SLionel Sambuc}; 50374684ddb6SLionel Sambuc 50384684ddb6SLionel Sambuctemplate <class _RealType> 50394684ddb6SLionel Sambuctemplate<class _URNG> 50404684ddb6SLionel Sambuc_RealType 50414684ddb6SLionel Sambucgamma_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 50424684ddb6SLionel Sambuc{ 50434684ddb6SLionel Sambuc result_type __a = __p.alpha(); 50444684ddb6SLionel Sambuc uniform_real_distribution<result_type> __gen(0, 1); 50454684ddb6SLionel Sambuc exponential_distribution<result_type> __egen; 50464684ddb6SLionel Sambuc result_type __x; 50474684ddb6SLionel Sambuc if (__a == 1) 50484684ddb6SLionel Sambuc __x = __egen(__g); 50494684ddb6SLionel Sambuc else if (__a > 1) 50504684ddb6SLionel Sambuc { 50514684ddb6SLionel Sambuc const result_type __b = __a - 1; 50524684ddb6SLionel Sambuc const result_type __c = 3 * __a - result_type(0.75); 50534684ddb6SLionel Sambuc while (true) 50544684ddb6SLionel Sambuc { 50554684ddb6SLionel Sambuc const result_type __u = __gen(__g); 50564684ddb6SLionel Sambuc const result_type __v = __gen(__g); 50574684ddb6SLionel Sambuc const result_type __w = __u * (1 - __u); 50584684ddb6SLionel Sambuc if (__w != 0) 50594684ddb6SLionel Sambuc { 50604684ddb6SLionel Sambuc const result_type __y = _VSTD::sqrt(__c / __w) * 50614684ddb6SLionel Sambuc (__u - result_type(0.5)); 50624684ddb6SLionel Sambuc __x = __b + __y; 50634684ddb6SLionel Sambuc if (__x >= 0) 50644684ddb6SLionel Sambuc { 50654684ddb6SLionel Sambuc const result_type __z = 64 * __w * __w * __w * __v * __v; 50664684ddb6SLionel Sambuc if (__z <= 1 - 2 * __y * __y / __x) 50674684ddb6SLionel Sambuc break; 50684684ddb6SLionel Sambuc if (_VSTD::log(__z) <= 2 * (__b * _VSTD::log(__x / __b) - __y)) 50694684ddb6SLionel Sambuc break; 50704684ddb6SLionel Sambuc } 50714684ddb6SLionel Sambuc } 50724684ddb6SLionel Sambuc } 50734684ddb6SLionel Sambuc } 50744684ddb6SLionel Sambuc else // __a < 1 50754684ddb6SLionel Sambuc { 50764684ddb6SLionel Sambuc while (true) 50774684ddb6SLionel Sambuc { 50784684ddb6SLionel Sambuc const result_type __u = __gen(__g); 50794684ddb6SLionel Sambuc const result_type __es = __egen(__g); 50804684ddb6SLionel Sambuc if (__u <= 1 - __a) 50814684ddb6SLionel Sambuc { 50824684ddb6SLionel Sambuc __x = _VSTD::pow(__u, 1 / __a); 50834684ddb6SLionel Sambuc if (__x <= __es) 50844684ddb6SLionel Sambuc break; 50854684ddb6SLionel Sambuc } 50864684ddb6SLionel Sambuc else 50874684ddb6SLionel Sambuc { 50884684ddb6SLionel Sambuc const result_type __e = -_VSTD::log((1-__u)/__a); 50894684ddb6SLionel Sambuc __x = _VSTD::pow(1 - __a + __a * __e, 1 / __a); 50904684ddb6SLionel Sambuc if (__x <= __e + __es) 50914684ddb6SLionel Sambuc break; 50924684ddb6SLionel Sambuc } 50934684ddb6SLionel Sambuc } 50944684ddb6SLionel Sambuc } 50954684ddb6SLionel Sambuc return __x * __p.beta(); 50964684ddb6SLionel Sambuc} 50974684ddb6SLionel Sambuc 50984684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _RT> 50994684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 51004684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 51014684ddb6SLionel Sambuc const gamma_distribution<_RT>& __x) 51024684ddb6SLionel Sambuc{ 51034684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__os); 51044684ddb6SLionel Sambuc __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 51054684ddb6SLionel Sambuc ios_base::scientific); 51064684ddb6SLionel Sambuc _CharT __sp = __os.widen(' '); 51074684ddb6SLionel Sambuc __os.fill(__sp); 51084684ddb6SLionel Sambuc __os << __x.alpha() << __sp << __x.beta(); 51094684ddb6SLionel Sambuc return __os; 51104684ddb6SLionel Sambuc} 51114684ddb6SLionel Sambuc 51124684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _RT> 51134684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 51144684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 51154684ddb6SLionel Sambuc gamma_distribution<_RT>& __x) 51164684ddb6SLionel Sambuc{ 51174684ddb6SLionel Sambuc typedef gamma_distribution<_RT> _Eng; 51184684ddb6SLionel Sambuc typedef typename _Eng::result_type result_type; 51194684ddb6SLionel Sambuc typedef typename _Eng::param_type param_type; 51204684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__is); 51214684ddb6SLionel Sambuc __is.flags(ios_base::dec | ios_base::skipws); 51224684ddb6SLionel Sambuc result_type __alpha; 51234684ddb6SLionel Sambuc result_type __beta; 51244684ddb6SLionel Sambuc __is >> __alpha >> __beta; 51254684ddb6SLionel Sambuc if (!__is.fail()) 51264684ddb6SLionel Sambuc __x.param(param_type(__alpha, __beta)); 51274684ddb6SLionel Sambuc return __is; 51284684ddb6SLionel Sambuc} 51294684ddb6SLionel Sambuc 51304684ddb6SLionel Sambuc// negative_binomial_distribution 51314684ddb6SLionel Sambuc 51324684ddb6SLionel Sambuctemplate<class _IntType = int> 51334684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY negative_binomial_distribution 51344684ddb6SLionel Sambuc{ 51354684ddb6SLionel Sambucpublic: 51364684ddb6SLionel Sambuc // types 51374684ddb6SLionel Sambuc typedef _IntType result_type; 51384684ddb6SLionel Sambuc 51394684ddb6SLionel Sambuc class _LIBCPP_TYPE_VIS_ONLY param_type 51404684ddb6SLionel Sambuc { 51414684ddb6SLionel Sambuc result_type __k_; 51424684ddb6SLionel Sambuc double __p_; 51434684ddb6SLionel Sambuc public: 51444684ddb6SLionel Sambuc typedef negative_binomial_distribution distribution_type; 51454684ddb6SLionel Sambuc 51464684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 51474684ddb6SLionel Sambuc explicit param_type(result_type __k = 1, double __p = 0.5) 51484684ddb6SLionel Sambuc : __k_(__k), __p_(__p) {} 51494684ddb6SLionel Sambuc 51504684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 51514684ddb6SLionel Sambuc result_type k() const {return __k_;} 51524684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 51534684ddb6SLionel Sambuc double p() const {return __p_;} 51544684ddb6SLionel Sambuc 51554684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 51564684ddb6SLionel Sambuc bool operator==(const param_type& __x, const param_type& __y) 51574684ddb6SLionel Sambuc {return __x.__k_ == __y.__k_ && __x.__p_ == __y.__p_;} 51584684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 51594684ddb6SLionel Sambuc bool operator!=(const param_type& __x, const param_type& __y) 51604684ddb6SLionel Sambuc {return !(__x == __y);} 51614684ddb6SLionel Sambuc }; 51624684ddb6SLionel Sambuc 51634684ddb6SLionel Sambucprivate: 51644684ddb6SLionel Sambuc param_type __p_; 51654684ddb6SLionel Sambuc 51664684ddb6SLionel Sambucpublic: 51674684ddb6SLionel Sambuc // constructor and reset functions 51684684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 51694684ddb6SLionel Sambuc explicit negative_binomial_distribution(result_type __k = 1, double __p = 0.5) 51704684ddb6SLionel Sambuc : __p_(__k, __p) {} 51714684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 51724684ddb6SLionel Sambuc explicit negative_binomial_distribution(const param_type& __p) : __p_(__p) {} 51734684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 51744684ddb6SLionel Sambuc void reset() {} 51754684ddb6SLionel Sambuc 51764684ddb6SLionel Sambuc // generating functions 51774684ddb6SLionel Sambuc template<class _URNG> 51784684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 51794684ddb6SLionel Sambuc result_type operator()(_URNG& __g) 51804684ddb6SLionel Sambuc {return (*this)(__g, __p_);} 51814684ddb6SLionel Sambuc template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 51824684ddb6SLionel Sambuc 51834684ddb6SLionel Sambuc // property functions 51844684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 51854684ddb6SLionel Sambuc result_type k() const {return __p_.k();} 51864684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 51874684ddb6SLionel Sambuc double p() const {return __p_.p();} 51884684ddb6SLionel Sambuc 51894684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 51904684ddb6SLionel Sambuc param_type param() const {return __p_;} 51914684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 51924684ddb6SLionel Sambuc void param(const param_type& __p) {__p_ = __p;} 51934684ddb6SLionel Sambuc 51944684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 51954684ddb6SLionel Sambuc result_type min() const {return 0;} 51964684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 51974684ddb6SLionel Sambuc result_type max() const {return numeric_limits<result_type>::max();} 51984684ddb6SLionel Sambuc 51994684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 52004684ddb6SLionel Sambuc bool operator==(const negative_binomial_distribution& __x, 52014684ddb6SLionel Sambuc const negative_binomial_distribution& __y) 52024684ddb6SLionel Sambuc {return __x.__p_ == __y.__p_;} 52034684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 52044684ddb6SLionel Sambuc bool operator!=(const negative_binomial_distribution& __x, 52054684ddb6SLionel Sambuc const negative_binomial_distribution& __y) 52064684ddb6SLionel Sambuc {return !(__x == __y);} 52074684ddb6SLionel Sambuc}; 52084684ddb6SLionel Sambuc 52094684ddb6SLionel Sambuctemplate <class _IntType> 52104684ddb6SLionel Sambuctemplate<class _URNG> 52114684ddb6SLionel Sambuc_IntType 52124684ddb6SLionel Sambucnegative_binomial_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr) 52134684ddb6SLionel Sambuc{ 52144684ddb6SLionel Sambuc result_type __k = __pr.k(); 52154684ddb6SLionel Sambuc double __p = __pr.p(); 52164684ddb6SLionel Sambuc if (__k <= 21 * __p) 52174684ddb6SLionel Sambuc { 52184684ddb6SLionel Sambuc bernoulli_distribution __gen(__p); 52194684ddb6SLionel Sambuc result_type __f = 0; 52204684ddb6SLionel Sambuc result_type __s = 0; 52214684ddb6SLionel Sambuc while (__s < __k) 52224684ddb6SLionel Sambuc { 52234684ddb6SLionel Sambuc if (__gen(__urng)) 52244684ddb6SLionel Sambuc ++__s; 52254684ddb6SLionel Sambuc else 52264684ddb6SLionel Sambuc ++__f; 52274684ddb6SLionel Sambuc } 52284684ddb6SLionel Sambuc return __f; 52294684ddb6SLionel Sambuc } 52304684ddb6SLionel Sambuc return poisson_distribution<result_type>(gamma_distribution<double> 52314684ddb6SLionel Sambuc (__k, (1-__p)/__p)(__urng))(__urng); 52324684ddb6SLionel Sambuc} 52334684ddb6SLionel Sambuc 52344684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _IntType> 52354684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 52364684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 52374684ddb6SLionel Sambuc const negative_binomial_distribution<_IntType>& __x) 52384684ddb6SLionel Sambuc{ 52394684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__os); 52404684ddb6SLionel Sambuc __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 52414684ddb6SLionel Sambuc ios_base::scientific); 52424684ddb6SLionel Sambuc _CharT __sp = __os.widen(' '); 52434684ddb6SLionel Sambuc __os.fill(__sp); 52444684ddb6SLionel Sambuc return __os << __x.k() << __sp << __x.p(); 52454684ddb6SLionel Sambuc} 52464684ddb6SLionel Sambuc 52474684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _IntType> 52484684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 52494684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 52504684ddb6SLionel Sambuc negative_binomial_distribution<_IntType>& __x) 52514684ddb6SLionel Sambuc{ 52524684ddb6SLionel Sambuc typedef negative_binomial_distribution<_IntType> _Eng; 52534684ddb6SLionel Sambuc typedef typename _Eng::result_type result_type; 52544684ddb6SLionel Sambuc typedef typename _Eng::param_type param_type; 52554684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__is); 52564684ddb6SLionel Sambuc __is.flags(ios_base::dec | ios_base::skipws); 52574684ddb6SLionel Sambuc result_type __k; 52584684ddb6SLionel Sambuc double __p; 52594684ddb6SLionel Sambuc __is >> __k >> __p; 52604684ddb6SLionel Sambuc if (!__is.fail()) 52614684ddb6SLionel Sambuc __x.param(param_type(__k, __p)); 52624684ddb6SLionel Sambuc return __is; 52634684ddb6SLionel Sambuc} 52644684ddb6SLionel Sambuc 52654684ddb6SLionel Sambuc// geometric_distribution 52664684ddb6SLionel Sambuc 52674684ddb6SLionel Sambuctemplate<class _IntType = int> 52684684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY geometric_distribution 52694684ddb6SLionel Sambuc{ 52704684ddb6SLionel Sambucpublic: 52714684ddb6SLionel Sambuc // types 52724684ddb6SLionel Sambuc typedef _IntType result_type; 52734684ddb6SLionel Sambuc 52744684ddb6SLionel Sambuc class _LIBCPP_TYPE_VIS_ONLY param_type 52754684ddb6SLionel Sambuc { 52764684ddb6SLionel Sambuc double __p_; 52774684ddb6SLionel Sambuc public: 52784684ddb6SLionel Sambuc typedef geometric_distribution distribution_type; 52794684ddb6SLionel Sambuc 52804684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 52814684ddb6SLionel Sambuc explicit param_type(double __p = 0.5) : __p_(__p) {} 52824684ddb6SLionel Sambuc 52834684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 52844684ddb6SLionel Sambuc double p() const {return __p_;} 52854684ddb6SLionel Sambuc 52864684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 52874684ddb6SLionel Sambuc bool operator==(const param_type& __x, const param_type& __y) 52884684ddb6SLionel Sambuc {return __x.__p_ == __y.__p_;} 52894684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 52904684ddb6SLionel Sambuc bool operator!=(const param_type& __x, const param_type& __y) 52914684ddb6SLionel Sambuc {return !(__x == __y);} 52924684ddb6SLionel Sambuc }; 52934684ddb6SLionel Sambuc 52944684ddb6SLionel Sambucprivate: 52954684ddb6SLionel Sambuc param_type __p_; 52964684ddb6SLionel Sambuc 52974684ddb6SLionel Sambucpublic: 52984684ddb6SLionel Sambuc // constructors and reset functions 52994684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 53004684ddb6SLionel Sambuc explicit geometric_distribution(double __p = 0.5) : __p_(__p) {} 53014684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 53024684ddb6SLionel Sambuc explicit geometric_distribution(const param_type& __p) : __p_(__p) {} 53034684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 53044684ddb6SLionel Sambuc void reset() {} 53054684ddb6SLionel Sambuc 53064684ddb6SLionel Sambuc // generating functions 53074684ddb6SLionel Sambuc template<class _URNG> 53084684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 53094684ddb6SLionel Sambuc result_type operator()(_URNG& __g) 53104684ddb6SLionel Sambuc {return (*this)(__g, __p_);} 53114684ddb6SLionel Sambuc template<class _URNG> 53124684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 53134684ddb6SLionel Sambuc result_type operator()(_URNG& __g, const param_type& __p) 53144684ddb6SLionel Sambuc {return negative_binomial_distribution<result_type>(1, __p.p())(__g);} 53154684ddb6SLionel Sambuc 53164684ddb6SLionel Sambuc // property functions 53174684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 53184684ddb6SLionel Sambuc double p() const {return __p_.p();} 53194684ddb6SLionel Sambuc 53204684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 53214684ddb6SLionel Sambuc param_type param() const {return __p_;} 53224684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 53234684ddb6SLionel Sambuc void param(const param_type& __p) {__p_ = __p;} 53244684ddb6SLionel Sambuc 53254684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 53264684ddb6SLionel Sambuc result_type min() const {return 0;} 53274684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 53284684ddb6SLionel Sambuc result_type max() const {return numeric_limits<result_type>::max();} 53294684ddb6SLionel Sambuc 53304684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 53314684ddb6SLionel Sambuc bool operator==(const geometric_distribution& __x, 53324684ddb6SLionel Sambuc const geometric_distribution& __y) 53334684ddb6SLionel Sambuc {return __x.__p_ == __y.__p_;} 53344684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 53354684ddb6SLionel Sambuc bool operator!=(const geometric_distribution& __x, 53364684ddb6SLionel Sambuc const geometric_distribution& __y) 53374684ddb6SLionel Sambuc {return !(__x == __y);} 53384684ddb6SLionel Sambuc}; 53394684ddb6SLionel Sambuc 53404684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _IntType> 53414684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 53424684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 53434684ddb6SLionel Sambuc const geometric_distribution<_IntType>& __x) 53444684ddb6SLionel Sambuc{ 53454684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__os); 53464684ddb6SLionel Sambuc __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 53474684ddb6SLionel Sambuc ios_base::scientific); 53484684ddb6SLionel Sambuc return __os << __x.p(); 53494684ddb6SLionel Sambuc} 53504684ddb6SLionel Sambuc 53514684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _IntType> 53524684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 53534684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 53544684ddb6SLionel Sambuc geometric_distribution<_IntType>& __x) 53554684ddb6SLionel Sambuc{ 53564684ddb6SLionel Sambuc typedef geometric_distribution<_IntType> _Eng; 53574684ddb6SLionel Sambuc typedef typename _Eng::param_type param_type; 53584684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__is); 53594684ddb6SLionel Sambuc __is.flags(ios_base::dec | ios_base::skipws); 53604684ddb6SLionel Sambuc double __p; 53614684ddb6SLionel Sambuc __is >> __p; 53624684ddb6SLionel Sambuc if (!__is.fail()) 53634684ddb6SLionel Sambuc __x.param(param_type(__p)); 53644684ddb6SLionel Sambuc return __is; 53654684ddb6SLionel Sambuc} 53664684ddb6SLionel Sambuc 53674684ddb6SLionel Sambuc// chi_squared_distribution 53684684ddb6SLionel Sambuc 53694684ddb6SLionel Sambuctemplate<class _RealType = double> 53704684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY chi_squared_distribution 53714684ddb6SLionel Sambuc{ 53724684ddb6SLionel Sambucpublic: 53734684ddb6SLionel Sambuc // types 53744684ddb6SLionel Sambuc typedef _RealType result_type; 53754684ddb6SLionel Sambuc 53764684ddb6SLionel Sambuc class _LIBCPP_TYPE_VIS_ONLY param_type 53774684ddb6SLionel Sambuc { 53784684ddb6SLionel Sambuc result_type __n_; 53794684ddb6SLionel Sambuc public: 53804684ddb6SLionel Sambuc typedef chi_squared_distribution distribution_type; 53814684ddb6SLionel Sambuc 53824684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 53834684ddb6SLionel Sambuc explicit param_type(result_type __n = 1) : __n_(__n) {} 53844684ddb6SLionel Sambuc 53854684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 53864684ddb6SLionel Sambuc result_type n() const {return __n_;} 53874684ddb6SLionel Sambuc 53884684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 53894684ddb6SLionel Sambuc bool operator==(const param_type& __x, const param_type& __y) 53904684ddb6SLionel Sambuc {return __x.__n_ == __y.__n_;} 53914684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 53924684ddb6SLionel Sambuc bool operator!=(const param_type& __x, const param_type& __y) 53934684ddb6SLionel Sambuc {return !(__x == __y);} 53944684ddb6SLionel Sambuc }; 53954684ddb6SLionel Sambuc 53964684ddb6SLionel Sambucprivate: 53974684ddb6SLionel Sambuc param_type __p_; 53984684ddb6SLionel Sambuc 53994684ddb6SLionel Sambucpublic: 54004684ddb6SLionel Sambuc // constructor and reset functions 54014684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 54024684ddb6SLionel Sambuc explicit chi_squared_distribution(result_type __n = 1) 54034684ddb6SLionel Sambuc : __p_(param_type(__n)) {} 54044684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 54054684ddb6SLionel Sambuc explicit chi_squared_distribution(const param_type& __p) 54064684ddb6SLionel Sambuc : __p_(__p) {} 54074684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 54084684ddb6SLionel Sambuc void reset() {} 54094684ddb6SLionel Sambuc 54104684ddb6SLionel Sambuc // generating functions 54114684ddb6SLionel Sambuc template<class _URNG> 54124684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 54134684ddb6SLionel Sambuc result_type operator()(_URNG& __g) 54144684ddb6SLionel Sambuc {return (*this)(__g, __p_);} 54154684ddb6SLionel Sambuc template<class _URNG> 54164684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 54174684ddb6SLionel Sambuc result_type operator()(_URNG& __g, const param_type& __p) 54184684ddb6SLionel Sambuc {return gamma_distribution<result_type>(__p.n() / 2, 2)(__g);} 54194684ddb6SLionel Sambuc 54204684ddb6SLionel Sambuc // property functions 54214684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 54224684ddb6SLionel Sambuc result_type n() const {return __p_.n();} 54234684ddb6SLionel Sambuc 54244684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 54254684ddb6SLionel Sambuc param_type param() const {return __p_;} 54264684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 54274684ddb6SLionel Sambuc void param(const param_type& __p) {__p_ = __p;} 54284684ddb6SLionel Sambuc 54294684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 54304684ddb6SLionel Sambuc result_type min() const {return 0;} 54314684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 54324684ddb6SLionel Sambuc result_type max() const {return numeric_limits<result_type>::infinity();} 54334684ddb6SLionel Sambuc 54344684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 54354684ddb6SLionel Sambuc bool operator==(const chi_squared_distribution& __x, 54364684ddb6SLionel Sambuc const chi_squared_distribution& __y) 54374684ddb6SLionel Sambuc {return __x.__p_ == __y.__p_;} 54384684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 54394684ddb6SLionel Sambuc bool operator!=(const chi_squared_distribution& __x, 54404684ddb6SLionel Sambuc const chi_squared_distribution& __y) 54414684ddb6SLionel Sambuc {return !(__x == __y);} 54424684ddb6SLionel Sambuc}; 54434684ddb6SLionel Sambuc 54444684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _RT> 54454684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 54464684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 54474684ddb6SLionel Sambuc const chi_squared_distribution<_RT>& __x) 54484684ddb6SLionel Sambuc{ 54494684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__os); 54504684ddb6SLionel Sambuc __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 54514684ddb6SLionel Sambuc ios_base::scientific); 54524684ddb6SLionel Sambuc __os << __x.n(); 54534684ddb6SLionel Sambuc return __os; 54544684ddb6SLionel Sambuc} 54554684ddb6SLionel Sambuc 54564684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _RT> 54574684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 54584684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 54594684ddb6SLionel Sambuc chi_squared_distribution<_RT>& __x) 54604684ddb6SLionel Sambuc{ 54614684ddb6SLionel Sambuc typedef chi_squared_distribution<_RT> _Eng; 54624684ddb6SLionel Sambuc typedef typename _Eng::result_type result_type; 54634684ddb6SLionel Sambuc typedef typename _Eng::param_type param_type; 54644684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__is); 54654684ddb6SLionel Sambuc __is.flags(ios_base::dec | ios_base::skipws); 54664684ddb6SLionel Sambuc result_type __n; 54674684ddb6SLionel Sambuc __is >> __n; 54684684ddb6SLionel Sambuc if (!__is.fail()) 54694684ddb6SLionel Sambuc __x.param(param_type(__n)); 54704684ddb6SLionel Sambuc return __is; 54714684ddb6SLionel Sambuc} 54724684ddb6SLionel Sambuc 54734684ddb6SLionel Sambuc// cauchy_distribution 54744684ddb6SLionel Sambuc 54754684ddb6SLionel Sambuctemplate<class _RealType = double> 54764684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY cauchy_distribution 54774684ddb6SLionel Sambuc{ 54784684ddb6SLionel Sambucpublic: 54794684ddb6SLionel Sambuc // types 54804684ddb6SLionel Sambuc typedef _RealType result_type; 54814684ddb6SLionel Sambuc 54824684ddb6SLionel Sambuc class _LIBCPP_TYPE_VIS_ONLY param_type 54834684ddb6SLionel Sambuc { 54844684ddb6SLionel Sambuc result_type __a_; 54854684ddb6SLionel Sambuc result_type __b_; 54864684ddb6SLionel Sambuc public: 54874684ddb6SLionel Sambuc typedef cauchy_distribution distribution_type; 54884684ddb6SLionel Sambuc 54894684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 54904684ddb6SLionel Sambuc explicit param_type(result_type __a = 0, result_type __b = 1) 54914684ddb6SLionel Sambuc : __a_(__a), __b_(__b) {} 54924684ddb6SLionel Sambuc 54934684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 54944684ddb6SLionel Sambuc result_type a() const {return __a_;} 54954684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 54964684ddb6SLionel Sambuc result_type b() const {return __b_;} 54974684ddb6SLionel Sambuc 54984684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 54994684ddb6SLionel Sambuc bool operator==(const param_type& __x, const param_type& __y) 55004684ddb6SLionel Sambuc {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} 55014684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 55024684ddb6SLionel Sambuc bool operator!=(const param_type& __x, const param_type& __y) 55034684ddb6SLionel Sambuc {return !(__x == __y);} 55044684ddb6SLionel Sambuc }; 55054684ddb6SLionel Sambuc 55064684ddb6SLionel Sambucprivate: 55074684ddb6SLionel Sambuc param_type __p_; 55084684ddb6SLionel Sambuc 55094684ddb6SLionel Sambucpublic: 55104684ddb6SLionel Sambuc // constructor and reset functions 55114684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 55124684ddb6SLionel Sambuc explicit cauchy_distribution(result_type __a = 0, result_type __b = 1) 55134684ddb6SLionel Sambuc : __p_(param_type(__a, __b)) {} 55144684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 55154684ddb6SLionel Sambuc explicit cauchy_distribution(const param_type& __p) 55164684ddb6SLionel Sambuc : __p_(__p) {} 55174684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 55184684ddb6SLionel Sambuc void reset() {} 55194684ddb6SLionel Sambuc 55204684ddb6SLionel Sambuc // generating functions 55214684ddb6SLionel Sambuc template<class _URNG> 55224684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 55234684ddb6SLionel Sambuc result_type operator()(_URNG& __g) 55244684ddb6SLionel Sambuc {return (*this)(__g, __p_);} 55254684ddb6SLionel Sambuc template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 55264684ddb6SLionel Sambuc 55274684ddb6SLionel Sambuc // property functions 55284684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 55294684ddb6SLionel Sambuc result_type a() const {return __p_.a();} 55304684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 55314684ddb6SLionel Sambuc result_type b() const {return __p_.b();} 55324684ddb6SLionel Sambuc 55334684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 55344684ddb6SLionel Sambuc param_type param() const {return __p_;} 55354684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 55364684ddb6SLionel Sambuc void param(const param_type& __p) {__p_ = __p;} 55374684ddb6SLionel Sambuc 55384684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 55394684ddb6SLionel Sambuc result_type min() const {return -numeric_limits<result_type>::infinity();} 55404684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 55414684ddb6SLionel Sambuc result_type max() const {return numeric_limits<result_type>::infinity();} 55424684ddb6SLionel Sambuc 55434684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 55444684ddb6SLionel Sambuc bool operator==(const cauchy_distribution& __x, 55454684ddb6SLionel Sambuc const cauchy_distribution& __y) 55464684ddb6SLionel Sambuc {return __x.__p_ == __y.__p_;} 55474684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 55484684ddb6SLionel Sambuc bool operator!=(const cauchy_distribution& __x, 55494684ddb6SLionel Sambuc const cauchy_distribution& __y) 55504684ddb6SLionel Sambuc {return !(__x == __y);} 55514684ddb6SLionel Sambuc}; 55524684ddb6SLionel Sambuc 55534684ddb6SLionel Sambuctemplate <class _RealType> 55544684ddb6SLionel Sambuctemplate<class _URNG> 55554684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 55564684ddb6SLionel Sambuc_RealType 55574684ddb6SLionel Sambuccauchy_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 55584684ddb6SLionel Sambuc{ 55594684ddb6SLionel Sambuc uniform_real_distribution<result_type> __gen; 55604684ddb6SLionel Sambuc // purposefully let tan arg get as close to pi/2 as it wants, tan will return a finite 55614684ddb6SLionel Sambuc return __p.a() + __p.b() * _VSTD::tan(3.1415926535897932384626433832795 * __gen(__g)); 55624684ddb6SLionel Sambuc} 55634684ddb6SLionel Sambuc 55644684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _RT> 55654684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 55664684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 55674684ddb6SLionel Sambuc const cauchy_distribution<_RT>& __x) 55684684ddb6SLionel Sambuc{ 55694684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__os); 55704684ddb6SLionel Sambuc __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 55714684ddb6SLionel Sambuc ios_base::scientific); 55724684ddb6SLionel Sambuc _CharT __sp = __os.widen(' '); 55734684ddb6SLionel Sambuc __os.fill(__sp); 55744684ddb6SLionel Sambuc __os << __x.a() << __sp << __x.b(); 55754684ddb6SLionel Sambuc return __os; 55764684ddb6SLionel Sambuc} 55774684ddb6SLionel Sambuc 55784684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _RT> 55794684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 55804684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 55814684ddb6SLionel Sambuc cauchy_distribution<_RT>& __x) 55824684ddb6SLionel Sambuc{ 55834684ddb6SLionel Sambuc typedef cauchy_distribution<_RT> _Eng; 55844684ddb6SLionel Sambuc typedef typename _Eng::result_type result_type; 55854684ddb6SLionel Sambuc typedef typename _Eng::param_type param_type; 55864684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__is); 55874684ddb6SLionel Sambuc __is.flags(ios_base::dec | ios_base::skipws); 55884684ddb6SLionel Sambuc result_type __a; 55894684ddb6SLionel Sambuc result_type __b; 55904684ddb6SLionel Sambuc __is >> __a >> __b; 55914684ddb6SLionel Sambuc if (!__is.fail()) 55924684ddb6SLionel Sambuc __x.param(param_type(__a, __b)); 55934684ddb6SLionel Sambuc return __is; 55944684ddb6SLionel Sambuc} 55954684ddb6SLionel Sambuc 55964684ddb6SLionel Sambuc// fisher_f_distribution 55974684ddb6SLionel Sambuc 55984684ddb6SLionel Sambuctemplate<class _RealType = double> 55994684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY fisher_f_distribution 56004684ddb6SLionel Sambuc{ 56014684ddb6SLionel Sambucpublic: 56024684ddb6SLionel Sambuc // types 56034684ddb6SLionel Sambuc typedef _RealType result_type; 56044684ddb6SLionel Sambuc 56054684ddb6SLionel Sambuc class _LIBCPP_TYPE_VIS_ONLY param_type 56064684ddb6SLionel Sambuc { 56074684ddb6SLionel Sambuc result_type __m_; 56084684ddb6SLionel Sambuc result_type __n_; 56094684ddb6SLionel Sambuc public: 56104684ddb6SLionel Sambuc typedef fisher_f_distribution distribution_type; 56114684ddb6SLionel Sambuc 56124684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 56134684ddb6SLionel Sambuc explicit param_type(result_type __m = 1, result_type __n = 1) 56144684ddb6SLionel Sambuc : __m_(__m), __n_(__n) {} 56154684ddb6SLionel Sambuc 56164684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 56174684ddb6SLionel Sambuc result_type m() const {return __m_;} 56184684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 56194684ddb6SLionel Sambuc result_type n() const {return __n_;} 56204684ddb6SLionel Sambuc 56214684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 56224684ddb6SLionel Sambuc bool operator==(const param_type& __x, const param_type& __y) 56234684ddb6SLionel Sambuc {return __x.__m_ == __y.__m_ && __x.__n_ == __y.__n_;} 56244684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 56254684ddb6SLionel Sambuc bool operator!=(const param_type& __x, const param_type& __y) 56264684ddb6SLionel Sambuc {return !(__x == __y);} 56274684ddb6SLionel Sambuc }; 56284684ddb6SLionel Sambuc 56294684ddb6SLionel Sambucprivate: 56304684ddb6SLionel Sambuc param_type __p_; 56314684ddb6SLionel Sambuc 56324684ddb6SLionel Sambucpublic: 56334684ddb6SLionel Sambuc // constructor and reset functions 56344684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 56354684ddb6SLionel Sambuc explicit fisher_f_distribution(result_type __m = 1, result_type __n = 1) 56364684ddb6SLionel Sambuc : __p_(param_type(__m, __n)) {} 56374684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 56384684ddb6SLionel Sambuc explicit fisher_f_distribution(const param_type& __p) 56394684ddb6SLionel Sambuc : __p_(__p) {} 56404684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 56414684ddb6SLionel Sambuc void reset() {} 56424684ddb6SLionel Sambuc 56434684ddb6SLionel Sambuc // generating functions 56444684ddb6SLionel Sambuc template<class _URNG> 56454684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 56464684ddb6SLionel Sambuc result_type operator()(_URNG& __g) 56474684ddb6SLionel Sambuc {return (*this)(__g, __p_);} 56484684ddb6SLionel Sambuc template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 56494684ddb6SLionel Sambuc 56504684ddb6SLionel Sambuc // property functions 56514684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 56524684ddb6SLionel Sambuc result_type m() const {return __p_.m();} 56534684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 56544684ddb6SLionel Sambuc result_type n() const {return __p_.n();} 56554684ddb6SLionel Sambuc 56564684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 56574684ddb6SLionel Sambuc param_type param() const {return __p_;} 56584684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 56594684ddb6SLionel Sambuc void param(const param_type& __p) {__p_ = __p;} 56604684ddb6SLionel Sambuc 56614684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 56624684ddb6SLionel Sambuc result_type min() const {return 0;} 56634684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 56644684ddb6SLionel Sambuc result_type max() const {return numeric_limits<result_type>::infinity();} 56654684ddb6SLionel Sambuc 56664684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 56674684ddb6SLionel Sambuc bool operator==(const fisher_f_distribution& __x, 56684684ddb6SLionel Sambuc const fisher_f_distribution& __y) 56694684ddb6SLionel Sambuc {return __x.__p_ == __y.__p_;} 56704684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 56714684ddb6SLionel Sambuc bool operator!=(const fisher_f_distribution& __x, 56724684ddb6SLionel Sambuc const fisher_f_distribution& __y) 56734684ddb6SLionel Sambuc {return !(__x == __y);} 56744684ddb6SLionel Sambuc}; 56754684ddb6SLionel Sambuc 56764684ddb6SLionel Sambuctemplate <class _RealType> 56774684ddb6SLionel Sambuctemplate<class _URNG> 56784684ddb6SLionel Sambuc_RealType 56794684ddb6SLionel Sambucfisher_f_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 56804684ddb6SLionel Sambuc{ 56814684ddb6SLionel Sambuc gamma_distribution<result_type> __gdm(__p.m() * result_type(.5)); 56824684ddb6SLionel Sambuc gamma_distribution<result_type> __gdn(__p.n() * result_type(.5)); 56834684ddb6SLionel Sambuc return __p.n() * __gdm(__g) / (__p.m() * __gdn(__g)); 56844684ddb6SLionel Sambuc} 56854684ddb6SLionel Sambuc 56864684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _RT> 56874684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 56884684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 56894684ddb6SLionel Sambuc const fisher_f_distribution<_RT>& __x) 56904684ddb6SLionel Sambuc{ 56914684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__os); 56924684ddb6SLionel Sambuc __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 56934684ddb6SLionel Sambuc ios_base::scientific); 56944684ddb6SLionel Sambuc _CharT __sp = __os.widen(' '); 56954684ddb6SLionel Sambuc __os.fill(__sp); 56964684ddb6SLionel Sambuc __os << __x.m() << __sp << __x.n(); 56974684ddb6SLionel Sambuc return __os; 56984684ddb6SLionel Sambuc} 56994684ddb6SLionel Sambuc 57004684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _RT> 57014684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 57024684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 57034684ddb6SLionel Sambuc fisher_f_distribution<_RT>& __x) 57044684ddb6SLionel Sambuc{ 57054684ddb6SLionel Sambuc typedef fisher_f_distribution<_RT> _Eng; 57064684ddb6SLionel Sambuc typedef typename _Eng::result_type result_type; 57074684ddb6SLionel Sambuc typedef typename _Eng::param_type param_type; 57084684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__is); 57094684ddb6SLionel Sambuc __is.flags(ios_base::dec | ios_base::skipws); 57104684ddb6SLionel Sambuc result_type __m; 57114684ddb6SLionel Sambuc result_type __n; 57124684ddb6SLionel Sambuc __is >> __m >> __n; 57134684ddb6SLionel Sambuc if (!__is.fail()) 57144684ddb6SLionel Sambuc __x.param(param_type(__m, __n)); 57154684ddb6SLionel Sambuc return __is; 57164684ddb6SLionel Sambuc} 57174684ddb6SLionel Sambuc 57184684ddb6SLionel Sambuc// student_t_distribution 57194684ddb6SLionel Sambuc 57204684ddb6SLionel Sambuctemplate<class _RealType = double> 57214684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY student_t_distribution 57224684ddb6SLionel Sambuc{ 57234684ddb6SLionel Sambucpublic: 57244684ddb6SLionel Sambuc // types 57254684ddb6SLionel Sambuc typedef _RealType result_type; 57264684ddb6SLionel Sambuc 57274684ddb6SLionel Sambuc class _LIBCPP_TYPE_VIS_ONLY param_type 57284684ddb6SLionel Sambuc { 57294684ddb6SLionel Sambuc result_type __n_; 57304684ddb6SLionel Sambuc public: 57314684ddb6SLionel Sambuc typedef student_t_distribution distribution_type; 57324684ddb6SLionel Sambuc 57334684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 57344684ddb6SLionel Sambuc explicit param_type(result_type __n = 1) : __n_(__n) {} 57354684ddb6SLionel Sambuc 57364684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 57374684ddb6SLionel Sambuc result_type n() const {return __n_;} 57384684ddb6SLionel Sambuc 57394684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 57404684ddb6SLionel Sambuc bool operator==(const param_type& __x, const param_type& __y) 57414684ddb6SLionel Sambuc {return __x.__n_ == __y.__n_;} 57424684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 57434684ddb6SLionel Sambuc bool operator!=(const param_type& __x, const param_type& __y) 57444684ddb6SLionel Sambuc {return !(__x == __y);} 57454684ddb6SLionel Sambuc }; 57464684ddb6SLionel Sambuc 57474684ddb6SLionel Sambucprivate: 57484684ddb6SLionel Sambuc param_type __p_; 57494684ddb6SLionel Sambuc normal_distribution<result_type> __nd_; 57504684ddb6SLionel Sambuc 57514684ddb6SLionel Sambucpublic: 57524684ddb6SLionel Sambuc // constructor and reset functions 57534684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 57544684ddb6SLionel Sambuc explicit student_t_distribution(result_type __n = 1) 57554684ddb6SLionel Sambuc : __p_(param_type(__n)) {} 57564684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 57574684ddb6SLionel Sambuc explicit student_t_distribution(const param_type& __p) 57584684ddb6SLionel Sambuc : __p_(__p) {} 57594684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 57604684ddb6SLionel Sambuc void reset() {__nd_.reset();} 57614684ddb6SLionel Sambuc 57624684ddb6SLionel Sambuc // generating functions 57634684ddb6SLionel Sambuc template<class _URNG> 57644684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 57654684ddb6SLionel Sambuc result_type operator()(_URNG& __g) 57664684ddb6SLionel Sambuc {return (*this)(__g, __p_);} 57674684ddb6SLionel Sambuc template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 57684684ddb6SLionel Sambuc 57694684ddb6SLionel Sambuc // property functions 57704684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 57714684ddb6SLionel Sambuc result_type n() const {return __p_.n();} 57724684ddb6SLionel Sambuc 57734684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 57744684ddb6SLionel Sambuc param_type param() const {return __p_;} 57754684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 57764684ddb6SLionel Sambuc void param(const param_type& __p) {__p_ = __p;} 57774684ddb6SLionel Sambuc 57784684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 57794684ddb6SLionel Sambuc result_type min() const {return -numeric_limits<result_type>::infinity();} 57804684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 57814684ddb6SLionel Sambuc result_type max() const {return numeric_limits<result_type>::infinity();} 57824684ddb6SLionel Sambuc 57834684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 57844684ddb6SLionel Sambuc bool operator==(const student_t_distribution& __x, 57854684ddb6SLionel Sambuc const student_t_distribution& __y) 57864684ddb6SLionel Sambuc {return __x.__p_ == __y.__p_;} 57874684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 57884684ddb6SLionel Sambuc bool operator!=(const student_t_distribution& __x, 57894684ddb6SLionel Sambuc const student_t_distribution& __y) 57904684ddb6SLionel Sambuc {return !(__x == __y);} 57914684ddb6SLionel Sambuc}; 57924684ddb6SLionel Sambuc 57934684ddb6SLionel Sambuctemplate <class _RealType> 57944684ddb6SLionel Sambuctemplate<class _URNG> 57954684ddb6SLionel Sambuc_RealType 57964684ddb6SLionel Sambucstudent_t_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 57974684ddb6SLionel Sambuc{ 57984684ddb6SLionel Sambuc gamma_distribution<result_type> __gd(__p.n() * .5, 2); 57994684ddb6SLionel Sambuc return __nd_(__g) * _VSTD::sqrt(__p.n()/__gd(__g)); 58004684ddb6SLionel Sambuc} 58014684ddb6SLionel Sambuc 58024684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _RT> 58034684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 58044684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 58054684ddb6SLionel Sambuc const student_t_distribution<_RT>& __x) 58064684ddb6SLionel Sambuc{ 58074684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__os); 58084684ddb6SLionel Sambuc __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 58094684ddb6SLionel Sambuc ios_base::scientific); 58104684ddb6SLionel Sambuc __os << __x.n(); 58114684ddb6SLionel Sambuc return __os; 58124684ddb6SLionel Sambuc} 58134684ddb6SLionel Sambuc 58144684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _RT> 58154684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 58164684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 58174684ddb6SLionel Sambuc student_t_distribution<_RT>& __x) 58184684ddb6SLionel Sambuc{ 58194684ddb6SLionel Sambuc typedef student_t_distribution<_RT> _Eng; 58204684ddb6SLionel Sambuc typedef typename _Eng::result_type result_type; 58214684ddb6SLionel Sambuc typedef typename _Eng::param_type param_type; 58224684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__is); 58234684ddb6SLionel Sambuc __is.flags(ios_base::dec | ios_base::skipws); 58244684ddb6SLionel Sambuc result_type __n; 58254684ddb6SLionel Sambuc __is >> __n; 58264684ddb6SLionel Sambuc if (!__is.fail()) 58274684ddb6SLionel Sambuc __x.param(param_type(__n)); 58284684ddb6SLionel Sambuc return __is; 58294684ddb6SLionel Sambuc} 58304684ddb6SLionel Sambuc 58314684ddb6SLionel Sambuc// discrete_distribution 58324684ddb6SLionel Sambuc 58334684ddb6SLionel Sambuctemplate<class _IntType = int> 58344684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY discrete_distribution 58354684ddb6SLionel Sambuc{ 58364684ddb6SLionel Sambucpublic: 58374684ddb6SLionel Sambuc // types 58384684ddb6SLionel Sambuc typedef _IntType result_type; 58394684ddb6SLionel Sambuc 58404684ddb6SLionel Sambuc class _LIBCPP_TYPE_VIS_ONLY param_type 58414684ddb6SLionel Sambuc { 58424684ddb6SLionel Sambuc vector<double> __p_; 58434684ddb6SLionel Sambuc public: 58444684ddb6SLionel Sambuc typedef discrete_distribution distribution_type; 58454684ddb6SLionel Sambuc 58464684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 58474684ddb6SLionel Sambuc param_type() {} 58484684ddb6SLionel Sambuc template<class _InputIterator> 58494684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 58504684ddb6SLionel Sambuc param_type(_InputIterator __f, _InputIterator __l) 58514684ddb6SLionel Sambuc : __p_(__f, __l) {__init();} 58524684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 58534684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 58544684ddb6SLionel Sambuc param_type(initializer_list<double> __wl) 58554684ddb6SLionel Sambuc : __p_(__wl.begin(), __wl.end()) {__init();} 58564684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 58574684ddb6SLionel Sambuc template<class _UnaryOperation> 58584684ddb6SLionel Sambuc param_type(size_t __nw, double __xmin, double __xmax, 58594684ddb6SLionel Sambuc _UnaryOperation __fw); 58604684ddb6SLionel Sambuc 58614684ddb6SLionel Sambuc vector<double> probabilities() const; 58624684ddb6SLionel Sambuc 58634684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 58644684ddb6SLionel Sambuc bool operator==(const param_type& __x, const param_type& __y) 58654684ddb6SLionel Sambuc {return __x.__p_ == __y.__p_;} 58664684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 58674684ddb6SLionel Sambuc bool operator!=(const param_type& __x, const param_type& __y) 58684684ddb6SLionel Sambuc {return !(__x == __y);} 58694684ddb6SLionel Sambuc 58704684ddb6SLionel Sambuc private: 58714684ddb6SLionel Sambuc void __init(); 58724684ddb6SLionel Sambuc 58734684ddb6SLionel Sambuc friend class discrete_distribution; 58744684ddb6SLionel Sambuc 58754684ddb6SLionel Sambuc template <class _CharT, class _Traits, class _IT> 58764684ddb6SLionel Sambuc friend 58774684ddb6SLionel Sambuc basic_ostream<_CharT, _Traits>& 58784684ddb6SLionel Sambuc operator<<(basic_ostream<_CharT, _Traits>& __os, 58794684ddb6SLionel Sambuc const discrete_distribution<_IT>& __x); 58804684ddb6SLionel Sambuc 58814684ddb6SLionel Sambuc template <class _CharT, class _Traits, class _IT> 58824684ddb6SLionel Sambuc friend 58834684ddb6SLionel Sambuc basic_istream<_CharT, _Traits>& 58844684ddb6SLionel Sambuc operator>>(basic_istream<_CharT, _Traits>& __is, 58854684ddb6SLionel Sambuc discrete_distribution<_IT>& __x); 58864684ddb6SLionel Sambuc }; 58874684ddb6SLionel Sambuc 58884684ddb6SLionel Sambucprivate: 58894684ddb6SLionel Sambuc param_type __p_; 58904684ddb6SLionel Sambuc 58914684ddb6SLionel Sambucpublic: 58924684ddb6SLionel Sambuc // constructor and reset functions 58934684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 58944684ddb6SLionel Sambuc discrete_distribution() {} 58954684ddb6SLionel Sambuc template<class _InputIterator> 58964684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 58974684ddb6SLionel Sambuc discrete_distribution(_InputIterator __f, _InputIterator __l) 58984684ddb6SLionel Sambuc : __p_(__f, __l) {} 58994684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 59004684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 59014684ddb6SLionel Sambuc discrete_distribution(initializer_list<double> __wl) 59024684ddb6SLionel Sambuc : __p_(__wl) {} 59034684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 59044684ddb6SLionel Sambuc template<class _UnaryOperation> 59054684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 59064684ddb6SLionel Sambuc discrete_distribution(size_t __nw, double __xmin, double __xmax, 59074684ddb6SLionel Sambuc _UnaryOperation __fw) 59084684ddb6SLionel Sambuc : __p_(__nw, __xmin, __xmax, __fw) {} 59094684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 59104684ddb6SLionel Sambuc explicit discrete_distribution(const param_type& __p) 59114684ddb6SLionel Sambuc : __p_(__p) {} 59124684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 59134684ddb6SLionel Sambuc void reset() {} 59144684ddb6SLionel Sambuc 59154684ddb6SLionel Sambuc // generating functions 59164684ddb6SLionel Sambuc template<class _URNG> 59174684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 59184684ddb6SLionel Sambuc result_type operator()(_URNG& __g) 59194684ddb6SLionel Sambuc {return (*this)(__g, __p_);} 59204684ddb6SLionel Sambuc template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 59214684ddb6SLionel Sambuc 59224684ddb6SLionel Sambuc // property functions 59234684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 59244684ddb6SLionel Sambuc vector<double> probabilities() const {return __p_.probabilities();} 59254684ddb6SLionel Sambuc 59264684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 59274684ddb6SLionel Sambuc param_type param() const {return __p_;} 59284684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 59294684ddb6SLionel Sambuc void param(const param_type& __p) {__p_ = __p;} 59304684ddb6SLionel Sambuc 59314684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 59324684ddb6SLionel Sambuc result_type min() const {return 0;} 59334684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 59344684ddb6SLionel Sambuc result_type max() const {return __p_.__p_.size();} 59354684ddb6SLionel Sambuc 59364684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 59374684ddb6SLionel Sambuc bool operator==(const discrete_distribution& __x, 59384684ddb6SLionel Sambuc const discrete_distribution& __y) 59394684ddb6SLionel Sambuc {return __x.__p_ == __y.__p_;} 59404684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 59414684ddb6SLionel Sambuc bool operator!=(const discrete_distribution& __x, 59424684ddb6SLionel Sambuc const discrete_distribution& __y) 59434684ddb6SLionel Sambuc {return !(__x == __y);} 59444684ddb6SLionel Sambuc 59454684ddb6SLionel Sambuc template <class _CharT, class _Traits, class _IT> 59464684ddb6SLionel Sambuc friend 59474684ddb6SLionel Sambuc basic_ostream<_CharT, _Traits>& 59484684ddb6SLionel Sambuc operator<<(basic_ostream<_CharT, _Traits>& __os, 59494684ddb6SLionel Sambuc const discrete_distribution<_IT>& __x); 59504684ddb6SLionel Sambuc 59514684ddb6SLionel Sambuc template <class _CharT, class _Traits, class _IT> 59524684ddb6SLionel Sambuc friend 59534684ddb6SLionel Sambuc basic_istream<_CharT, _Traits>& 59544684ddb6SLionel Sambuc operator>>(basic_istream<_CharT, _Traits>& __is, 59554684ddb6SLionel Sambuc discrete_distribution<_IT>& __x); 59564684ddb6SLionel Sambuc}; 59574684ddb6SLionel Sambuc 59584684ddb6SLionel Sambuctemplate<class _IntType> 59594684ddb6SLionel Sambuctemplate<class _UnaryOperation> 59604684ddb6SLionel Sambucdiscrete_distribution<_IntType>::param_type::param_type(size_t __nw, 59614684ddb6SLionel Sambuc double __xmin, 59624684ddb6SLionel Sambuc double __xmax, 59634684ddb6SLionel Sambuc _UnaryOperation __fw) 59644684ddb6SLionel Sambuc{ 59654684ddb6SLionel Sambuc if (__nw > 1) 59664684ddb6SLionel Sambuc { 59674684ddb6SLionel Sambuc __p_.reserve(__nw - 1); 59684684ddb6SLionel Sambuc double __d = (__xmax - __xmin) / __nw; 59694684ddb6SLionel Sambuc double __d2 = __d / 2; 59704684ddb6SLionel Sambuc for (size_t __k = 0; __k < __nw; ++__k) 59714684ddb6SLionel Sambuc __p_.push_back(__fw(__xmin + __k * __d + __d2)); 59724684ddb6SLionel Sambuc __init(); 59734684ddb6SLionel Sambuc } 59744684ddb6SLionel Sambuc} 59754684ddb6SLionel Sambuc 59764684ddb6SLionel Sambuctemplate<class _IntType> 59774684ddb6SLionel Sambucvoid 59784684ddb6SLionel Sambucdiscrete_distribution<_IntType>::param_type::__init() 59794684ddb6SLionel Sambuc{ 59804684ddb6SLionel Sambuc if (!__p_.empty()) 59814684ddb6SLionel Sambuc { 59824684ddb6SLionel Sambuc if (__p_.size() > 1) 59834684ddb6SLionel Sambuc { 59844684ddb6SLionel Sambuc double __s = _VSTD::accumulate(__p_.begin(), __p_.end(), 0.0); 59854684ddb6SLionel Sambuc for (_VSTD::vector<double>::iterator __i = __p_.begin(), __e = __p_.end(); 59864684ddb6SLionel Sambuc __i < __e; ++__i) 59874684ddb6SLionel Sambuc *__i /= __s; 59884684ddb6SLionel Sambuc vector<double> __t(__p_.size() - 1); 59894684ddb6SLionel Sambuc _VSTD::partial_sum(__p_.begin(), __p_.end() - 1, __t.begin()); 59904684ddb6SLionel Sambuc swap(__p_, __t); 59914684ddb6SLionel Sambuc } 59924684ddb6SLionel Sambuc else 59934684ddb6SLionel Sambuc { 59944684ddb6SLionel Sambuc __p_.clear(); 59954684ddb6SLionel Sambuc __p_.shrink_to_fit(); 59964684ddb6SLionel Sambuc } 59974684ddb6SLionel Sambuc } 59984684ddb6SLionel Sambuc} 59994684ddb6SLionel Sambuc 60004684ddb6SLionel Sambuctemplate<class _IntType> 60014684ddb6SLionel Sambucvector<double> 60024684ddb6SLionel Sambucdiscrete_distribution<_IntType>::param_type::probabilities() const 60034684ddb6SLionel Sambuc{ 60044684ddb6SLionel Sambuc size_t __n = __p_.size(); 60054684ddb6SLionel Sambuc _VSTD::vector<double> __p(__n+1); 60064684ddb6SLionel Sambuc _VSTD::adjacent_difference(__p_.begin(), __p_.end(), __p.begin()); 60074684ddb6SLionel Sambuc if (__n > 0) 60084684ddb6SLionel Sambuc __p[__n] = 1 - __p_[__n-1]; 60094684ddb6SLionel Sambuc else 60104684ddb6SLionel Sambuc __p[0] = 1; 60114684ddb6SLionel Sambuc return __p; 60124684ddb6SLionel Sambuc} 60134684ddb6SLionel Sambuc 60144684ddb6SLionel Sambuctemplate<class _IntType> 60154684ddb6SLionel Sambuctemplate<class _URNG> 60164684ddb6SLionel Sambuc_IntType 60174684ddb6SLionel Sambucdiscrete_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p) 60184684ddb6SLionel Sambuc{ 60194684ddb6SLionel Sambuc uniform_real_distribution<double> __gen; 60204684ddb6SLionel Sambuc return static_cast<_IntType>( 60214684ddb6SLionel Sambuc _VSTD::upper_bound(__p.__p_.begin(), __p.__p_.end(), __gen(__g)) - 60224684ddb6SLionel Sambuc __p.__p_.begin()); 60234684ddb6SLionel Sambuc} 60244684ddb6SLionel Sambuc 60254684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _IT> 60264684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 60274684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 60284684ddb6SLionel Sambuc const discrete_distribution<_IT>& __x) 60294684ddb6SLionel Sambuc{ 60304684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__os); 60314684ddb6SLionel Sambuc __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 60324684ddb6SLionel Sambuc ios_base::scientific); 60334684ddb6SLionel Sambuc _CharT __sp = __os.widen(' '); 60344684ddb6SLionel Sambuc __os.fill(__sp); 60354684ddb6SLionel Sambuc size_t __n = __x.__p_.__p_.size(); 60364684ddb6SLionel Sambuc __os << __n; 60374684ddb6SLionel Sambuc for (size_t __i = 0; __i < __n; ++__i) 60384684ddb6SLionel Sambuc __os << __sp << __x.__p_.__p_[__i]; 60394684ddb6SLionel Sambuc return __os; 60404684ddb6SLionel Sambuc} 60414684ddb6SLionel Sambuc 60424684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _IT> 60434684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 60444684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 60454684ddb6SLionel Sambuc discrete_distribution<_IT>& __x) 60464684ddb6SLionel Sambuc{ 60474684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__is); 60484684ddb6SLionel Sambuc __is.flags(ios_base::dec | ios_base::skipws); 60494684ddb6SLionel Sambuc size_t __n; 60504684ddb6SLionel Sambuc __is >> __n; 60514684ddb6SLionel Sambuc vector<double> __p(__n); 60524684ddb6SLionel Sambuc for (size_t __i = 0; __i < __n; ++__i) 60534684ddb6SLionel Sambuc __is >> __p[__i]; 60544684ddb6SLionel Sambuc if (!__is.fail()) 60554684ddb6SLionel Sambuc swap(__x.__p_.__p_, __p); 60564684ddb6SLionel Sambuc return __is; 60574684ddb6SLionel Sambuc} 60584684ddb6SLionel Sambuc 60594684ddb6SLionel Sambuc// piecewise_constant_distribution 60604684ddb6SLionel Sambuc 60614684ddb6SLionel Sambuctemplate<class _RealType = double> 60624684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY piecewise_constant_distribution 60634684ddb6SLionel Sambuc{ 60644684ddb6SLionel Sambucpublic: 60654684ddb6SLionel Sambuc // types 60664684ddb6SLionel Sambuc typedef _RealType result_type; 60674684ddb6SLionel Sambuc 60684684ddb6SLionel Sambuc class _LIBCPP_TYPE_VIS_ONLY param_type 60694684ddb6SLionel Sambuc { 60704684ddb6SLionel Sambuc vector<result_type> __b_; 60714684ddb6SLionel Sambuc vector<result_type> __densities_; 60724684ddb6SLionel Sambuc vector<result_type> __areas_; 60734684ddb6SLionel Sambuc public: 60744684ddb6SLionel Sambuc typedef piecewise_constant_distribution distribution_type; 60754684ddb6SLionel Sambuc 60764684ddb6SLionel Sambuc param_type(); 60774684ddb6SLionel Sambuc template<class _InputIteratorB, class _InputIteratorW> 60784684ddb6SLionel Sambuc param_type(_InputIteratorB __fB, _InputIteratorB __lB, 60794684ddb6SLionel Sambuc _InputIteratorW __fW); 60804684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 60814684ddb6SLionel Sambuc template<class _UnaryOperation> 60824684ddb6SLionel Sambuc param_type(initializer_list<result_type> __bl, _UnaryOperation __fw); 60834684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 60844684ddb6SLionel Sambuc template<class _UnaryOperation> 60854684ddb6SLionel Sambuc param_type(size_t __nw, result_type __xmin, result_type __xmax, 60864684ddb6SLionel Sambuc _UnaryOperation __fw); 60874684ddb6SLionel Sambuc param_type & operator=(const param_type& __rhs); 60884684ddb6SLionel Sambuc 60894684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 60904684ddb6SLionel Sambuc vector<result_type> intervals() const {return __b_;} 60914684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 60924684ddb6SLionel Sambuc vector<result_type> densities() const {return __densities_;} 60934684ddb6SLionel Sambuc 60944684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 60954684ddb6SLionel Sambuc bool operator==(const param_type& __x, const param_type& __y) 60964684ddb6SLionel Sambuc {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;} 60974684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 60984684ddb6SLionel Sambuc bool operator!=(const param_type& __x, const param_type& __y) 60994684ddb6SLionel Sambuc {return !(__x == __y);} 61004684ddb6SLionel Sambuc 61014684ddb6SLionel Sambuc private: 61024684ddb6SLionel Sambuc void __init(); 61034684ddb6SLionel Sambuc 61044684ddb6SLionel Sambuc friend class piecewise_constant_distribution; 61054684ddb6SLionel Sambuc 61064684ddb6SLionel Sambuc template <class _CharT, class _Traits, class _RT> 61074684ddb6SLionel Sambuc friend 61084684ddb6SLionel Sambuc basic_ostream<_CharT, _Traits>& 61094684ddb6SLionel Sambuc operator<<(basic_ostream<_CharT, _Traits>& __os, 61104684ddb6SLionel Sambuc const piecewise_constant_distribution<_RT>& __x); 61114684ddb6SLionel Sambuc 61124684ddb6SLionel Sambuc template <class _CharT, class _Traits, class _RT> 61134684ddb6SLionel Sambuc friend 61144684ddb6SLionel Sambuc basic_istream<_CharT, _Traits>& 61154684ddb6SLionel Sambuc operator>>(basic_istream<_CharT, _Traits>& __is, 61164684ddb6SLionel Sambuc piecewise_constant_distribution<_RT>& __x); 61174684ddb6SLionel Sambuc }; 61184684ddb6SLionel Sambuc 61194684ddb6SLionel Sambucprivate: 61204684ddb6SLionel Sambuc param_type __p_; 61214684ddb6SLionel Sambuc 61224684ddb6SLionel Sambucpublic: 61234684ddb6SLionel Sambuc // constructor and reset functions 61244684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 61254684ddb6SLionel Sambuc piecewise_constant_distribution() {} 61264684ddb6SLionel Sambuc template<class _InputIteratorB, class _InputIteratorW> 61274684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 61284684ddb6SLionel Sambuc piecewise_constant_distribution(_InputIteratorB __fB, 61294684ddb6SLionel Sambuc _InputIteratorB __lB, 61304684ddb6SLionel Sambuc _InputIteratorW __fW) 61314684ddb6SLionel Sambuc : __p_(__fB, __lB, __fW) {} 61324684ddb6SLionel Sambuc 61334684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 61344684ddb6SLionel Sambuc template<class _UnaryOperation> 61354684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 61364684ddb6SLionel Sambuc piecewise_constant_distribution(initializer_list<result_type> __bl, 61374684ddb6SLionel Sambuc _UnaryOperation __fw) 61384684ddb6SLionel Sambuc : __p_(__bl, __fw) {} 61394684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 61404684ddb6SLionel Sambuc 61414684ddb6SLionel Sambuc template<class _UnaryOperation> 61424684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 61434684ddb6SLionel Sambuc piecewise_constant_distribution(size_t __nw, result_type __xmin, 61444684ddb6SLionel Sambuc result_type __xmax, _UnaryOperation __fw) 61454684ddb6SLionel Sambuc : __p_(__nw, __xmin, __xmax, __fw) {} 61464684ddb6SLionel Sambuc 61474684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 61484684ddb6SLionel Sambuc explicit piecewise_constant_distribution(const param_type& __p) 61494684ddb6SLionel Sambuc : __p_(__p) {} 61504684ddb6SLionel Sambuc 61514684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 61524684ddb6SLionel Sambuc void reset() {} 61534684ddb6SLionel Sambuc 61544684ddb6SLionel Sambuc // generating functions 61554684ddb6SLionel Sambuc template<class _URNG> 61564684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 61574684ddb6SLionel Sambuc result_type operator()(_URNG& __g) 61584684ddb6SLionel Sambuc {return (*this)(__g, __p_);} 61594684ddb6SLionel Sambuc template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 61604684ddb6SLionel Sambuc 61614684ddb6SLionel Sambuc // property functions 61624684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 61634684ddb6SLionel Sambuc vector<result_type> intervals() const {return __p_.intervals();} 61644684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 61654684ddb6SLionel Sambuc vector<result_type> densities() const {return __p_.densities();} 61664684ddb6SLionel Sambuc 61674684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 61684684ddb6SLionel Sambuc param_type param() const {return __p_;} 61694684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 61704684ddb6SLionel Sambuc void param(const param_type& __p) {__p_ = __p;} 61714684ddb6SLionel Sambuc 61724684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 61734684ddb6SLionel Sambuc result_type min() const {return __p_.__b_.front();} 61744684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 61754684ddb6SLionel Sambuc result_type max() const {return __p_.__b_.back();} 61764684ddb6SLionel Sambuc 61774684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 61784684ddb6SLionel Sambuc bool operator==(const piecewise_constant_distribution& __x, 61794684ddb6SLionel Sambuc const piecewise_constant_distribution& __y) 61804684ddb6SLionel Sambuc {return __x.__p_ == __y.__p_;} 61814684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 61824684ddb6SLionel Sambuc bool operator!=(const piecewise_constant_distribution& __x, 61834684ddb6SLionel Sambuc const piecewise_constant_distribution& __y) 61844684ddb6SLionel Sambuc {return !(__x == __y);} 61854684ddb6SLionel Sambuc 61864684ddb6SLionel Sambuc template <class _CharT, class _Traits, class _RT> 61874684ddb6SLionel Sambuc friend 61884684ddb6SLionel Sambuc basic_ostream<_CharT, _Traits>& 61894684ddb6SLionel Sambuc operator<<(basic_ostream<_CharT, _Traits>& __os, 61904684ddb6SLionel Sambuc const piecewise_constant_distribution<_RT>& __x); 61914684ddb6SLionel Sambuc 61924684ddb6SLionel Sambuc template <class _CharT, class _Traits, class _RT> 61934684ddb6SLionel Sambuc friend 61944684ddb6SLionel Sambuc basic_istream<_CharT, _Traits>& 61954684ddb6SLionel Sambuc operator>>(basic_istream<_CharT, _Traits>& __is, 61964684ddb6SLionel Sambuc piecewise_constant_distribution<_RT>& __x); 61974684ddb6SLionel Sambuc}; 61984684ddb6SLionel Sambuc 61994684ddb6SLionel Sambuctemplate<class _RealType> 62004684ddb6SLionel Sambuctypename piecewise_constant_distribution<_RealType>::param_type & 62014684ddb6SLionel Sambucpiecewise_constant_distribution<_RealType>::param_type::operator= 62024684ddb6SLionel Sambuc (const param_type& __rhs) 62034684ddb6SLionel Sambuc{ 62044684ddb6SLionel Sambuc// These can throw 62054684ddb6SLionel Sambuc __b_.reserve (__rhs.__b_.size ()); 62064684ddb6SLionel Sambuc __densities_.reserve(__rhs.__densities_.size()); 62074684ddb6SLionel Sambuc __areas_.reserve (__rhs.__areas_.size()); 62084684ddb6SLionel Sambuc 62094684ddb6SLionel Sambuc// These can not throw 62104684ddb6SLionel Sambuc __b_ = __rhs.__b_; 62114684ddb6SLionel Sambuc __densities_ = __rhs.__densities_; 62124684ddb6SLionel Sambuc __areas_ = __rhs.__areas_; 62134684ddb6SLionel Sambuc return *this; 62144684ddb6SLionel Sambuc} 62154684ddb6SLionel Sambuc 62164684ddb6SLionel Sambuctemplate<class _RealType> 62174684ddb6SLionel Sambucvoid 62184684ddb6SLionel Sambucpiecewise_constant_distribution<_RealType>::param_type::__init() 62194684ddb6SLionel Sambuc{ 62204684ddb6SLionel Sambuc // __densities_ contains non-normalized areas 62214684ddb6SLionel Sambuc result_type __total_area = _VSTD::accumulate(__densities_.begin(), 62224684ddb6SLionel Sambuc __densities_.end(), 62234684ddb6SLionel Sambuc result_type()); 62244684ddb6SLionel Sambuc for (size_t __i = 0; __i < __densities_.size(); ++__i) 62254684ddb6SLionel Sambuc __densities_[__i] /= __total_area; 62264684ddb6SLionel Sambuc // __densities_ contains normalized areas 62274684ddb6SLionel Sambuc __areas_.assign(__densities_.size(), result_type()); 62284684ddb6SLionel Sambuc _VSTD::partial_sum(__densities_.begin(), __densities_.end() - 1, 62294684ddb6SLionel Sambuc __areas_.begin() + 1); 62304684ddb6SLionel Sambuc // __areas_ contains partial sums of normalized areas: [0, __densities_ - 1] 62314684ddb6SLionel Sambuc __densities_.back() = 1 - __areas_.back(); // correct round off error 62324684ddb6SLionel Sambuc for (size_t __i = 0; __i < __densities_.size(); ++__i) 62334684ddb6SLionel Sambuc __densities_[__i] /= (__b_[__i+1] - __b_[__i]); 62344684ddb6SLionel Sambuc // __densities_ now contains __densities_ 62354684ddb6SLionel Sambuc} 62364684ddb6SLionel Sambuc 62374684ddb6SLionel Sambuctemplate<class _RealType> 62384684ddb6SLionel Sambucpiecewise_constant_distribution<_RealType>::param_type::param_type() 62394684ddb6SLionel Sambuc : __b_(2), 62404684ddb6SLionel Sambuc __densities_(1, 1.0), 62414684ddb6SLionel Sambuc __areas_(1, 0.0) 62424684ddb6SLionel Sambuc{ 62434684ddb6SLionel Sambuc __b_[1] = 1; 62444684ddb6SLionel Sambuc} 62454684ddb6SLionel Sambuc 62464684ddb6SLionel Sambuctemplate<class _RealType> 62474684ddb6SLionel Sambuctemplate<class _InputIteratorB, class _InputIteratorW> 62484684ddb6SLionel Sambucpiecewise_constant_distribution<_RealType>::param_type::param_type( 62494684ddb6SLionel Sambuc _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW) 62504684ddb6SLionel Sambuc : __b_(__fB, __lB) 62514684ddb6SLionel Sambuc{ 62524684ddb6SLionel Sambuc if (__b_.size() < 2) 62534684ddb6SLionel Sambuc { 62544684ddb6SLionel Sambuc __b_.resize(2); 62554684ddb6SLionel Sambuc __b_[0] = 0; 62564684ddb6SLionel Sambuc __b_[1] = 1; 62574684ddb6SLionel Sambuc __densities_.assign(1, 1.0); 62584684ddb6SLionel Sambuc __areas_.assign(1, 0.0); 62594684ddb6SLionel Sambuc } 62604684ddb6SLionel Sambuc else 62614684ddb6SLionel Sambuc { 62624684ddb6SLionel Sambuc __densities_.reserve(__b_.size() - 1); 62634684ddb6SLionel Sambuc for (size_t __i = 0; __i < __b_.size() - 1; ++__i, ++__fW) 62644684ddb6SLionel Sambuc __densities_.push_back(*__fW); 62654684ddb6SLionel Sambuc __init(); 62664684ddb6SLionel Sambuc } 62674684ddb6SLionel Sambuc} 62684684ddb6SLionel Sambuc 62694684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 62704684ddb6SLionel Sambuc 62714684ddb6SLionel Sambuctemplate<class _RealType> 62724684ddb6SLionel Sambuctemplate<class _UnaryOperation> 62734684ddb6SLionel Sambucpiecewise_constant_distribution<_RealType>::param_type::param_type( 62744684ddb6SLionel Sambuc initializer_list<result_type> __bl, _UnaryOperation __fw) 62754684ddb6SLionel Sambuc : __b_(__bl.begin(), __bl.end()) 62764684ddb6SLionel Sambuc{ 62774684ddb6SLionel Sambuc if (__b_.size() < 2) 62784684ddb6SLionel Sambuc { 62794684ddb6SLionel Sambuc __b_.resize(2); 62804684ddb6SLionel Sambuc __b_[0] = 0; 62814684ddb6SLionel Sambuc __b_[1] = 1; 62824684ddb6SLionel Sambuc __densities_.assign(1, 1.0); 62834684ddb6SLionel Sambuc __areas_.assign(1, 0.0); 62844684ddb6SLionel Sambuc } 62854684ddb6SLionel Sambuc else 62864684ddb6SLionel Sambuc { 62874684ddb6SLionel Sambuc __densities_.reserve(__b_.size() - 1); 62884684ddb6SLionel Sambuc for (size_t __i = 0; __i < __b_.size() - 1; ++__i) 62894684ddb6SLionel Sambuc __densities_.push_back(__fw((__b_[__i+1] + __b_[__i])*.5)); 62904684ddb6SLionel Sambuc __init(); 62914684ddb6SLionel Sambuc } 62924684ddb6SLionel Sambuc} 62934684ddb6SLionel Sambuc 62944684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 62954684ddb6SLionel Sambuc 62964684ddb6SLionel Sambuctemplate<class _RealType> 62974684ddb6SLionel Sambuctemplate<class _UnaryOperation> 62984684ddb6SLionel Sambucpiecewise_constant_distribution<_RealType>::param_type::param_type( 62994684ddb6SLionel Sambuc size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw) 63004684ddb6SLionel Sambuc : __b_(__nw == 0 ? 2 : __nw + 1) 63014684ddb6SLionel Sambuc{ 63024684ddb6SLionel Sambuc size_t __n = __b_.size() - 1; 63034684ddb6SLionel Sambuc result_type __d = (__xmax - __xmin) / __n; 63044684ddb6SLionel Sambuc __densities_.reserve(__n); 63054684ddb6SLionel Sambuc for (size_t __i = 0; __i < __n; ++__i) 63064684ddb6SLionel Sambuc { 63074684ddb6SLionel Sambuc __b_[__i] = __xmin + __i * __d; 63084684ddb6SLionel Sambuc __densities_.push_back(__fw(__b_[__i] + __d*.5)); 63094684ddb6SLionel Sambuc } 63104684ddb6SLionel Sambuc __b_[__n] = __xmax; 63114684ddb6SLionel Sambuc __init(); 63124684ddb6SLionel Sambuc} 63134684ddb6SLionel Sambuc 63144684ddb6SLionel Sambuctemplate<class _RealType> 63154684ddb6SLionel Sambuctemplate<class _URNG> 63164684ddb6SLionel Sambuc_RealType 63174684ddb6SLionel Sambucpiecewise_constant_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 63184684ddb6SLionel Sambuc{ 63194684ddb6SLionel Sambuc typedef uniform_real_distribution<result_type> _Gen; 63204684ddb6SLionel Sambuc result_type __u = _Gen()(__g); 63214684ddb6SLionel Sambuc ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(), 63224684ddb6SLionel Sambuc __u) - __p.__areas_.begin() - 1; 63234684ddb6SLionel Sambuc return (__u - __p.__areas_[__k]) / __p.__densities_[__k] + __p.__b_[__k]; 63244684ddb6SLionel Sambuc} 63254684ddb6SLionel Sambuc 63264684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _RT> 63274684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 63284684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 63294684ddb6SLionel Sambuc const piecewise_constant_distribution<_RT>& __x) 63304684ddb6SLionel Sambuc{ 63314684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__os); 63324684ddb6SLionel Sambuc __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 63334684ddb6SLionel Sambuc ios_base::scientific); 63344684ddb6SLionel Sambuc _CharT __sp = __os.widen(' '); 63354684ddb6SLionel Sambuc __os.fill(__sp); 63364684ddb6SLionel Sambuc size_t __n = __x.__p_.__b_.size(); 63374684ddb6SLionel Sambuc __os << __n; 63384684ddb6SLionel Sambuc for (size_t __i = 0; __i < __n; ++__i) 63394684ddb6SLionel Sambuc __os << __sp << __x.__p_.__b_[__i]; 63404684ddb6SLionel Sambuc __n = __x.__p_.__densities_.size(); 63414684ddb6SLionel Sambuc __os << __sp << __n; 63424684ddb6SLionel Sambuc for (size_t __i = 0; __i < __n; ++__i) 63434684ddb6SLionel Sambuc __os << __sp << __x.__p_.__densities_[__i]; 63444684ddb6SLionel Sambuc __n = __x.__p_.__areas_.size(); 63454684ddb6SLionel Sambuc __os << __sp << __n; 63464684ddb6SLionel Sambuc for (size_t __i = 0; __i < __n; ++__i) 63474684ddb6SLionel Sambuc __os << __sp << __x.__p_.__areas_[__i]; 63484684ddb6SLionel Sambuc return __os; 63494684ddb6SLionel Sambuc} 63504684ddb6SLionel Sambuc 63514684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _RT> 63524684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 63534684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 63544684ddb6SLionel Sambuc piecewise_constant_distribution<_RT>& __x) 63554684ddb6SLionel Sambuc{ 63564684ddb6SLionel Sambuc typedef piecewise_constant_distribution<_RT> _Eng; 63574684ddb6SLionel Sambuc typedef typename _Eng::result_type result_type; 63584684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__is); 63594684ddb6SLionel Sambuc __is.flags(ios_base::dec | ios_base::skipws); 63604684ddb6SLionel Sambuc size_t __n; 63614684ddb6SLionel Sambuc __is >> __n; 63624684ddb6SLionel Sambuc vector<result_type> __b(__n); 63634684ddb6SLionel Sambuc for (size_t __i = 0; __i < __n; ++__i) 63644684ddb6SLionel Sambuc __is >> __b[__i]; 63654684ddb6SLionel Sambuc __is >> __n; 63664684ddb6SLionel Sambuc vector<result_type> __densities(__n); 63674684ddb6SLionel Sambuc for (size_t __i = 0; __i < __n; ++__i) 63684684ddb6SLionel Sambuc __is >> __densities[__i]; 63694684ddb6SLionel Sambuc __is >> __n; 63704684ddb6SLionel Sambuc vector<result_type> __areas(__n); 63714684ddb6SLionel Sambuc for (size_t __i = 0; __i < __n; ++__i) 63724684ddb6SLionel Sambuc __is >> __areas[__i]; 63734684ddb6SLionel Sambuc if (!__is.fail()) 63744684ddb6SLionel Sambuc { 63754684ddb6SLionel Sambuc swap(__x.__p_.__b_, __b); 63764684ddb6SLionel Sambuc swap(__x.__p_.__densities_, __densities); 63774684ddb6SLionel Sambuc swap(__x.__p_.__areas_, __areas); 63784684ddb6SLionel Sambuc } 63794684ddb6SLionel Sambuc return __is; 63804684ddb6SLionel Sambuc} 63814684ddb6SLionel Sambuc 63824684ddb6SLionel Sambuc// piecewise_linear_distribution 63834684ddb6SLionel Sambuc 63844684ddb6SLionel Sambuctemplate<class _RealType = double> 63854684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY piecewise_linear_distribution 63864684ddb6SLionel Sambuc{ 63874684ddb6SLionel Sambucpublic: 63884684ddb6SLionel Sambuc // types 63894684ddb6SLionel Sambuc typedef _RealType result_type; 63904684ddb6SLionel Sambuc 63914684ddb6SLionel Sambuc class _LIBCPP_TYPE_VIS_ONLY param_type 63924684ddb6SLionel Sambuc { 63934684ddb6SLionel Sambuc vector<result_type> __b_; 63944684ddb6SLionel Sambuc vector<result_type> __densities_; 63954684ddb6SLionel Sambuc vector<result_type> __areas_; 63964684ddb6SLionel Sambuc public: 63974684ddb6SLionel Sambuc typedef piecewise_linear_distribution distribution_type; 63984684ddb6SLionel Sambuc 63994684ddb6SLionel Sambuc param_type(); 64004684ddb6SLionel Sambuc template<class _InputIteratorB, class _InputIteratorW> 64014684ddb6SLionel Sambuc param_type(_InputIteratorB __fB, _InputIteratorB __lB, 64024684ddb6SLionel Sambuc _InputIteratorW __fW); 64034684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 64044684ddb6SLionel Sambuc template<class _UnaryOperation> 64054684ddb6SLionel Sambuc param_type(initializer_list<result_type> __bl, _UnaryOperation __fw); 64064684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 64074684ddb6SLionel Sambuc template<class _UnaryOperation> 64084684ddb6SLionel Sambuc param_type(size_t __nw, result_type __xmin, result_type __xmax, 64094684ddb6SLionel Sambuc _UnaryOperation __fw); 64104684ddb6SLionel Sambuc param_type & operator=(const param_type& __rhs); 64114684ddb6SLionel Sambuc 64124684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 64134684ddb6SLionel Sambuc vector<result_type> intervals() const {return __b_;} 64144684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 64154684ddb6SLionel Sambuc vector<result_type> densities() const {return __densities_;} 64164684ddb6SLionel Sambuc 64174684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 64184684ddb6SLionel Sambuc bool operator==(const param_type& __x, const param_type& __y) 64194684ddb6SLionel Sambuc {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;} 64204684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 64214684ddb6SLionel Sambuc bool operator!=(const param_type& __x, const param_type& __y) 64224684ddb6SLionel Sambuc {return !(__x == __y);} 64234684ddb6SLionel Sambuc 64244684ddb6SLionel Sambuc private: 64254684ddb6SLionel Sambuc void __init(); 64264684ddb6SLionel Sambuc 64274684ddb6SLionel Sambuc friend class piecewise_linear_distribution; 64284684ddb6SLionel Sambuc 64294684ddb6SLionel Sambuc template <class _CharT, class _Traits, class _RT> 64304684ddb6SLionel Sambuc friend 64314684ddb6SLionel Sambuc basic_ostream<_CharT, _Traits>& 64324684ddb6SLionel Sambuc operator<<(basic_ostream<_CharT, _Traits>& __os, 64334684ddb6SLionel Sambuc const piecewise_linear_distribution<_RT>& __x); 64344684ddb6SLionel Sambuc 64354684ddb6SLionel Sambuc template <class _CharT, class _Traits, class _RT> 64364684ddb6SLionel Sambuc friend 64374684ddb6SLionel Sambuc basic_istream<_CharT, _Traits>& 64384684ddb6SLionel Sambuc operator>>(basic_istream<_CharT, _Traits>& __is, 64394684ddb6SLionel Sambuc piecewise_linear_distribution<_RT>& __x); 64404684ddb6SLionel Sambuc }; 64414684ddb6SLionel Sambuc 64424684ddb6SLionel Sambucprivate: 64434684ddb6SLionel Sambuc param_type __p_; 64444684ddb6SLionel Sambuc 64454684ddb6SLionel Sambucpublic: 64464684ddb6SLionel Sambuc // constructor and reset functions 64474684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 64484684ddb6SLionel Sambuc piecewise_linear_distribution() {} 64494684ddb6SLionel Sambuc template<class _InputIteratorB, class _InputIteratorW> 64504684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 64514684ddb6SLionel Sambuc piecewise_linear_distribution(_InputIteratorB __fB, 64524684ddb6SLionel Sambuc _InputIteratorB __lB, 64534684ddb6SLionel Sambuc _InputIteratorW __fW) 64544684ddb6SLionel Sambuc : __p_(__fB, __lB, __fW) {} 64554684ddb6SLionel Sambuc 64564684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 64574684ddb6SLionel Sambuc template<class _UnaryOperation> 64584684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 64594684ddb6SLionel Sambuc piecewise_linear_distribution(initializer_list<result_type> __bl, 64604684ddb6SLionel Sambuc _UnaryOperation __fw) 64614684ddb6SLionel Sambuc : __p_(__bl, __fw) {} 64624684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 64634684ddb6SLionel Sambuc 64644684ddb6SLionel Sambuc template<class _UnaryOperation> 64654684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 64664684ddb6SLionel Sambuc piecewise_linear_distribution(size_t __nw, result_type __xmin, 64674684ddb6SLionel Sambuc result_type __xmax, _UnaryOperation __fw) 64684684ddb6SLionel Sambuc : __p_(__nw, __xmin, __xmax, __fw) {} 64694684ddb6SLionel Sambuc 64704684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 64714684ddb6SLionel Sambuc explicit piecewise_linear_distribution(const param_type& __p) 64724684ddb6SLionel Sambuc : __p_(__p) {} 64734684ddb6SLionel Sambuc 64744684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 64754684ddb6SLionel Sambuc void reset() {} 64764684ddb6SLionel Sambuc 64774684ddb6SLionel Sambuc // generating functions 64784684ddb6SLionel Sambuc template<class _URNG> 64794684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 64804684ddb6SLionel Sambuc result_type operator()(_URNG& __g) 64814684ddb6SLionel Sambuc {return (*this)(__g, __p_);} 64824684ddb6SLionel Sambuc template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 64834684ddb6SLionel Sambuc 64844684ddb6SLionel Sambuc // property functions 64854684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 64864684ddb6SLionel Sambuc vector<result_type> intervals() const {return __p_.intervals();} 64874684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 64884684ddb6SLionel Sambuc vector<result_type> densities() const {return __p_.densities();} 64894684ddb6SLionel Sambuc 64904684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 64914684ddb6SLionel Sambuc param_type param() const {return __p_;} 64924684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 64934684ddb6SLionel Sambuc void param(const param_type& __p) {__p_ = __p;} 64944684ddb6SLionel Sambuc 64954684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 64964684ddb6SLionel Sambuc result_type min() const {return __p_.__b_.front();} 64974684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 64984684ddb6SLionel Sambuc result_type max() const {return __p_.__b_.back();} 64994684ddb6SLionel Sambuc 65004684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 65014684ddb6SLionel Sambuc bool operator==(const piecewise_linear_distribution& __x, 65024684ddb6SLionel Sambuc const piecewise_linear_distribution& __y) 65034684ddb6SLionel Sambuc {return __x.__p_ == __y.__p_;} 65044684ddb6SLionel Sambuc friend _LIBCPP_INLINE_VISIBILITY 65054684ddb6SLionel Sambuc bool operator!=(const piecewise_linear_distribution& __x, 65064684ddb6SLionel Sambuc const piecewise_linear_distribution& __y) 65074684ddb6SLionel Sambuc {return !(__x == __y);} 65084684ddb6SLionel Sambuc 65094684ddb6SLionel Sambuc template <class _CharT, class _Traits, class _RT> 65104684ddb6SLionel Sambuc friend 65114684ddb6SLionel Sambuc basic_ostream<_CharT, _Traits>& 65124684ddb6SLionel Sambuc operator<<(basic_ostream<_CharT, _Traits>& __os, 65134684ddb6SLionel Sambuc const piecewise_linear_distribution<_RT>& __x); 65144684ddb6SLionel Sambuc 65154684ddb6SLionel Sambuc template <class _CharT, class _Traits, class _RT> 65164684ddb6SLionel Sambuc friend 65174684ddb6SLionel Sambuc basic_istream<_CharT, _Traits>& 65184684ddb6SLionel Sambuc operator>>(basic_istream<_CharT, _Traits>& __is, 65194684ddb6SLionel Sambuc piecewise_linear_distribution<_RT>& __x); 65204684ddb6SLionel Sambuc}; 65214684ddb6SLionel Sambuc 65224684ddb6SLionel Sambuctemplate<class _RealType> 65234684ddb6SLionel Sambuctypename piecewise_linear_distribution<_RealType>::param_type & 65244684ddb6SLionel Sambucpiecewise_linear_distribution<_RealType>::param_type::operator= 65254684ddb6SLionel Sambuc (const param_type& __rhs) 65264684ddb6SLionel Sambuc{ 65274684ddb6SLionel Sambuc// These can throw 65284684ddb6SLionel Sambuc __b_.reserve (__rhs.__b_.size ()); 65294684ddb6SLionel Sambuc __densities_.reserve(__rhs.__densities_.size()); 65304684ddb6SLionel Sambuc __areas_.reserve (__rhs.__areas_.size()); 65314684ddb6SLionel Sambuc 65324684ddb6SLionel Sambuc// These can not throw 65334684ddb6SLionel Sambuc __b_ = __rhs.__b_; 65344684ddb6SLionel Sambuc __densities_ = __rhs.__densities_; 65354684ddb6SLionel Sambuc __areas_ = __rhs.__areas_; 65364684ddb6SLionel Sambuc return *this; 65374684ddb6SLionel Sambuc} 65384684ddb6SLionel Sambuc 65394684ddb6SLionel Sambuc 65404684ddb6SLionel Sambuctemplate<class _RealType> 65414684ddb6SLionel Sambucvoid 65424684ddb6SLionel Sambucpiecewise_linear_distribution<_RealType>::param_type::__init() 65434684ddb6SLionel Sambuc{ 65444684ddb6SLionel Sambuc __areas_.assign(__densities_.size() - 1, result_type()); 65454684ddb6SLionel Sambuc result_type _Sp = 0; 65464684ddb6SLionel Sambuc for (size_t __i = 0; __i < __areas_.size(); ++__i) 65474684ddb6SLionel Sambuc { 65484684ddb6SLionel Sambuc __areas_[__i] = (__densities_[__i+1] + __densities_[__i]) * 65494684ddb6SLionel Sambuc (__b_[__i+1] - __b_[__i]) * .5; 65504684ddb6SLionel Sambuc _Sp += __areas_[__i]; 65514684ddb6SLionel Sambuc } 65524684ddb6SLionel Sambuc for (size_t __i = __areas_.size(); __i > 1;) 65534684ddb6SLionel Sambuc { 65544684ddb6SLionel Sambuc --__i; 65554684ddb6SLionel Sambuc __areas_[__i] = __areas_[__i-1] / _Sp; 65564684ddb6SLionel Sambuc } 65574684ddb6SLionel Sambuc __areas_[0] = 0; 65584684ddb6SLionel Sambuc for (size_t __i = 1; __i < __areas_.size(); ++__i) 65594684ddb6SLionel Sambuc __areas_[__i] += __areas_[__i-1]; 65604684ddb6SLionel Sambuc for (size_t __i = 0; __i < __densities_.size(); ++__i) 65614684ddb6SLionel Sambuc __densities_[__i] /= _Sp; 65624684ddb6SLionel Sambuc} 65634684ddb6SLionel Sambuc 65644684ddb6SLionel Sambuctemplate<class _RealType> 65654684ddb6SLionel Sambucpiecewise_linear_distribution<_RealType>::param_type::param_type() 65664684ddb6SLionel Sambuc : __b_(2), 65674684ddb6SLionel Sambuc __densities_(2, 1.0), 65684684ddb6SLionel Sambuc __areas_(1, 0.0) 65694684ddb6SLionel Sambuc{ 65704684ddb6SLionel Sambuc __b_[1] = 1; 65714684ddb6SLionel Sambuc} 65724684ddb6SLionel Sambuc 65734684ddb6SLionel Sambuctemplate<class _RealType> 65744684ddb6SLionel Sambuctemplate<class _InputIteratorB, class _InputIteratorW> 65754684ddb6SLionel Sambucpiecewise_linear_distribution<_RealType>::param_type::param_type( 65764684ddb6SLionel Sambuc _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW) 65774684ddb6SLionel Sambuc : __b_(__fB, __lB) 65784684ddb6SLionel Sambuc{ 65794684ddb6SLionel Sambuc if (__b_.size() < 2) 65804684ddb6SLionel Sambuc { 65814684ddb6SLionel Sambuc __b_.resize(2); 65824684ddb6SLionel Sambuc __b_[0] = 0; 65834684ddb6SLionel Sambuc __b_[1] = 1; 65844684ddb6SLionel Sambuc __densities_.assign(2, 1.0); 65854684ddb6SLionel Sambuc __areas_.assign(1, 0.0); 65864684ddb6SLionel Sambuc } 65874684ddb6SLionel Sambuc else 65884684ddb6SLionel Sambuc { 65894684ddb6SLionel Sambuc __densities_.reserve(__b_.size()); 65904684ddb6SLionel Sambuc for (size_t __i = 0; __i < __b_.size(); ++__i, ++__fW) 65914684ddb6SLionel Sambuc __densities_.push_back(*__fW); 65924684ddb6SLionel Sambuc __init(); 65934684ddb6SLionel Sambuc } 65944684ddb6SLionel Sambuc} 65954684ddb6SLionel Sambuc 65964684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 65974684ddb6SLionel Sambuc 65984684ddb6SLionel Sambuctemplate<class _RealType> 65994684ddb6SLionel Sambuctemplate<class _UnaryOperation> 66004684ddb6SLionel Sambucpiecewise_linear_distribution<_RealType>::param_type::param_type( 66014684ddb6SLionel Sambuc initializer_list<result_type> __bl, _UnaryOperation __fw) 66024684ddb6SLionel Sambuc : __b_(__bl.begin(), __bl.end()) 66034684ddb6SLionel Sambuc{ 66044684ddb6SLionel Sambuc if (__b_.size() < 2) 66054684ddb6SLionel Sambuc { 66064684ddb6SLionel Sambuc __b_.resize(2); 66074684ddb6SLionel Sambuc __b_[0] = 0; 66084684ddb6SLionel Sambuc __b_[1] = 1; 66094684ddb6SLionel Sambuc __densities_.assign(2, 1.0); 66104684ddb6SLionel Sambuc __areas_.assign(1, 0.0); 66114684ddb6SLionel Sambuc } 66124684ddb6SLionel Sambuc else 66134684ddb6SLionel Sambuc { 66144684ddb6SLionel Sambuc __densities_.reserve(__b_.size()); 66154684ddb6SLionel Sambuc for (size_t __i = 0; __i < __b_.size(); ++__i) 66164684ddb6SLionel Sambuc __densities_.push_back(__fw(__b_[__i])); 66174684ddb6SLionel Sambuc __init(); 66184684ddb6SLionel Sambuc } 66194684ddb6SLionel Sambuc} 66204684ddb6SLionel Sambuc 66214684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 66224684ddb6SLionel Sambuc 66234684ddb6SLionel Sambuctemplate<class _RealType> 66244684ddb6SLionel Sambuctemplate<class _UnaryOperation> 66254684ddb6SLionel Sambucpiecewise_linear_distribution<_RealType>::param_type::param_type( 66264684ddb6SLionel Sambuc size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw) 66274684ddb6SLionel Sambuc : __b_(__nw == 0 ? 2 : __nw + 1) 66284684ddb6SLionel Sambuc{ 66294684ddb6SLionel Sambuc size_t __n = __b_.size() - 1; 66304684ddb6SLionel Sambuc result_type __d = (__xmax - __xmin) / __n; 66314684ddb6SLionel Sambuc __densities_.reserve(__b_.size()); 66324684ddb6SLionel Sambuc for (size_t __i = 0; __i < __n; ++__i) 66334684ddb6SLionel Sambuc { 66344684ddb6SLionel Sambuc __b_[__i] = __xmin + __i * __d; 66354684ddb6SLionel Sambuc __densities_.push_back(__fw(__b_[__i])); 66364684ddb6SLionel Sambuc } 66374684ddb6SLionel Sambuc __b_[__n] = __xmax; 66384684ddb6SLionel Sambuc __densities_.push_back(__fw(__b_[__n])); 66394684ddb6SLionel Sambuc __init(); 66404684ddb6SLionel Sambuc} 66414684ddb6SLionel Sambuc 66424684ddb6SLionel Sambuctemplate<class _RealType> 66434684ddb6SLionel Sambuctemplate<class _URNG> 66444684ddb6SLionel Sambuc_RealType 66454684ddb6SLionel Sambucpiecewise_linear_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 66464684ddb6SLionel Sambuc{ 66474684ddb6SLionel Sambuc typedef uniform_real_distribution<result_type> _Gen; 66484684ddb6SLionel Sambuc result_type __u = _Gen()(__g); 66494684ddb6SLionel Sambuc ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(), 66504684ddb6SLionel Sambuc __u) - __p.__areas_.begin() - 1; 66514684ddb6SLionel Sambuc __u -= __p.__areas_[__k]; 66524684ddb6SLionel Sambuc const result_type __dk = __p.__densities_[__k]; 66534684ddb6SLionel Sambuc const result_type __dk1 = __p.__densities_[__k+1]; 66544684ddb6SLionel Sambuc const result_type __deltad = __dk1 - __dk; 66554684ddb6SLionel Sambuc const result_type __bk = __p.__b_[__k]; 66564684ddb6SLionel Sambuc if (__deltad == 0) 66574684ddb6SLionel Sambuc return __u / __dk + __bk; 66584684ddb6SLionel Sambuc const result_type __bk1 = __p.__b_[__k+1]; 66594684ddb6SLionel Sambuc const result_type __deltab = __bk1 - __bk; 66604684ddb6SLionel Sambuc return (__bk * __dk1 - __bk1 * __dk + 66614684ddb6SLionel Sambuc _VSTD::sqrt(__deltab * (__deltab * __dk * __dk + 2 * __deltad * __u))) / 66624684ddb6SLionel Sambuc __deltad; 66634684ddb6SLionel Sambuc} 66644684ddb6SLionel Sambuc 66654684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _RT> 66664684ddb6SLionel Sambucbasic_ostream<_CharT, _Traits>& 66674684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _Traits>& __os, 66684684ddb6SLionel Sambuc const piecewise_linear_distribution<_RT>& __x) 66694684ddb6SLionel Sambuc{ 66704684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__os); 66714684ddb6SLionel Sambuc __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 66724684ddb6SLionel Sambuc ios_base::scientific); 66734684ddb6SLionel Sambuc _CharT __sp = __os.widen(' '); 66744684ddb6SLionel Sambuc __os.fill(__sp); 66754684ddb6SLionel Sambuc size_t __n = __x.__p_.__b_.size(); 66764684ddb6SLionel Sambuc __os << __n; 66774684ddb6SLionel Sambuc for (size_t __i = 0; __i < __n; ++__i) 66784684ddb6SLionel Sambuc __os << __sp << __x.__p_.__b_[__i]; 66794684ddb6SLionel Sambuc __n = __x.__p_.__densities_.size(); 66804684ddb6SLionel Sambuc __os << __sp << __n; 66814684ddb6SLionel Sambuc for (size_t __i = 0; __i < __n; ++__i) 66824684ddb6SLionel Sambuc __os << __sp << __x.__p_.__densities_[__i]; 66834684ddb6SLionel Sambuc __n = __x.__p_.__areas_.size(); 66844684ddb6SLionel Sambuc __os << __sp << __n; 66854684ddb6SLionel Sambuc for (size_t __i = 0; __i < __n; ++__i) 66864684ddb6SLionel Sambuc __os << __sp << __x.__p_.__areas_[__i]; 66874684ddb6SLionel Sambuc return __os; 66884684ddb6SLionel Sambuc} 66894684ddb6SLionel Sambuc 66904684ddb6SLionel Sambuctemplate <class _CharT, class _Traits, class _RT> 66914684ddb6SLionel Sambucbasic_istream<_CharT, _Traits>& 66924684ddb6SLionel Sambucoperator>>(basic_istream<_CharT, _Traits>& __is, 66934684ddb6SLionel Sambuc piecewise_linear_distribution<_RT>& __x) 66944684ddb6SLionel Sambuc{ 66954684ddb6SLionel Sambuc typedef piecewise_linear_distribution<_RT> _Eng; 66964684ddb6SLionel Sambuc typedef typename _Eng::result_type result_type; 66974684ddb6SLionel Sambuc __save_flags<_CharT, _Traits> __lx(__is); 66984684ddb6SLionel Sambuc __is.flags(ios_base::dec | ios_base::skipws); 66994684ddb6SLionel Sambuc size_t __n; 67004684ddb6SLionel Sambuc __is >> __n; 67014684ddb6SLionel Sambuc vector<result_type> __b(__n); 67024684ddb6SLionel Sambuc for (size_t __i = 0; __i < __n; ++__i) 67034684ddb6SLionel Sambuc __is >> __b[__i]; 67044684ddb6SLionel Sambuc __is >> __n; 67054684ddb6SLionel Sambuc vector<result_type> __densities(__n); 67064684ddb6SLionel Sambuc for (size_t __i = 0; __i < __n; ++__i) 67074684ddb6SLionel Sambuc __is >> __densities[__i]; 67084684ddb6SLionel Sambuc __is >> __n; 67094684ddb6SLionel Sambuc vector<result_type> __areas(__n); 67104684ddb6SLionel Sambuc for (size_t __i = 0; __i < __n; ++__i) 67114684ddb6SLionel Sambuc __is >> __areas[__i]; 67124684ddb6SLionel Sambuc if (!__is.fail()) 67134684ddb6SLionel Sambuc { 67144684ddb6SLionel Sambuc swap(__x.__p_.__b_, __b); 67154684ddb6SLionel Sambuc swap(__x.__p_.__densities_, __densities); 67164684ddb6SLionel Sambuc swap(__x.__p_.__areas_, __areas); 67174684ddb6SLionel Sambuc } 67184684ddb6SLionel Sambuc return __is; 67194684ddb6SLionel Sambuc} 67204684ddb6SLionel Sambuc 67214684ddb6SLionel Sambuc_LIBCPP_END_NAMESPACE_STD 67224684ddb6SLionel Sambuc 67234684ddb6SLionel Sambuc#endif // _LIBCPP_RANDOM 6724