1*0b57cec5SDimitry Andric// -*- C++ -*- 2*0b57cec5SDimitry Andric//===--------------------------- random -----------------------------------===// 3*0b57cec5SDimitry Andric// 4*0b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5*0b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 6*0b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7*0b57cec5SDimitry Andric// 8*0b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 9*0b57cec5SDimitry Andric 10*0b57cec5SDimitry Andric#ifndef _LIBCPP_RANDOM 11*0b57cec5SDimitry Andric#define _LIBCPP_RANDOM 12*0b57cec5SDimitry Andric 13*0b57cec5SDimitry Andric/* 14*0b57cec5SDimitry Andric random synopsis 15*0b57cec5SDimitry Andric 16*0b57cec5SDimitry Andric#include <initializer_list> 17*0b57cec5SDimitry Andric 18*0b57cec5SDimitry Andricnamespace std 19*0b57cec5SDimitry Andric{ 20*0b57cec5SDimitry Andric 21*0b57cec5SDimitry Andric// Engines 22*0b57cec5SDimitry Andric 23*0b57cec5SDimitry Andrictemplate <class UIntType, UIntType a, UIntType c, UIntType m> 24*0b57cec5SDimitry Andricclass linear_congruential_engine 25*0b57cec5SDimitry Andric{ 26*0b57cec5SDimitry Andricpublic: 27*0b57cec5SDimitry Andric // types 28*0b57cec5SDimitry Andric typedef UIntType result_type; 29*0b57cec5SDimitry Andric 30*0b57cec5SDimitry Andric // engine characteristics 31*0b57cec5SDimitry Andric static constexpr result_type multiplier = a; 32*0b57cec5SDimitry Andric static constexpr result_type increment = c; 33*0b57cec5SDimitry Andric static constexpr result_type modulus = m; 34*0b57cec5SDimitry Andric static constexpr result_type min() { return c == 0u ? 1u: 0u;} 35*0b57cec5SDimitry Andric static constexpr result_type max() { return m - 1u;} 36*0b57cec5SDimitry Andric static constexpr result_type default_seed = 1u; 37*0b57cec5SDimitry Andric 38*0b57cec5SDimitry Andric // constructors and seeding functions 39*0b57cec5SDimitry Andric explicit linear_congruential_engine(result_type s = default_seed); 40*0b57cec5SDimitry Andric template<class Sseq> explicit linear_congruential_engine(Sseq& q); 41*0b57cec5SDimitry Andric void seed(result_type s = default_seed); 42*0b57cec5SDimitry Andric template<class Sseq> void seed(Sseq& q); 43*0b57cec5SDimitry Andric 44*0b57cec5SDimitry Andric // generating functions 45*0b57cec5SDimitry Andric result_type operator()(); 46*0b57cec5SDimitry Andric void discard(unsigned long long z); 47*0b57cec5SDimitry Andric}; 48*0b57cec5SDimitry Andric 49*0b57cec5SDimitry Andrictemplate <class UIntType, UIntType a, UIntType c, UIntType m> 50*0b57cec5SDimitry Andricbool 51*0b57cec5SDimitry Andricoperator==(const linear_congruential_engine<UIntType, a, c, m>& x, 52*0b57cec5SDimitry Andric const linear_congruential_engine<UIntType, a, c, m>& y); 53*0b57cec5SDimitry Andric 54*0b57cec5SDimitry Andrictemplate <class UIntType, UIntType a, UIntType c, UIntType m> 55*0b57cec5SDimitry Andricbool 56*0b57cec5SDimitry Andricoperator!=(const linear_congruential_engine<UIntType, a, c, m>& x, 57*0b57cec5SDimitry Andric const linear_congruential_engine<UIntType, a, c, m>& y); 58*0b57cec5SDimitry Andric 59*0b57cec5SDimitry Andrictemplate <class charT, class traits, 60*0b57cec5SDimitry Andric class UIntType, UIntType a, UIntType c, UIntType m> 61*0b57cec5SDimitry Andricbasic_ostream<charT, traits>& 62*0b57cec5SDimitry Andricoperator<<(basic_ostream<charT, traits>& os, 63*0b57cec5SDimitry Andric const linear_congruential_engine<UIntType, a, c, m>& x); 64*0b57cec5SDimitry Andric 65*0b57cec5SDimitry Andrictemplate <class charT, class traits, 66*0b57cec5SDimitry Andric class UIntType, UIntType a, UIntType c, UIntType m> 67*0b57cec5SDimitry Andricbasic_istream<charT, traits>& 68*0b57cec5SDimitry Andricoperator>>(basic_istream<charT, traits>& is, 69*0b57cec5SDimitry Andric linear_congruential_engine<UIntType, a, c, m>& x); 70*0b57cec5SDimitry Andric 71*0b57cec5SDimitry Andrictemplate <class UIntType, size_t w, size_t n, size_t m, size_t r, 72*0b57cec5SDimitry Andric UIntType a, size_t u, UIntType d, size_t s, 73*0b57cec5SDimitry Andric UIntType b, size_t t, UIntType c, size_t l, UIntType f> 74*0b57cec5SDimitry Andricclass mersenne_twister_engine 75*0b57cec5SDimitry Andric{ 76*0b57cec5SDimitry Andricpublic: 77*0b57cec5SDimitry Andric // types 78*0b57cec5SDimitry Andric typedef UIntType result_type; 79*0b57cec5SDimitry Andric 80*0b57cec5SDimitry Andric // engine characteristics 81*0b57cec5SDimitry Andric static constexpr size_t word_size = w; 82*0b57cec5SDimitry Andric static constexpr size_t state_size = n; 83*0b57cec5SDimitry Andric static constexpr size_t shift_size = m; 84*0b57cec5SDimitry Andric static constexpr size_t mask_bits = r; 85*0b57cec5SDimitry Andric static constexpr result_type xor_mask = a; 86*0b57cec5SDimitry Andric static constexpr size_t tempering_u = u; 87*0b57cec5SDimitry Andric static constexpr result_type tempering_d = d; 88*0b57cec5SDimitry Andric static constexpr size_t tempering_s = s; 89*0b57cec5SDimitry Andric static constexpr result_type tempering_b = b; 90*0b57cec5SDimitry Andric static constexpr size_t tempering_t = t; 91*0b57cec5SDimitry Andric static constexpr result_type tempering_c = c; 92*0b57cec5SDimitry Andric static constexpr size_t tempering_l = l; 93*0b57cec5SDimitry Andric static constexpr result_type initialization_multiplier = f; 94*0b57cec5SDimitry Andric static constexpr result_type min () { return 0; } 95*0b57cec5SDimitry Andric static constexpr result_type max() { return 2^w - 1; } 96*0b57cec5SDimitry Andric static constexpr result_type default_seed = 5489u; 97*0b57cec5SDimitry Andric 98*0b57cec5SDimitry Andric // constructors and seeding functions 99*0b57cec5SDimitry Andric explicit mersenne_twister_engine(result_type value = default_seed); 100*0b57cec5SDimitry Andric template<class Sseq> explicit mersenne_twister_engine(Sseq& q); 101*0b57cec5SDimitry Andric void seed(result_type value = default_seed); 102*0b57cec5SDimitry Andric template<class Sseq> void seed(Sseq& q); 103*0b57cec5SDimitry Andric 104*0b57cec5SDimitry Andric // generating functions 105*0b57cec5SDimitry Andric result_type operator()(); 106*0b57cec5SDimitry Andric void discard(unsigned long long z); 107*0b57cec5SDimitry Andric}; 108*0b57cec5SDimitry Andric 109*0b57cec5SDimitry Andrictemplate <class UIntType, size_t w, size_t n, size_t m, size_t r, 110*0b57cec5SDimitry Andric UIntType a, size_t u, UIntType d, size_t s, 111*0b57cec5SDimitry Andric UIntType b, size_t t, UIntType c, size_t l, UIntType f> 112*0b57cec5SDimitry Andricbool 113*0b57cec5SDimitry Andricoperator==( 114*0b57cec5SDimitry Andric const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x, 115*0b57cec5SDimitry Andric const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& y); 116*0b57cec5SDimitry Andric 117*0b57cec5SDimitry Andrictemplate <class UIntType, size_t w, size_t n, size_t m, size_t r, 118*0b57cec5SDimitry Andric UIntType a, size_t u, UIntType d, size_t s, 119*0b57cec5SDimitry Andric UIntType b, size_t t, UIntType c, size_t l, UIntType f> 120*0b57cec5SDimitry Andricbool 121*0b57cec5SDimitry Andricoperator!=( 122*0b57cec5SDimitry Andric const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x, 123*0b57cec5SDimitry Andric const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& y); 124*0b57cec5SDimitry Andric 125*0b57cec5SDimitry Andrictemplate <class charT, class traits, 126*0b57cec5SDimitry Andric class UIntType, size_t w, size_t n, size_t m, size_t r, 127*0b57cec5SDimitry Andric UIntType a, size_t u, UIntType d, size_t s, 128*0b57cec5SDimitry Andric UIntType b, size_t t, UIntType c, size_t l, UIntType f> 129*0b57cec5SDimitry Andricbasic_ostream<charT, traits>& 130*0b57cec5SDimitry Andricoperator<<(basic_ostream<charT, traits>& os, 131*0b57cec5SDimitry Andric const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x); 132*0b57cec5SDimitry Andric 133*0b57cec5SDimitry Andrictemplate <class charT, class traits, 134*0b57cec5SDimitry Andric class UIntType, size_t w, size_t n, size_t m, size_t r, 135*0b57cec5SDimitry Andric UIntType a, size_t u, UIntType d, size_t s, 136*0b57cec5SDimitry Andric UIntType b, size_t t, UIntType c, size_t l, UIntType f> 137*0b57cec5SDimitry Andricbasic_istream<charT, traits>& 138*0b57cec5SDimitry Andricoperator>>(basic_istream<charT, traits>& is, 139*0b57cec5SDimitry Andric mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x); 140*0b57cec5SDimitry Andric 141*0b57cec5SDimitry Andrictemplate<class UIntType, size_t w, size_t s, size_t r> 142*0b57cec5SDimitry Andricclass subtract_with_carry_engine 143*0b57cec5SDimitry Andric{ 144*0b57cec5SDimitry Andricpublic: 145*0b57cec5SDimitry Andric // types 146*0b57cec5SDimitry Andric typedef UIntType result_type; 147*0b57cec5SDimitry Andric 148*0b57cec5SDimitry Andric // engine characteristics 149*0b57cec5SDimitry Andric static constexpr size_t word_size = w; 150*0b57cec5SDimitry Andric static constexpr size_t short_lag = s; 151*0b57cec5SDimitry Andric static constexpr size_t long_lag = r; 152*0b57cec5SDimitry Andric static constexpr result_type min() { return 0; } 153*0b57cec5SDimitry Andric static constexpr result_type max() { return m-1; } 154*0b57cec5SDimitry Andric static constexpr result_type default_seed = 19780503u; 155*0b57cec5SDimitry Andric 156*0b57cec5SDimitry Andric // constructors and seeding functions 157*0b57cec5SDimitry Andric explicit subtract_with_carry_engine(result_type value = default_seed); 158*0b57cec5SDimitry Andric template<class Sseq> explicit subtract_with_carry_engine(Sseq& q); 159*0b57cec5SDimitry Andric void seed(result_type value = default_seed); 160*0b57cec5SDimitry Andric template<class Sseq> void seed(Sseq& q); 161*0b57cec5SDimitry Andric 162*0b57cec5SDimitry Andric // generating functions 163*0b57cec5SDimitry Andric result_type operator()(); 164*0b57cec5SDimitry Andric void discard(unsigned long long z); 165*0b57cec5SDimitry Andric}; 166*0b57cec5SDimitry Andric 167*0b57cec5SDimitry Andrictemplate<class UIntType, size_t w, size_t s, size_t r> 168*0b57cec5SDimitry Andricbool 169*0b57cec5SDimitry Andricoperator==( 170*0b57cec5SDimitry Andric const subtract_with_carry_engine<UIntType, w, s, r>& x, 171*0b57cec5SDimitry Andric const subtract_with_carry_engine<UIntType, w, s, r>& y); 172*0b57cec5SDimitry Andric 173*0b57cec5SDimitry Andrictemplate<class UIntType, size_t w, size_t s, size_t r> 174*0b57cec5SDimitry Andricbool 175*0b57cec5SDimitry Andricoperator!=( 176*0b57cec5SDimitry Andric const subtract_with_carry_engine<UIntType, w, s, r>& x, 177*0b57cec5SDimitry Andric const subtract_with_carry_engine<UIntType, w, s, r>& y); 178*0b57cec5SDimitry Andric 179*0b57cec5SDimitry Andrictemplate <class charT, class traits, 180*0b57cec5SDimitry Andric class UIntType, size_t w, size_t s, size_t r> 181*0b57cec5SDimitry Andricbasic_ostream<charT, traits>& 182*0b57cec5SDimitry Andricoperator<<(basic_ostream<charT, traits>& os, 183*0b57cec5SDimitry Andric const subtract_with_carry_engine<UIntType, w, s, r>& x); 184*0b57cec5SDimitry Andric 185*0b57cec5SDimitry Andrictemplate <class charT, class traits, 186*0b57cec5SDimitry Andric class UIntType, size_t w, size_t s, size_t r> 187*0b57cec5SDimitry Andricbasic_istream<charT, traits>& 188*0b57cec5SDimitry Andricoperator>>(basic_istream<charT, traits>& is, 189*0b57cec5SDimitry Andric subtract_with_carry_engine<UIntType, w, s, r>& x); 190*0b57cec5SDimitry Andric 191*0b57cec5SDimitry Andrictemplate<class Engine, size_t p, size_t r> 192*0b57cec5SDimitry Andricclass discard_block_engine 193*0b57cec5SDimitry Andric{ 194*0b57cec5SDimitry Andricpublic: 195*0b57cec5SDimitry Andric // types 196*0b57cec5SDimitry Andric typedef typename Engine::result_type result_type; 197*0b57cec5SDimitry Andric 198*0b57cec5SDimitry Andric // engine characteristics 199*0b57cec5SDimitry Andric static constexpr size_t block_size = p; 200*0b57cec5SDimitry Andric static constexpr size_t used_block = r; 201*0b57cec5SDimitry Andric static constexpr result_type min() { return Engine::min(); } 202*0b57cec5SDimitry Andric static constexpr result_type max() { return Engine::max(); } 203*0b57cec5SDimitry Andric 204*0b57cec5SDimitry Andric // constructors and seeding functions 205*0b57cec5SDimitry Andric discard_block_engine(); 206*0b57cec5SDimitry Andric explicit discard_block_engine(const Engine& e); 207*0b57cec5SDimitry Andric explicit discard_block_engine(Engine&& e); 208*0b57cec5SDimitry Andric explicit discard_block_engine(result_type s); 209*0b57cec5SDimitry Andric template<class Sseq> explicit discard_block_engine(Sseq& q); 210*0b57cec5SDimitry Andric void seed(); 211*0b57cec5SDimitry Andric void seed(result_type s); 212*0b57cec5SDimitry Andric template<class Sseq> void seed(Sseq& q); 213*0b57cec5SDimitry Andric 214*0b57cec5SDimitry Andric // generating functions 215*0b57cec5SDimitry Andric result_type operator()(); 216*0b57cec5SDimitry Andric void discard(unsigned long long z); 217*0b57cec5SDimitry Andric 218*0b57cec5SDimitry Andric // property functions 219*0b57cec5SDimitry Andric const Engine& base() const noexcept; 220*0b57cec5SDimitry Andric}; 221*0b57cec5SDimitry Andric 222*0b57cec5SDimitry Andrictemplate<class Engine, size_t p, size_t r> 223*0b57cec5SDimitry Andricbool 224*0b57cec5SDimitry Andricoperator==( 225*0b57cec5SDimitry Andric const discard_block_engine<Engine, p, r>& x, 226*0b57cec5SDimitry Andric const discard_block_engine<Engine, p, r>& y); 227*0b57cec5SDimitry Andric 228*0b57cec5SDimitry Andrictemplate<class Engine, size_t p, size_t r> 229*0b57cec5SDimitry Andricbool 230*0b57cec5SDimitry Andricoperator!=( 231*0b57cec5SDimitry Andric const discard_block_engine<Engine, p, r>& x, 232*0b57cec5SDimitry Andric const discard_block_engine<Engine, p, r>& y); 233*0b57cec5SDimitry Andric 234*0b57cec5SDimitry Andrictemplate <class charT, class traits, 235*0b57cec5SDimitry Andric class Engine, size_t p, size_t r> 236*0b57cec5SDimitry Andricbasic_ostream<charT, traits>& 237*0b57cec5SDimitry Andricoperator<<(basic_ostream<charT, traits>& os, 238*0b57cec5SDimitry Andric const discard_block_engine<Engine, p, r>& x); 239*0b57cec5SDimitry Andric 240*0b57cec5SDimitry Andrictemplate <class charT, class traits, 241*0b57cec5SDimitry Andric class Engine, size_t p, size_t r> 242*0b57cec5SDimitry Andricbasic_istream<charT, traits>& 243*0b57cec5SDimitry Andricoperator>>(basic_istream<charT, traits>& is, 244*0b57cec5SDimitry Andric discard_block_engine<Engine, p, r>& x); 245*0b57cec5SDimitry Andric 246*0b57cec5SDimitry Andrictemplate<class Engine, size_t w, class UIntType> 247*0b57cec5SDimitry Andricclass independent_bits_engine 248*0b57cec5SDimitry Andric{ 249*0b57cec5SDimitry Andricpublic: 250*0b57cec5SDimitry Andric // types 251*0b57cec5SDimitry Andric typedef UIntType result_type; 252*0b57cec5SDimitry Andric 253*0b57cec5SDimitry Andric // engine characteristics 254*0b57cec5SDimitry Andric static constexpr result_type min() { return 0; } 255*0b57cec5SDimitry Andric static constexpr result_type max() { return 2^w - 1; } 256*0b57cec5SDimitry Andric 257*0b57cec5SDimitry Andric // constructors and seeding functions 258*0b57cec5SDimitry Andric independent_bits_engine(); 259*0b57cec5SDimitry Andric explicit independent_bits_engine(const Engine& e); 260*0b57cec5SDimitry Andric explicit independent_bits_engine(Engine&& e); 261*0b57cec5SDimitry Andric explicit independent_bits_engine(result_type s); 262*0b57cec5SDimitry Andric template<class Sseq> explicit independent_bits_engine(Sseq& q); 263*0b57cec5SDimitry Andric void seed(); 264*0b57cec5SDimitry Andric void seed(result_type s); 265*0b57cec5SDimitry Andric template<class Sseq> void seed(Sseq& q); 266*0b57cec5SDimitry Andric 267*0b57cec5SDimitry Andric // generating functions 268*0b57cec5SDimitry Andric result_type operator()(); void discard(unsigned long long z); 269*0b57cec5SDimitry Andric 270*0b57cec5SDimitry Andric // property functions 271*0b57cec5SDimitry Andric const Engine& base() const noexcept; 272*0b57cec5SDimitry Andric}; 273*0b57cec5SDimitry Andric 274*0b57cec5SDimitry Andrictemplate<class Engine, size_t w, class UIntType> 275*0b57cec5SDimitry Andricbool 276*0b57cec5SDimitry Andricoperator==( 277*0b57cec5SDimitry Andric const independent_bits_engine<Engine, w, UIntType>& x, 278*0b57cec5SDimitry Andric const independent_bits_engine<Engine, w, UIntType>& y); 279*0b57cec5SDimitry Andric 280*0b57cec5SDimitry Andrictemplate<class Engine, size_t w, class UIntType> 281*0b57cec5SDimitry Andricbool 282*0b57cec5SDimitry Andricoperator!=( 283*0b57cec5SDimitry Andric const independent_bits_engine<Engine, w, UIntType>& x, 284*0b57cec5SDimitry Andric const independent_bits_engine<Engine, w, UIntType>& y); 285*0b57cec5SDimitry Andric 286*0b57cec5SDimitry Andrictemplate <class charT, class traits, 287*0b57cec5SDimitry Andric class Engine, size_t w, class UIntType> 288*0b57cec5SDimitry Andricbasic_ostream<charT, traits>& 289*0b57cec5SDimitry Andricoperator<<(basic_ostream<charT, traits>& os, 290*0b57cec5SDimitry Andric const independent_bits_engine<Engine, w, UIntType>& x); 291*0b57cec5SDimitry Andric 292*0b57cec5SDimitry Andrictemplate <class charT, class traits, 293*0b57cec5SDimitry Andric class Engine, size_t w, class UIntType> 294*0b57cec5SDimitry Andricbasic_istream<charT, traits>& 295*0b57cec5SDimitry Andricoperator>>(basic_istream<charT, traits>& is, 296*0b57cec5SDimitry Andric independent_bits_engine<Engine, w, UIntType>& x); 297*0b57cec5SDimitry Andric 298*0b57cec5SDimitry Andrictemplate<class Engine, size_t k> 299*0b57cec5SDimitry Andricclass shuffle_order_engine 300*0b57cec5SDimitry Andric{ 301*0b57cec5SDimitry Andricpublic: 302*0b57cec5SDimitry Andric // types 303*0b57cec5SDimitry Andric typedef typename Engine::result_type result_type; 304*0b57cec5SDimitry Andric 305*0b57cec5SDimitry Andric // engine characteristics 306*0b57cec5SDimitry Andric static constexpr size_t table_size = k; 307*0b57cec5SDimitry Andric static constexpr result_type min() { return Engine::min; } 308*0b57cec5SDimitry Andric static constexpr result_type max() { return Engine::max; } 309*0b57cec5SDimitry Andric 310*0b57cec5SDimitry Andric // constructors and seeding functions 311*0b57cec5SDimitry Andric shuffle_order_engine(); 312*0b57cec5SDimitry Andric explicit shuffle_order_engine(const Engine& e); 313*0b57cec5SDimitry Andric explicit shuffle_order_engine(Engine&& e); 314*0b57cec5SDimitry Andric explicit shuffle_order_engine(result_type s); 315*0b57cec5SDimitry Andric template<class Sseq> explicit shuffle_order_engine(Sseq& q); 316*0b57cec5SDimitry Andric void seed(); 317*0b57cec5SDimitry Andric void seed(result_type s); 318*0b57cec5SDimitry Andric template<class Sseq> void seed(Sseq& q); 319*0b57cec5SDimitry Andric 320*0b57cec5SDimitry Andric // generating functions 321*0b57cec5SDimitry Andric result_type operator()(); 322*0b57cec5SDimitry Andric void discard(unsigned long long z); 323*0b57cec5SDimitry Andric 324*0b57cec5SDimitry Andric // property functions 325*0b57cec5SDimitry Andric const Engine& base() const noexcept; 326*0b57cec5SDimitry Andric}; 327*0b57cec5SDimitry Andric 328*0b57cec5SDimitry Andrictemplate<class Engine, size_t k> 329*0b57cec5SDimitry Andricbool 330*0b57cec5SDimitry Andricoperator==( 331*0b57cec5SDimitry Andric const shuffle_order_engine<Engine, k>& x, 332*0b57cec5SDimitry Andric const shuffle_order_engine<Engine, k>& y); 333*0b57cec5SDimitry Andric 334*0b57cec5SDimitry Andrictemplate<class Engine, size_t k> 335*0b57cec5SDimitry Andricbool 336*0b57cec5SDimitry Andricoperator!=( 337*0b57cec5SDimitry Andric const shuffle_order_engine<Engine, k>& x, 338*0b57cec5SDimitry Andric const shuffle_order_engine<Engine, k>& y); 339*0b57cec5SDimitry Andric 340*0b57cec5SDimitry Andrictemplate <class charT, class traits, 341*0b57cec5SDimitry Andric class Engine, size_t k> 342*0b57cec5SDimitry Andricbasic_ostream<charT, traits>& 343*0b57cec5SDimitry Andricoperator<<(basic_ostream<charT, traits>& os, 344*0b57cec5SDimitry Andric const shuffle_order_engine<Engine, k>& x); 345*0b57cec5SDimitry Andric 346*0b57cec5SDimitry Andrictemplate <class charT, class traits, 347*0b57cec5SDimitry Andric class Engine, size_t k> 348*0b57cec5SDimitry Andricbasic_istream<charT, traits>& 349*0b57cec5SDimitry Andricoperator>>(basic_istream<charT, traits>& is, 350*0b57cec5SDimitry Andric shuffle_order_engine<Engine, k>& x); 351*0b57cec5SDimitry Andric 352*0b57cec5SDimitry Andrictypedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647> 353*0b57cec5SDimitry Andric minstd_rand0; 354*0b57cec5SDimitry Andrictypedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647> 355*0b57cec5SDimitry Andric minstd_rand; 356*0b57cec5SDimitry Andrictypedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31, 357*0b57cec5SDimitry Andric 0x9908b0df, 358*0b57cec5SDimitry Andric 11, 0xffffffff, 359*0b57cec5SDimitry Andric 7, 0x9d2c5680, 360*0b57cec5SDimitry Andric 15, 0xefc60000, 361*0b57cec5SDimitry Andric 18, 1812433253> mt19937; 362*0b57cec5SDimitry Andrictypedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31, 363*0b57cec5SDimitry Andric 0xb5026f5aa96619e9, 364*0b57cec5SDimitry Andric 29, 0x5555555555555555, 365*0b57cec5SDimitry Andric 17, 0x71d67fffeda60000, 366*0b57cec5SDimitry Andric 37, 0xfff7eee000000000, 367*0b57cec5SDimitry Andric 43, 6364136223846793005> mt19937_64; 368*0b57cec5SDimitry Andrictypedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> ranlux24_base; 369*0b57cec5SDimitry Andrictypedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> ranlux48_base; 370*0b57cec5SDimitry Andrictypedef discard_block_engine<ranlux24_base, 223, 23> ranlux24; 371*0b57cec5SDimitry Andrictypedef discard_block_engine<ranlux48_base, 389, 11> ranlux48; 372*0b57cec5SDimitry Andrictypedef shuffle_order_engine<minstd_rand0, 256> knuth_b; 373*0b57cec5SDimitry Andrictypedef minstd_rand default_random_engine; 374*0b57cec5SDimitry Andric 375*0b57cec5SDimitry Andric// Generators 376*0b57cec5SDimitry Andric 377*0b57cec5SDimitry Andricclass random_device 378*0b57cec5SDimitry Andric{ 379*0b57cec5SDimitry Andricpublic: 380*0b57cec5SDimitry Andric // types 381*0b57cec5SDimitry Andric typedef unsigned int result_type; 382*0b57cec5SDimitry Andric 383*0b57cec5SDimitry Andric // generator characteristics 384*0b57cec5SDimitry Andric static constexpr result_type min() { return numeric_limits<result_type>::min(); } 385*0b57cec5SDimitry Andric static constexpr result_type max() { return numeric_limits<result_type>::max(); } 386*0b57cec5SDimitry Andric 387*0b57cec5SDimitry Andric // constructors 388*0b57cec5SDimitry Andric explicit random_device(const string& token = "/dev/urandom"); 389*0b57cec5SDimitry Andric 390*0b57cec5SDimitry Andric // generating functions 391*0b57cec5SDimitry Andric result_type operator()(); 392*0b57cec5SDimitry Andric 393*0b57cec5SDimitry Andric // property functions 394*0b57cec5SDimitry Andric double entropy() const noexcept; 395*0b57cec5SDimitry Andric 396*0b57cec5SDimitry Andric // no copy functions 397*0b57cec5SDimitry Andric random_device(const random_device& ) = delete; 398*0b57cec5SDimitry Andric void operator=(const random_device& ) = delete; 399*0b57cec5SDimitry Andric}; 400*0b57cec5SDimitry Andric 401*0b57cec5SDimitry Andric// Utilities 402*0b57cec5SDimitry Andric 403*0b57cec5SDimitry Andricclass seed_seq 404*0b57cec5SDimitry Andric{ 405*0b57cec5SDimitry Andricpublic: 406*0b57cec5SDimitry Andric // types 407*0b57cec5SDimitry Andric typedef uint_least32_t result_type; 408*0b57cec5SDimitry Andric 409*0b57cec5SDimitry Andric // constructors 410*0b57cec5SDimitry Andric seed_seq(); 411*0b57cec5SDimitry Andric template<class T> 412*0b57cec5SDimitry Andric seed_seq(initializer_list<T> il); 413*0b57cec5SDimitry Andric template<class InputIterator> 414*0b57cec5SDimitry Andric seed_seq(InputIterator begin, InputIterator end); 415*0b57cec5SDimitry Andric 416*0b57cec5SDimitry Andric // generating functions 417*0b57cec5SDimitry Andric template<class RandomAccessIterator> 418*0b57cec5SDimitry Andric void generate(RandomAccessIterator begin, RandomAccessIterator end); 419*0b57cec5SDimitry Andric 420*0b57cec5SDimitry Andric // property functions 421*0b57cec5SDimitry Andric size_t size() const; 422*0b57cec5SDimitry Andric template<class OutputIterator> 423*0b57cec5SDimitry Andric void param(OutputIterator dest) const; 424*0b57cec5SDimitry Andric 425*0b57cec5SDimitry Andric // no copy functions 426*0b57cec5SDimitry Andric seed_seq(const seed_seq&) = delete; 427*0b57cec5SDimitry Andric void operator=(const seed_seq& ) = delete; 428*0b57cec5SDimitry Andric}; 429*0b57cec5SDimitry Andric 430*0b57cec5SDimitry Andrictemplate<class RealType, size_t bits, class URNG> 431*0b57cec5SDimitry Andric RealType generate_canonical(URNG& g); 432*0b57cec5SDimitry Andric 433*0b57cec5SDimitry Andric// Distributions 434*0b57cec5SDimitry Andric 435*0b57cec5SDimitry Andrictemplate<class IntType = int> 436*0b57cec5SDimitry Andricclass uniform_int_distribution 437*0b57cec5SDimitry Andric{ 438*0b57cec5SDimitry Andricpublic: 439*0b57cec5SDimitry Andric // types 440*0b57cec5SDimitry Andric typedef IntType result_type; 441*0b57cec5SDimitry Andric 442*0b57cec5SDimitry Andric class param_type 443*0b57cec5SDimitry Andric { 444*0b57cec5SDimitry Andric public: 445*0b57cec5SDimitry Andric typedef uniform_int_distribution distribution_type; 446*0b57cec5SDimitry Andric 447*0b57cec5SDimitry Andric explicit param_type(IntType a = 0, 448*0b57cec5SDimitry Andric IntType b = numeric_limits<IntType>::max()); 449*0b57cec5SDimitry Andric 450*0b57cec5SDimitry Andric result_type a() const; 451*0b57cec5SDimitry Andric result_type b() const; 452*0b57cec5SDimitry Andric 453*0b57cec5SDimitry Andric friend bool operator==(const param_type& x, const param_type& y); 454*0b57cec5SDimitry Andric friend bool operator!=(const param_type& x, const param_type& y); 455*0b57cec5SDimitry Andric }; 456*0b57cec5SDimitry Andric 457*0b57cec5SDimitry Andric // constructors and reset functions 458*0b57cec5SDimitry Andric explicit uniform_int_distribution(IntType a = 0, 459*0b57cec5SDimitry Andric IntType b = numeric_limits<IntType>::max()); 460*0b57cec5SDimitry Andric explicit uniform_int_distribution(const param_type& parm); 461*0b57cec5SDimitry Andric void reset(); 462*0b57cec5SDimitry Andric 463*0b57cec5SDimitry Andric // generating functions 464*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g); 465*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g, const param_type& parm); 466*0b57cec5SDimitry Andric 467*0b57cec5SDimitry Andric // property functions 468*0b57cec5SDimitry Andric result_type a() const; 469*0b57cec5SDimitry Andric result_type b() const; 470*0b57cec5SDimitry Andric 471*0b57cec5SDimitry Andric param_type param() const; 472*0b57cec5SDimitry Andric void param(const param_type& parm); 473*0b57cec5SDimitry Andric 474*0b57cec5SDimitry Andric result_type min() const; 475*0b57cec5SDimitry Andric result_type max() const; 476*0b57cec5SDimitry Andric 477*0b57cec5SDimitry Andric friend bool operator==(const uniform_int_distribution& x, 478*0b57cec5SDimitry Andric const uniform_int_distribution& y); 479*0b57cec5SDimitry Andric friend bool operator!=(const uniform_int_distribution& x, 480*0b57cec5SDimitry Andric const uniform_int_distribution& y); 481*0b57cec5SDimitry Andric 482*0b57cec5SDimitry Andric template <class charT, class traits> 483*0b57cec5SDimitry Andric friend 484*0b57cec5SDimitry Andric basic_ostream<charT, traits>& 485*0b57cec5SDimitry Andric operator<<(basic_ostream<charT, traits>& os, 486*0b57cec5SDimitry Andric const uniform_int_distribution& x); 487*0b57cec5SDimitry Andric 488*0b57cec5SDimitry Andric template <class charT, class traits> 489*0b57cec5SDimitry Andric friend 490*0b57cec5SDimitry Andric basic_istream<charT, traits>& 491*0b57cec5SDimitry Andric operator>>(basic_istream<charT, traits>& is, 492*0b57cec5SDimitry Andric uniform_int_distribution& x); 493*0b57cec5SDimitry Andric}; 494*0b57cec5SDimitry Andric 495*0b57cec5SDimitry Andrictemplate<class RealType = double> 496*0b57cec5SDimitry Andricclass uniform_real_distribution 497*0b57cec5SDimitry Andric{ 498*0b57cec5SDimitry Andricpublic: 499*0b57cec5SDimitry Andric // types 500*0b57cec5SDimitry Andric typedef RealType result_type; 501*0b57cec5SDimitry Andric 502*0b57cec5SDimitry Andric class param_type 503*0b57cec5SDimitry Andric { 504*0b57cec5SDimitry Andric public: 505*0b57cec5SDimitry Andric typedef uniform_real_distribution distribution_type; 506*0b57cec5SDimitry Andric 507*0b57cec5SDimitry Andric explicit param_type(RealType a = 0, 508*0b57cec5SDimitry Andric RealType b = 1); 509*0b57cec5SDimitry Andric 510*0b57cec5SDimitry Andric result_type a() const; 511*0b57cec5SDimitry Andric result_type b() const; 512*0b57cec5SDimitry Andric 513*0b57cec5SDimitry Andric friend bool operator==(const param_type& x, const param_type& y); 514*0b57cec5SDimitry Andric friend bool operator!=(const param_type& x, const param_type& y); 515*0b57cec5SDimitry Andric }; 516*0b57cec5SDimitry Andric 517*0b57cec5SDimitry Andric // constructors and reset functions 518*0b57cec5SDimitry Andric explicit uniform_real_distribution(RealType a = 0.0, RealType b = 1.0); 519*0b57cec5SDimitry Andric explicit uniform_real_distribution(const param_type& parm); 520*0b57cec5SDimitry Andric void reset(); 521*0b57cec5SDimitry Andric 522*0b57cec5SDimitry Andric // generating functions 523*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g); 524*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g, const param_type& parm); 525*0b57cec5SDimitry Andric 526*0b57cec5SDimitry Andric // property functions 527*0b57cec5SDimitry Andric result_type a() const; 528*0b57cec5SDimitry Andric result_type b() const; 529*0b57cec5SDimitry Andric 530*0b57cec5SDimitry Andric param_type param() const; 531*0b57cec5SDimitry Andric void param(const param_type& parm); 532*0b57cec5SDimitry Andric 533*0b57cec5SDimitry Andric result_type min() const; 534*0b57cec5SDimitry Andric result_type max() const; 535*0b57cec5SDimitry Andric 536*0b57cec5SDimitry Andric friend bool operator==(const uniform_real_distribution& x, 537*0b57cec5SDimitry Andric const uniform_real_distribution& y); 538*0b57cec5SDimitry Andric friend bool operator!=(const uniform_real_distribution& x, 539*0b57cec5SDimitry Andric const uniform_real_distribution& y); 540*0b57cec5SDimitry Andric 541*0b57cec5SDimitry Andric template <class charT, class traits> 542*0b57cec5SDimitry Andric friend 543*0b57cec5SDimitry Andric basic_ostream<charT, traits>& 544*0b57cec5SDimitry Andric operator<<(basic_ostream<charT, traits>& os, 545*0b57cec5SDimitry Andric const uniform_real_distribution& x); 546*0b57cec5SDimitry Andric 547*0b57cec5SDimitry Andric template <class charT, class traits> 548*0b57cec5SDimitry Andric friend 549*0b57cec5SDimitry Andric basic_istream<charT, traits>& 550*0b57cec5SDimitry Andric operator>>(basic_istream<charT, traits>& is, 551*0b57cec5SDimitry Andric uniform_real_distribution& x); 552*0b57cec5SDimitry Andric}; 553*0b57cec5SDimitry Andric 554*0b57cec5SDimitry Andricclass bernoulli_distribution 555*0b57cec5SDimitry Andric{ 556*0b57cec5SDimitry Andricpublic: 557*0b57cec5SDimitry Andric // types 558*0b57cec5SDimitry Andric typedef bool result_type; 559*0b57cec5SDimitry Andric 560*0b57cec5SDimitry Andric class param_type 561*0b57cec5SDimitry Andric { 562*0b57cec5SDimitry Andric public: 563*0b57cec5SDimitry Andric typedef bernoulli_distribution distribution_type; 564*0b57cec5SDimitry Andric 565*0b57cec5SDimitry Andric explicit param_type(double p = 0.5); 566*0b57cec5SDimitry Andric 567*0b57cec5SDimitry Andric double p() const; 568*0b57cec5SDimitry Andric 569*0b57cec5SDimitry Andric friend bool operator==(const param_type& x, const param_type& y); 570*0b57cec5SDimitry Andric friend bool operator!=(const param_type& x, const param_type& y); 571*0b57cec5SDimitry Andric }; 572*0b57cec5SDimitry Andric 573*0b57cec5SDimitry Andric // constructors and reset functions 574*0b57cec5SDimitry Andric explicit bernoulli_distribution(double p = 0.5); 575*0b57cec5SDimitry Andric explicit bernoulli_distribution(const param_type& parm); 576*0b57cec5SDimitry Andric void reset(); 577*0b57cec5SDimitry Andric 578*0b57cec5SDimitry Andric // generating functions 579*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g); 580*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g, const param_type& parm); 581*0b57cec5SDimitry Andric 582*0b57cec5SDimitry Andric // property functions 583*0b57cec5SDimitry Andric double p() const; 584*0b57cec5SDimitry Andric 585*0b57cec5SDimitry Andric param_type param() const; 586*0b57cec5SDimitry Andric void param(const param_type& parm); 587*0b57cec5SDimitry Andric 588*0b57cec5SDimitry Andric result_type min() const; 589*0b57cec5SDimitry Andric result_type max() const; 590*0b57cec5SDimitry Andric 591*0b57cec5SDimitry Andric friend bool operator==(const bernoulli_distribution& x, 592*0b57cec5SDimitry Andric const bernoulli_distribution& y); 593*0b57cec5SDimitry Andric friend bool operator!=(const bernoulli_distribution& x, 594*0b57cec5SDimitry Andric const bernoulli_distribution& y); 595*0b57cec5SDimitry Andric 596*0b57cec5SDimitry Andric template <class charT, class traits> 597*0b57cec5SDimitry Andric friend 598*0b57cec5SDimitry Andric basic_ostream<charT, traits>& 599*0b57cec5SDimitry Andric operator<<(basic_ostream<charT, traits>& os, 600*0b57cec5SDimitry Andric const bernoulli_distribution& x); 601*0b57cec5SDimitry Andric 602*0b57cec5SDimitry Andric template <class charT, class traits> 603*0b57cec5SDimitry Andric friend 604*0b57cec5SDimitry Andric basic_istream<charT, traits>& 605*0b57cec5SDimitry Andric operator>>(basic_istream<charT, traits>& is, 606*0b57cec5SDimitry Andric bernoulli_distribution& x); 607*0b57cec5SDimitry Andric}; 608*0b57cec5SDimitry Andric 609*0b57cec5SDimitry Andrictemplate<class IntType = int> 610*0b57cec5SDimitry Andricclass binomial_distribution 611*0b57cec5SDimitry Andric{ 612*0b57cec5SDimitry Andricpublic: 613*0b57cec5SDimitry Andric // types 614*0b57cec5SDimitry Andric typedef IntType result_type; 615*0b57cec5SDimitry Andric 616*0b57cec5SDimitry Andric class param_type 617*0b57cec5SDimitry Andric { 618*0b57cec5SDimitry Andric public: 619*0b57cec5SDimitry Andric typedef binomial_distribution distribution_type; 620*0b57cec5SDimitry Andric 621*0b57cec5SDimitry Andric explicit param_type(IntType t = 1, double p = 0.5); 622*0b57cec5SDimitry Andric 623*0b57cec5SDimitry Andric IntType t() const; 624*0b57cec5SDimitry Andric double p() const; 625*0b57cec5SDimitry Andric 626*0b57cec5SDimitry Andric friend bool operator==(const param_type& x, const param_type& y); 627*0b57cec5SDimitry Andric friend bool operator!=(const param_type& x, const param_type& y); 628*0b57cec5SDimitry Andric }; 629*0b57cec5SDimitry Andric 630*0b57cec5SDimitry Andric // constructors and reset functions 631*0b57cec5SDimitry Andric explicit binomial_distribution(IntType t = 1, double p = 0.5); 632*0b57cec5SDimitry Andric explicit binomial_distribution(const param_type& parm); 633*0b57cec5SDimitry Andric void reset(); 634*0b57cec5SDimitry Andric 635*0b57cec5SDimitry Andric // generating functions 636*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g); 637*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g, const param_type& parm); 638*0b57cec5SDimitry Andric 639*0b57cec5SDimitry Andric // property functions 640*0b57cec5SDimitry Andric IntType t() const; 641*0b57cec5SDimitry Andric double p() const; 642*0b57cec5SDimitry Andric 643*0b57cec5SDimitry Andric param_type param() const; 644*0b57cec5SDimitry Andric void param(const param_type& parm); 645*0b57cec5SDimitry Andric 646*0b57cec5SDimitry Andric result_type min() const; 647*0b57cec5SDimitry Andric result_type max() const; 648*0b57cec5SDimitry Andric 649*0b57cec5SDimitry Andric friend bool operator==(const binomial_distribution& x, 650*0b57cec5SDimitry Andric const binomial_distribution& y); 651*0b57cec5SDimitry Andric friend bool operator!=(const binomial_distribution& x, 652*0b57cec5SDimitry Andric const binomial_distribution& y); 653*0b57cec5SDimitry Andric 654*0b57cec5SDimitry Andric template <class charT, class traits> 655*0b57cec5SDimitry Andric friend 656*0b57cec5SDimitry Andric basic_ostream<charT, traits>& 657*0b57cec5SDimitry Andric operator<<(basic_ostream<charT, traits>& os, 658*0b57cec5SDimitry Andric const binomial_distribution& x); 659*0b57cec5SDimitry Andric 660*0b57cec5SDimitry Andric template <class charT, class traits> 661*0b57cec5SDimitry Andric friend 662*0b57cec5SDimitry Andric basic_istream<charT, traits>& 663*0b57cec5SDimitry Andric operator>>(basic_istream<charT, traits>& is, 664*0b57cec5SDimitry Andric binomial_distribution& x); 665*0b57cec5SDimitry Andric}; 666*0b57cec5SDimitry Andric 667*0b57cec5SDimitry Andrictemplate<class IntType = int> 668*0b57cec5SDimitry Andricclass geometric_distribution 669*0b57cec5SDimitry Andric{ 670*0b57cec5SDimitry Andricpublic: 671*0b57cec5SDimitry Andric // types 672*0b57cec5SDimitry Andric typedef IntType result_type; 673*0b57cec5SDimitry Andric 674*0b57cec5SDimitry Andric class param_type 675*0b57cec5SDimitry Andric { 676*0b57cec5SDimitry Andric public: 677*0b57cec5SDimitry Andric typedef geometric_distribution distribution_type; 678*0b57cec5SDimitry Andric 679*0b57cec5SDimitry Andric explicit param_type(double p = 0.5); 680*0b57cec5SDimitry Andric 681*0b57cec5SDimitry Andric double p() const; 682*0b57cec5SDimitry Andric 683*0b57cec5SDimitry Andric friend bool operator==(const param_type& x, const param_type& y); 684*0b57cec5SDimitry Andric friend bool operator!=(const param_type& x, const param_type& y); 685*0b57cec5SDimitry Andric }; 686*0b57cec5SDimitry Andric 687*0b57cec5SDimitry Andric // constructors and reset functions 688*0b57cec5SDimitry Andric explicit geometric_distribution(double p = 0.5); 689*0b57cec5SDimitry Andric explicit geometric_distribution(const param_type& parm); 690*0b57cec5SDimitry Andric void reset(); 691*0b57cec5SDimitry Andric 692*0b57cec5SDimitry Andric // generating functions 693*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g); 694*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g, const param_type& parm); 695*0b57cec5SDimitry Andric 696*0b57cec5SDimitry Andric // property functions 697*0b57cec5SDimitry Andric double p() const; 698*0b57cec5SDimitry Andric 699*0b57cec5SDimitry Andric param_type param() const; 700*0b57cec5SDimitry Andric void param(const param_type& parm); 701*0b57cec5SDimitry Andric 702*0b57cec5SDimitry Andric result_type min() const; 703*0b57cec5SDimitry Andric result_type max() const; 704*0b57cec5SDimitry Andric 705*0b57cec5SDimitry Andric friend bool operator==(const geometric_distribution& x, 706*0b57cec5SDimitry Andric const geometric_distribution& y); 707*0b57cec5SDimitry Andric friend bool operator!=(const geometric_distribution& x, 708*0b57cec5SDimitry Andric const geometric_distribution& y); 709*0b57cec5SDimitry Andric 710*0b57cec5SDimitry Andric template <class charT, class traits> 711*0b57cec5SDimitry Andric friend 712*0b57cec5SDimitry Andric basic_ostream<charT, traits>& 713*0b57cec5SDimitry Andric operator<<(basic_ostream<charT, traits>& os, 714*0b57cec5SDimitry Andric const geometric_distribution& x); 715*0b57cec5SDimitry Andric 716*0b57cec5SDimitry Andric template <class charT, class traits> 717*0b57cec5SDimitry Andric friend 718*0b57cec5SDimitry Andric basic_istream<charT, traits>& 719*0b57cec5SDimitry Andric operator>>(basic_istream<charT, traits>& is, 720*0b57cec5SDimitry Andric geometric_distribution& x); 721*0b57cec5SDimitry Andric}; 722*0b57cec5SDimitry Andric 723*0b57cec5SDimitry Andrictemplate<class IntType = int> 724*0b57cec5SDimitry Andricclass negative_binomial_distribution 725*0b57cec5SDimitry Andric{ 726*0b57cec5SDimitry Andricpublic: 727*0b57cec5SDimitry Andric // types 728*0b57cec5SDimitry Andric typedef IntType result_type; 729*0b57cec5SDimitry Andric 730*0b57cec5SDimitry Andric class param_type 731*0b57cec5SDimitry Andric { 732*0b57cec5SDimitry Andric public: 733*0b57cec5SDimitry Andric typedef negative_binomial_distribution distribution_type; 734*0b57cec5SDimitry Andric 735*0b57cec5SDimitry Andric explicit param_type(result_type k = 1, double p = 0.5); 736*0b57cec5SDimitry Andric 737*0b57cec5SDimitry Andric result_type k() const; 738*0b57cec5SDimitry Andric double p() const; 739*0b57cec5SDimitry Andric 740*0b57cec5SDimitry Andric friend bool operator==(const param_type& x, const param_type& y); 741*0b57cec5SDimitry Andric friend bool operator!=(const param_type& x, const param_type& y); 742*0b57cec5SDimitry Andric }; 743*0b57cec5SDimitry Andric 744*0b57cec5SDimitry Andric // constructor and reset functions 745*0b57cec5SDimitry Andric explicit negative_binomial_distribution(result_type k = 1, double p = 0.5); 746*0b57cec5SDimitry Andric explicit negative_binomial_distribution(const param_type& parm); 747*0b57cec5SDimitry Andric void reset(); 748*0b57cec5SDimitry Andric 749*0b57cec5SDimitry Andric // generating functions 750*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g); 751*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g, const param_type& parm); 752*0b57cec5SDimitry Andric 753*0b57cec5SDimitry Andric // property functions 754*0b57cec5SDimitry Andric result_type k() const; 755*0b57cec5SDimitry Andric double p() const; 756*0b57cec5SDimitry Andric 757*0b57cec5SDimitry Andric param_type param() const; 758*0b57cec5SDimitry Andric void param(const param_type& parm); 759*0b57cec5SDimitry Andric 760*0b57cec5SDimitry Andric result_type min() const; 761*0b57cec5SDimitry Andric result_type max() const; 762*0b57cec5SDimitry Andric 763*0b57cec5SDimitry Andric friend bool operator==(const negative_binomial_distribution& x, 764*0b57cec5SDimitry Andric const negative_binomial_distribution& y); 765*0b57cec5SDimitry Andric friend bool operator!=(const negative_binomial_distribution& x, 766*0b57cec5SDimitry Andric const negative_binomial_distribution& y); 767*0b57cec5SDimitry Andric 768*0b57cec5SDimitry Andric template <class charT, class traits> 769*0b57cec5SDimitry Andric friend 770*0b57cec5SDimitry Andric basic_ostream<charT, traits>& 771*0b57cec5SDimitry Andric operator<<(basic_ostream<charT, traits>& os, 772*0b57cec5SDimitry Andric const negative_binomial_distribution& x); 773*0b57cec5SDimitry Andric 774*0b57cec5SDimitry Andric template <class charT, class traits> 775*0b57cec5SDimitry Andric friend 776*0b57cec5SDimitry Andric basic_istream<charT, traits>& 777*0b57cec5SDimitry Andric operator>>(basic_istream<charT, traits>& is, 778*0b57cec5SDimitry Andric negative_binomial_distribution& x); 779*0b57cec5SDimitry Andric}; 780*0b57cec5SDimitry Andric 781*0b57cec5SDimitry Andrictemplate<class IntType = int> 782*0b57cec5SDimitry Andricclass poisson_distribution 783*0b57cec5SDimitry Andric{ 784*0b57cec5SDimitry Andricpublic: 785*0b57cec5SDimitry Andric // types 786*0b57cec5SDimitry Andric typedef IntType result_type; 787*0b57cec5SDimitry Andric 788*0b57cec5SDimitry Andric class param_type 789*0b57cec5SDimitry Andric { 790*0b57cec5SDimitry Andric public: 791*0b57cec5SDimitry Andric typedef poisson_distribution distribution_type; 792*0b57cec5SDimitry Andric 793*0b57cec5SDimitry Andric explicit param_type(double mean = 1.0); 794*0b57cec5SDimitry Andric 795*0b57cec5SDimitry Andric double mean() const; 796*0b57cec5SDimitry Andric 797*0b57cec5SDimitry Andric friend bool operator==(const param_type& x, const param_type& y); 798*0b57cec5SDimitry Andric friend bool operator!=(const param_type& x, const param_type& y); 799*0b57cec5SDimitry Andric }; 800*0b57cec5SDimitry Andric 801*0b57cec5SDimitry Andric // constructors and reset functions 802*0b57cec5SDimitry Andric explicit poisson_distribution(double mean = 1.0); 803*0b57cec5SDimitry Andric explicit poisson_distribution(const param_type& parm); 804*0b57cec5SDimitry Andric void reset(); 805*0b57cec5SDimitry Andric 806*0b57cec5SDimitry Andric // generating functions 807*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g); 808*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g, const param_type& parm); 809*0b57cec5SDimitry Andric 810*0b57cec5SDimitry Andric // property functions 811*0b57cec5SDimitry Andric double mean() const; 812*0b57cec5SDimitry Andric 813*0b57cec5SDimitry Andric param_type param() const; 814*0b57cec5SDimitry Andric void param(const param_type& parm); 815*0b57cec5SDimitry Andric 816*0b57cec5SDimitry Andric result_type min() const; 817*0b57cec5SDimitry Andric result_type max() const; 818*0b57cec5SDimitry Andric 819*0b57cec5SDimitry Andric friend bool operator==(const poisson_distribution& x, 820*0b57cec5SDimitry Andric const poisson_distribution& y); 821*0b57cec5SDimitry Andric friend bool operator!=(const poisson_distribution& x, 822*0b57cec5SDimitry Andric const poisson_distribution& y); 823*0b57cec5SDimitry Andric 824*0b57cec5SDimitry Andric template <class charT, class traits> 825*0b57cec5SDimitry Andric friend 826*0b57cec5SDimitry Andric basic_ostream<charT, traits>& 827*0b57cec5SDimitry Andric operator<<(basic_ostream<charT, traits>& os, 828*0b57cec5SDimitry Andric const poisson_distribution& x); 829*0b57cec5SDimitry Andric 830*0b57cec5SDimitry Andric template <class charT, class traits> 831*0b57cec5SDimitry Andric friend 832*0b57cec5SDimitry Andric basic_istream<charT, traits>& 833*0b57cec5SDimitry Andric operator>>(basic_istream<charT, traits>& is, 834*0b57cec5SDimitry Andric poisson_distribution& x); 835*0b57cec5SDimitry Andric}; 836*0b57cec5SDimitry Andric 837*0b57cec5SDimitry Andrictemplate<class RealType = double> 838*0b57cec5SDimitry Andricclass exponential_distribution 839*0b57cec5SDimitry Andric{ 840*0b57cec5SDimitry Andricpublic: 841*0b57cec5SDimitry Andric // types 842*0b57cec5SDimitry Andric typedef RealType result_type; 843*0b57cec5SDimitry Andric 844*0b57cec5SDimitry Andric class param_type 845*0b57cec5SDimitry Andric { 846*0b57cec5SDimitry Andric public: 847*0b57cec5SDimitry Andric typedef exponential_distribution distribution_type; 848*0b57cec5SDimitry Andric 849*0b57cec5SDimitry Andric explicit param_type(result_type lambda = 1.0); 850*0b57cec5SDimitry Andric 851*0b57cec5SDimitry Andric result_type lambda() const; 852*0b57cec5SDimitry Andric 853*0b57cec5SDimitry Andric friend bool operator==(const param_type& x, const param_type& y); 854*0b57cec5SDimitry Andric friend bool operator!=(const param_type& x, const param_type& y); 855*0b57cec5SDimitry Andric }; 856*0b57cec5SDimitry Andric 857*0b57cec5SDimitry Andric // constructors and reset functions 858*0b57cec5SDimitry Andric explicit exponential_distribution(result_type lambda = 1.0); 859*0b57cec5SDimitry Andric explicit exponential_distribution(const param_type& parm); 860*0b57cec5SDimitry Andric void reset(); 861*0b57cec5SDimitry Andric 862*0b57cec5SDimitry Andric // generating functions 863*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g); 864*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g, const param_type& parm); 865*0b57cec5SDimitry Andric 866*0b57cec5SDimitry Andric // property functions 867*0b57cec5SDimitry Andric result_type lambda() const; 868*0b57cec5SDimitry Andric 869*0b57cec5SDimitry Andric param_type param() const; 870*0b57cec5SDimitry Andric void param(const param_type& parm); 871*0b57cec5SDimitry Andric 872*0b57cec5SDimitry Andric result_type min() const; 873*0b57cec5SDimitry Andric result_type max() const; 874*0b57cec5SDimitry Andric 875*0b57cec5SDimitry Andric friend bool operator==(const exponential_distribution& x, 876*0b57cec5SDimitry Andric const exponential_distribution& y); 877*0b57cec5SDimitry Andric friend bool operator!=(const exponential_distribution& x, 878*0b57cec5SDimitry Andric const exponential_distribution& y); 879*0b57cec5SDimitry Andric 880*0b57cec5SDimitry Andric template <class charT, class traits> 881*0b57cec5SDimitry Andric friend 882*0b57cec5SDimitry Andric basic_ostream<charT, traits>& 883*0b57cec5SDimitry Andric operator<<(basic_ostream<charT, traits>& os, 884*0b57cec5SDimitry Andric const exponential_distribution& x); 885*0b57cec5SDimitry Andric 886*0b57cec5SDimitry Andric template <class charT, class traits> 887*0b57cec5SDimitry Andric friend 888*0b57cec5SDimitry Andric basic_istream<charT, traits>& 889*0b57cec5SDimitry Andric operator>>(basic_istream<charT, traits>& is, 890*0b57cec5SDimitry Andric exponential_distribution& x); 891*0b57cec5SDimitry Andric}; 892*0b57cec5SDimitry Andric 893*0b57cec5SDimitry Andrictemplate<class RealType = double> 894*0b57cec5SDimitry Andricclass gamma_distribution 895*0b57cec5SDimitry Andric{ 896*0b57cec5SDimitry Andricpublic: 897*0b57cec5SDimitry Andric // types 898*0b57cec5SDimitry Andric typedef RealType result_type; 899*0b57cec5SDimitry Andric 900*0b57cec5SDimitry Andric class param_type 901*0b57cec5SDimitry Andric { 902*0b57cec5SDimitry Andric public: 903*0b57cec5SDimitry Andric typedef gamma_distribution distribution_type; 904*0b57cec5SDimitry Andric 905*0b57cec5SDimitry Andric explicit param_type(result_type alpha = 1, result_type beta = 1); 906*0b57cec5SDimitry Andric 907*0b57cec5SDimitry Andric result_type alpha() const; 908*0b57cec5SDimitry Andric result_type beta() const; 909*0b57cec5SDimitry Andric 910*0b57cec5SDimitry Andric friend bool operator==(const param_type& x, const param_type& y); 911*0b57cec5SDimitry Andric friend bool operator!=(const param_type& x, const param_type& y); 912*0b57cec5SDimitry Andric }; 913*0b57cec5SDimitry Andric 914*0b57cec5SDimitry Andric // constructors and reset functions 915*0b57cec5SDimitry Andric explicit gamma_distribution(result_type alpha = 1, result_type beta = 1); 916*0b57cec5SDimitry Andric explicit gamma_distribution(const param_type& parm); 917*0b57cec5SDimitry Andric void reset(); 918*0b57cec5SDimitry Andric 919*0b57cec5SDimitry Andric // generating functions 920*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g); 921*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g, const param_type& parm); 922*0b57cec5SDimitry Andric 923*0b57cec5SDimitry Andric // property functions 924*0b57cec5SDimitry Andric result_type alpha() const; 925*0b57cec5SDimitry Andric result_type beta() const; 926*0b57cec5SDimitry Andric 927*0b57cec5SDimitry Andric param_type param() const; 928*0b57cec5SDimitry Andric void param(const param_type& parm); 929*0b57cec5SDimitry Andric 930*0b57cec5SDimitry Andric result_type min() const; 931*0b57cec5SDimitry Andric result_type max() const; 932*0b57cec5SDimitry Andric 933*0b57cec5SDimitry Andric friend bool operator==(const gamma_distribution& x, 934*0b57cec5SDimitry Andric const gamma_distribution& y); 935*0b57cec5SDimitry Andric friend bool operator!=(const gamma_distribution& x, 936*0b57cec5SDimitry Andric const gamma_distribution& y); 937*0b57cec5SDimitry Andric 938*0b57cec5SDimitry Andric template <class charT, class traits> 939*0b57cec5SDimitry Andric friend 940*0b57cec5SDimitry Andric basic_ostream<charT, traits>& 941*0b57cec5SDimitry Andric operator<<(basic_ostream<charT, traits>& os, 942*0b57cec5SDimitry Andric const gamma_distribution& x); 943*0b57cec5SDimitry Andric 944*0b57cec5SDimitry Andric template <class charT, class traits> 945*0b57cec5SDimitry Andric friend 946*0b57cec5SDimitry Andric basic_istream<charT, traits>& 947*0b57cec5SDimitry Andric operator>>(basic_istream<charT, traits>& is, 948*0b57cec5SDimitry Andric gamma_distribution& x); 949*0b57cec5SDimitry Andric}; 950*0b57cec5SDimitry Andric 951*0b57cec5SDimitry Andrictemplate<class RealType = double> 952*0b57cec5SDimitry Andricclass weibull_distribution 953*0b57cec5SDimitry Andric{ 954*0b57cec5SDimitry Andricpublic: 955*0b57cec5SDimitry Andric // types 956*0b57cec5SDimitry Andric typedef RealType result_type; 957*0b57cec5SDimitry Andric 958*0b57cec5SDimitry Andric class param_type 959*0b57cec5SDimitry Andric { 960*0b57cec5SDimitry Andric public: 961*0b57cec5SDimitry Andric typedef weibull_distribution distribution_type; 962*0b57cec5SDimitry Andric 963*0b57cec5SDimitry Andric explicit param_type(result_type alpha = 1, result_type beta = 1); 964*0b57cec5SDimitry Andric 965*0b57cec5SDimitry Andric result_type a() const; 966*0b57cec5SDimitry Andric result_type b() const; 967*0b57cec5SDimitry Andric 968*0b57cec5SDimitry Andric friend bool operator==(const param_type& x, const param_type& y); 969*0b57cec5SDimitry Andric friend bool operator!=(const param_type& x, const param_type& y); 970*0b57cec5SDimitry Andric }; 971*0b57cec5SDimitry Andric 972*0b57cec5SDimitry Andric // constructor and reset functions 973*0b57cec5SDimitry Andric explicit weibull_distribution(result_type a = 1, result_type b = 1); 974*0b57cec5SDimitry Andric explicit weibull_distribution(const param_type& parm); 975*0b57cec5SDimitry Andric void reset(); 976*0b57cec5SDimitry Andric 977*0b57cec5SDimitry Andric // generating functions 978*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g); 979*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g, const param_type& parm); 980*0b57cec5SDimitry Andric 981*0b57cec5SDimitry Andric // property functions 982*0b57cec5SDimitry Andric result_type a() const; 983*0b57cec5SDimitry Andric result_type b() const; 984*0b57cec5SDimitry Andric 985*0b57cec5SDimitry Andric param_type param() const; 986*0b57cec5SDimitry Andric void param(const param_type& parm); 987*0b57cec5SDimitry Andric 988*0b57cec5SDimitry Andric result_type min() const; 989*0b57cec5SDimitry Andric result_type max() const; 990*0b57cec5SDimitry Andric 991*0b57cec5SDimitry Andric friend bool operator==(const weibull_distribution& x, 992*0b57cec5SDimitry Andric const weibull_distribution& y); 993*0b57cec5SDimitry Andric friend bool operator!=(const weibull_distribution& x, 994*0b57cec5SDimitry Andric const weibull_distribution& y); 995*0b57cec5SDimitry Andric 996*0b57cec5SDimitry Andric template <class charT, class traits> 997*0b57cec5SDimitry Andric friend 998*0b57cec5SDimitry Andric basic_ostream<charT, traits>& 999*0b57cec5SDimitry Andric operator<<(basic_ostream<charT, traits>& os, 1000*0b57cec5SDimitry Andric const weibull_distribution& x); 1001*0b57cec5SDimitry Andric 1002*0b57cec5SDimitry Andric template <class charT, class traits> 1003*0b57cec5SDimitry Andric friend 1004*0b57cec5SDimitry Andric basic_istream<charT, traits>& 1005*0b57cec5SDimitry Andric operator>>(basic_istream<charT, traits>& is, 1006*0b57cec5SDimitry Andric weibull_distribution& x); 1007*0b57cec5SDimitry Andric}; 1008*0b57cec5SDimitry Andric 1009*0b57cec5SDimitry Andrictemplate<class RealType = double> 1010*0b57cec5SDimitry Andricclass extreme_value_distribution 1011*0b57cec5SDimitry Andric{ 1012*0b57cec5SDimitry Andricpublic: 1013*0b57cec5SDimitry Andric // types 1014*0b57cec5SDimitry Andric typedef RealType result_type; 1015*0b57cec5SDimitry Andric 1016*0b57cec5SDimitry Andric class param_type 1017*0b57cec5SDimitry Andric { 1018*0b57cec5SDimitry Andric public: 1019*0b57cec5SDimitry Andric typedef extreme_value_distribution distribution_type; 1020*0b57cec5SDimitry Andric 1021*0b57cec5SDimitry Andric explicit param_type(result_type a = 0, result_type b = 1); 1022*0b57cec5SDimitry Andric 1023*0b57cec5SDimitry Andric result_type a() const; 1024*0b57cec5SDimitry Andric result_type b() const; 1025*0b57cec5SDimitry Andric 1026*0b57cec5SDimitry Andric friend bool operator==(const param_type& x, const param_type& y); 1027*0b57cec5SDimitry Andric friend bool operator!=(const param_type& x, const param_type& y); 1028*0b57cec5SDimitry Andric }; 1029*0b57cec5SDimitry Andric 1030*0b57cec5SDimitry Andric // constructor and reset functions 1031*0b57cec5SDimitry Andric explicit extreme_value_distribution(result_type a = 0, result_type b = 1); 1032*0b57cec5SDimitry Andric explicit extreme_value_distribution(const param_type& parm); 1033*0b57cec5SDimitry Andric void reset(); 1034*0b57cec5SDimitry Andric 1035*0b57cec5SDimitry Andric // generating functions 1036*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g); 1037*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g, const param_type& parm); 1038*0b57cec5SDimitry Andric 1039*0b57cec5SDimitry Andric // property functions 1040*0b57cec5SDimitry Andric result_type a() const; 1041*0b57cec5SDimitry Andric result_type b() const; 1042*0b57cec5SDimitry Andric 1043*0b57cec5SDimitry Andric param_type param() const; 1044*0b57cec5SDimitry Andric void param(const param_type& parm); 1045*0b57cec5SDimitry Andric 1046*0b57cec5SDimitry Andric result_type min() const; 1047*0b57cec5SDimitry Andric result_type max() const; 1048*0b57cec5SDimitry Andric 1049*0b57cec5SDimitry Andric friend bool operator==(const extreme_value_distribution& x, 1050*0b57cec5SDimitry Andric const extreme_value_distribution& y); 1051*0b57cec5SDimitry Andric friend bool operator!=(const extreme_value_distribution& x, 1052*0b57cec5SDimitry Andric const extreme_value_distribution& y); 1053*0b57cec5SDimitry Andric 1054*0b57cec5SDimitry Andric template <class charT, class traits> 1055*0b57cec5SDimitry Andric friend 1056*0b57cec5SDimitry Andric basic_ostream<charT, traits>& 1057*0b57cec5SDimitry Andric operator<<(basic_ostream<charT, traits>& os, 1058*0b57cec5SDimitry Andric const extreme_value_distribution& x); 1059*0b57cec5SDimitry Andric 1060*0b57cec5SDimitry Andric template <class charT, class traits> 1061*0b57cec5SDimitry Andric friend 1062*0b57cec5SDimitry Andric basic_istream<charT, traits>& 1063*0b57cec5SDimitry Andric operator>>(basic_istream<charT, traits>& is, 1064*0b57cec5SDimitry Andric extreme_value_distribution& x); 1065*0b57cec5SDimitry Andric}; 1066*0b57cec5SDimitry Andric 1067*0b57cec5SDimitry Andrictemplate<class RealType = double> 1068*0b57cec5SDimitry Andricclass normal_distribution 1069*0b57cec5SDimitry Andric{ 1070*0b57cec5SDimitry Andricpublic: 1071*0b57cec5SDimitry Andric // types 1072*0b57cec5SDimitry Andric typedef RealType result_type; 1073*0b57cec5SDimitry Andric 1074*0b57cec5SDimitry Andric class param_type 1075*0b57cec5SDimitry Andric { 1076*0b57cec5SDimitry Andric public: 1077*0b57cec5SDimitry Andric typedef normal_distribution distribution_type; 1078*0b57cec5SDimitry Andric 1079*0b57cec5SDimitry Andric explicit param_type(result_type mean = 0, result_type stddev = 1); 1080*0b57cec5SDimitry Andric 1081*0b57cec5SDimitry Andric result_type mean() const; 1082*0b57cec5SDimitry Andric result_type stddev() const; 1083*0b57cec5SDimitry Andric 1084*0b57cec5SDimitry Andric friend bool operator==(const param_type& x, const param_type& y); 1085*0b57cec5SDimitry Andric friend bool operator!=(const param_type& x, const param_type& y); 1086*0b57cec5SDimitry Andric }; 1087*0b57cec5SDimitry Andric 1088*0b57cec5SDimitry Andric // constructors and reset functions 1089*0b57cec5SDimitry Andric explicit normal_distribution(result_type mean = 0, result_type stddev = 1); 1090*0b57cec5SDimitry Andric explicit normal_distribution(const param_type& parm); 1091*0b57cec5SDimitry Andric void reset(); 1092*0b57cec5SDimitry Andric 1093*0b57cec5SDimitry Andric // generating functions 1094*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g); 1095*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g, const param_type& parm); 1096*0b57cec5SDimitry Andric 1097*0b57cec5SDimitry Andric // property functions 1098*0b57cec5SDimitry Andric result_type mean() const; 1099*0b57cec5SDimitry Andric result_type stddev() const; 1100*0b57cec5SDimitry Andric 1101*0b57cec5SDimitry Andric param_type param() const; 1102*0b57cec5SDimitry Andric void param(const param_type& parm); 1103*0b57cec5SDimitry Andric 1104*0b57cec5SDimitry Andric result_type min() const; 1105*0b57cec5SDimitry Andric result_type max() const; 1106*0b57cec5SDimitry Andric 1107*0b57cec5SDimitry Andric friend bool operator==(const normal_distribution& x, 1108*0b57cec5SDimitry Andric const normal_distribution& y); 1109*0b57cec5SDimitry Andric friend bool operator!=(const normal_distribution& x, 1110*0b57cec5SDimitry Andric const normal_distribution& y); 1111*0b57cec5SDimitry Andric 1112*0b57cec5SDimitry Andric template <class charT, class traits> 1113*0b57cec5SDimitry Andric friend 1114*0b57cec5SDimitry Andric basic_ostream<charT, traits>& 1115*0b57cec5SDimitry Andric operator<<(basic_ostream<charT, traits>& os, 1116*0b57cec5SDimitry Andric const normal_distribution& x); 1117*0b57cec5SDimitry Andric 1118*0b57cec5SDimitry Andric template <class charT, class traits> 1119*0b57cec5SDimitry Andric friend 1120*0b57cec5SDimitry Andric basic_istream<charT, traits>& 1121*0b57cec5SDimitry Andric operator>>(basic_istream<charT, traits>& is, 1122*0b57cec5SDimitry Andric normal_distribution& x); 1123*0b57cec5SDimitry Andric}; 1124*0b57cec5SDimitry Andric 1125*0b57cec5SDimitry Andrictemplate<class RealType = double> 1126*0b57cec5SDimitry Andricclass lognormal_distribution 1127*0b57cec5SDimitry Andric{ 1128*0b57cec5SDimitry Andricpublic: 1129*0b57cec5SDimitry Andric // types 1130*0b57cec5SDimitry Andric typedef RealType result_type; 1131*0b57cec5SDimitry Andric 1132*0b57cec5SDimitry Andric class param_type 1133*0b57cec5SDimitry Andric { 1134*0b57cec5SDimitry Andric public: 1135*0b57cec5SDimitry Andric typedef lognormal_distribution distribution_type; 1136*0b57cec5SDimitry Andric 1137*0b57cec5SDimitry Andric explicit param_type(result_type m = 0, result_type s = 1); 1138*0b57cec5SDimitry Andric 1139*0b57cec5SDimitry Andric result_type m() const; 1140*0b57cec5SDimitry Andric result_type s() const; 1141*0b57cec5SDimitry Andric 1142*0b57cec5SDimitry Andric friend bool operator==(const param_type& x, const param_type& y); 1143*0b57cec5SDimitry Andric friend bool operator!=(const param_type& x, const param_type& y); 1144*0b57cec5SDimitry Andric }; 1145*0b57cec5SDimitry Andric 1146*0b57cec5SDimitry Andric // constructor and reset functions 1147*0b57cec5SDimitry Andric explicit lognormal_distribution(result_type m = 0, result_type s = 1); 1148*0b57cec5SDimitry Andric explicit lognormal_distribution(const param_type& parm); 1149*0b57cec5SDimitry Andric void reset(); 1150*0b57cec5SDimitry Andric 1151*0b57cec5SDimitry Andric // generating functions 1152*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g); 1153*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g, const param_type& parm); 1154*0b57cec5SDimitry Andric 1155*0b57cec5SDimitry Andric // property functions 1156*0b57cec5SDimitry Andric result_type m() const; 1157*0b57cec5SDimitry Andric result_type s() const; 1158*0b57cec5SDimitry Andric 1159*0b57cec5SDimitry Andric param_type param() const; 1160*0b57cec5SDimitry Andric void param(const param_type& parm); 1161*0b57cec5SDimitry Andric 1162*0b57cec5SDimitry Andric result_type min() const; 1163*0b57cec5SDimitry Andric result_type max() const; 1164*0b57cec5SDimitry Andric 1165*0b57cec5SDimitry Andric friend bool operator==(const lognormal_distribution& x, 1166*0b57cec5SDimitry Andric const lognormal_distribution& y); 1167*0b57cec5SDimitry Andric friend bool operator!=(const lognormal_distribution& x, 1168*0b57cec5SDimitry Andric const lognormal_distribution& y); 1169*0b57cec5SDimitry Andric 1170*0b57cec5SDimitry Andric template <class charT, class traits> 1171*0b57cec5SDimitry Andric friend 1172*0b57cec5SDimitry Andric basic_ostream<charT, traits>& 1173*0b57cec5SDimitry Andric operator<<(basic_ostream<charT, traits>& os, 1174*0b57cec5SDimitry Andric const lognormal_distribution& x); 1175*0b57cec5SDimitry Andric 1176*0b57cec5SDimitry Andric template <class charT, class traits> 1177*0b57cec5SDimitry Andric friend 1178*0b57cec5SDimitry Andric basic_istream<charT, traits>& 1179*0b57cec5SDimitry Andric operator>>(basic_istream<charT, traits>& is, 1180*0b57cec5SDimitry Andric lognormal_distribution& x); 1181*0b57cec5SDimitry Andric}; 1182*0b57cec5SDimitry Andric 1183*0b57cec5SDimitry Andrictemplate<class RealType = double> 1184*0b57cec5SDimitry Andricclass chi_squared_distribution 1185*0b57cec5SDimitry Andric{ 1186*0b57cec5SDimitry Andricpublic: 1187*0b57cec5SDimitry Andric // types 1188*0b57cec5SDimitry Andric typedef RealType result_type; 1189*0b57cec5SDimitry Andric 1190*0b57cec5SDimitry Andric class param_type 1191*0b57cec5SDimitry Andric { 1192*0b57cec5SDimitry Andric public: 1193*0b57cec5SDimitry Andric typedef chi_squared_distribution distribution_type; 1194*0b57cec5SDimitry Andric 1195*0b57cec5SDimitry Andric explicit param_type(result_type n = 1); 1196*0b57cec5SDimitry Andric 1197*0b57cec5SDimitry Andric result_type n() const; 1198*0b57cec5SDimitry Andric 1199*0b57cec5SDimitry Andric friend bool operator==(const param_type& x, const param_type& y); 1200*0b57cec5SDimitry Andric friend bool operator!=(const param_type& x, const param_type& y); 1201*0b57cec5SDimitry Andric }; 1202*0b57cec5SDimitry Andric 1203*0b57cec5SDimitry Andric // constructor and reset functions 1204*0b57cec5SDimitry Andric explicit chi_squared_distribution(result_type n = 1); 1205*0b57cec5SDimitry Andric explicit chi_squared_distribution(const param_type& parm); 1206*0b57cec5SDimitry Andric void reset(); 1207*0b57cec5SDimitry Andric 1208*0b57cec5SDimitry Andric // generating functions 1209*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g); 1210*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g, const param_type& parm); 1211*0b57cec5SDimitry Andric 1212*0b57cec5SDimitry Andric // property functions 1213*0b57cec5SDimitry Andric result_type n() const; 1214*0b57cec5SDimitry Andric 1215*0b57cec5SDimitry Andric param_type param() const; 1216*0b57cec5SDimitry Andric void param(const param_type& parm); 1217*0b57cec5SDimitry Andric 1218*0b57cec5SDimitry Andric result_type min() const; 1219*0b57cec5SDimitry Andric result_type max() const; 1220*0b57cec5SDimitry Andric 1221*0b57cec5SDimitry Andric friend bool operator==(const chi_squared_distribution& x, 1222*0b57cec5SDimitry Andric const chi_squared_distribution& y); 1223*0b57cec5SDimitry Andric friend bool operator!=(const chi_squared_distribution& x, 1224*0b57cec5SDimitry Andric const chi_squared_distribution& y); 1225*0b57cec5SDimitry Andric 1226*0b57cec5SDimitry Andric template <class charT, class traits> 1227*0b57cec5SDimitry Andric friend 1228*0b57cec5SDimitry Andric basic_ostream<charT, traits>& 1229*0b57cec5SDimitry Andric operator<<(basic_ostream<charT, traits>& os, 1230*0b57cec5SDimitry Andric const chi_squared_distribution& x); 1231*0b57cec5SDimitry Andric 1232*0b57cec5SDimitry Andric template <class charT, class traits> 1233*0b57cec5SDimitry Andric friend 1234*0b57cec5SDimitry Andric basic_istream<charT, traits>& 1235*0b57cec5SDimitry Andric operator>>(basic_istream<charT, traits>& is, 1236*0b57cec5SDimitry Andric chi_squared_distribution& x); 1237*0b57cec5SDimitry Andric}; 1238*0b57cec5SDimitry Andric 1239*0b57cec5SDimitry Andrictemplate<class RealType = double> 1240*0b57cec5SDimitry Andricclass cauchy_distribution 1241*0b57cec5SDimitry Andric{ 1242*0b57cec5SDimitry Andricpublic: 1243*0b57cec5SDimitry Andric // types 1244*0b57cec5SDimitry Andric typedef RealType result_type; 1245*0b57cec5SDimitry Andric 1246*0b57cec5SDimitry Andric class param_type 1247*0b57cec5SDimitry Andric { 1248*0b57cec5SDimitry Andric public: 1249*0b57cec5SDimitry Andric typedef cauchy_distribution distribution_type; 1250*0b57cec5SDimitry Andric 1251*0b57cec5SDimitry Andric explicit param_type(result_type a = 0, result_type b = 1); 1252*0b57cec5SDimitry Andric 1253*0b57cec5SDimitry Andric result_type a() const; 1254*0b57cec5SDimitry Andric result_type b() const; 1255*0b57cec5SDimitry Andric 1256*0b57cec5SDimitry Andric friend bool operator==(const param_type& x, const param_type& y); 1257*0b57cec5SDimitry Andric friend bool operator!=(const param_type& x, const param_type& y); 1258*0b57cec5SDimitry Andric }; 1259*0b57cec5SDimitry Andric 1260*0b57cec5SDimitry Andric // constructor and reset functions 1261*0b57cec5SDimitry Andric explicit cauchy_distribution(result_type a = 0, result_type b = 1); 1262*0b57cec5SDimitry Andric explicit cauchy_distribution(const param_type& parm); 1263*0b57cec5SDimitry Andric void reset(); 1264*0b57cec5SDimitry Andric 1265*0b57cec5SDimitry Andric // generating functions 1266*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g); 1267*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g, const param_type& parm); 1268*0b57cec5SDimitry Andric 1269*0b57cec5SDimitry Andric // property functions 1270*0b57cec5SDimitry Andric result_type a() const; 1271*0b57cec5SDimitry Andric result_type b() const; 1272*0b57cec5SDimitry Andric 1273*0b57cec5SDimitry Andric param_type param() const; 1274*0b57cec5SDimitry Andric void param(const param_type& parm); 1275*0b57cec5SDimitry Andric 1276*0b57cec5SDimitry Andric result_type min() const; 1277*0b57cec5SDimitry Andric result_type max() const; 1278*0b57cec5SDimitry Andric 1279*0b57cec5SDimitry Andric friend bool operator==(const cauchy_distribution& x, 1280*0b57cec5SDimitry Andric const cauchy_distribution& y); 1281*0b57cec5SDimitry Andric friend bool operator!=(const cauchy_distribution& x, 1282*0b57cec5SDimitry Andric const cauchy_distribution& y); 1283*0b57cec5SDimitry Andric 1284*0b57cec5SDimitry Andric template <class charT, class traits> 1285*0b57cec5SDimitry Andric friend 1286*0b57cec5SDimitry Andric basic_ostream<charT, traits>& 1287*0b57cec5SDimitry Andric operator<<(basic_ostream<charT, traits>& os, 1288*0b57cec5SDimitry Andric const cauchy_distribution& x); 1289*0b57cec5SDimitry Andric 1290*0b57cec5SDimitry Andric template <class charT, class traits> 1291*0b57cec5SDimitry Andric friend 1292*0b57cec5SDimitry Andric basic_istream<charT, traits>& 1293*0b57cec5SDimitry Andric operator>>(basic_istream<charT, traits>& is, 1294*0b57cec5SDimitry Andric cauchy_distribution& x); 1295*0b57cec5SDimitry Andric}; 1296*0b57cec5SDimitry Andric 1297*0b57cec5SDimitry Andrictemplate<class RealType = double> 1298*0b57cec5SDimitry Andricclass fisher_f_distribution 1299*0b57cec5SDimitry Andric{ 1300*0b57cec5SDimitry Andricpublic: 1301*0b57cec5SDimitry Andric // types 1302*0b57cec5SDimitry Andric typedef RealType result_type; 1303*0b57cec5SDimitry Andric 1304*0b57cec5SDimitry Andric class param_type 1305*0b57cec5SDimitry Andric { 1306*0b57cec5SDimitry Andric public: 1307*0b57cec5SDimitry Andric typedef fisher_f_distribution distribution_type; 1308*0b57cec5SDimitry Andric 1309*0b57cec5SDimitry Andric explicit param_type(result_type m = 1, result_type n = 1); 1310*0b57cec5SDimitry Andric 1311*0b57cec5SDimitry Andric result_type m() const; 1312*0b57cec5SDimitry Andric result_type n() const; 1313*0b57cec5SDimitry Andric 1314*0b57cec5SDimitry Andric friend bool operator==(const param_type& x, const param_type& y); 1315*0b57cec5SDimitry Andric friend bool operator!=(const param_type& x, const param_type& y); 1316*0b57cec5SDimitry Andric }; 1317*0b57cec5SDimitry Andric 1318*0b57cec5SDimitry Andric // constructor and reset functions 1319*0b57cec5SDimitry Andric explicit fisher_f_distribution(result_type m = 1, result_type n = 1); 1320*0b57cec5SDimitry Andric explicit fisher_f_distribution(const param_type& parm); 1321*0b57cec5SDimitry Andric void reset(); 1322*0b57cec5SDimitry Andric 1323*0b57cec5SDimitry Andric // generating functions 1324*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g); 1325*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g, const param_type& parm); 1326*0b57cec5SDimitry Andric 1327*0b57cec5SDimitry Andric // property functions 1328*0b57cec5SDimitry Andric result_type m() const; 1329*0b57cec5SDimitry Andric result_type n() const; 1330*0b57cec5SDimitry Andric 1331*0b57cec5SDimitry Andric param_type param() const; 1332*0b57cec5SDimitry Andric void param(const param_type& parm); 1333*0b57cec5SDimitry Andric 1334*0b57cec5SDimitry Andric result_type min() const; 1335*0b57cec5SDimitry Andric result_type max() const; 1336*0b57cec5SDimitry Andric 1337*0b57cec5SDimitry Andric friend bool operator==(const fisher_f_distribution& x, 1338*0b57cec5SDimitry Andric const fisher_f_distribution& y); 1339*0b57cec5SDimitry Andric friend bool operator!=(const fisher_f_distribution& x, 1340*0b57cec5SDimitry Andric const fisher_f_distribution& y); 1341*0b57cec5SDimitry Andric 1342*0b57cec5SDimitry Andric template <class charT, class traits> 1343*0b57cec5SDimitry Andric friend 1344*0b57cec5SDimitry Andric basic_ostream<charT, traits>& 1345*0b57cec5SDimitry Andric operator<<(basic_ostream<charT, traits>& os, 1346*0b57cec5SDimitry Andric const fisher_f_distribution& x); 1347*0b57cec5SDimitry Andric 1348*0b57cec5SDimitry Andric template <class charT, class traits> 1349*0b57cec5SDimitry Andric friend 1350*0b57cec5SDimitry Andric basic_istream<charT, traits>& 1351*0b57cec5SDimitry Andric operator>>(basic_istream<charT, traits>& is, 1352*0b57cec5SDimitry Andric fisher_f_distribution& x); 1353*0b57cec5SDimitry Andric}; 1354*0b57cec5SDimitry Andric 1355*0b57cec5SDimitry Andrictemplate<class RealType = double> 1356*0b57cec5SDimitry Andricclass student_t_distribution 1357*0b57cec5SDimitry Andric{ 1358*0b57cec5SDimitry Andricpublic: 1359*0b57cec5SDimitry Andric // types 1360*0b57cec5SDimitry Andric typedef RealType result_type; 1361*0b57cec5SDimitry Andric 1362*0b57cec5SDimitry Andric class param_type 1363*0b57cec5SDimitry Andric { 1364*0b57cec5SDimitry Andric public: 1365*0b57cec5SDimitry Andric typedef student_t_distribution distribution_type; 1366*0b57cec5SDimitry Andric 1367*0b57cec5SDimitry Andric explicit param_type(result_type n = 1); 1368*0b57cec5SDimitry Andric 1369*0b57cec5SDimitry Andric result_type n() const; 1370*0b57cec5SDimitry Andric 1371*0b57cec5SDimitry Andric friend bool operator==(const param_type& x, const param_type& y); 1372*0b57cec5SDimitry Andric friend bool operator!=(const param_type& x, const param_type& y); 1373*0b57cec5SDimitry Andric }; 1374*0b57cec5SDimitry Andric 1375*0b57cec5SDimitry Andric // constructor and reset functions 1376*0b57cec5SDimitry Andric explicit student_t_distribution(result_type n = 1); 1377*0b57cec5SDimitry Andric explicit student_t_distribution(const param_type& parm); 1378*0b57cec5SDimitry Andric void reset(); 1379*0b57cec5SDimitry Andric 1380*0b57cec5SDimitry Andric // generating functions 1381*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g); 1382*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g, const param_type& parm); 1383*0b57cec5SDimitry Andric 1384*0b57cec5SDimitry Andric // property functions 1385*0b57cec5SDimitry Andric result_type n() const; 1386*0b57cec5SDimitry Andric 1387*0b57cec5SDimitry Andric param_type param() const; 1388*0b57cec5SDimitry Andric void param(const param_type& parm); 1389*0b57cec5SDimitry Andric 1390*0b57cec5SDimitry Andric result_type min() const; 1391*0b57cec5SDimitry Andric result_type max() const; 1392*0b57cec5SDimitry Andric 1393*0b57cec5SDimitry Andric friend bool operator==(const student_t_distribution& x, 1394*0b57cec5SDimitry Andric const student_t_distribution& y); 1395*0b57cec5SDimitry Andric friend bool operator!=(const student_t_distribution& x, 1396*0b57cec5SDimitry Andric const student_t_distribution& y); 1397*0b57cec5SDimitry Andric 1398*0b57cec5SDimitry Andric template <class charT, class traits> 1399*0b57cec5SDimitry Andric friend 1400*0b57cec5SDimitry Andric basic_ostream<charT, traits>& 1401*0b57cec5SDimitry Andric operator<<(basic_ostream<charT, traits>& os, 1402*0b57cec5SDimitry Andric const student_t_distribution& x); 1403*0b57cec5SDimitry Andric 1404*0b57cec5SDimitry Andric template <class charT, class traits> 1405*0b57cec5SDimitry Andric friend 1406*0b57cec5SDimitry Andric basic_istream<charT, traits>& 1407*0b57cec5SDimitry Andric operator>>(basic_istream<charT, traits>& is, 1408*0b57cec5SDimitry Andric student_t_distribution& x); 1409*0b57cec5SDimitry Andric}; 1410*0b57cec5SDimitry Andric 1411*0b57cec5SDimitry Andrictemplate<class IntType = int> 1412*0b57cec5SDimitry Andricclass discrete_distribution 1413*0b57cec5SDimitry Andric{ 1414*0b57cec5SDimitry Andricpublic: 1415*0b57cec5SDimitry Andric // types 1416*0b57cec5SDimitry Andric typedef IntType result_type; 1417*0b57cec5SDimitry Andric 1418*0b57cec5SDimitry Andric class param_type 1419*0b57cec5SDimitry Andric { 1420*0b57cec5SDimitry Andric public: 1421*0b57cec5SDimitry Andric typedef discrete_distribution distribution_type; 1422*0b57cec5SDimitry Andric 1423*0b57cec5SDimitry Andric param_type(); 1424*0b57cec5SDimitry Andric template<class InputIterator> 1425*0b57cec5SDimitry Andric param_type(InputIterator firstW, InputIterator lastW); 1426*0b57cec5SDimitry Andric param_type(initializer_list<double> wl); 1427*0b57cec5SDimitry Andric template<class UnaryOperation> 1428*0b57cec5SDimitry Andric param_type(size_t nw, double xmin, double xmax, UnaryOperation fw); 1429*0b57cec5SDimitry Andric 1430*0b57cec5SDimitry Andric vector<double> probabilities() const; 1431*0b57cec5SDimitry Andric 1432*0b57cec5SDimitry Andric friend bool operator==(const param_type& x, const param_type& y); 1433*0b57cec5SDimitry Andric friend bool operator!=(const param_type& x, const param_type& y); 1434*0b57cec5SDimitry Andric }; 1435*0b57cec5SDimitry Andric 1436*0b57cec5SDimitry Andric // constructor and reset functions 1437*0b57cec5SDimitry Andric discrete_distribution(); 1438*0b57cec5SDimitry Andric template<class InputIterator> 1439*0b57cec5SDimitry Andric discrete_distribution(InputIterator firstW, InputIterator lastW); 1440*0b57cec5SDimitry Andric discrete_distribution(initializer_list<double> wl); 1441*0b57cec5SDimitry Andric template<class UnaryOperation> 1442*0b57cec5SDimitry Andric discrete_distribution(size_t nw, double xmin, double xmax, 1443*0b57cec5SDimitry Andric UnaryOperation fw); 1444*0b57cec5SDimitry Andric explicit discrete_distribution(const param_type& parm); 1445*0b57cec5SDimitry Andric void reset(); 1446*0b57cec5SDimitry Andric 1447*0b57cec5SDimitry Andric // generating functions 1448*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g); 1449*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g, const param_type& parm); 1450*0b57cec5SDimitry Andric 1451*0b57cec5SDimitry Andric // property functions 1452*0b57cec5SDimitry Andric vector<double> probabilities() const; 1453*0b57cec5SDimitry Andric 1454*0b57cec5SDimitry Andric param_type param() const; 1455*0b57cec5SDimitry Andric void param(const param_type& parm); 1456*0b57cec5SDimitry Andric 1457*0b57cec5SDimitry Andric result_type min() const; 1458*0b57cec5SDimitry Andric result_type max() const; 1459*0b57cec5SDimitry Andric 1460*0b57cec5SDimitry Andric friend bool operator==(const discrete_distribution& x, 1461*0b57cec5SDimitry Andric const discrete_distribution& y); 1462*0b57cec5SDimitry Andric friend bool operator!=(const discrete_distribution& x, 1463*0b57cec5SDimitry Andric const discrete_distribution& y); 1464*0b57cec5SDimitry Andric 1465*0b57cec5SDimitry Andric template <class charT, class traits> 1466*0b57cec5SDimitry Andric friend 1467*0b57cec5SDimitry Andric basic_ostream<charT, traits>& 1468*0b57cec5SDimitry Andric operator<<(basic_ostream<charT, traits>& os, 1469*0b57cec5SDimitry Andric const discrete_distribution& x); 1470*0b57cec5SDimitry Andric 1471*0b57cec5SDimitry Andric template <class charT, class traits> 1472*0b57cec5SDimitry Andric friend 1473*0b57cec5SDimitry Andric basic_istream<charT, traits>& 1474*0b57cec5SDimitry Andric operator>>(basic_istream<charT, traits>& is, 1475*0b57cec5SDimitry Andric discrete_distribution& x); 1476*0b57cec5SDimitry Andric}; 1477*0b57cec5SDimitry Andric 1478*0b57cec5SDimitry Andrictemplate<class RealType = double> 1479*0b57cec5SDimitry Andricclass piecewise_constant_distribution 1480*0b57cec5SDimitry Andric{ 1481*0b57cec5SDimitry Andric // types 1482*0b57cec5SDimitry Andric typedef RealType result_type; 1483*0b57cec5SDimitry Andric 1484*0b57cec5SDimitry Andric class param_type 1485*0b57cec5SDimitry Andric { 1486*0b57cec5SDimitry Andric public: 1487*0b57cec5SDimitry Andric typedef piecewise_constant_distribution distribution_type; 1488*0b57cec5SDimitry Andric 1489*0b57cec5SDimitry Andric param_type(); 1490*0b57cec5SDimitry Andric template<class InputIteratorB, class InputIteratorW> 1491*0b57cec5SDimitry Andric param_type(InputIteratorB firstB, InputIteratorB lastB, 1492*0b57cec5SDimitry Andric InputIteratorW firstW); 1493*0b57cec5SDimitry Andric template<class UnaryOperation> 1494*0b57cec5SDimitry Andric param_type(initializer_list<result_type> bl, UnaryOperation fw); 1495*0b57cec5SDimitry Andric template<class UnaryOperation> 1496*0b57cec5SDimitry Andric param_type(size_t nw, result_type xmin, result_type xmax, 1497*0b57cec5SDimitry Andric UnaryOperation fw); 1498*0b57cec5SDimitry Andric 1499*0b57cec5SDimitry Andric vector<result_type> intervals() const; 1500*0b57cec5SDimitry Andric vector<result_type> densities() const; 1501*0b57cec5SDimitry Andric 1502*0b57cec5SDimitry Andric friend bool operator==(const param_type& x, const param_type& y); 1503*0b57cec5SDimitry Andric friend bool operator!=(const param_type& x, const param_type& y); 1504*0b57cec5SDimitry Andric }; 1505*0b57cec5SDimitry Andric 1506*0b57cec5SDimitry Andric // constructor and reset functions 1507*0b57cec5SDimitry Andric piecewise_constant_distribution(); 1508*0b57cec5SDimitry Andric template<class InputIteratorB, class InputIteratorW> 1509*0b57cec5SDimitry Andric piecewise_constant_distribution(InputIteratorB firstB, 1510*0b57cec5SDimitry Andric InputIteratorB lastB, 1511*0b57cec5SDimitry Andric InputIteratorW firstW); 1512*0b57cec5SDimitry Andric template<class UnaryOperation> 1513*0b57cec5SDimitry Andric piecewise_constant_distribution(initializer_list<result_type> bl, 1514*0b57cec5SDimitry Andric UnaryOperation fw); 1515*0b57cec5SDimitry Andric template<class UnaryOperation> 1516*0b57cec5SDimitry Andric piecewise_constant_distribution(size_t nw, result_type xmin, 1517*0b57cec5SDimitry Andric result_type xmax, UnaryOperation fw); 1518*0b57cec5SDimitry Andric explicit piecewise_constant_distribution(const param_type& parm); 1519*0b57cec5SDimitry Andric void reset(); 1520*0b57cec5SDimitry Andric 1521*0b57cec5SDimitry Andric // generating functions 1522*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g); 1523*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g, const param_type& parm); 1524*0b57cec5SDimitry Andric 1525*0b57cec5SDimitry Andric // property functions 1526*0b57cec5SDimitry Andric vector<result_type> intervals() const; 1527*0b57cec5SDimitry Andric vector<result_type> densities() const; 1528*0b57cec5SDimitry Andric 1529*0b57cec5SDimitry Andric param_type param() const; 1530*0b57cec5SDimitry Andric void param(const param_type& parm); 1531*0b57cec5SDimitry Andric 1532*0b57cec5SDimitry Andric result_type min() const; 1533*0b57cec5SDimitry Andric result_type max() const; 1534*0b57cec5SDimitry Andric 1535*0b57cec5SDimitry Andric friend bool operator==(const piecewise_constant_distribution& x, 1536*0b57cec5SDimitry Andric const piecewise_constant_distribution& y); 1537*0b57cec5SDimitry Andric friend bool operator!=(const piecewise_constant_distribution& x, 1538*0b57cec5SDimitry Andric const piecewise_constant_distribution& y); 1539*0b57cec5SDimitry Andric 1540*0b57cec5SDimitry Andric template <class charT, class traits> 1541*0b57cec5SDimitry Andric friend 1542*0b57cec5SDimitry Andric basic_ostream<charT, traits>& 1543*0b57cec5SDimitry Andric operator<<(basic_ostream<charT, traits>& os, 1544*0b57cec5SDimitry Andric const piecewise_constant_distribution& x); 1545*0b57cec5SDimitry Andric 1546*0b57cec5SDimitry Andric template <class charT, class traits> 1547*0b57cec5SDimitry Andric friend 1548*0b57cec5SDimitry Andric basic_istream<charT, traits>& 1549*0b57cec5SDimitry Andric operator>>(basic_istream<charT, traits>& is, 1550*0b57cec5SDimitry Andric piecewise_constant_distribution& x); 1551*0b57cec5SDimitry Andric}; 1552*0b57cec5SDimitry Andric 1553*0b57cec5SDimitry Andrictemplate<class RealType = double> 1554*0b57cec5SDimitry Andricclass piecewise_linear_distribution 1555*0b57cec5SDimitry Andric{ 1556*0b57cec5SDimitry Andric // types 1557*0b57cec5SDimitry Andric typedef RealType result_type; 1558*0b57cec5SDimitry Andric 1559*0b57cec5SDimitry Andric class param_type 1560*0b57cec5SDimitry Andric { 1561*0b57cec5SDimitry Andric public: 1562*0b57cec5SDimitry Andric typedef piecewise_linear_distribution distribution_type; 1563*0b57cec5SDimitry Andric 1564*0b57cec5SDimitry Andric param_type(); 1565*0b57cec5SDimitry Andric template<class InputIteratorB, class InputIteratorW> 1566*0b57cec5SDimitry Andric param_type(InputIteratorB firstB, InputIteratorB lastB, 1567*0b57cec5SDimitry Andric InputIteratorW firstW); 1568*0b57cec5SDimitry Andric template<class UnaryOperation> 1569*0b57cec5SDimitry Andric param_type(initializer_list<result_type> bl, UnaryOperation fw); 1570*0b57cec5SDimitry Andric template<class UnaryOperation> 1571*0b57cec5SDimitry Andric param_type(size_t nw, result_type xmin, result_type xmax, 1572*0b57cec5SDimitry Andric UnaryOperation fw); 1573*0b57cec5SDimitry Andric 1574*0b57cec5SDimitry Andric vector<result_type> intervals() const; 1575*0b57cec5SDimitry Andric vector<result_type> densities() const; 1576*0b57cec5SDimitry Andric 1577*0b57cec5SDimitry Andric friend bool operator==(const param_type& x, const param_type& y); 1578*0b57cec5SDimitry Andric friend bool operator!=(const param_type& x, const param_type& y); 1579*0b57cec5SDimitry Andric }; 1580*0b57cec5SDimitry Andric 1581*0b57cec5SDimitry Andric // constructor and reset functions 1582*0b57cec5SDimitry Andric piecewise_linear_distribution(); 1583*0b57cec5SDimitry Andric template<class InputIteratorB, class InputIteratorW> 1584*0b57cec5SDimitry Andric piecewise_linear_distribution(InputIteratorB firstB, 1585*0b57cec5SDimitry Andric InputIteratorB lastB, 1586*0b57cec5SDimitry Andric InputIteratorW firstW); 1587*0b57cec5SDimitry Andric 1588*0b57cec5SDimitry Andric template<class UnaryOperation> 1589*0b57cec5SDimitry Andric piecewise_linear_distribution(initializer_list<result_type> bl, 1590*0b57cec5SDimitry Andric UnaryOperation fw); 1591*0b57cec5SDimitry Andric 1592*0b57cec5SDimitry Andric template<class UnaryOperation> 1593*0b57cec5SDimitry Andric piecewise_linear_distribution(size_t nw, result_type xmin, 1594*0b57cec5SDimitry Andric result_type xmax, UnaryOperation fw); 1595*0b57cec5SDimitry Andric 1596*0b57cec5SDimitry Andric explicit piecewise_linear_distribution(const param_type& parm); 1597*0b57cec5SDimitry Andric void reset(); 1598*0b57cec5SDimitry Andric 1599*0b57cec5SDimitry Andric // generating functions 1600*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g); 1601*0b57cec5SDimitry Andric template<class URNG> result_type operator()(URNG& g, const param_type& parm); 1602*0b57cec5SDimitry Andric 1603*0b57cec5SDimitry Andric // property functions 1604*0b57cec5SDimitry Andric vector<result_type> intervals() const; 1605*0b57cec5SDimitry Andric vector<result_type> densities() const; 1606*0b57cec5SDimitry Andric 1607*0b57cec5SDimitry Andric param_type param() const; 1608*0b57cec5SDimitry Andric void param(const param_type& parm); 1609*0b57cec5SDimitry Andric 1610*0b57cec5SDimitry Andric result_type min() const; 1611*0b57cec5SDimitry Andric result_type max() const; 1612*0b57cec5SDimitry Andric 1613*0b57cec5SDimitry Andric friend bool operator==(const piecewise_linear_distribution& x, 1614*0b57cec5SDimitry Andric const piecewise_linear_distribution& y); 1615*0b57cec5SDimitry Andric friend bool operator!=(const piecewise_linear_distribution& x, 1616*0b57cec5SDimitry Andric const piecewise_linear_distribution& y); 1617*0b57cec5SDimitry Andric 1618*0b57cec5SDimitry Andric template <class charT, class traits> 1619*0b57cec5SDimitry Andric friend 1620*0b57cec5SDimitry Andric basic_ostream<charT, traits>& 1621*0b57cec5SDimitry Andric operator<<(basic_ostream<charT, traits>& os, 1622*0b57cec5SDimitry Andric const piecewise_linear_distribution& x); 1623*0b57cec5SDimitry Andric 1624*0b57cec5SDimitry Andric template <class charT, class traits> 1625*0b57cec5SDimitry Andric friend 1626*0b57cec5SDimitry Andric basic_istream<charT, traits>& 1627*0b57cec5SDimitry Andric operator>>(basic_istream<charT, traits>& is, 1628*0b57cec5SDimitry Andric piecewise_linear_distribution& x); 1629*0b57cec5SDimitry Andric}; 1630*0b57cec5SDimitry Andric 1631*0b57cec5SDimitry Andric} // std 1632*0b57cec5SDimitry Andric*/ 1633*0b57cec5SDimitry Andric 1634*0b57cec5SDimitry Andric#include <__config> 1635*0b57cec5SDimitry Andric#include <cstddef> 1636*0b57cec5SDimitry Andric#include <cstdint> 1637*0b57cec5SDimitry Andric#include <cmath> 1638*0b57cec5SDimitry Andric#include <type_traits> 1639*0b57cec5SDimitry Andric#include <initializer_list> 1640*0b57cec5SDimitry Andric#include <limits> 1641*0b57cec5SDimitry Andric#include <algorithm> 1642*0b57cec5SDimitry Andric#include <numeric> 1643*0b57cec5SDimitry Andric#include <vector> 1644*0b57cec5SDimitry Andric#include <string> 1645*0b57cec5SDimitry Andric#include <istream> 1646*0b57cec5SDimitry Andric#include <ostream> 1647*0b57cec5SDimitry Andric 1648*0b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 1649*0b57cec5SDimitry Andric#pragma GCC system_header 1650*0b57cec5SDimitry Andric#endif 1651*0b57cec5SDimitry Andric 1652*0b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS 1653*0b57cec5SDimitry Andric#include <__undef_macros> 1654*0b57cec5SDimitry Andric 1655*0b57cec5SDimitry Andric 1656*0b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 1657*0b57cec5SDimitry Andric 1658*0b57cec5SDimitry Andric// __is_seed_sequence 1659*0b57cec5SDimitry Andric 1660*0b57cec5SDimitry Andrictemplate <class _Sseq, class _Engine> 1661*0b57cec5SDimitry Andricstruct __is_seed_sequence 1662*0b57cec5SDimitry Andric{ 1663*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const bool value = 1664*0b57cec5SDimitry Andric !is_convertible<_Sseq, typename _Engine::result_type>::value && 1665*0b57cec5SDimitry Andric !is_same<typename remove_cv<_Sseq>::type, _Engine>::value; 1666*0b57cec5SDimitry Andric}; 1667*0b57cec5SDimitry Andric 1668*0b57cec5SDimitry Andric// linear_congruential_engine 1669*0b57cec5SDimitry Andric 1670*0b57cec5SDimitry Andrictemplate <unsigned long long __a, unsigned long long __c, 1671*0b57cec5SDimitry Andric unsigned long long __m, unsigned long long _Mp, 1672*0b57cec5SDimitry Andric bool _MightOverflow = (__a != 0 && __m != 0 && __m-1 > (_Mp-__c)/__a)> 1673*0b57cec5SDimitry Andricstruct __lce_ta; 1674*0b57cec5SDimitry Andric 1675*0b57cec5SDimitry Andric// 64 1676*0b57cec5SDimitry Andric 1677*0b57cec5SDimitry Andrictemplate <unsigned long long __a, unsigned long long __c, unsigned long long __m> 1678*0b57cec5SDimitry Andricstruct __lce_ta<__a, __c, __m, (unsigned long long)(~0), true> 1679*0b57cec5SDimitry Andric{ 1680*0b57cec5SDimitry Andric typedef unsigned long long result_type; 1681*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1682*0b57cec5SDimitry Andric static result_type next(result_type __x) 1683*0b57cec5SDimitry Andric { 1684*0b57cec5SDimitry Andric // Schrage's algorithm 1685*0b57cec5SDimitry Andric const result_type __q = __m / __a; 1686*0b57cec5SDimitry Andric const result_type __r = __m % __a; 1687*0b57cec5SDimitry Andric const result_type __t0 = __a * (__x % __q); 1688*0b57cec5SDimitry Andric const result_type __t1 = __r * (__x / __q); 1689*0b57cec5SDimitry Andric __x = __t0 + (__t0 < __t1) * __m - __t1; 1690*0b57cec5SDimitry Andric __x += __c - (__x >= __m - __c) * __m; 1691*0b57cec5SDimitry Andric return __x; 1692*0b57cec5SDimitry Andric } 1693*0b57cec5SDimitry Andric}; 1694*0b57cec5SDimitry Andric 1695*0b57cec5SDimitry Andrictemplate <unsigned long long __a, unsigned long long __m> 1696*0b57cec5SDimitry Andricstruct __lce_ta<__a, 0, __m, (unsigned long long)(~0), true> 1697*0b57cec5SDimitry Andric{ 1698*0b57cec5SDimitry Andric typedef unsigned long long result_type; 1699*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1700*0b57cec5SDimitry Andric static result_type next(result_type __x) 1701*0b57cec5SDimitry Andric { 1702*0b57cec5SDimitry Andric // Schrage's algorithm 1703*0b57cec5SDimitry Andric const result_type __q = __m / __a; 1704*0b57cec5SDimitry Andric const result_type __r = __m % __a; 1705*0b57cec5SDimitry Andric const result_type __t0 = __a * (__x % __q); 1706*0b57cec5SDimitry Andric const result_type __t1 = __r * (__x / __q); 1707*0b57cec5SDimitry Andric __x = __t0 + (__t0 < __t1) * __m - __t1; 1708*0b57cec5SDimitry Andric return __x; 1709*0b57cec5SDimitry Andric } 1710*0b57cec5SDimitry Andric}; 1711*0b57cec5SDimitry Andric 1712*0b57cec5SDimitry Andrictemplate <unsigned long long __a, unsigned long long __c, unsigned long long __m> 1713*0b57cec5SDimitry Andricstruct __lce_ta<__a, __c, __m, (unsigned long long)(~0), false> 1714*0b57cec5SDimitry Andric{ 1715*0b57cec5SDimitry Andric typedef unsigned long long result_type; 1716*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1717*0b57cec5SDimitry Andric static result_type next(result_type __x) 1718*0b57cec5SDimitry Andric { 1719*0b57cec5SDimitry Andric return (__a * __x + __c) % __m; 1720*0b57cec5SDimitry Andric } 1721*0b57cec5SDimitry Andric}; 1722*0b57cec5SDimitry Andric 1723*0b57cec5SDimitry Andrictemplate <unsigned long long __a, unsigned long long __c> 1724*0b57cec5SDimitry Andricstruct __lce_ta<__a, __c, 0, (unsigned long long)(~0), false> 1725*0b57cec5SDimitry Andric{ 1726*0b57cec5SDimitry Andric typedef unsigned long long result_type; 1727*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1728*0b57cec5SDimitry Andric static result_type next(result_type __x) 1729*0b57cec5SDimitry Andric { 1730*0b57cec5SDimitry Andric return __a * __x + __c; 1731*0b57cec5SDimitry Andric } 1732*0b57cec5SDimitry Andric}; 1733*0b57cec5SDimitry Andric 1734*0b57cec5SDimitry Andric// 32 1735*0b57cec5SDimitry Andric 1736*0b57cec5SDimitry Andrictemplate <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp> 1737*0b57cec5SDimitry Andricstruct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), true> 1738*0b57cec5SDimitry Andric{ 1739*0b57cec5SDimitry Andric typedef unsigned result_type; 1740*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1741*0b57cec5SDimitry Andric static result_type next(result_type __x) 1742*0b57cec5SDimitry Andric { 1743*0b57cec5SDimitry Andric const result_type __a = static_cast<result_type>(_Ap); 1744*0b57cec5SDimitry Andric const result_type __c = static_cast<result_type>(_Cp); 1745*0b57cec5SDimitry Andric const result_type __m = static_cast<result_type>(_Mp); 1746*0b57cec5SDimitry Andric // Schrage's algorithm 1747*0b57cec5SDimitry Andric const result_type __q = __m / __a; 1748*0b57cec5SDimitry Andric const result_type __r = __m % __a; 1749*0b57cec5SDimitry Andric const result_type __t0 = __a * (__x % __q); 1750*0b57cec5SDimitry Andric const result_type __t1 = __r * (__x / __q); 1751*0b57cec5SDimitry Andric __x = __t0 + (__t0 < __t1) * __m - __t1; 1752*0b57cec5SDimitry Andric __x += __c - (__x >= __m - __c) * __m; 1753*0b57cec5SDimitry Andric return __x; 1754*0b57cec5SDimitry Andric } 1755*0b57cec5SDimitry Andric}; 1756*0b57cec5SDimitry Andric 1757*0b57cec5SDimitry Andrictemplate <unsigned long long _Ap, unsigned long long _Mp> 1758*0b57cec5SDimitry Andricstruct __lce_ta<_Ap, 0, _Mp, unsigned(~0), true> 1759*0b57cec5SDimitry Andric{ 1760*0b57cec5SDimitry Andric typedef unsigned result_type; 1761*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1762*0b57cec5SDimitry Andric static result_type next(result_type __x) 1763*0b57cec5SDimitry Andric { 1764*0b57cec5SDimitry Andric const result_type __a = static_cast<result_type>(_Ap); 1765*0b57cec5SDimitry Andric const result_type __m = static_cast<result_type>(_Mp); 1766*0b57cec5SDimitry Andric // Schrage's algorithm 1767*0b57cec5SDimitry Andric const result_type __q = __m / __a; 1768*0b57cec5SDimitry Andric const result_type __r = __m % __a; 1769*0b57cec5SDimitry Andric const result_type __t0 = __a * (__x % __q); 1770*0b57cec5SDimitry Andric const result_type __t1 = __r * (__x / __q); 1771*0b57cec5SDimitry Andric __x = __t0 + (__t0 < __t1) * __m - __t1; 1772*0b57cec5SDimitry Andric return __x; 1773*0b57cec5SDimitry Andric } 1774*0b57cec5SDimitry Andric}; 1775*0b57cec5SDimitry Andric 1776*0b57cec5SDimitry Andrictemplate <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp> 1777*0b57cec5SDimitry Andricstruct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), false> 1778*0b57cec5SDimitry Andric{ 1779*0b57cec5SDimitry Andric typedef unsigned result_type; 1780*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1781*0b57cec5SDimitry Andric static result_type next(result_type __x) 1782*0b57cec5SDimitry Andric { 1783*0b57cec5SDimitry Andric const result_type __a = static_cast<result_type>(_Ap); 1784*0b57cec5SDimitry Andric const result_type __c = static_cast<result_type>(_Cp); 1785*0b57cec5SDimitry Andric const result_type __m = static_cast<result_type>(_Mp); 1786*0b57cec5SDimitry Andric return (__a * __x + __c) % __m; 1787*0b57cec5SDimitry Andric } 1788*0b57cec5SDimitry Andric}; 1789*0b57cec5SDimitry Andric 1790*0b57cec5SDimitry Andrictemplate <unsigned long long _Ap, unsigned long long _Cp> 1791*0b57cec5SDimitry Andricstruct __lce_ta<_Ap, _Cp, 0, unsigned(~0), false> 1792*0b57cec5SDimitry Andric{ 1793*0b57cec5SDimitry Andric typedef unsigned result_type; 1794*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1795*0b57cec5SDimitry Andric static result_type next(result_type __x) 1796*0b57cec5SDimitry Andric { 1797*0b57cec5SDimitry Andric const result_type __a = static_cast<result_type>(_Ap); 1798*0b57cec5SDimitry Andric const result_type __c = static_cast<result_type>(_Cp); 1799*0b57cec5SDimitry Andric return __a * __x + __c; 1800*0b57cec5SDimitry Andric } 1801*0b57cec5SDimitry Andric}; 1802*0b57cec5SDimitry Andric 1803*0b57cec5SDimitry Andric// 16 1804*0b57cec5SDimitry Andric 1805*0b57cec5SDimitry Andrictemplate <unsigned long long __a, unsigned long long __c, unsigned long long __m, bool __b> 1806*0b57cec5SDimitry Andricstruct __lce_ta<__a, __c, __m, (unsigned short)(~0), __b> 1807*0b57cec5SDimitry Andric{ 1808*0b57cec5SDimitry Andric typedef unsigned short result_type; 1809*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1810*0b57cec5SDimitry Andric static result_type next(result_type __x) 1811*0b57cec5SDimitry Andric { 1812*0b57cec5SDimitry Andric return static_cast<result_type>(__lce_ta<__a, __c, __m, unsigned(~0)>::next(__x)); 1813*0b57cec5SDimitry Andric } 1814*0b57cec5SDimitry Andric}; 1815*0b57cec5SDimitry Andric 1816*0b57cec5SDimitry Andrictemplate <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 1817*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS linear_congruential_engine; 1818*0b57cec5SDimitry Andric 1819*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, 1820*0b57cec5SDimitry Andric class _Up, _Up _Ap, _Up _Cp, _Up _Np> 1821*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 1822*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 1823*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 1824*0b57cec5SDimitry Andric const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&); 1825*0b57cec5SDimitry Andric 1826*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, 1827*0b57cec5SDimitry Andric class _Up, _Up _Ap, _Up _Cp, _Up _Np> 1828*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 1829*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 1830*0b57cec5SDimitry Andric linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x); 1831*0b57cec5SDimitry Andric 1832*0b57cec5SDimitry Andrictemplate <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 1833*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS linear_congruential_engine 1834*0b57cec5SDimitry Andric{ 1835*0b57cec5SDimitry Andricpublic: 1836*0b57cec5SDimitry Andric // types 1837*0b57cec5SDimitry Andric typedef _UIntType result_type; 1838*0b57cec5SDimitry Andric 1839*0b57cec5SDimitry Andricprivate: 1840*0b57cec5SDimitry Andric result_type __x_; 1841*0b57cec5SDimitry Andric 1842*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type _Mp = result_type(~0); 1843*0b57cec5SDimitry Andric 1844*0b57cec5SDimitry Andric static_assert(__m == 0 || __a < __m, "linear_congruential_engine invalid parameters"); 1845*0b57cec5SDimitry Andric static_assert(__m == 0 || __c < __m, "linear_congruential_engine invalid parameters"); 1846*0b57cec5SDimitry Andricpublic: 1847*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type _Min = __c == 0u ? 1u: 0u; 1848*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type _Max = __m - 1u; 1849*0b57cec5SDimitry Andric static_assert(_Min < _Max, "linear_congruential_engine invalid parameters"); 1850*0b57cec5SDimitry Andric 1851*0b57cec5SDimitry Andric // engine characteristics 1852*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type multiplier = __a; 1853*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type increment = __c; 1854*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type modulus = __m; 1855*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1856*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR result_type min() {return _Min;} 1857*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1858*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR result_type max() {return _Max;} 1859*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type default_seed = 1u; 1860*0b57cec5SDimitry Andric 1861*0b57cec5SDimitry Andric // constructors and seeding functions 1862*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1863*0b57cec5SDimitry Andric explicit linear_congruential_engine(result_type __s = default_seed) 1864*0b57cec5SDimitry Andric {seed(__s);} 1865*0b57cec5SDimitry Andric template<class _Sseq> 1866*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1867*0b57cec5SDimitry Andric explicit linear_congruential_engine(_Sseq& __q, 1868*0b57cec5SDimitry Andric typename enable_if<__is_seed_sequence<_Sseq, linear_congruential_engine>::value>::type* = 0) 1869*0b57cec5SDimitry Andric {seed(__q);} 1870*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1871*0b57cec5SDimitry Andric void seed(result_type __s = default_seed) 1872*0b57cec5SDimitry Andric {seed(integral_constant<bool, __m == 0>(), 1873*0b57cec5SDimitry Andric integral_constant<bool, __c == 0>(), __s);} 1874*0b57cec5SDimitry Andric template<class _Sseq> 1875*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1876*0b57cec5SDimitry Andric typename enable_if 1877*0b57cec5SDimitry Andric < 1878*0b57cec5SDimitry Andric __is_seed_sequence<_Sseq, linear_congruential_engine>::value, 1879*0b57cec5SDimitry Andric void 1880*0b57cec5SDimitry Andric >::type 1881*0b57cec5SDimitry Andric seed(_Sseq& __q) 1882*0b57cec5SDimitry Andric {__seed(__q, integral_constant<unsigned, 1883*0b57cec5SDimitry Andric 1 + (__m == 0 ? (sizeof(result_type) * __CHAR_BIT__ - 1)/32 1884*0b57cec5SDimitry Andric : (__m > 0x100000000ull))>());} 1885*0b57cec5SDimitry Andric 1886*0b57cec5SDimitry Andric // generating functions 1887*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1888*0b57cec5SDimitry Andric result_type operator()() 1889*0b57cec5SDimitry Andric {return __x_ = static_cast<result_type>(__lce_ta<__a, __c, __m, _Mp>::next(__x_));} 1890*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1891*0b57cec5SDimitry Andric void discard(unsigned long long __z) {for (; __z; --__z) operator()();} 1892*0b57cec5SDimitry Andric 1893*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 1894*0b57cec5SDimitry Andric bool operator==(const linear_congruential_engine& __x, 1895*0b57cec5SDimitry Andric const linear_congruential_engine& __y) 1896*0b57cec5SDimitry Andric {return __x.__x_ == __y.__x_;} 1897*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 1898*0b57cec5SDimitry Andric bool operator!=(const linear_congruential_engine& __x, 1899*0b57cec5SDimitry Andric const linear_congruential_engine& __y) 1900*0b57cec5SDimitry Andric {return !(__x == __y);} 1901*0b57cec5SDimitry Andric 1902*0b57cec5SDimitry Andricprivate: 1903*0b57cec5SDimitry Andric 1904*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1905*0b57cec5SDimitry Andric void seed(true_type, true_type, result_type __s) {__x_ = __s == 0 ? 1 : __s;} 1906*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1907*0b57cec5SDimitry Andric void seed(true_type, false_type, result_type __s) {__x_ = __s;} 1908*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1909*0b57cec5SDimitry Andric void seed(false_type, true_type, result_type __s) {__x_ = __s % __m == 0 ? 1910*0b57cec5SDimitry Andric 1 : __s % __m;} 1911*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1912*0b57cec5SDimitry Andric void seed(false_type, false_type, result_type __s) {__x_ = __s % __m;} 1913*0b57cec5SDimitry Andric 1914*0b57cec5SDimitry Andric template<class _Sseq> 1915*0b57cec5SDimitry Andric void __seed(_Sseq& __q, integral_constant<unsigned, 1>); 1916*0b57cec5SDimitry Andric template<class _Sseq> 1917*0b57cec5SDimitry Andric void __seed(_Sseq& __q, integral_constant<unsigned, 2>); 1918*0b57cec5SDimitry Andric 1919*0b57cec5SDimitry Andric template <class _CharT, class _Traits, 1920*0b57cec5SDimitry Andric class _Up, _Up _Ap, _Up _Cp, _Up _Np> 1921*0b57cec5SDimitry Andric friend 1922*0b57cec5SDimitry Andric basic_ostream<_CharT, _Traits>& 1923*0b57cec5SDimitry Andric operator<<(basic_ostream<_CharT, _Traits>& __os, 1924*0b57cec5SDimitry Andric const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&); 1925*0b57cec5SDimitry Andric 1926*0b57cec5SDimitry Andric template <class _CharT, class _Traits, 1927*0b57cec5SDimitry Andric class _Up, _Up _Ap, _Up _Cp, _Up _Np> 1928*0b57cec5SDimitry Andric friend 1929*0b57cec5SDimitry Andric basic_istream<_CharT, _Traits>& 1930*0b57cec5SDimitry Andric operator>>(basic_istream<_CharT, _Traits>& __is, 1931*0b57cec5SDimitry Andric linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x); 1932*0b57cec5SDimitry Andric}; 1933*0b57cec5SDimitry Andric 1934*0b57cec5SDimitry Andrictemplate <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 1935*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type 1936*0b57cec5SDimitry Andric linear_congruential_engine<_UIntType, __a, __c, __m>::multiplier; 1937*0b57cec5SDimitry Andric 1938*0b57cec5SDimitry Andrictemplate <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 1939*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type 1940*0b57cec5SDimitry Andric linear_congruential_engine<_UIntType, __a, __c, __m>::increment; 1941*0b57cec5SDimitry Andric 1942*0b57cec5SDimitry Andrictemplate <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 1943*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type 1944*0b57cec5SDimitry Andric linear_congruential_engine<_UIntType, __a, __c, __m>::modulus; 1945*0b57cec5SDimitry Andric 1946*0b57cec5SDimitry Andrictemplate <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 1947*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type 1948*0b57cec5SDimitry Andric linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed; 1949*0b57cec5SDimitry Andric 1950*0b57cec5SDimitry Andrictemplate <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 1951*0b57cec5SDimitry Andrictemplate<class _Sseq> 1952*0b57cec5SDimitry Andricvoid 1953*0b57cec5SDimitry Andriclinear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, 1954*0b57cec5SDimitry Andric integral_constant<unsigned, 1>) 1955*0b57cec5SDimitry Andric{ 1956*0b57cec5SDimitry Andric const unsigned __k = 1; 1957*0b57cec5SDimitry Andric uint32_t __ar[__k+3]; 1958*0b57cec5SDimitry Andric __q.generate(__ar, __ar + __k + 3); 1959*0b57cec5SDimitry Andric result_type __s = static_cast<result_type>(__ar[3] % __m); 1960*0b57cec5SDimitry Andric __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; 1961*0b57cec5SDimitry Andric} 1962*0b57cec5SDimitry Andric 1963*0b57cec5SDimitry Andrictemplate <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 1964*0b57cec5SDimitry Andrictemplate<class _Sseq> 1965*0b57cec5SDimitry Andricvoid 1966*0b57cec5SDimitry Andriclinear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, 1967*0b57cec5SDimitry Andric integral_constant<unsigned, 2>) 1968*0b57cec5SDimitry Andric{ 1969*0b57cec5SDimitry Andric const unsigned __k = 2; 1970*0b57cec5SDimitry Andric uint32_t __ar[__k+3]; 1971*0b57cec5SDimitry Andric __q.generate(__ar, __ar + __k + 3); 1972*0b57cec5SDimitry Andric result_type __s = static_cast<result_type>((__ar[3] + 1973*0b57cec5SDimitry Andric ((uint64_t)__ar[4] << 32)) % __m); 1974*0b57cec5SDimitry Andric __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; 1975*0b57cec5SDimitry Andric} 1976*0b57cec5SDimitry Andric 1977*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, 1978*0b57cec5SDimitry Andric class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 1979*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 1980*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 1981*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 1982*0b57cec5SDimitry Andric const linear_congruential_engine<_UIntType, __a, __c, __m>& __x) 1983*0b57cec5SDimitry Andric{ 1984*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__os); 1985*0b57cec5SDimitry Andric __os.flags(ios_base::dec | ios_base::left); 1986*0b57cec5SDimitry Andric __os.fill(__os.widen(' ')); 1987*0b57cec5SDimitry Andric return __os << __x.__x_; 1988*0b57cec5SDimitry Andric} 1989*0b57cec5SDimitry Andric 1990*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, 1991*0b57cec5SDimitry Andric class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> 1992*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 1993*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 1994*0b57cec5SDimitry Andric linear_congruential_engine<_UIntType, __a, __c, __m>& __x) 1995*0b57cec5SDimitry Andric{ 1996*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__is); 1997*0b57cec5SDimitry Andric __is.flags(ios_base::dec | ios_base::skipws); 1998*0b57cec5SDimitry Andric _UIntType __t; 1999*0b57cec5SDimitry Andric __is >> __t; 2000*0b57cec5SDimitry Andric if (!__is.fail()) 2001*0b57cec5SDimitry Andric __x.__x_ = __t; 2002*0b57cec5SDimitry Andric return __is; 2003*0b57cec5SDimitry Andric} 2004*0b57cec5SDimitry Andric 2005*0b57cec5SDimitry Andrictypedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647> 2006*0b57cec5SDimitry Andric minstd_rand0; 2007*0b57cec5SDimitry Andrictypedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647> 2008*0b57cec5SDimitry Andric minstd_rand; 2009*0b57cec5SDimitry Andrictypedef minstd_rand default_random_engine; 2010*0b57cec5SDimitry Andric// mersenne_twister_engine 2011*0b57cec5SDimitry Andric 2012*0b57cec5SDimitry Andrictemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2013*0b57cec5SDimitry Andric _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2014*0b57cec5SDimitry Andric _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2015*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS mersenne_twister_engine; 2016*0b57cec5SDimitry Andric 2017*0b57cec5SDimitry Andrictemplate <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 2018*0b57cec5SDimitry Andric _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, 2019*0b57cec5SDimitry Andric _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> 2020*0b57cec5SDimitry Andricbool 2021*0b57cec5SDimitry Andricoperator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 2022*0b57cec5SDimitry Andric _Bp, _Tp, _Cp, _Lp, _Fp>& __x, 2023*0b57cec5SDimitry Andric const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 2024*0b57cec5SDimitry Andric _Bp, _Tp, _Cp, _Lp, _Fp>& __y); 2025*0b57cec5SDimitry Andric 2026*0b57cec5SDimitry Andrictemplate <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 2027*0b57cec5SDimitry Andric _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, 2028*0b57cec5SDimitry Andric _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> 2029*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 2030*0b57cec5SDimitry Andricbool 2031*0b57cec5SDimitry Andricoperator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 2032*0b57cec5SDimitry Andric _Bp, _Tp, _Cp, _Lp, _Fp>& __x, 2033*0b57cec5SDimitry Andric const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 2034*0b57cec5SDimitry Andric _Bp, _Tp, _Cp, _Lp, _Fp>& __y); 2035*0b57cec5SDimitry Andric 2036*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, 2037*0b57cec5SDimitry Andric class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 2038*0b57cec5SDimitry Andric _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, 2039*0b57cec5SDimitry Andric _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> 2040*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 2041*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 2042*0b57cec5SDimitry Andric const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 2043*0b57cec5SDimitry Andric _Bp, _Tp, _Cp, _Lp, _Fp>& __x); 2044*0b57cec5SDimitry Andric 2045*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, 2046*0b57cec5SDimitry Andric class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 2047*0b57cec5SDimitry Andric _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, 2048*0b57cec5SDimitry Andric _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> 2049*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 2050*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 2051*0b57cec5SDimitry Andric mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 2052*0b57cec5SDimitry Andric _Bp, _Tp, _Cp, _Lp, _Fp>& __x); 2053*0b57cec5SDimitry Andric 2054*0b57cec5SDimitry Andrictemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2055*0b57cec5SDimitry Andric _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2056*0b57cec5SDimitry Andric _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2057*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS mersenne_twister_engine 2058*0b57cec5SDimitry Andric{ 2059*0b57cec5SDimitry Andricpublic: 2060*0b57cec5SDimitry Andric // types 2061*0b57cec5SDimitry Andric typedef _UIntType result_type; 2062*0b57cec5SDimitry Andric 2063*0b57cec5SDimitry Andricprivate: 2064*0b57cec5SDimitry Andric result_type __x_[__n]; 2065*0b57cec5SDimitry Andric size_t __i_; 2066*0b57cec5SDimitry Andric 2067*0b57cec5SDimitry Andric static_assert( 0 < __m, "mersenne_twister_engine invalid parameters"); 2068*0b57cec5SDimitry Andric static_assert(__m <= __n, "mersenne_twister_engine invalid parameters"); 2069*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; 2070*0b57cec5SDimitry Andric static_assert(__w <= _Dt, "mersenne_twister_engine invalid parameters"); 2071*0b57cec5SDimitry Andric static_assert( 2 <= __w, "mersenne_twister_engine invalid parameters"); 2072*0b57cec5SDimitry Andric static_assert(__r <= __w, "mersenne_twister_engine invalid parameters"); 2073*0b57cec5SDimitry Andric static_assert(__u <= __w, "mersenne_twister_engine invalid parameters"); 2074*0b57cec5SDimitry Andric static_assert(__s <= __w, "mersenne_twister_engine invalid parameters"); 2075*0b57cec5SDimitry Andric static_assert(__t <= __w, "mersenne_twister_engine invalid parameters"); 2076*0b57cec5SDimitry Andric static_assert(__l <= __w, "mersenne_twister_engine invalid parameters"); 2077*0b57cec5SDimitry Andricpublic: 2078*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type _Min = 0; 2079*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : 2080*0b57cec5SDimitry Andric (result_type(1) << __w) - result_type(1); 2081*0b57cec5SDimitry Andric static_assert(_Min < _Max, "mersenne_twister_engine invalid parameters"); 2082*0b57cec5SDimitry Andric static_assert(__a <= _Max, "mersenne_twister_engine invalid parameters"); 2083*0b57cec5SDimitry Andric static_assert(__b <= _Max, "mersenne_twister_engine invalid parameters"); 2084*0b57cec5SDimitry Andric static_assert(__c <= _Max, "mersenne_twister_engine invalid parameters"); 2085*0b57cec5SDimitry Andric static_assert(__d <= _Max, "mersenne_twister_engine invalid parameters"); 2086*0b57cec5SDimitry Andric static_assert(__f <= _Max, "mersenne_twister_engine invalid parameters"); 2087*0b57cec5SDimitry Andric 2088*0b57cec5SDimitry Andric // engine characteristics 2089*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const size_t word_size = __w; 2090*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const size_t state_size = __n; 2091*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const size_t shift_size = __m; 2092*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const size_t mask_bits = __r; 2093*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type xor_mask = __a; 2094*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const size_t tempering_u = __u; 2095*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type tempering_d = __d; 2096*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const size_t tempering_s = __s; 2097*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type tempering_b = __b; 2098*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const size_t tempering_t = __t; 2099*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type tempering_c = __c; 2100*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const size_t tempering_l = __l; 2101*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type initialization_multiplier = __f; 2102*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2103*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR result_type min() { return _Min; } 2104*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2105*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR result_type max() { return _Max; } 2106*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type default_seed = 5489u; 2107*0b57cec5SDimitry Andric 2108*0b57cec5SDimitry Andric // constructors and seeding functions 2109*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2110*0b57cec5SDimitry Andric explicit mersenne_twister_engine(result_type __sd = default_seed) 2111*0b57cec5SDimitry Andric {seed(__sd);} 2112*0b57cec5SDimitry Andric template<class _Sseq> 2113*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2114*0b57cec5SDimitry Andric explicit mersenne_twister_engine(_Sseq& __q, 2115*0b57cec5SDimitry Andric typename enable_if<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value>::type* = 0) 2116*0b57cec5SDimitry Andric {seed(__q);} 2117*0b57cec5SDimitry Andric void seed(result_type __sd = default_seed); 2118*0b57cec5SDimitry Andric template<class _Sseq> 2119*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2120*0b57cec5SDimitry Andric typename enable_if 2121*0b57cec5SDimitry Andric < 2122*0b57cec5SDimitry Andric __is_seed_sequence<_Sseq, mersenne_twister_engine>::value, 2123*0b57cec5SDimitry Andric void 2124*0b57cec5SDimitry Andric >::type 2125*0b57cec5SDimitry Andric seed(_Sseq& __q) 2126*0b57cec5SDimitry Andric {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());} 2127*0b57cec5SDimitry Andric 2128*0b57cec5SDimitry Andric // generating functions 2129*0b57cec5SDimitry Andric result_type operator()(); 2130*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2131*0b57cec5SDimitry Andric void discard(unsigned long long __z) {for (; __z; --__z) operator()();} 2132*0b57cec5SDimitry Andric 2133*0b57cec5SDimitry Andric template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 2134*0b57cec5SDimitry Andric _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, 2135*0b57cec5SDimitry Andric _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> 2136*0b57cec5SDimitry Andric friend 2137*0b57cec5SDimitry Andric bool 2138*0b57cec5SDimitry Andric operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 2139*0b57cec5SDimitry Andric _Bp, _Tp, _Cp, _Lp, _Fp>& __x, 2140*0b57cec5SDimitry Andric const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 2141*0b57cec5SDimitry Andric _Bp, _Tp, _Cp, _Lp, _Fp>& __y); 2142*0b57cec5SDimitry Andric 2143*0b57cec5SDimitry Andric template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 2144*0b57cec5SDimitry Andric _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, 2145*0b57cec5SDimitry Andric _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> 2146*0b57cec5SDimitry Andric friend 2147*0b57cec5SDimitry Andric bool 2148*0b57cec5SDimitry Andric operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 2149*0b57cec5SDimitry Andric _Bp, _Tp, _Cp, _Lp, _Fp>& __x, 2150*0b57cec5SDimitry Andric const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 2151*0b57cec5SDimitry Andric _Bp, _Tp, _Cp, _Lp, _Fp>& __y); 2152*0b57cec5SDimitry Andric 2153*0b57cec5SDimitry Andric template <class _CharT, class _Traits, 2154*0b57cec5SDimitry Andric class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 2155*0b57cec5SDimitry Andric _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, 2156*0b57cec5SDimitry Andric _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> 2157*0b57cec5SDimitry Andric friend 2158*0b57cec5SDimitry Andric basic_ostream<_CharT, _Traits>& 2159*0b57cec5SDimitry Andric operator<<(basic_ostream<_CharT, _Traits>& __os, 2160*0b57cec5SDimitry Andric const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 2161*0b57cec5SDimitry Andric _Bp, _Tp, _Cp, _Lp, _Fp>& __x); 2162*0b57cec5SDimitry Andric 2163*0b57cec5SDimitry Andric template <class _CharT, class _Traits, 2164*0b57cec5SDimitry Andric class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 2165*0b57cec5SDimitry Andric _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, 2166*0b57cec5SDimitry Andric _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> 2167*0b57cec5SDimitry Andric friend 2168*0b57cec5SDimitry Andric basic_istream<_CharT, _Traits>& 2169*0b57cec5SDimitry Andric operator>>(basic_istream<_CharT, _Traits>& __is, 2170*0b57cec5SDimitry Andric mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 2171*0b57cec5SDimitry Andric _Bp, _Tp, _Cp, _Lp, _Fp>& __x); 2172*0b57cec5SDimitry Andricprivate: 2173*0b57cec5SDimitry Andric 2174*0b57cec5SDimitry Andric template<class _Sseq> 2175*0b57cec5SDimitry Andric void __seed(_Sseq& __q, integral_constant<unsigned, 1>); 2176*0b57cec5SDimitry Andric template<class _Sseq> 2177*0b57cec5SDimitry Andric void __seed(_Sseq& __q, integral_constant<unsigned, 2>); 2178*0b57cec5SDimitry Andric 2179*0b57cec5SDimitry Andric template <size_t __count> 2180*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2181*0b57cec5SDimitry Andric static 2182*0b57cec5SDimitry Andric typename enable_if 2183*0b57cec5SDimitry Andric < 2184*0b57cec5SDimitry Andric __count < __w, 2185*0b57cec5SDimitry Andric result_type 2186*0b57cec5SDimitry Andric >::type 2187*0b57cec5SDimitry Andric __lshift(result_type __x) {return (__x << __count) & _Max;} 2188*0b57cec5SDimitry Andric 2189*0b57cec5SDimitry Andric template <size_t __count> 2190*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2191*0b57cec5SDimitry Andric static 2192*0b57cec5SDimitry Andric typename enable_if 2193*0b57cec5SDimitry Andric < 2194*0b57cec5SDimitry Andric (__count >= __w), 2195*0b57cec5SDimitry Andric result_type 2196*0b57cec5SDimitry Andric >::type 2197*0b57cec5SDimitry Andric __lshift(result_type) {return result_type(0);} 2198*0b57cec5SDimitry Andric 2199*0b57cec5SDimitry Andric template <size_t __count> 2200*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2201*0b57cec5SDimitry Andric static 2202*0b57cec5SDimitry Andric typename enable_if 2203*0b57cec5SDimitry Andric < 2204*0b57cec5SDimitry Andric __count < _Dt, 2205*0b57cec5SDimitry Andric result_type 2206*0b57cec5SDimitry Andric >::type 2207*0b57cec5SDimitry Andric __rshift(result_type __x) {return __x >> __count;} 2208*0b57cec5SDimitry Andric 2209*0b57cec5SDimitry Andric template <size_t __count> 2210*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2211*0b57cec5SDimitry Andric static 2212*0b57cec5SDimitry Andric typename enable_if 2213*0b57cec5SDimitry Andric < 2214*0b57cec5SDimitry Andric (__count >= _Dt), 2215*0b57cec5SDimitry Andric result_type 2216*0b57cec5SDimitry Andric >::type 2217*0b57cec5SDimitry Andric __rshift(result_type) {return result_type(0);} 2218*0b57cec5SDimitry Andric}; 2219*0b57cec5SDimitry Andric 2220*0b57cec5SDimitry Andrictemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2221*0b57cec5SDimitry Andric _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2222*0b57cec5SDimitry Andric _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2223*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR const size_t 2224*0b57cec5SDimitry Andric mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::word_size; 2225*0b57cec5SDimitry Andric 2226*0b57cec5SDimitry Andrictemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2227*0b57cec5SDimitry Andric _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2228*0b57cec5SDimitry Andric _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2229*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR const size_t 2230*0b57cec5SDimitry Andric mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::state_size; 2231*0b57cec5SDimitry Andric 2232*0b57cec5SDimitry Andrictemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2233*0b57cec5SDimitry Andric _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2234*0b57cec5SDimitry Andric _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2235*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR const size_t 2236*0b57cec5SDimitry Andric mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::shift_size; 2237*0b57cec5SDimitry Andric 2238*0b57cec5SDimitry Andrictemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2239*0b57cec5SDimitry Andric _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2240*0b57cec5SDimitry Andric _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2241*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR const size_t 2242*0b57cec5SDimitry Andric mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mask_bits; 2243*0b57cec5SDimitry Andric 2244*0b57cec5SDimitry Andrictemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2245*0b57cec5SDimitry Andric _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2246*0b57cec5SDimitry Andric _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2247*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type 2248*0b57cec5SDimitry Andric mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::xor_mask; 2249*0b57cec5SDimitry Andric 2250*0b57cec5SDimitry Andrictemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2251*0b57cec5SDimitry Andric _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2252*0b57cec5SDimitry Andric _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2253*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR const size_t 2254*0b57cec5SDimitry Andric mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_u; 2255*0b57cec5SDimitry Andric 2256*0b57cec5SDimitry Andrictemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2257*0b57cec5SDimitry Andric _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2258*0b57cec5SDimitry Andric _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2259*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type 2260*0b57cec5SDimitry Andric mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_d; 2261*0b57cec5SDimitry Andric 2262*0b57cec5SDimitry Andrictemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2263*0b57cec5SDimitry Andric _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2264*0b57cec5SDimitry Andric _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2265*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR const size_t 2266*0b57cec5SDimitry Andric mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_s; 2267*0b57cec5SDimitry Andric 2268*0b57cec5SDimitry Andrictemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2269*0b57cec5SDimitry Andric _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2270*0b57cec5SDimitry Andric _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2271*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type 2272*0b57cec5SDimitry Andric mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_b; 2273*0b57cec5SDimitry Andric 2274*0b57cec5SDimitry Andrictemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2275*0b57cec5SDimitry Andric _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2276*0b57cec5SDimitry Andric _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2277*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR const size_t 2278*0b57cec5SDimitry Andric mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_t; 2279*0b57cec5SDimitry Andric 2280*0b57cec5SDimitry Andrictemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2281*0b57cec5SDimitry Andric _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2282*0b57cec5SDimitry Andric _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2283*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type 2284*0b57cec5SDimitry Andric mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_c; 2285*0b57cec5SDimitry Andric 2286*0b57cec5SDimitry Andrictemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2287*0b57cec5SDimitry Andric _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2288*0b57cec5SDimitry Andric _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2289*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR const size_t 2290*0b57cec5SDimitry Andric mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_l; 2291*0b57cec5SDimitry Andric 2292*0b57cec5SDimitry Andrictemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2293*0b57cec5SDimitry Andric _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2294*0b57cec5SDimitry Andric _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2295*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type 2296*0b57cec5SDimitry Andric mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::initialization_multiplier; 2297*0b57cec5SDimitry Andric 2298*0b57cec5SDimitry Andrictemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2299*0b57cec5SDimitry Andric _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2300*0b57cec5SDimitry Andric _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2301*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type 2302*0b57cec5SDimitry Andric mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::default_seed; 2303*0b57cec5SDimitry Andric 2304*0b57cec5SDimitry Andrictemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2305*0b57cec5SDimitry Andric _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2306*0b57cec5SDimitry Andric _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2307*0b57cec5SDimitry Andricvoid 2308*0b57cec5SDimitry Andricmersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, 2309*0b57cec5SDimitry Andric __t, __c, __l, __f>::seed(result_type __sd) 2310*0b57cec5SDimitry Andric _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 2311*0b57cec5SDimitry Andric{ // __w >= 2 2312*0b57cec5SDimitry Andric __x_[0] = __sd & _Max; 2313*0b57cec5SDimitry Andric for (size_t __i = 1; __i < __n; ++__i) 2314*0b57cec5SDimitry Andric __x_[__i] = (__f * (__x_[__i-1] ^ __rshift<__w - 2>(__x_[__i-1])) + __i) & _Max; 2315*0b57cec5SDimitry Andric __i_ = 0; 2316*0b57cec5SDimitry Andric} 2317*0b57cec5SDimitry Andric 2318*0b57cec5SDimitry Andrictemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2319*0b57cec5SDimitry Andric _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2320*0b57cec5SDimitry Andric _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2321*0b57cec5SDimitry Andrictemplate<class _Sseq> 2322*0b57cec5SDimitry Andricvoid 2323*0b57cec5SDimitry Andricmersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, 2324*0b57cec5SDimitry Andric __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 1>) 2325*0b57cec5SDimitry Andric{ 2326*0b57cec5SDimitry Andric const unsigned __k = 1; 2327*0b57cec5SDimitry Andric uint32_t __ar[__n * __k]; 2328*0b57cec5SDimitry Andric __q.generate(__ar, __ar + __n * __k); 2329*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __n; ++__i) 2330*0b57cec5SDimitry Andric __x_[__i] = static_cast<result_type>(__ar[__i] & _Max); 2331*0b57cec5SDimitry Andric const result_type __mask = __r == _Dt ? result_type(~0) : 2332*0b57cec5SDimitry Andric (result_type(1) << __r) - result_type(1); 2333*0b57cec5SDimitry Andric __i_ = 0; 2334*0b57cec5SDimitry Andric if ((__x_[0] & ~__mask) == 0) 2335*0b57cec5SDimitry Andric { 2336*0b57cec5SDimitry Andric for (size_t __i = 1; __i < __n; ++__i) 2337*0b57cec5SDimitry Andric if (__x_[__i] != 0) 2338*0b57cec5SDimitry Andric return; 2339*0b57cec5SDimitry Andric __x_[0] = result_type(1) << (__w - 1); 2340*0b57cec5SDimitry Andric } 2341*0b57cec5SDimitry Andric} 2342*0b57cec5SDimitry Andric 2343*0b57cec5SDimitry Andrictemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2344*0b57cec5SDimitry Andric _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2345*0b57cec5SDimitry Andric _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2346*0b57cec5SDimitry Andrictemplate<class _Sseq> 2347*0b57cec5SDimitry Andricvoid 2348*0b57cec5SDimitry Andricmersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, 2349*0b57cec5SDimitry Andric __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 2>) 2350*0b57cec5SDimitry Andric{ 2351*0b57cec5SDimitry Andric const unsigned __k = 2; 2352*0b57cec5SDimitry Andric uint32_t __ar[__n * __k]; 2353*0b57cec5SDimitry Andric __q.generate(__ar, __ar + __n * __k); 2354*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __n; ++__i) 2355*0b57cec5SDimitry Andric __x_[__i] = static_cast<result_type>( 2356*0b57cec5SDimitry Andric (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); 2357*0b57cec5SDimitry Andric const result_type __mask = __r == _Dt ? result_type(~0) : 2358*0b57cec5SDimitry Andric (result_type(1) << __r) - result_type(1); 2359*0b57cec5SDimitry Andric __i_ = 0; 2360*0b57cec5SDimitry Andric if ((__x_[0] & ~__mask) == 0) 2361*0b57cec5SDimitry Andric { 2362*0b57cec5SDimitry Andric for (size_t __i = 1; __i < __n; ++__i) 2363*0b57cec5SDimitry Andric if (__x_[__i] != 0) 2364*0b57cec5SDimitry Andric return; 2365*0b57cec5SDimitry Andric __x_[0] = result_type(1) << (__w - 1); 2366*0b57cec5SDimitry Andric } 2367*0b57cec5SDimitry Andric} 2368*0b57cec5SDimitry Andric 2369*0b57cec5SDimitry Andrictemplate <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, 2370*0b57cec5SDimitry Andric _UIntType __a, size_t __u, _UIntType __d, size_t __s, 2371*0b57cec5SDimitry Andric _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> 2372*0b57cec5SDimitry Andric_UIntType 2373*0b57cec5SDimitry Andricmersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, 2374*0b57cec5SDimitry Andric __t, __c, __l, __f>::operator()() 2375*0b57cec5SDimitry Andric{ 2376*0b57cec5SDimitry Andric const size_t __j = (__i_ + 1) % __n; 2377*0b57cec5SDimitry Andric const result_type __mask = __r == _Dt ? result_type(~0) : 2378*0b57cec5SDimitry Andric (result_type(1) << __r) - result_type(1); 2379*0b57cec5SDimitry Andric const result_type _Yp = (__x_[__i_] & ~__mask) | (__x_[__j] & __mask); 2380*0b57cec5SDimitry Andric const size_t __k = (__i_ + __m) % __n; 2381*0b57cec5SDimitry Andric __x_[__i_] = __x_[__k] ^ __rshift<1>(_Yp) ^ (__a * (_Yp & 1)); 2382*0b57cec5SDimitry Andric result_type __z = __x_[__i_] ^ (__rshift<__u>(__x_[__i_]) & __d); 2383*0b57cec5SDimitry Andric __i_ = __j; 2384*0b57cec5SDimitry Andric __z ^= __lshift<__s>(__z) & __b; 2385*0b57cec5SDimitry Andric __z ^= __lshift<__t>(__z) & __c; 2386*0b57cec5SDimitry Andric return __z ^ __rshift<__l>(__z); 2387*0b57cec5SDimitry Andric} 2388*0b57cec5SDimitry Andric 2389*0b57cec5SDimitry Andrictemplate <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 2390*0b57cec5SDimitry Andric _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, 2391*0b57cec5SDimitry Andric _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> 2392*0b57cec5SDimitry Andricbool 2393*0b57cec5SDimitry Andricoperator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 2394*0b57cec5SDimitry Andric _Bp, _Tp, _Cp, _Lp, _Fp>& __x, 2395*0b57cec5SDimitry Andric const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 2396*0b57cec5SDimitry Andric _Bp, _Tp, _Cp, _Lp, _Fp>& __y) 2397*0b57cec5SDimitry Andric{ 2398*0b57cec5SDimitry Andric if (__x.__i_ == __y.__i_) 2399*0b57cec5SDimitry Andric return _VSTD::equal(__x.__x_, __x.__x_ + _Np, __y.__x_); 2400*0b57cec5SDimitry Andric if (__x.__i_ == 0 || __y.__i_ == 0) 2401*0b57cec5SDimitry Andric { 2402*0b57cec5SDimitry Andric size_t __j = _VSTD::min(_Np - __x.__i_, _Np - __y.__i_); 2403*0b57cec5SDimitry Andric if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, 2404*0b57cec5SDimitry Andric __y.__x_ + __y.__i_)) 2405*0b57cec5SDimitry Andric return false; 2406*0b57cec5SDimitry Andric if (__x.__i_ == 0) 2407*0b57cec5SDimitry Andric return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Np, __y.__x_); 2408*0b57cec5SDimitry Andric return _VSTD::equal(__x.__x_, __x.__x_ + (_Np - __j), __y.__x_ + __j); 2409*0b57cec5SDimitry Andric } 2410*0b57cec5SDimitry Andric if (__x.__i_ < __y.__i_) 2411*0b57cec5SDimitry Andric { 2412*0b57cec5SDimitry Andric size_t __j = _Np - __y.__i_; 2413*0b57cec5SDimitry Andric if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), 2414*0b57cec5SDimitry Andric __y.__x_ + __y.__i_)) 2415*0b57cec5SDimitry Andric return false; 2416*0b57cec5SDimitry Andric if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Np, 2417*0b57cec5SDimitry Andric __y.__x_)) 2418*0b57cec5SDimitry Andric return false; 2419*0b57cec5SDimitry Andric return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_, 2420*0b57cec5SDimitry Andric __y.__x_ + (_Np - (__x.__i_ + __j))); 2421*0b57cec5SDimitry Andric } 2422*0b57cec5SDimitry Andric size_t __j = _Np - __x.__i_; 2423*0b57cec5SDimitry Andric if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), 2424*0b57cec5SDimitry Andric __x.__x_ + __x.__i_)) 2425*0b57cec5SDimitry Andric return false; 2426*0b57cec5SDimitry Andric if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Np, 2427*0b57cec5SDimitry Andric __x.__x_)) 2428*0b57cec5SDimitry Andric return false; 2429*0b57cec5SDimitry Andric return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_, 2430*0b57cec5SDimitry Andric __x.__x_ + (_Np - (__y.__i_ + __j))); 2431*0b57cec5SDimitry Andric} 2432*0b57cec5SDimitry Andric 2433*0b57cec5SDimitry Andrictemplate <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 2434*0b57cec5SDimitry Andric _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, 2435*0b57cec5SDimitry Andric _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> 2436*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 2437*0b57cec5SDimitry Andricbool 2438*0b57cec5SDimitry Andricoperator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 2439*0b57cec5SDimitry Andric _Bp, _Tp, _Cp, _Lp, _Fp>& __x, 2440*0b57cec5SDimitry Andric const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 2441*0b57cec5SDimitry Andric _Bp, _Tp, _Cp, _Lp, _Fp>& __y) 2442*0b57cec5SDimitry Andric{ 2443*0b57cec5SDimitry Andric return !(__x == __y); 2444*0b57cec5SDimitry Andric} 2445*0b57cec5SDimitry Andric 2446*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, 2447*0b57cec5SDimitry Andric class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 2448*0b57cec5SDimitry Andric _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, 2449*0b57cec5SDimitry Andric _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> 2450*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 2451*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 2452*0b57cec5SDimitry Andric const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 2453*0b57cec5SDimitry Andric _Bp, _Tp, _Cp, _Lp, _Fp>& __x) 2454*0b57cec5SDimitry Andric{ 2455*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__os); 2456*0b57cec5SDimitry Andric __os.flags(ios_base::dec | ios_base::left); 2457*0b57cec5SDimitry Andric _CharT __sp = __os.widen(' '); 2458*0b57cec5SDimitry Andric __os.fill(__sp); 2459*0b57cec5SDimitry Andric __os << __x.__x_[__x.__i_]; 2460*0b57cec5SDimitry Andric for (size_t __j = __x.__i_ + 1; __j < _Np; ++__j) 2461*0b57cec5SDimitry Andric __os << __sp << __x.__x_[__j]; 2462*0b57cec5SDimitry Andric for (size_t __j = 0; __j < __x.__i_; ++__j) 2463*0b57cec5SDimitry Andric __os << __sp << __x.__x_[__j]; 2464*0b57cec5SDimitry Andric return __os; 2465*0b57cec5SDimitry Andric} 2466*0b57cec5SDimitry Andric 2467*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, 2468*0b57cec5SDimitry Andric class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, 2469*0b57cec5SDimitry Andric _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, 2470*0b57cec5SDimitry Andric _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> 2471*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 2472*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 2473*0b57cec5SDimitry Andric mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, 2474*0b57cec5SDimitry Andric _Bp, _Tp, _Cp, _Lp, _Fp>& __x) 2475*0b57cec5SDimitry Andric{ 2476*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__is); 2477*0b57cec5SDimitry Andric __is.flags(ios_base::dec | ios_base::skipws); 2478*0b57cec5SDimitry Andric _UInt __t[_Np]; 2479*0b57cec5SDimitry Andric for (size_t __i = 0; __i < _Np; ++__i) 2480*0b57cec5SDimitry Andric __is >> __t[__i]; 2481*0b57cec5SDimitry Andric if (!__is.fail()) 2482*0b57cec5SDimitry Andric { 2483*0b57cec5SDimitry Andric for (size_t __i = 0; __i < _Np; ++__i) 2484*0b57cec5SDimitry Andric __x.__x_[__i] = __t[__i]; 2485*0b57cec5SDimitry Andric __x.__i_ = 0; 2486*0b57cec5SDimitry Andric } 2487*0b57cec5SDimitry Andric return __is; 2488*0b57cec5SDimitry Andric} 2489*0b57cec5SDimitry Andric 2490*0b57cec5SDimitry Andrictypedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31, 2491*0b57cec5SDimitry Andric 0x9908b0df, 11, 0xffffffff, 2492*0b57cec5SDimitry Andric 7, 0x9d2c5680, 2493*0b57cec5SDimitry Andric 15, 0xefc60000, 2494*0b57cec5SDimitry Andric 18, 1812433253> mt19937; 2495*0b57cec5SDimitry Andrictypedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31, 2496*0b57cec5SDimitry Andric 0xb5026f5aa96619e9ULL, 29, 0x5555555555555555ULL, 2497*0b57cec5SDimitry Andric 17, 0x71d67fffeda60000ULL, 2498*0b57cec5SDimitry Andric 37, 0xfff7eee000000000ULL, 2499*0b57cec5SDimitry Andric 43, 6364136223846793005ULL> mt19937_64; 2500*0b57cec5SDimitry Andric 2501*0b57cec5SDimitry Andric// subtract_with_carry_engine 2502*0b57cec5SDimitry Andric 2503*0b57cec5SDimitry Andrictemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 2504*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine; 2505*0b57cec5SDimitry Andric 2506*0b57cec5SDimitry Andrictemplate<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> 2507*0b57cec5SDimitry Andricbool 2508*0b57cec5SDimitry Andricoperator==( 2509*0b57cec5SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, 2510*0b57cec5SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); 2511*0b57cec5SDimitry Andric 2512*0b57cec5SDimitry Andrictemplate<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> 2513*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 2514*0b57cec5SDimitry Andricbool 2515*0b57cec5SDimitry Andricoperator!=( 2516*0b57cec5SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, 2517*0b57cec5SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); 2518*0b57cec5SDimitry Andric 2519*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, 2520*0b57cec5SDimitry Andric class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> 2521*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 2522*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 2523*0b57cec5SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); 2524*0b57cec5SDimitry Andric 2525*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, 2526*0b57cec5SDimitry Andric class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> 2527*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 2528*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 2529*0b57cec5SDimitry Andric subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); 2530*0b57cec5SDimitry Andric 2531*0b57cec5SDimitry Andrictemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 2532*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine 2533*0b57cec5SDimitry Andric{ 2534*0b57cec5SDimitry Andricpublic: 2535*0b57cec5SDimitry Andric // types 2536*0b57cec5SDimitry Andric typedef _UIntType result_type; 2537*0b57cec5SDimitry Andric 2538*0b57cec5SDimitry Andricprivate: 2539*0b57cec5SDimitry Andric result_type __x_[__r]; 2540*0b57cec5SDimitry Andric result_type __c_; 2541*0b57cec5SDimitry Andric size_t __i_; 2542*0b57cec5SDimitry Andric 2543*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; 2544*0b57cec5SDimitry Andric static_assert( 0 < __w, "subtract_with_carry_engine invalid parameters"); 2545*0b57cec5SDimitry Andric static_assert(__w <= _Dt, "subtract_with_carry_engine invalid parameters"); 2546*0b57cec5SDimitry Andric static_assert( 0 < __s, "subtract_with_carry_engine invalid parameters"); 2547*0b57cec5SDimitry Andric static_assert(__s < __r, "subtract_with_carry_engine invalid parameters"); 2548*0b57cec5SDimitry Andricpublic: 2549*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type _Min = 0; 2550*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : 2551*0b57cec5SDimitry Andric (result_type(1) << __w) - result_type(1); 2552*0b57cec5SDimitry Andric static_assert(_Min < _Max, "subtract_with_carry_engine invalid parameters"); 2553*0b57cec5SDimitry Andric 2554*0b57cec5SDimitry Andric // engine characteristics 2555*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const size_t word_size = __w; 2556*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const size_t short_lag = __s; 2557*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const size_t long_lag = __r; 2558*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2559*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR result_type min() { return _Min; } 2560*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2561*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR result_type max() { return _Max; } 2562*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type default_seed = 19780503u; 2563*0b57cec5SDimitry Andric 2564*0b57cec5SDimitry Andric // constructors and seeding functions 2565*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2566*0b57cec5SDimitry Andric explicit subtract_with_carry_engine(result_type __sd = default_seed) 2567*0b57cec5SDimitry Andric {seed(__sd);} 2568*0b57cec5SDimitry Andric template<class _Sseq> 2569*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2570*0b57cec5SDimitry Andric explicit subtract_with_carry_engine(_Sseq& __q, 2571*0b57cec5SDimitry Andric typename enable_if<__is_seed_sequence<_Sseq, subtract_with_carry_engine>::value>::type* = 0) 2572*0b57cec5SDimitry Andric {seed(__q);} 2573*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2574*0b57cec5SDimitry Andric void seed(result_type __sd = default_seed) 2575*0b57cec5SDimitry Andric {seed(__sd, integral_constant<unsigned, 1 + (__w - 1) / 32>());} 2576*0b57cec5SDimitry Andric template<class _Sseq> 2577*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2578*0b57cec5SDimitry Andric typename enable_if 2579*0b57cec5SDimitry Andric < 2580*0b57cec5SDimitry Andric __is_seed_sequence<_Sseq, subtract_with_carry_engine>::value, 2581*0b57cec5SDimitry Andric void 2582*0b57cec5SDimitry Andric >::type 2583*0b57cec5SDimitry Andric seed(_Sseq& __q) 2584*0b57cec5SDimitry Andric {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());} 2585*0b57cec5SDimitry Andric 2586*0b57cec5SDimitry Andric // generating functions 2587*0b57cec5SDimitry Andric result_type operator()(); 2588*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2589*0b57cec5SDimitry Andric void discard(unsigned long long __z) {for (; __z; --__z) operator()();} 2590*0b57cec5SDimitry Andric 2591*0b57cec5SDimitry Andric template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> 2592*0b57cec5SDimitry Andric friend 2593*0b57cec5SDimitry Andric bool 2594*0b57cec5SDimitry Andric operator==( 2595*0b57cec5SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, 2596*0b57cec5SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); 2597*0b57cec5SDimitry Andric 2598*0b57cec5SDimitry Andric template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> 2599*0b57cec5SDimitry Andric friend 2600*0b57cec5SDimitry Andric bool 2601*0b57cec5SDimitry Andric operator!=( 2602*0b57cec5SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, 2603*0b57cec5SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); 2604*0b57cec5SDimitry Andric 2605*0b57cec5SDimitry Andric template <class _CharT, class _Traits, 2606*0b57cec5SDimitry Andric class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> 2607*0b57cec5SDimitry Andric friend 2608*0b57cec5SDimitry Andric basic_ostream<_CharT, _Traits>& 2609*0b57cec5SDimitry Andric operator<<(basic_ostream<_CharT, _Traits>& __os, 2610*0b57cec5SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); 2611*0b57cec5SDimitry Andric 2612*0b57cec5SDimitry Andric template <class _CharT, class _Traits, 2613*0b57cec5SDimitry Andric class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> 2614*0b57cec5SDimitry Andric friend 2615*0b57cec5SDimitry Andric basic_istream<_CharT, _Traits>& 2616*0b57cec5SDimitry Andric operator>>(basic_istream<_CharT, _Traits>& __is, 2617*0b57cec5SDimitry Andric subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); 2618*0b57cec5SDimitry Andric 2619*0b57cec5SDimitry Andricprivate: 2620*0b57cec5SDimitry Andric 2621*0b57cec5SDimitry Andric void seed(result_type __sd, integral_constant<unsigned, 1>); 2622*0b57cec5SDimitry Andric void seed(result_type __sd, integral_constant<unsigned, 2>); 2623*0b57cec5SDimitry Andric template<class _Sseq> 2624*0b57cec5SDimitry Andric void __seed(_Sseq& __q, integral_constant<unsigned, 1>); 2625*0b57cec5SDimitry Andric template<class _Sseq> 2626*0b57cec5SDimitry Andric void __seed(_Sseq& __q, integral_constant<unsigned, 2>); 2627*0b57cec5SDimitry Andric}; 2628*0b57cec5SDimitry Andric 2629*0b57cec5SDimitry Andrictemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 2630*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size; 2631*0b57cec5SDimitry Andric 2632*0b57cec5SDimitry Andrictemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 2633*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::short_lag; 2634*0b57cec5SDimitry Andric 2635*0b57cec5SDimitry Andrictemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 2636*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag; 2637*0b57cec5SDimitry Andric 2638*0b57cec5SDimitry Andrictemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 2639*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR const typename subtract_with_carry_engine<_UIntType, __w, __s, __r>::result_type 2640*0b57cec5SDimitry Andric subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed; 2641*0b57cec5SDimitry Andric 2642*0b57cec5SDimitry Andrictemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 2643*0b57cec5SDimitry Andricvoid 2644*0b57cec5SDimitry Andricsubtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, 2645*0b57cec5SDimitry Andric integral_constant<unsigned, 1>) 2646*0b57cec5SDimitry Andric{ 2647*0b57cec5SDimitry Andric linear_congruential_engine<result_type, 40014u, 0u, 2147483563u> 2648*0b57cec5SDimitry Andric __e(__sd == 0u ? default_seed : __sd); 2649*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __r; ++__i) 2650*0b57cec5SDimitry Andric __x_[__i] = static_cast<result_type>(__e() & _Max); 2651*0b57cec5SDimitry Andric __c_ = __x_[__r-1] == 0; 2652*0b57cec5SDimitry Andric __i_ = 0; 2653*0b57cec5SDimitry Andric} 2654*0b57cec5SDimitry Andric 2655*0b57cec5SDimitry Andrictemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 2656*0b57cec5SDimitry Andricvoid 2657*0b57cec5SDimitry Andricsubtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, 2658*0b57cec5SDimitry Andric integral_constant<unsigned, 2>) 2659*0b57cec5SDimitry Andric{ 2660*0b57cec5SDimitry Andric linear_congruential_engine<result_type, 40014u, 0u, 2147483563u> 2661*0b57cec5SDimitry Andric __e(__sd == 0u ? default_seed : __sd); 2662*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __r; ++__i) 2663*0b57cec5SDimitry Andric { 2664*0b57cec5SDimitry Andric result_type __e0 = __e(); 2665*0b57cec5SDimitry Andric __x_[__i] = static_cast<result_type>( 2666*0b57cec5SDimitry Andric (__e0 + ((uint64_t)__e() << 32)) & _Max); 2667*0b57cec5SDimitry Andric } 2668*0b57cec5SDimitry Andric __c_ = __x_[__r-1] == 0; 2669*0b57cec5SDimitry Andric __i_ = 0; 2670*0b57cec5SDimitry Andric} 2671*0b57cec5SDimitry Andric 2672*0b57cec5SDimitry Andrictemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 2673*0b57cec5SDimitry Andrictemplate<class _Sseq> 2674*0b57cec5SDimitry Andricvoid 2675*0b57cec5SDimitry Andricsubtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q, 2676*0b57cec5SDimitry Andric integral_constant<unsigned, 1>) 2677*0b57cec5SDimitry Andric{ 2678*0b57cec5SDimitry Andric const unsigned __k = 1; 2679*0b57cec5SDimitry Andric uint32_t __ar[__r * __k]; 2680*0b57cec5SDimitry Andric __q.generate(__ar, __ar + __r * __k); 2681*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __r; ++__i) 2682*0b57cec5SDimitry Andric __x_[__i] = static_cast<result_type>(__ar[__i] & _Max); 2683*0b57cec5SDimitry Andric __c_ = __x_[__r-1] == 0; 2684*0b57cec5SDimitry Andric __i_ = 0; 2685*0b57cec5SDimitry Andric} 2686*0b57cec5SDimitry Andric 2687*0b57cec5SDimitry Andrictemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 2688*0b57cec5SDimitry Andrictemplate<class _Sseq> 2689*0b57cec5SDimitry Andricvoid 2690*0b57cec5SDimitry Andricsubtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q, 2691*0b57cec5SDimitry Andric integral_constant<unsigned, 2>) 2692*0b57cec5SDimitry Andric{ 2693*0b57cec5SDimitry Andric const unsigned __k = 2; 2694*0b57cec5SDimitry Andric uint32_t __ar[__r * __k]; 2695*0b57cec5SDimitry Andric __q.generate(__ar, __ar + __r * __k); 2696*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __r; ++__i) 2697*0b57cec5SDimitry Andric __x_[__i] = static_cast<result_type>( 2698*0b57cec5SDimitry Andric (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); 2699*0b57cec5SDimitry Andric __c_ = __x_[__r-1] == 0; 2700*0b57cec5SDimitry Andric __i_ = 0; 2701*0b57cec5SDimitry Andric} 2702*0b57cec5SDimitry Andric 2703*0b57cec5SDimitry Andrictemplate<class _UIntType, size_t __w, size_t __s, size_t __r> 2704*0b57cec5SDimitry Andric_UIntType 2705*0b57cec5SDimitry Andricsubtract_with_carry_engine<_UIntType, __w, __s, __r>::operator()() 2706*0b57cec5SDimitry Andric{ 2707*0b57cec5SDimitry Andric const result_type& __xs = __x_[(__i_ + (__r - __s)) % __r]; 2708*0b57cec5SDimitry Andric result_type& __xr = __x_[__i_]; 2709*0b57cec5SDimitry Andric result_type __new_c = __c_ == 0 ? __xs < __xr : __xs != 0 ? __xs <= __xr : 1; 2710*0b57cec5SDimitry Andric __xr = (__xs - __xr - __c_) & _Max; 2711*0b57cec5SDimitry Andric __c_ = __new_c; 2712*0b57cec5SDimitry Andric __i_ = (__i_ + 1) % __r; 2713*0b57cec5SDimitry Andric return __xr; 2714*0b57cec5SDimitry Andric} 2715*0b57cec5SDimitry Andric 2716*0b57cec5SDimitry Andrictemplate<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> 2717*0b57cec5SDimitry Andricbool 2718*0b57cec5SDimitry Andricoperator==( 2719*0b57cec5SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, 2720*0b57cec5SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y) 2721*0b57cec5SDimitry Andric{ 2722*0b57cec5SDimitry Andric if (__x.__c_ != __y.__c_) 2723*0b57cec5SDimitry Andric return false; 2724*0b57cec5SDimitry Andric if (__x.__i_ == __y.__i_) 2725*0b57cec5SDimitry Andric return _VSTD::equal(__x.__x_, __x.__x_ + _Rp, __y.__x_); 2726*0b57cec5SDimitry Andric if (__x.__i_ == 0 || __y.__i_ == 0) 2727*0b57cec5SDimitry Andric { 2728*0b57cec5SDimitry Andric size_t __j = _VSTD::min(_Rp - __x.__i_, _Rp - __y.__i_); 2729*0b57cec5SDimitry Andric if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, 2730*0b57cec5SDimitry Andric __y.__x_ + __y.__i_)) 2731*0b57cec5SDimitry Andric return false; 2732*0b57cec5SDimitry Andric if (__x.__i_ == 0) 2733*0b57cec5SDimitry Andric return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Rp, __y.__x_); 2734*0b57cec5SDimitry Andric return _VSTD::equal(__x.__x_, __x.__x_ + (_Rp - __j), __y.__x_ + __j); 2735*0b57cec5SDimitry Andric } 2736*0b57cec5SDimitry Andric if (__x.__i_ < __y.__i_) 2737*0b57cec5SDimitry Andric { 2738*0b57cec5SDimitry Andric size_t __j = _Rp - __y.__i_; 2739*0b57cec5SDimitry Andric if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), 2740*0b57cec5SDimitry Andric __y.__x_ + __y.__i_)) 2741*0b57cec5SDimitry Andric return false; 2742*0b57cec5SDimitry Andric if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Rp, 2743*0b57cec5SDimitry Andric __y.__x_)) 2744*0b57cec5SDimitry Andric return false; 2745*0b57cec5SDimitry Andric return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_, 2746*0b57cec5SDimitry Andric __y.__x_ + (_Rp - (__x.__i_ + __j))); 2747*0b57cec5SDimitry Andric } 2748*0b57cec5SDimitry Andric size_t __j = _Rp - __x.__i_; 2749*0b57cec5SDimitry Andric if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), 2750*0b57cec5SDimitry Andric __x.__x_ + __x.__i_)) 2751*0b57cec5SDimitry Andric return false; 2752*0b57cec5SDimitry Andric if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Rp, 2753*0b57cec5SDimitry Andric __x.__x_)) 2754*0b57cec5SDimitry Andric return false; 2755*0b57cec5SDimitry Andric return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_, 2756*0b57cec5SDimitry Andric __x.__x_ + (_Rp - (__y.__i_ + __j))); 2757*0b57cec5SDimitry Andric} 2758*0b57cec5SDimitry Andric 2759*0b57cec5SDimitry Andrictemplate<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> 2760*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 2761*0b57cec5SDimitry Andricbool 2762*0b57cec5SDimitry Andricoperator!=( 2763*0b57cec5SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, 2764*0b57cec5SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y) 2765*0b57cec5SDimitry Andric{ 2766*0b57cec5SDimitry Andric return !(__x == __y); 2767*0b57cec5SDimitry Andric} 2768*0b57cec5SDimitry Andric 2769*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, 2770*0b57cec5SDimitry Andric class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> 2771*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 2772*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 2773*0b57cec5SDimitry Andric const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x) 2774*0b57cec5SDimitry Andric{ 2775*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__os); 2776*0b57cec5SDimitry Andric __os.flags(ios_base::dec | ios_base::left); 2777*0b57cec5SDimitry Andric _CharT __sp = __os.widen(' '); 2778*0b57cec5SDimitry Andric __os.fill(__sp); 2779*0b57cec5SDimitry Andric __os << __x.__x_[__x.__i_]; 2780*0b57cec5SDimitry Andric for (size_t __j = __x.__i_ + 1; __j < _Rp; ++__j) 2781*0b57cec5SDimitry Andric __os << __sp << __x.__x_[__j]; 2782*0b57cec5SDimitry Andric for (size_t __j = 0; __j < __x.__i_; ++__j) 2783*0b57cec5SDimitry Andric __os << __sp << __x.__x_[__j]; 2784*0b57cec5SDimitry Andric __os << __sp << __x.__c_; 2785*0b57cec5SDimitry Andric return __os; 2786*0b57cec5SDimitry Andric} 2787*0b57cec5SDimitry Andric 2788*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, 2789*0b57cec5SDimitry Andric class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> 2790*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 2791*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 2792*0b57cec5SDimitry Andric subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x) 2793*0b57cec5SDimitry Andric{ 2794*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__is); 2795*0b57cec5SDimitry Andric __is.flags(ios_base::dec | ios_base::skipws); 2796*0b57cec5SDimitry Andric _UInt __t[_Rp+1]; 2797*0b57cec5SDimitry Andric for (size_t __i = 0; __i < _Rp+1; ++__i) 2798*0b57cec5SDimitry Andric __is >> __t[__i]; 2799*0b57cec5SDimitry Andric if (!__is.fail()) 2800*0b57cec5SDimitry Andric { 2801*0b57cec5SDimitry Andric for (size_t __i = 0; __i < _Rp; ++__i) 2802*0b57cec5SDimitry Andric __x.__x_[__i] = __t[__i]; 2803*0b57cec5SDimitry Andric __x.__c_ = __t[_Rp]; 2804*0b57cec5SDimitry Andric __x.__i_ = 0; 2805*0b57cec5SDimitry Andric } 2806*0b57cec5SDimitry Andric return __is; 2807*0b57cec5SDimitry Andric} 2808*0b57cec5SDimitry Andric 2809*0b57cec5SDimitry Andrictypedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> ranlux24_base; 2810*0b57cec5SDimitry Andrictypedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> ranlux48_base; 2811*0b57cec5SDimitry Andric 2812*0b57cec5SDimitry Andric// discard_block_engine 2813*0b57cec5SDimitry Andric 2814*0b57cec5SDimitry Andrictemplate<class _Engine, size_t __p, size_t __r> 2815*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS discard_block_engine 2816*0b57cec5SDimitry Andric{ 2817*0b57cec5SDimitry Andric _Engine __e_; 2818*0b57cec5SDimitry Andric int __n_; 2819*0b57cec5SDimitry Andric 2820*0b57cec5SDimitry Andric static_assert( 0 < __r, "discard_block_engine invalid parameters"); 2821*0b57cec5SDimitry Andric static_assert(__r <= __p, "discard_block_engine invalid parameters"); 2822*0b57cec5SDimitry Andric static_assert(__r <= INT_MAX, "discard_block_engine invalid parameters"); 2823*0b57cec5SDimitry Andricpublic: 2824*0b57cec5SDimitry Andric // types 2825*0b57cec5SDimitry Andric typedef typename _Engine::result_type result_type; 2826*0b57cec5SDimitry Andric 2827*0b57cec5SDimitry Andric // engine characteristics 2828*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const size_t block_size = __p; 2829*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const size_t used_block = __r; 2830*0b57cec5SDimitry Andric 2831*0b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 2832*0b57cec5SDimitry Andric static const result_type _Min = _Engine::_Min; 2833*0b57cec5SDimitry Andric static const result_type _Max = _Engine::_Max; 2834*0b57cec5SDimitry Andric#else 2835*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min(); 2836*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max(); 2837*0b57cec5SDimitry Andric#endif 2838*0b57cec5SDimitry Andric 2839*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2840*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR result_type min() { return _Engine::min(); } 2841*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2842*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR result_type max() { return _Engine::max(); } 2843*0b57cec5SDimitry Andric 2844*0b57cec5SDimitry Andric // constructors and seeding functions 2845*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2846*0b57cec5SDimitry Andric discard_block_engine() : __n_(0) {} 2847*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2848*0b57cec5SDimitry Andric explicit discard_block_engine(const _Engine& __e) 2849*0b57cec5SDimitry Andric : __e_(__e), __n_(0) {} 2850*0b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 2851*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2852*0b57cec5SDimitry Andric explicit discard_block_engine(_Engine&& __e) 2853*0b57cec5SDimitry Andric : __e_(_VSTD::move(__e)), __n_(0) {} 2854*0b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 2855*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2856*0b57cec5SDimitry Andric explicit discard_block_engine(result_type __sd) : __e_(__sd), __n_(0) {} 2857*0b57cec5SDimitry Andric template<class _Sseq> 2858*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2859*0b57cec5SDimitry Andric explicit discard_block_engine(_Sseq& __q, 2860*0b57cec5SDimitry Andric typename enable_if<__is_seed_sequence<_Sseq, discard_block_engine>::value && 2861*0b57cec5SDimitry Andric !is_convertible<_Sseq, _Engine>::value>::type* = 0) 2862*0b57cec5SDimitry Andric : __e_(__q), __n_(0) {} 2863*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2864*0b57cec5SDimitry Andric void seed() {__e_.seed(); __n_ = 0;} 2865*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2866*0b57cec5SDimitry Andric void seed(result_type __sd) {__e_.seed(__sd); __n_ = 0;} 2867*0b57cec5SDimitry Andric template<class _Sseq> 2868*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2869*0b57cec5SDimitry Andric typename enable_if 2870*0b57cec5SDimitry Andric < 2871*0b57cec5SDimitry Andric __is_seed_sequence<_Sseq, discard_block_engine>::value, 2872*0b57cec5SDimitry Andric void 2873*0b57cec5SDimitry Andric >::type 2874*0b57cec5SDimitry Andric seed(_Sseq& __q) {__e_.seed(__q); __n_ = 0;} 2875*0b57cec5SDimitry Andric 2876*0b57cec5SDimitry Andric // generating functions 2877*0b57cec5SDimitry Andric result_type operator()(); 2878*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2879*0b57cec5SDimitry Andric void discard(unsigned long long __z) {for (; __z; --__z) operator()();} 2880*0b57cec5SDimitry Andric 2881*0b57cec5SDimitry Andric // property functions 2882*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2883*0b57cec5SDimitry Andric const _Engine& base() const _NOEXCEPT {return __e_;} 2884*0b57cec5SDimitry Andric 2885*0b57cec5SDimitry Andric template<class _Eng, size_t _Pp, size_t _Rp> 2886*0b57cec5SDimitry Andric friend 2887*0b57cec5SDimitry Andric bool 2888*0b57cec5SDimitry Andric operator==( 2889*0b57cec5SDimitry Andric const discard_block_engine<_Eng, _Pp, _Rp>& __x, 2890*0b57cec5SDimitry Andric const discard_block_engine<_Eng, _Pp, _Rp>& __y); 2891*0b57cec5SDimitry Andric 2892*0b57cec5SDimitry Andric template<class _Eng, size_t _Pp, size_t _Rp> 2893*0b57cec5SDimitry Andric friend 2894*0b57cec5SDimitry Andric bool 2895*0b57cec5SDimitry Andric operator!=( 2896*0b57cec5SDimitry Andric const discard_block_engine<_Eng, _Pp, _Rp>& __x, 2897*0b57cec5SDimitry Andric const discard_block_engine<_Eng, _Pp, _Rp>& __y); 2898*0b57cec5SDimitry Andric 2899*0b57cec5SDimitry Andric template <class _CharT, class _Traits, 2900*0b57cec5SDimitry Andric class _Eng, size_t _Pp, size_t _Rp> 2901*0b57cec5SDimitry Andric friend 2902*0b57cec5SDimitry Andric basic_ostream<_CharT, _Traits>& 2903*0b57cec5SDimitry Andric operator<<(basic_ostream<_CharT, _Traits>& __os, 2904*0b57cec5SDimitry Andric const discard_block_engine<_Eng, _Pp, _Rp>& __x); 2905*0b57cec5SDimitry Andric 2906*0b57cec5SDimitry Andric template <class _CharT, class _Traits, 2907*0b57cec5SDimitry Andric class _Eng, size_t _Pp, size_t _Rp> 2908*0b57cec5SDimitry Andric friend 2909*0b57cec5SDimitry Andric basic_istream<_CharT, _Traits>& 2910*0b57cec5SDimitry Andric operator>>(basic_istream<_CharT, _Traits>& __is, 2911*0b57cec5SDimitry Andric discard_block_engine<_Eng, _Pp, _Rp>& __x); 2912*0b57cec5SDimitry Andric}; 2913*0b57cec5SDimitry Andric 2914*0b57cec5SDimitry Andrictemplate<class _Engine, size_t __p, size_t __r> 2915*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::block_size; 2916*0b57cec5SDimitry Andric 2917*0b57cec5SDimitry Andrictemplate<class _Engine, size_t __p, size_t __r> 2918*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::used_block; 2919*0b57cec5SDimitry Andric 2920*0b57cec5SDimitry Andrictemplate<class _Engine, size_t __p, size_t __r> 2921*0b57cec5SDimitry Andrictypename discard_block_engine<_Engine, __p, __r>::result_type 2922*0b57cec5SDimitry Andricdiscard_block_engine<_Engine, __p, __r>::operator()() 2923*0b57cec5SDimitry Andric{ 2924*0b57cec5SDimitry Andric if (__n_ >= static_cast<int>(__r)) 2925*0b57cec5SDimitry Andric { 2926*0b57cec5SDimitry Andric __e_.discard(__p - __r); 2927*0b57cec5SDimitry Andric __n_ = 0; 2928*0b57cec5SDimitry Andric } 2929*0b57cec5SDimitry Andric ++__n_; 2930*0b57cec5SDimitry Andric return __e_(); 2931*0b57cec5SDimitry Andric} 2932*0b57cec5SDimitry Andric 2933*0b57cec5SDimitry Andrictemplate<class _Eng, size_t _Pp, size_t _Rp> 2934*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 2935*0b57cec5SDimitry Andricbool 2936*0b57cec5SDimitry Andricoperator==(const discard_block_engine<_Eng, _Pp, _Rp>& __x, 2937*0b57cec5SDimitry Andric const discard_block_engine<_Eng, _Pp, _Rp>& __y) 2938*0b57cec5SDimitry Andric{ 2939*0b57cec5SDimitry Andric return __x.__n_ == __y.__n_ && __x.__e_ == __y.__e_; 2940*0b57cec5SDimitry Andric} 2941*0b57cec5SDimitry Andric 2942*0b57cec5SDimitry Andrictemplate<class _Eng, size_t _Pp, size_t _Rp> 2943*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 2944*0b57cec5SDimitry Andricbool 2945*0b57cec5SDimitry Andricoperator!=(const discard_block_engine<_Eng, _Pp, _Rp>& __x, 2946*0b57cec5SDimitry Andric const discard_block_engine<_Eng, _Pp, _Rp>& __y) 2947*0b57cec5SDimitry Andric{ 2948*0b57cec5SDimitry Andric return !(__x == __y); 2949*0b57cec5SDimitry Andric} 2950*0b57cec5SDimitry Andric 2951*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, 2952*0b57cec5SDimitry Andric class _Eng, size_t _Pp, size_t _Rp> 2953*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 2954*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 2955*0b57cec5SDimitry Andric const discard_block_engine<_Eng, _Pp, _Rp>& __x) 2956*0b57cec5SDimitry Andric{ 2957*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__os); 2958*0b57cec5SDimitry Andric __os.flags(ios_base::dec | ios_base::left); 2959*0b57cec5SDimitry Andric _CharT __sp = __os.widen(' '); 2960*0b57cec5SDimitry Andric __os.fill(__sp); 2961*0b57cec5SDimitry Andric return __os << __x.__e_ << __sp << __x.__n_; 2962*0b57cec5SDimitry Andric} 2963*0b57cec5SDimitry Andric 2964*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, 2965*0b57cec5SDimitry Andric class _Eng, size_t _Pp, size_t _Rp> 2966*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 2967*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 2968*0b57cec5SDimitry Andric discard_block_engine<_Eng, _Pp, _Rp>& __x) 2969*0b57cec5SDimitry Andric{ 2970*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__is); 2971*0b57cec5SDimitry Andric __is.flags(ios_base::dec | ios_base::skipws); 2972*0b57cec5SDimitry Andric _Eng __e; 2973*0b57cec5SDimitry Andric int __n; 2974*0b57cec5SDimitry Andric __is >> __e >> __n; 2975*0b57cec5SDimitry Andric if (!__is.fail()) 2976*0b57cec5SDimitry Andric { 2977*0b57cec5SDimitry Andric __x.__e_ = __e; 2978*0b57cec5SDimitry Andric __x.__n_ = __n; 2979*0b57cec5SDimitry Andric } 2980*0b57cec5SDimitry Andric return __is; 2981*0b57cec5SDimitry Andric} 2982*0b57cec5SDimitry Andric 2983*0b57cec5SDimitry Andrictypedef discard_block_engine<ranlux24_base, 223, 23> ranlux24; 2984*0b57cec5SDimitry Andrictypedef discard_block_engine<ranlux48_base, 389, 11> ranlux48; 2985*0b57cec5SDimitry Andric 2986*0b57cec5SDimitry Andric// independent_bits_engine 2987*0b57cec5SDimitry Andric 2988*0b57cec5SDimitry Andrictemplate<class _Engine, size_t __w, class _UIntType> 2989*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS independent_bits_engine 2990*0b57cec5SDimitry Andric{ 2991*0b57cec5SDimitry Andric template <class _UInt, _UInt _R0, size_t _Wp, size_t _Mp> 2992*0b57cec5SDimitry Andric class __get_n 2993*0b57cec5SDimitry Andric { 2994*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const size_t _Dt = numeric_limits<_UInt>::digits; 2995*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const size_t _Np = _Wp / _Mp + (_Wp % _Mp != 0); 2996*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const size_t _W0 = _Wp / _Np; 2997*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const _UInt _Y0 = _W0 >= _Dt ? 0 : (_R0 >> _W0) << _W0; 2998*0b57cec5SDimitry Andric public: 2999*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const size_t value = _R0 - _Y0 > _Y0 / _Np ? _Np + 1 : _Np; 3000*0b57cec5SDimitry Andric }; 3001*0b57cec5SDimitry Andricpublic: 3002*0b57cec5SDimitry Andric // types 3003*0b57cec5SDimitry Andric typedef _UIntType result_type; 3004*0b57cec5SDimitry Andric 3005*0b57cec5SDimitry Andricprivate: 3006*0b57cec5SDimitry Andric _Engine __e_; 3007*0b57cec5SDimitry Andric 3008*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; 3009*0b57cec5SDimitry Andric static_assert( 0 < __w, "independent_bits_engine invalid parameters"); 3010*0b57cec5SDimitry Andric static_assert(__w <= _Dt, "independent_bits_engine invalid parameters"); 3011*0b57cec5SDimitry Andric 3012*0b57cec5SDimitry Andric typedef typename _Engine::result_type _Engine_result_type; 3013*0b57cec5SDimitry Andric typedef typename conditional 3014*0b57cec5SDimitry Andric < 3015*0b57cec5SDimitry Andric sizeof(_Engine_result_type) <= sizeof(result_type), 3016*0b57cec5SDimitry Andric result_type, 3017*0b57cec5SDimitry Andric _Engine_result_type 3018*0b57cec5SDimitry Andric >::type _Working_result_type; 3019*0b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 3020*0b57cec5SDimitry Andric static const _Working_result_type _Rp = _Engine::_Max - _Engine::_Min 3021*0b57cec5SDimitry Andric + _Working_result_type(1); 3022*0b57cec5SDimitry Andric#else 3023*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const _Working_result_type _Rp = _Engine::max() - _Engine::min() 3024*0b57cec5SDimitry Andric + _Working_result_type(1); 3025*0b57cec5SDimitry Andric#endif 3026*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const size_t __m = __log2<_Working_result_type, _Rp>::value; 3027*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const size_t __n = __get_n<_Working_result_type, _Rp, __w, __m>::value; 3028*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const size_t __w0 = __w / __n; 3029*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const size_t __n0 = __n - __w % __n; 3030*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const size_t _WDt = numeric_limits<_Working_result_type>::digits; 3031*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const size_t _EDt = numeric_limits<_Engine_result_type>::digits; 3032*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const _Working_result_type __y0 = __w0 >= _WDt ? 0 : 3033*0b57cec5SDimitry Andric (_Rp >> __w0) << __w0; 3034*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const _Working_result_type __y1 = __w0 >= _WDt - 1 ? 0 : 3035*0b57cec5SDimitry Andric (_Rp >> (__w0+1)) << (__w0+1); 3036*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const _Engine_result_type __mask0 = __w0 > 0 ? 3037*0b57cec5SDimitry Andric _Engine_result_type(~0) >> (_EDt - __w0) : 3038*0b57cec5SDimitry Andric _Engine_result_type(0); 3039*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const _Engine_result_type __mask1 = __w0 < _EDt - 1 ? 3040*0b57cec5SDimitry Andric _Engine_result_type(~0) >> (_EDt - (__w0 + 1)) : 3041*0b57cec5SDimitry Andric _Engine_result_type(~0); 3042*0b57cec5SDimitry Andricpublic: 3043*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type _Min = 0; 3044*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : 3045*0b57cec5SDimitry Andric (result_type(1) << __w) - result_type(1); 3046*0b57cec5SDimitry Andric static_assert(_Min < _Max, "independent_bits_engine invalid parameters"); 3047*0b57cec5SDimitry Andric 3048*0b57cec5SDimitry Andric // engine characteristics 3049*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3050*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR result_type min() { return _Min; } 3051*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3052*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR result_type max() { return _Max; } 3053*0b57cec5SDimitry Andric 3054*0b57cec5SDimitry Andric // constructors and seeding functions 3055*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3056*0b57cec5SDimitry Andric independent_bits_engine() {} 3057*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3058*0b57cec5SDimitry Andric explicit independent_bits_engine(const _Engine& __e) 3059*0b57cec5SDimitry Andric : __e_(__e) {} 3060*0b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 3061*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3062*0b57cec5SDimitry Andric explicit independent_bits_engine(_Engine&& __e) 3063*0b57cec5SDimitry Andric : __e_(_VSTD::move(__e)) {} 3064*0b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 3065*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3066*0b57cec5SDimitry Andric explicit independent_bits_engine(result_type __sd) : __e_(__sd) {} 3067*0b57cec5SDimitry Andric template<class _Sseq> 3068*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3069*0b57cec5SDimitry Andric explicit independent_bits_engine(_Sseq& __q, 3070*0b57cec5SDimitry Andric typename enable_if<__is_seed_sequence<_Sseq, independent_bits_engine>::value && 3071*0b57cec5SDimitry Andric !is_convertible<_Sseq, _Engine>::value>::type* = 0) 3072*0b57cec5SDimitry Andric : __e_(__q) {} 3073*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3074*0b57cec5SDimitry Andric void seed() {__e_.seed();} 3075*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3076*0b57cec5SDimitry Andric void seed(result_type __sd) {__e_.seed(__sd);} 3077*0b57cec5SDimitry Andric template<class _Sseq> 3078*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3079*0b57cec5SDimitry Andric typename enable_if 3080*0b57cec5SDimitry Andric < 3081*0b57cec5SDimitry Andric __is_seed_sequence<_Sseq, independent_bits_engine>::value, 3082*0b57cec5SDimitry Andric void 3083*0b57cec5SDimitry Andric >::type 3084*0b57cec5SDimitry Andric seed(_Sseq& __q) {__e_.seed(__q);} 3085*0b57cec5SDimitry Andric 3086*0b57cec5SDimitry Andric // generating functions 3087*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3088*0b57cec5SDimitry Andric result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());} 3089*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3090*0b57cec5SDimitry Andric void discard(unsigned long long __z) {for (; __z; --__z) operator()();} 3091*0b57cec5SDimitry Andric 3092*0b57cec5SDimitry Andric // property functions 3093*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3094*0b57cec5SDimitry Andric const _Engine& base() const _NOEXCEPT {return __e_;} 3095*0b57cec5SDimitry Andric 3096*0b57cec5SDimitry Andric template<class _Eng, size_t _Wp, class _UInt> 3097*0b57cec5SDimitry Andric friend 3098*0b57cec5SDimitry Andric bool 3099*0b57cec5SDimitry Andric operator==( 3100*0b57cec5SDimitry Andric const independent_bits_engine<_Eng, _Wp, _UInt>& __x, 3101*0b57cec5SDimitry Andric const independent_bits_engine<_Eng, _Wp, _UInt>& __y); 3102*0b57cec5SDimitry Andric 3103*0b57cec5SDimitry Andric template<class _Eng, size_t _Wp, class _UInt> 3104*0b57cec5SDimitry Andric friend 3105*0b57cec5SDimitry Andric bool 3106*0b57cec5SDimitry Andric operator!=( 3107*0b57cec5SDimitry Andric const independent_bits_engine<_Eng, _Wp, _UInt>& __x, 3108*0b57cec5SDimitry Andric const independent_bits_engine<_Eng, _Wp, _UInt>& __y); 3109*0b57cec5SDimitry Andric 3110*0b57cec5SDimitry Andric template <class _CharT, class _Traits, 3111*0b57cec5SDimitry Andric class _Eng, size_t _Wp, class _UInt> 3112*0b57cec5SDimitry Andric friend 3113*0b57cec5SDimitry Andric basic_ostream<_CharT, _Traits>& 3114*0b57cec5SDimitry Andric operator<<(basic_ostream<_CharT, _Traits>& __os, 3115*0b57cec5SDimitry Andric const independent_bits_engine<_Eng, _Wp, _UInt>& __x); 3116*0b57cec5SDimitry Andric 3117*0b57cec5SDimitry Andric template <class _CharT, class _Traits, 3118*0b57cec5SDimitry Andric class _Eng, size_t _Wp, class _UInt> 3119*0b57cec5SDimitry Andric friend 3120*0b57cec5SDimitry Andric basic_istream<_CharT, _Traits>& 3121*0b57cec5SDimitry Andric operator>>(basic_istream<_CharT, _Traits>& __is, 3122*0b57cec5SDimitry Andric independent_bits_engine<_Eng, _Wp, _UInt>& __x); 3123*0b57cec5SDimitry Andric 3124*0b57cec5SDimitry Andricprivate: 3125*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3126*0b57cec5SDimitry Andric result_type __eval(false_type); 3127*0b57cec5SDimitry Andric result_type __eval(true_type); 3128*0b57cec5SDimitry Andric 3129*0b57cec5SDimitry Andric template <size_t __count> 3130*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3131*0b57cec5SDimitry Andric static 3132*0b57cec5SDimitry Andric typename enable_if 3133*0b57cec5SDimitry Andric < 3134*0b57cec5SDimitry Andric __count < _Dt, 3135*0b57cec5SDimitry Andric result_type 3136*0b57cec5SDimitry Andric >::type 3137*0b57cec5SDimitry Andric __lshift(result_type __x) {return __x << __count;} 3138*0b57cec5SDimitry Andric 3139*0b57cec5SDimitry Andric template <size_t __count> 3140*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3141*0b57cec5SDimitry Andric static 3142*0b57cec5SDimitry Andric typename enable_if 3143*0b57cec5SDimitry Andric < 3144*0b57cec5SDimitry Andric (__count >= _Dt), 3145*0b57cec5SDimitry Andric result_type 3146*0b57cec5SDimitry Andric >::type 3147*0b57cec5SDimitry Andric __lshift(result_type) {return result_type(0);} 3148*0b57cec5SDimitry Andric}; 3149*0b57cec5SDimitry Andric 3150*0b57cec5SDimitry Andrictemplate<class _Engine, size_t __w, class _UIntType> 3151*0b57cec5SDimitry Andricinline 3152*0b57cec5SDimitry Andric_UIntType 3153*0b57cec5SDimitry Andricindependent_bits_engine<_Engine, __w, _UIntType>::__eval(false_type) 3154*0b57cec5SDimitry Andric{ 3155*0b57cec5SDimitry Andric return static_cast<result_type>(__e_() & __mask0); 3156*0b57cec5SDimitry Andric} 3157*0b57cec5SDimitry Andric 3158*0b57cec5SDimitry Andrictemplate<class _Engine, size_t __w, class _UIntType> 3159*0b57cec5SDimitry Andric_UIntType 3160*0b57cec5SDimitry Andricindependent_bits_engine<_Engine, __w, _UIntType>::__eval(true_type) 3161*0b57cec5SDimitry Andric{ 3162*0b57cec5SDimitry Andric result_type _Sp = 0; 3163*0b57cec5SDimitry Andric for (size_t __k = 0; __k < __n0; ++__k) 3164*0b57cec5SDimitry Andric { 3165*0b57cec5SDimitry Andric _Engine_result_type __u; 3166*0b57cec5SDimitry Andric do 3167*0b57cec5SDimitry Andric { 3168*0b57cec5SDimitry Andric __u = __e_() - _Engine::min(); 3169*0b57cec5SDimitry Andric } while (__u >= __y0); 3170*0b57cec5SDimitry Andric _Sp = static_cast<result_type>(__lshift<__w0>(_Sp) + (__u & __mask0)); 3171*0b57cec5SDimitry Andric } 3172*0b57cec5SDimitry Andric for (size_t __k = __n0; __k < __n; ++__k) 3173*0b57cec5SDimitry Andric { 3174*0b57cec5SDimitry Andric _Engine_result_type __u; 3175*0b57cec5SDimitry Andric do 3176*0b57cec5SDimitry Andric { 3177*0b57cec5SDimitry Andric __u = __e_() - _Engine::min(); 3178*0b57cec5SDimitry Andric } while (__u >= __y1); 3179*0b57cec5SDimitry Andric _Sp = static_cast<result_type>(__lshift<__w0+1>(_Sp) + (__u & __mask1)); 3180*0b57cec5SDimitry Andric } 3181*0b57cec5SDimitry Andric return _Sp; 3182*0b57cec5SDimitry Andric} 3183*0b57cec5SDimitry Andric 3184*0b57cec5SDimitry Andrictemplate<class _Eng, size_t _Wp, class _UInt> 3185*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 3186*0b57cec5SDimitry Andricbool 3187*0b57cec5SDimitry Andricoperator==( 3188*0b57cec5SDimitry Andric const independent_bits_engine<_Eng, _Wp, _UInt>& __x, 3189*0b57cec5SDimitry Andric const independent_bits_engine<_Eng, _Wp, _UInt>& __y) 3190*0b57cec5SDimitry Andric{ 3191*0b57cec5SDimitry Andric return __x.base() == __y.base(); 3192*0b57cec5SDimitry Andric} 3193*0b57cec5SDimitry Andric 3194*0b57cec5SDimitry Andrictemplate<class _Eng, size_t _Wp, class _UInt> 3195*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 3196*0b57cec5SDimitry Andricbool 3197*0b57cec5SDimitry Andricoperator!=( 3198*0b57cec5SDimitry Andric const independent_bits_engine<_Eng, _Wp, _UInt>& __x, 3199*0b57cec5SDimitry Andric const independent_bits_engine<_Eng, _Wp, _UInt>& __y) 3200*0b57cec5SDimitry Andric{ 3201*0b57cec5SDimitry Andric return !(__x == __y); 3202*0b57cec5SDimitry Andric} 3203*0b57cec5SDimitry Andric 3204*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, 3205*0b57cec5SDimitry Andric class _Eng, size_t _Wp, class _UInt> 3206*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 3207*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 3208*0b57cec5SDimitry Andric const independent_bits_engine<_Eng, _Wp, _UInt>& __x) 3209*0b57cec5SDimitry Andric{ 3210*0b57cec5SDimitry Andric return __os << __x.base(); 3211*0b57cec5SDimitry Andric} 3212*0b57cec5SDimitry Andric 3213*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, 3214*0b57cec5SDimitry Andric class _Eng, size_t _Wp, class _UInt> 3215*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 3216*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 3217*0b57cec5SDimitry Andric independent_bits_engine<_Eng, _Wp, _UInt>& __x) 3218*0b57cec5SDimitry Andric{ 3219*0b57cec5SDimitry Andric _Eng __e; 3220*0b57cec5SDimitry Andric __is >> __e; 3221*0b57cec5SDimitry Andric if (!__is.fail()) 3222*0b57cec5SDimitry Andric __x.__e_ = __e; 3223*0b57cec5SDimitry Andric return __is; 3224*0b57cec5SDimitry Andric} 3225*0b57cec5SDimitry Andric 3226*0b57cec5SDimitry Andric// shuffle_order_engine 3227*0b57cec5SDimitry Andric 3228*0b57cec5SDimitry Andrictemplate <uint64_t _Xp, uint64_t _Yp> 3229*0b57cec5SDimitry Andricstruct __ugcd 3230*0b57cec5SDimitry Andric{ 3231*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const uint64_t value = __ugcd<_Yp, _Xp % _Yp>::value; 3232*0b57cec5SDimitry Andric}; 3233*0b57cec5SDimitry Andric 3234*0b57cec5SDimitry Andrictemplate <uint64_t _Xp> 3235*0b57cec5SDimitry Andricstruct __ugcd<_Xp, 0> 3236*0b57cec5SDimitry Andric{ 3237*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const uint64_t value = _Xp; 3238*0b57cec5SDimitry Andric}; 3239*0b57cec5SDimitry Andric 3240*0b57cec5SDimitry Andrictemplate <uint64_t _Np, uint64_t _Dp> 3241*0b57cec5SDimitry Andricclass __uratio 3242*0b57cec5SDimitry Andric{ 3243*0b57cec5SDimitry Andric static_assert(_Dp != 0, "__uratio divide by 0"); 3244*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const uint64_t __gcd = __ugcd<_Np, _Dp>::value; 3245*0b57cec5SDimitry Andricpublic: 3246*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const uint64_t num = _Np / __gcd; 3247*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const uint64_t den = _Dp / __gcd; 3248*0b57cec5SDimitry Andric 3249*0b57cec5SDimitry Andric typedef __uratio<num, den> type; 3250*0b57cec5SDimitry Andric}; 3251*0b57cec5SDimitry Andric 3252*0b57cec5SDimitry Andrictemplate<class _Engine, size_t __k> 3253*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS shuffle_order_engine 3254*0b57cec5SDimitry Andric{ 3255*0b57cec5SDimitry Andric static_assert(0 < __k, "shuffle_order_engine invalid parameters"); 3256*0b57cec5SDimitry Andricpublic: 3257*0b57cec5SDimitry Andric // types 3258*0b57cec5SDimitry Andric typedef typename _Engine::result_type result_type; 3259*0b57cec5SDimitry Andric 3260*0b57cec5SDimitry Andricprivate: 3261*0b57cec5SDimitry Andric _Engine __e_; 3262*0b57cec5SDimitry Andric result_type _V_[__k]; 3263*0b57cec5SDimitry Andric result_type _Y_; 3264*0b57cec5SDimitry Andric 3265*0b57cec5SDimitry Andricpublic: 3266*0b57cec5SDimitry Andric // engine characteristics 3267*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const size_t table_size = __k; 3268*0b57cec5SDimitry Andric 3269*0b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 3270*0b57cec5SDimitry Andric static const result_type _Min = _Engine::_Min; 3271*0b57cec5SDimitry Andric static const result_type _Max = _Engine::_Max; 3272*0b57cec5SDimitry Andric#else 3273*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min(); 3274*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max(); 3275*0b57cec5SDimitry Andric#endif 3276*0b57cec5SDimitry Andric static_assert(_Min < _Max, "shuffle_order_engine invalid parameters"); 3277*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3278*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR result_type min() { return _Min; } 3279*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3280*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR result_type max() { return _Max; } 3281*0b57cec5SDimitry Andric 3282*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const unsigned long long _Rp = _Max - _Min + 1ull; 3283*0b57cec5SDimitry Andric 3284*0b57cec5SDimitry Andric // constructors and seeding functions 3285*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3286*0b57cec5SDimitry Andric shuffle_order_engine() {__init();} 3287*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3288*0b57cec5SDimitry Andric explicit shuffle_order_engine(const _Engine& __e) 3289*0b57cec5SDimitry Andric : __e_(__e) {__init();} 3290*0b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 3291*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3292*0b57cec5SDimitry Andric explicit shuffle_order_engine(_Engine&& __e) 3293*0b57cec5SDimitry Andric : __e_(_VSTD::move(__e)) {__init();} 3294*0b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 3295*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3296*0b57cec5SDimitry Andric explicit shuffle_order_engine(result_type __sd) : __e_(__sd) {__init();} 3297*0b57cec5SDimitry Andric template<class _Sseq> 3298*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3299*0b57cec5SDimitry Andric explicit shuffle_order_engine(_Sseq& __q, 3300*0b57cec5SDimitry Andric typename enable_if<__is_seed_sequence<_Sseq, shuffle_order_engine>::value && 3301*0b57cec5SDimitry Andric !is_convertible<_Sseq, _Engine>::value>::type* = 0) 3302*0b57cec5SDimitry Andric : __e_(__q) {__init();} 3303*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3304*0b57cec5SDimitry Andric void seed() {__e_.seed(); __init();} 3305*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3306*0b57cec5SDimitry Andric void seed(result_type __sd) {__e_.seed(__sd); __init();} 3307*0b57cec5SDimitry Andric template<class _Sseq> 3308*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3309*0b57cec5SDimitry Andric typename enable_if 3310*0b57cec5SDimitry Andric < 3311*0b57cec5SDimitry Andric __is_seed_sequence<_Sseq, shuffle_order_engine>::value, 3312*0b57cec5SDimitry Andric void 3313*0b57cec5SDimitry Andric >::type 3314*0b57cec5SDimitry Andric seed(_Sseq& __q) {__e_.seed(__q); __init();} 3315*0b57cec5SDimitry Andric 3316*0b57cec5SDimitry Andric // generating functions 3317*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3318*0b57cec5SDimitry Andric result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());} 3319*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3320*0b57cec5SDimitry Andric void discard(unsigned long long __z) {for (; __z; --__z) operator()();} 3321*0b57cec5SDimitry Andric 3322*0b57cec5SDimitry Andric // property functions 3323*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3324*0b57cec5SDimitry Andric const _Engine& base() const _NOEXCEPT {return __e_;} 3325*0b57cec5SDimitry Andric 3326*0b57cec5SDimitry Andricprivate: 3327*0b57cec5SDimitry Andric template<class _Eng, size_t _Kp> 3328*0b57cec5SDimitry Andric friend 3329*0b57cec5SDimitry Andric bool 3330*0b57cec5SDimitry Andric operator==( 3331*0b57cec5SDimitry Andric const shuffle_order_engine<_Eng, _Kp>& __x, 3332*0b57cec5SDimitry Andric const shuffle_order_engine<_Eng, _Kp>& __y); 3333*0b57cec5SDimitry Andric 3334*0b57cec5SDimitry Andric template<class _Eng, size_t _Kp> 3335*0b57cec5SDimitry Andric friend 3336*0b57cec5SDimitry Andric bool 3337*0b57cec5SDimitry Andric operator!=( 3338*0b57cec5SDimitry Andric const shuffle_order_engine<_Eng, _Kp>& __x, 3339*0b57cec5SDimitry Andric const shuffle_order_engine<_Eng, _Kp>& __y); 3340*0b57cec5SDimitry Andric 3341*0b57cec5SDimitry Andric template <class _CharT, class _Traits, 3342*0b57cec5SDimitry Andric class _Eng, size_t _Kp> 3343*0b57cec5SDimitry Andric friend 3344*0b57cec5SDimitry Andric basic_ostream<_CharT, _Traits>& 3345*0b57cec5SDimitry Andric operator<<(basic_ostream<_CharT, _Traits>& __os, 3346*0b57cec5SDimitry Andric const shuffle_order_engine<_Eng, _Kp>& __x); 3347*0b57cec5SDimitry Andric 3348*0b57cec5SDimitry Andric template <class _CharT, class _Traits, 3349*0b57cec5SDimitry Andric class _Eng, size_t _Kp> 3350*0b57cec5SDimitry Andric friend 3351*0b57cec5SDimitry Andric basic_istream<_CharT, _Traits>& 3352*0b57cec5SDimitry Andric operator>>(basic_istream<_CharT, _Traits>& __is, 3353*0b57cec5SDimitry Andric shuffle_order_engine<_Eng, _Kp>& __x); 3354*0b57cec5SDimitry Andric 3355*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3356*0b57cec5SDimitry Andric void __init() 3357*0b57cec5SDimitry Andric { 3358*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __k; ++__i) 3359*0b57cec5SDimitry Andric _V_[__i] = __e_(); 3360*0b57cec5SDimitry Andric _Y_ = __e_(); 3361*0b57cec5SDimitry Andric } 3362*0b57cec5SDimitry Andric 3363*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3364*0b57cec5SDimitry Andric result_type __eval(false_type) {return __eval2(integral_constant<bool, __k & 1>());} 3365*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3366*0b57cec5SDimitry Andric result_type __eval(true_type) {return __eval(__uratio<__k, _Rp>());} 3367*0b57cec5SDimitry Andric 3368*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3369*0b57cec5SDimitry Andric result_type __eval2(false_type) {return __eval(__uratio<__k/2, 0x8000000000000000ull>());} 3370*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3371*0b57cec5SDimitry Andric result_type __eval2(true_type) {return __evalf<__k, 0>();} 3372*0b57cec5SDimitry Andric 3373*0b57cec5SDimitry Andric template <uint64_t _Np, uint64_t _Dp> 3374*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3375*0b57cec5SDimitry Andric typename enable_if 3376*0b57cec5SDimitry Andric < 3377*0b57cec5SDimitry Andric (__uratio<_Np, _Dp>::num > 0xFFFFFFFFFFFFFFFFull / (_Max - _Min)), 3378*0b57cec5SDimitry Andric result_type 3379*0b57cec5SDimitry Andric >::type 3380*0b57cec5SDimitry Andric __eval(__uratio<_Np, _Dp>) 3381*0b57cec5SDimitry Andric {return __evalf<__uratio<_Np, _Dp>::num, __uratio<_Np, _Dp>::den>();} 3382*0b57cec5SDimitry Andric 3383*0b57cec5SDimitry Andric template <uint64_t _Np, uint64_t _Dp> 3384*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3385*0b57cec5SDimitry Andric typename enable_if 3386*0b57cec5SDimitry Andric < 3387*0b57cec5SDimitry Andric __uratio<_Np, _Dp>::num <= 0xFFFFFFFFFFFFFFFFull / (_Max - _Min), 3388*0b57cec5SDimitry Andric result_type 3389*0b57cec5SDimitry Andric >::type 3390*0b57cec5SDimitry Andric __eval(__uratio<_Np, _Dp>) 3391*0b57cec5SDimitry Andric { 3392*0b57cec5SDimitry Andric const size_t __j = static_cast<size_t>(__uratio<_Np, _Dp>::num * (_Y_ - _Min) 3393*0b57cec5SDimitry Andric / __uratio<_Np, _Dp>::den); 3394*0b57cec5SDimitry Andric _Y_ = _V_[__j]; 3395*0b57cec5SDimitry Andric _V_[__j] = __e_(); 3396*0b57cec5SDimitry Andric return _Y_; 3397*0b57cec5SDimitry Andric } 3398*0b57cec5SDimitry Andric 3399*0b57cec5SDimitry Andric template <uint64_t __n, uint64_t __d> 3400*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3401*0b57cec5SDimitry Andric result_type __evalf() 3402*0b57cec5SDimitry Andric { 3403*0b57cec5SDimitry Andric const double _Fp = __d == 0 ? 3404*0b57cec5SDimitry Andric __n / (2. * 0x8000000000000000ull) : 3405*0b57cec5SDimitry Andric __n / (double)__d; 3406*0b57cec5SDimitry Andric const size_t __j = static_cast<size_t>(_Fp * (_Y_ - _Min)); 3407*0b57cec5SDimitry Andric _Y_ = _V_[__j]; 3408*0b57cec5SDimitry Andric _V_[__j] = __e_(); 3409*0b57cec5SDimitry Andric return _Y_; 3410*0b57cec5SDimitry Andric } 3411*0b57cec5SDimitry Andric}; 3412*0b57cec5SDimitry Andric 3413*0b57cec5SDimitry Andrictemplate<class _Engine, size_t __k> 3414*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR const size_t shuffle_order_engine<_Engine, __k>::table_size; 3415*0b57cec5SDimitry Andric 3416*0b57cec5SDimitry Andrictemplate<class _Eng, size_t _Kp> 3417*0b57cec5SDimitry Andricbool 3418*0b57cec5SDimitry Andricoperator==( 3419*0b57cec5SDimitry Andric const shuffle_order_engine<_Eng, _Kp>& __x, 3420*0b57cec5SDimitry Andric const shuffle_order_engine<_Eng, _Kp>& __y) 3421*0b57cec5SDimitry Andric{ 3422*0b57cec5SDimitry Andric return __x._Y_ == __y._Y_ && _VSTD::equal(__x._V_, __x._V_ + _Kp, __y._V_) && 3423*0b57cec5SDimitry Andric __x.__e_ == __y.__e_; 3424*0b57cec5SDimitry Andric} 3425*0b57cec5SDimitry Andric 3426*0b57cec5SDimitry Andrictemplate<class _Eng, size_t _Kp> 3427*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 3428*0b57cec5SDimitry Andricbool 3429*0b57cec5SDimitry Andricoperator!=( 3430*0b57cec5SDimitry Andric const shuffle_order_engine<_Eng, _Kp>& __x, 3431*0b57cec5SDimitry Andric const shuffle_order_engine<_Eng, _Kp>& __y) 3432*0b57cec5SDimitry Andric{ 3433*0b57cec5SDimitry Andric return !(__x == __y); 3434*0b57cec5SDimitry Andric} 3435*0b57cec5SDimitry Andric 3436*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, 3437*0b57cec5SDimitry Andric class _Eng, size_t _Kp> 3438*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 3439*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 3440*0b57cec5SDimitry Andric const shuffle_order_engine<_Eng, _Kp>& __x) 3441*0b57cec5SDimitry Andric{ 3442*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__os); 3443*0b57cec5SDimitry Andric __os.flags(ios_base::dec | ios_base::left); 3444*0b57cec5SDimitry Andric _CharT __sp = __os.widen(' '); 3445*0b57cec5SDimitry Andric __os.fill(__sp); 3446*0b57cec5SDimitry Andric __os << __x.__e_ << __sp << __x._V_[0]; 3447*0b57cec5SDimitry Andric for (size_t __i = 1; __i < _Kp; ++__i) 3448*0b57cec5SDimitry Andric __os << __sp << __x._V_[__i]; 3449*0b57cec5SDimitry Andric return __os << __sp << __x._Y_; 3450*0b57cec5SDimitry Andric} 3451*0b57cec5SDimitry Andric 3452*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, 3453*0b57cec5SDimitry Andric class _Eng, size_t _Kp> 3454*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 3455*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 3456*0b57cec5SDimitry Andric shuffle_order_engine<_Eng, _Kp>& __x) 3457*0b57cec5SDimitry Andric{ 3458*0b57cec5SDimitry Andric typedef typename shuffle_order_engine<_Eng, _Kp>::result_type result_type; 3459*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__is); 3460*0b57cec5SDimitry Andric __is.flags(ios_base::dec | ios_base::skipws); 3461*0b57cec5SDimitry Andric _Eng __e; 3462*0b57cec5SDimitry Andric result_type _Vp[_Kp+1]; 3463*0b57cec5SDimitry Andric __is >> __e; 3464*0b57cec5SDimitry Andric for (size_t __i = 0; __i < _Kp+1; ++__i) 3465*0b57cec5SDimitry Andric __is >> _Vp[__i]; 3466*0b57cec5SDimitry Andric if (!__is.fail()) 3467*0b57cec5SDimitry Andric { 3468*0b57cec5SDimitry Andric __x.__e_ = __e; 3469*0b57cec5SDimitry Andric for (size_t __i = 0; __i < _Kp; ++__i) 3470*0b57cec5SDimitry Andric __x._V_[__i] = _Vp[__i]; 3471*0b57cec5SDimitry Andric __x._Y_ = _Vp[_Kp]; 3472*0b57cec5SDimitry Andric } 3473*0b57cec5SDimitry Andric return __is; 3474*0b57cec5SDimitry Andric} 3475*0b57cec5SDimitry Andric 3476*0b57cec5SDimitry Andrictypedef shuffle_order_engine<minstd_rand0, 256> knuth_b; 3477*0b57cec5SDimitry Andric 3478*0b57cec5SDimitry Andric// random_device 3479*0b57cec5SDimitry Andric 3480*0b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS random_device 3481*0b57cec5SDimitry Andric{ 3482*0b57cec5SDimitry Andric#ifdef _LIBCPP_USING_DEV_RANDOM 3483*0b57cec5SDimitry Andric int __f_; 3484*0b57cec5SDimitry Andric#endif // defined(_LIBCPP_USING_DEV_RANDOM) 3485*0b57cec5SDimitry Andricpublic: 3486*0b57cec5SDimitry Andric // types 3487*0b57cec5SDimitry Andric typedef unsigned result_type; 3488*0b57cec5SDimitry Andric 3489*0b57cec5SDimitry Andric // generator characteristics 3490*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type _Min = 0; 3491*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR const result_type _Max = 0xFFFFFFFFu; 3492*0b57cec5SDimitry Andric 3493*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3494*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR result_type min() { return _Min;} 3495*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3496*0b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR result_type max() { return _Max;} 3497*0b57cec5SDimitry Andric 3498*0b57cec5SDimitry Andric // constructors 3499*0b57cec5SDimitry Andric explicit random_device(const string& __token = "/dev/urandom"); 3500*0b57cec5SDimitry Andric ~random_device(); 3501*0b57cec5SDimitry Andric 3502*0b57cec5SDimitry Andric // generating functions 3503*0b57cec5SDimitry Andric result_type operator()(); 3504*0b57cec5SDimitry Andric 3505*0b57cec5SDimitry Andric // property functions 3506*0b57cec5SDimitry Andric double entropy() const _NOEXCEPT; 3507*0b57cec5SDimitry Andric 3508*0b57cec5SDimitry Andricprivate: 3509*0b57cec5SDimitry Andric // no copy functions 3510*0b57cec5SDimitry Andric random_device(const random_device&); // = delete; 3511*0b57cec5SDimitry Andric random_device& operator=(const random_device&); // = delete; 3512*0b57cec5SDimitry Andric}; 3513*0b57cec5SDimitry Andric 3514*0b57cec5SDimitry Andric// seed_seq 3515*0b57cec5SDimitry Andric 3516*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS seed_seq 3517*0b57cec5SDimitry Andric{ 3518*0b57cec5SDimitry Andricpublic: 3519*0b57cec5SDimitry Andric // types 3520*0b57cec5SDimitry Andric typedef uint32_t result_type; 3521*0b57cec5SDimitry Andric 3522*0b57cec5SDimitry Andricprivate: 3523*0b57cec5SDimitry Andric vector<result_type> __v_; 3524*0b57cec5SDimitry Andric 3525*0b57cec5SDimitry Andric template<class _InputIterator> 3526*0b57cec5SDimitry Andric void init(_InputIterator __first, _InputIterator __last); 3527*0b57cec5SDimitry Andricpublic: 3528*0b57cec5SDimitry Andric // constructors 3529*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3530*0b57cec5SDimitry Andric seed_seq() _NOEXCEPT {} 3531*0b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 3532*0b57cec5SDimitry Andric template<class _Tp> 3533*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3534*0b57cec5SDimitry Andric seed_seq(initializer_list<_Tp> __il) {init(__il.begin(), __il.end());} 3535*0b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 3536*0b57cec5SDimitry Andric 3537*0b57cec5SDimitry Andric template<class _InputIterator> 3538*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3539*0b57cec5SDimitry Andric seed_seq(_InputIterator __first, _InputIterator __last) 3540*0b57cec5SDimitry Andric {init(__first, __last);} 3541*0b57cec5SDimitry Andric 3542*0b57cec5SDimitry Andric // generating functions 3543*0b57cec5SDimitry Andric template<class _RandomAccessIterator> 3544*0b57cec5SDimitry Andric void generate(_RandomAccessIterator __first, _RandomAccessIterator __last); 3545*0b57cec5SDimitry Andric 3546*0b57cec5SDimitry Andric // property functions 3547*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3548*0b57cec5SDimitry Andric size_t size() const _NOEXCEPT {return __v_.size();} 3549*0b57cec5SDimitry Andric template<class _OutputIterator> 3550*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3551*0b57cec5SDimitry Andric void param(_OutputIterator __dest) const 3552*0b57cec5SDimitry Andric {_VSTD::copy(__v_.begin(), __v_.end(), __dest);} 3553*0b57cec5SDimitry Andric 3554*0b57cec5SDimitry Andricprivate: 3555*0b57cec5SDimitry Andric // no copy functions 3556*0b57cec5SDimitry Andric seed_seq(const seed_seq&); // = delete; 3557*0b57cec5SDimitry Andric void operator=(const seed_seq&); // = delete; 3558*0b57cec5SDimitry Andric 3559*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3560*0b57cec5SDimitry Andric static result_type _Tp(result_type __x) {return __x ^ (__x >> 27);} 3561*0b57cec5SDimitry Andric}; 3562*0b57cec5SDimitry Andric 3563*0b57cec5SDimitry Andrictemplate<class _InputIterator> 3564*0b57cec5SDimitry Andricvoid 3565*0b57cec5SDimitry Andricseed_seq::init(_InputIterator __first, _InputIterator __last) 3566*0b57cec5SDimitry Andric{ 3567*0b57cec5SDimitry Andric for (_InputIterator __s = __first; __s != __last; ++__s) 3568*0b57cec5SDimitry Andric __v_.push_back(*__s & 0xFFFFFFFF); 3569*0b57cec5SDimitry Andric} 3570*0b57cec5SDimitry Andric 3571*0b57cec5SDimitry Andrictemplate<class _RandomAccessIterator> 3572*0b57cec5SDimitry Andricvoid 3573*0b57cec5SDimitry Andricseed_seq::generate(_RandomAccessIterator __first, _RandomAccessIterator __last) 3574*0b57cec5SDimitry Andric{ 3575*0b57cec5SDimitry Andric if (__first != __last) 3576*0b57cec5SDimitry Andric { 3577*0b57cec5SDimitry Andric _VSTD::fill(__first, __last, 0x8b8b8b8b); 3578*0b57cec5SDimitry Andric const size_t __n = static_cast<size_t>(__last - __first); 3579*0b57cec5SDimitry Andric const size_t __s = __v_.size(); 3580*0b57cec5SDimitry Andric const size_t __t = (__n >= 623) ? 11 3581*0b57cec5SDimitry Andric : (__n >= 68) ? 7 3582*0b57cec5SDimitry Andric : (__n >= 39) ? 5 3583*0b57cec5SDimitry Andric : (__n >= 7) ? 3 3584*0b57cec5SDimitry Andric : (__n - 1) / 2; 3585*0b57cec5SDimitry Andric const size_t __p = (__n - __t) / 2; 3586*0b57cec5SDimitry Andric const size_t __q = __p + __t; 3587*0b57cec5SDimitry Andric const size_t __m = _VSTD::max(__s + 1, __n); 3588*0b57cec5SDimitry Andric // __k = 0; 3589*0b57cec5SDimitry Andric { 3590*0b57cec5SDimitry Andric result_type __r = 1664525 * _Tp(__first[0] ^ __first[__p] 3591*0b57cec5SDimitry Andric ^ __first[__n - 1]); 3592*0b57cec5SDimitry Andric __first[__p] += __r; 3593*0b57cec5SDimitry Andric __r += __s; 3594*0b57cec5SDimitry Andric __first[__q] += __r; 3595*0b57cec5SDimitry Andric __first[0] = __r; 3596*0b57cec5SDimitry Andric } 3597*0b57cec5SDimitry Andric for (size_t __k = 1; __k <= __s; ++__k) 3598*0b57cec5SDimitry Andric { 3599*0b57cec5SDimitry Andric const size_t __kmodn = __k % __n; 3600*0b57cec5SDimitry Andric const size_t __kpmodn = (__k + __p) % __n; 3601*0b57cec5SDimitry Andric result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn] 3602*0b57cec5SDimitry Andric ^ __first[(__k - 1) % __n]); 3603*0b57cec5SDimitry Andric __first[__kpmodn] += __r; 3604*0b57cec5SDimitry Andric __r += __kmodn + __v_[__k-1]; 3605*0b57cec5SDimitry Andric __first[(__k + __q) % __n] += __r; 3606*0b57cec5SDimitry Andric __first[__kmodn] = __r; 3607*0b57cec5SDimitry Andric } 3608*0b57cec5SDimitry Andric for (size_t __k = __s + 1; __k < __m; ++__k) 3609*0b57cec5SDimitry Andric { 3610*0b57cec5SDimitry Andric const size_t __kmodn = __k % __n; 3611*0b57cec5SDimitry Andric const size_t __kpmodn = (__k + __p) % __n; 3612*0b57cec5SDimitry Andric result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn] 3613*0b57cec5SDimitry Andric ^ __first[(__k - 1) % __n]); 3614*0b57cec5SDimitry Andric __first[__kpmodn] += __r; 3615*0b57cec5SDimitry Andric __r += __kmodn; 3616*0b57cec5SDimitry Andric __first[(__k + __q) % __n] += __r; 3617*0b57cec5SDimitry Andric __first[__kmodn] = __r; 3618*0b57cec5SDimitry Andric } 3619*0b57cec5SDimitry Andric for (size_t __k = __m; __k < __m + __n; ++__k) 3620*0b57cec5SDimitry Andric { 3621*0b57cec5SDimitry Andric const size_t __kmodn = __k % __n; 3622*0b57cec5SDimitry Andric const size_t __kpmodn = (__k + __p) % __n; 3623*0b57cec5SDimitry Andric result_type __r = 1566083941 * _Tp(__first[__kmodn] + 3624*0b57cec5SDimitry Andric __first[__kpmodn] + 3625*0b57cec5SDimitry Andric __first[(__k - 1) % __n]); 3626*0b57cec5SDimitry Andric __first[__kpmodn] ^= __r; 3627*0b57cec5SDimitry Andric __r -= __kmodn; 3628*0b57cec5SDimitry Andric __first[(__k + __q) % __n] ^= __r; 3629*0b57cec5SDimitry Andric __first[__kmodn] = __r; 3630*0b57cec5SDimitry Andric } 3631*0b57cec5SDimitry Andric } 3632*0b57cec5SDimitry Andric} 3633*0b57cec5SDimitry Andric 3634*0b57cec5SDimitry Andric// generate_canonical 3635*0b57cec5SDimitry Andric 3636*0b57cec5SDimitry Andrictemplate<class _RealType, size_t __bits, class _URNG> 3637*0b57cec5SDimitry Andric_RealType 3638*0b57cec5SDimitry Andricgenerate_canonical(_URNG& __g) 3639*0b57cec5SDimitry Andric{ 3640*0b57cec5SDimitry Andric const size_t _Dt = numeric_limits<_RealType>::digits; 3641*0b57cec5SDimitry Andric const size_t __b = _Dt < __bits ? _Dt : __bits; 3642*0b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 3643*0b57cec5SDimitry Andric const size_t __logR = __log2<uint64_t, _URNG::_Max - _URNG::_Min + uint64_t(1)>::value; 3644*0b57cec5SDimitry Andric#else 3645*0b57cec5SDimitry Andric const size_t __logR = __log2<uint64_t, _URNG::max() - _URNG::min() + uint64_t(1)>::value; 3646*0b57cec5SDimitry Andric#endif 3647*0b57cec5SDimitry Andric const size_t __k = __b / __logR + (__b % __logR != 0) + (__b == 0); 3648*0b57cec5SDimitry Andric const _RealType _Rp = _URNG::max() - _URNG::min() + _RealType(1); 3649*0b57cec5SDimitry Andric _RealType __base = _Rp; 3650*0b57cec5SDimitry Andric _RealType _Sp = __g() - _URNG::min(); 3651*0b57cec5SDimitry Andric for (size_t __i = 1; __i < __k; ++__i, __base *= _Rp) 3652*0b57cec5SDimitry Andric _Sp += (__g() - _URNG::min()) * __base; 3653*0b57cec5SDimitry Andric return _Sp / __base; 3654*0b57cec5SDimitry Andric} 3655*0b57cec5SDimitry Andric 3656*0b57cec5SDimitry Andric// uniform_int_distribution 3657*0b57cec5SDimitry Andric 3658*0b57cec5SDimitry Andric// in <algorithm> 3659*0b57cec5SDimitry Andric 3660*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _IT> 3661*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 3662*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 3663*0b57cec5SDimitry Andric const uniform_int_distribution<_IT>& __x) 3664*0b57cec5SDimitry Andric{ 3665*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__os); 3666*0b57cec5SDimitry Andric __os.flags(ios_base::dec | ios_base::left); 3667*0b57cec5SDimitry Andric _CharT __sp = __os.widen(' '); 3668*0b57cec5SDimitry Andric __os.fill(__sp); 3669*0b57cec5SDimitry Andric return __os << __x.a() << __sp << __x.b(); 3670*0b57cec5SDimitry Andric} 3671*0b57cec5SDimitry Andric 3672*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _IT> 3673*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 3674*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 3675*0b57cec5SDimitry Andric uniform_int_distribution<_IT>& __x) 3676*0b57cec5SDimitry Andric{ 3677*0b57cec5SDimitry Andric typedef uniform_int_distribution<_IT> _Eng; 3678*0b57cec5SDimitry Andric typedef typename _Eng::result_type result_type; 3679*0b57cec5SDimitry Andric typedef typename _Eng::param_type param_type; 3680*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__is); 3681*0b57cec5SDimitry Andric __is.flags(ios_base::dec | ios_base::skipws); 3682*0b57cec5SDimitry Andric result_type __a; 3683*0b57cec5SDimitry Andric result_type __b; 3684*0b57cec5SDimitry Andric __is >> __a >> __b; 3685*0b57cec5SDimitry Andric if (!__is.fail()) 3686*0b57cec5SDimitry Andric __x.param(param_type(__a, __b)); 3687*0b57cec5SDimitry Andric return __is; 3688*0b57cec5SDimitry Andric} 3689*0b57cec5SDimitry Andric 3690*0b57cec5SDimitry Andric// uniform_real_distribution 3691*0b57cec5SDimitry Andric 3692*0b57cec5SDimitry Andrictemplate<class _RealType = double> 3693*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS uniform_real_distribution 3694*0b57cec5SDimitry Andric{ 3695*0b57cec5SDimitry Andricpublic: 3696*0b57cec5SDimitry Andric // types 3697*0b57cec5SDimitry Andric typedef _RealType result_type; 3698*0b57cec5SDimitry Andric 3699*0b57cec5SDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 3700*0b57cec5SDimitry Andric { 3701*0b57cec5SDimitry Andric result_type __a_; 3702*0b57cec5SDimitry Andric result_type __b_; 3703*0b57cec5SDimitry Andric public: 3704*0b57cec5SDimitry Andric typedef uniform_real_distribution distribution_type; 3705*0b57cec5SDimitry Andric 3706*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3707*0b57cec5SDimitry Andric explicit param_type(result_type __a = 0, 3708*0b57cec5SDimitry Andric result_type __b = 1) 3709*0b57cec5SDimitry Andric : __a_(__a), __b_(__b) {} 3710*0b57cec5SDimitry Andric 3711*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3712*0b57cec5SDimitry Andric result_type a() const {return __a_;} 3713*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3714*0b57cec5SDimitry Andric result_type b() const {return __b_;} 3715*0b57cec5SDimitry Andric 3716*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 3717*0b57cec5SDimitry Andric bool operator==(const param_type& __x, const param_type& __y) 3718*0b57cec5SDimitry Andric {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} 3719*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 3720*0b57cec5SDimitry Andric bool operator!=(const param_type& __x, const param_type& __y) 3721*0b57cec5SDimitry Andric {return !(__x == __y);} 3722*0b57cec5SDimitry Andric }; 3723*0b57cec5SDimitry Andric 3724*0b57cec5SDimitry Andricprivate: 3725*0b57cec5SDimitry Andric param_type __p_; 3726*0b57cec5SDimitry Andric 3727*0b57cec5SDimitry Andricpublic: 3728*0b57cec5SDimitry Andric // constructors and reset functions 3729*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3730*0b57cec5SDimitry Andric explicit uniform_real_distribution(result_type __a = 0, result_type __b = 1) 3731*0b57cec5SDimitry Andric : __p_(param_type(__a, __b)) {} 3732*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3733*0b57cec5SDimitry Andric explicit uniform_real_distribution(const param_type& __p) : __p_(__p) {} 3734*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3735*0b57cec5SDimitry Andric void reset() {} 3736*0b57cec5SDimitry Andric 3737*0b57cec5SDimitry Andric // generating functions 3738*0b57cec5SDimitry Andric template<class _URNG> 3739*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3740*0b57cec5SDimitry Andric result_type operator()(_URNG& __g) 3741*0b57cec5SDimitry Andric {return (*this)(__g, __p_);} 3742*0b57cec5SDimitry Andric template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p); 3743*0b57cec5SDimitry Andric 3744*0b57cec5SDimitry Andric // property functions 3745*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3746*0b57cec5SDimitry Andric result_type a() const {return __p_.a();} 3747*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3748*0b57cec5SDimitry Andric result_type b() const {return __p_.b();} 3749*0b57cec5SDimitry Andric 3750*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3751*0b57cec5SDimitry Andric param_type param() const {return __p_;} 3752*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3753*0b57cec5SDimitry Andric void param(const param_type& __p) {__p_ = __p;} 3754*0b57cec5SDimitry Andric 3755*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3756*0b57cec5SDimitry Andric result_type min() const {return a();} 3757*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3758*0b57cec5SDimitry Andric result_type max() const {return b();} 3759*0b57cec5SDimitry Andric 3760*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 3761*0b57cec5SDimitry Andric bool operator==(const uniform_real_distribution& __x, 3762*0b57cec5SDimitry Andric const uniform_real_distribution& __y) 3763*0b57cec5SDimitry Andric {return __x.__p_ == __y.__p_;} 3764*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 3765*0b57cec5SDimitry Andric bool operator!=(const uniform_real_distribution& __x, 3766*0b57cec5SDimitry Andric const uniform_real_distribution& __y) 3767*0b57cec5SDimitry Andric {return !(__x == __y);} 3768*0b57cec5SDimitry Andric}; 3769*0b57cec5SDimitry Andric 3770*0b57cec5SDimitry Andrictemplate<class _RealType> 3771*0b57cec5SDimitry Andrictemplate<class _URNG> 3772*0b57cec5SDimitry Andricinline 3773*0b57cec5SDimitry Andrictypename uniform_real_distribution<_RealType>::result_type 3774*0b57cec5SDimitry Andricuniform_real_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 3775*0b57cec5SDimitry Andric{ 3776*0b57cec5SDimitry Andric return (__p.b() - __p.a()) 3777*0b57cec5SDimitry Andric * _VSTD::generate_canonical<_RealType, numeric_limits<_RealType>::digits>(__g) 3778*0b57cec5SDimitry Andric + __p.a(); 3779*0b57cec5SDimitry Andric} 3780*0b57cec5SDimitry Andric 3781*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _RT> 3782*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 3783*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 3784*0b57cec5SDimitry Andric const uniform_real_distribution<_RT>& __x) 3785*0b57cec5SDimitry Andric{ 3786*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__os); 3787*0b57cec5SDimitry Andric __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 3788*0b57cec5SDimitry Andric ios_base::scientific); 3789*0b57cec5SDimitry Andric _CharT __sp = __os.widen(' '); 3790*0b57cec5SDimitry Andric __os.fill(__sp); 3791*0b57cec5SDimitry Andric return __os << __x.a() << __sp << __x.b(); 3792*0b57cec5SDimitry Andric} 3793*0b57cec5SDimitry Andric 3794*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _RT> 3795*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 3796*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 3797*0b57cec5SDimitry Andric uniform_real_distribution<_RT>& __x) 3798*0b57cec5SDimitry Andric{ 3799*0b57cec5SDimitry Andric typedef uniform_real_distribution<_RT> _Eng; 3800*0b57cec5SDimitry Andric typedef typename _Eng::result_type result_type; 3801*0b57cec5SDimitry Andric typedef typename _Eng::param_type param_type; 3802*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__is); 3803*0b57cec5SDimitry Andric __is.flags(ios_base::dec | ios_base::skipws); 3804*0b57cec5SDimitry Andric result_type __a; 3805*0b57cec5SDimitry Andric result_type __b; 3806*0b57cec5SDimitry Andric __is >> __a >> __b; 3807*0b57cec5SDimitry Andric if (!__is.fail()) 3808*0b57cec5SDimitry Andric __x.param(param_type(__a, __b)); 3809*0b57cec5SDimitry Andric return __is; 3810*0b57cec5SDimitry Andric} 3811*0b57cec5SDimitry Andric 3812*0b57cec5SDimitry Andric// bernoulli_distribution 3813*0b57cec5SDimitry Andric 3814*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS bernoulli_distribution 3815*0b57cec5SDimitry Andric{ 3816*0b57cec5SDimitry Andricpublic: 3817*0b57cec5SDimitry Andric // types 3818*0b57cec5SDimitry Andric typedef bool result_type; 3819*0b57cec5SDimitry Andric 3820*0b57cec5SDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 3821*0b57cec5SDimitry Andric { 3822*0b57cec5SDimitry Andric double __p_; 3823*0b57cec5SDimitry Andric public: 3824*0b57cec5SDimitry Andric typedef bernoulli_distribution distribution_type; 3825*0b57cec5SDimitry Andric 3826*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3827*0b57cec5SDimitry Andric explicit param_type(double __p = 0.5) : __p_(__p) {} 3828*0b57cec5SDimitry Andric 3829*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3830*0b57cec5SDimitry Andric double p() const {return __p_;} 3831*0b57cec5SDimitry Andric 3832*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 3833*0b57cec5SDimitry Andric bool operator==(const param_type& __x, const param_type& __y) 3834*0b57cec5SDimitry Andric {return __x.__p_ == __y.__p_;} 3835*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 3836*0b57cec5SDimitry Andric bool operator!=(const param_type& __x, const param_type& __y) 3837*0b57cec5SDimitry Andric {return !(__x == __y);} 3838*0b57cec5SDimitry Andric }; 3839*0b57cec5SDimitry Andric 3840*0b57cec5SDimitry Andricprivate: 3841*0b57cec5SDimitry Andric param_type __p_; 3842*0b57cec5SDimitry Andric 3843*0b57cec5SDimitry Andricpublic: 3844*0b57cec5SDimitry Andric // constructors and reset functions 3845*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3846*0b57cec5SDimitry Andric explicit bernoulli_distribution(double __p = 0.5) 3847*0b57cec5SDimitry Andric : __p_(param_type(__p)) {} 3848*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3849*0b57cec5SDimitry Andric explicit bernoulli_distribution(const param_type& __p) : __p_(__p) {} 3850*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3851*0b57cec5SDimitry Andric void reset() {} 3852*0b57cec5SDimitry Andric 3853*0b57cec5SDimitry Andric // generating functions 3854*0b57cec5SDimitry Andric template<class _URNG> 3855*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3856*0b57cec5SDimitry Andric result_type operator()(_URNG& __g) 3857*0b57cec5SDimitry Andric {return (*this)(__g, __p_);} 3858*0b57cec5SDimitry Andric template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p); 3859*0b57cec5SDimitry Andric 3860*0b57cec5SDimitry Andric // property functions 3861*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3862*0b57cec5SDimitry Andric double p() const {return __p_.p();} 3863*0b57cec5SDimitry Andric 3864*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3865*0b57cec5SDimitry Andric param_type param() const {return __p_;} 3866*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3867*0b57cec5SDimitry Andric void param(const param_type& __p) {__p_ = __p;} 3868*0b57cec5SDimitry Andric 3869*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3870*0b57cec5SDimitry Andric result_type min() const {return false;} 3871*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3872*0b57cec5SDimitry Andric result_type max() const {return true;} 3873*0b57cec5SDimitry Andric 3874*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 3875*0b57cec5SDimitry Andric bool operator==(const bernoulli_distribution& __x, 3876*0b57cec5SDimitry Andric const bernoulli_distribution& __y) 3877*0b57cec5SDimitry Andric {return __x.__p_ == __y.__p_;} 3878*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 3879*0b57cec5SDimitry Andric bool operator!=(const bernoulli_distribution& __x, 3880*0b57cec5SDimitry Andric const bernoulli_distribution& __y) 3881*0b57cec5SDimitry Andric {return !(__x == __y);} 3882*0b57cec5SDimitry Andric}; 3883*0b57cec5SDimitry Andric 3884*0b57cec5SDimitry Andrictemplate<class _URNG> 3885*0b57cec5SDimitry Andricinline 3886*0b57cec5SDimitry Andricbernoulli_distribution::result_type 3887*0b57cec5SDimitry Andricbernoulli_distribution::operator()(_URNG& __g, const param_type& __p) 3888*0b57cec5SDimitry Andric{ 3889*0b57cec5SDimitry Andric uniform_real_distribution<double> __gen; 3890*0b57cec5SDimitry Andric return __gen(__g) < __p.p(); 3891*0b57cec5SDimitry Andric} 3892*0b57cec5SDimitry Andric 3893*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 3894*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 3895*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, const bernoulli_distribution& __x) 3896*0b57cec5SDimitry Andric{ 3897*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__os); 3898*0b57cec5SDimitry Andric __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 3899*0b57cec5SDimitry Andric ios_base::scientific); 3900*0b57cec5SDimitry Andric _CharT __sp = __os.widen(' '); 3901*0b57cec5SDimitry Andric __os.fill(__sp); 3902*0b57cec5SDimitry Andric return __os << __x.p(); 3903*0b57cec5SDimitry Andric} 3904*0b57cec5SDimitry Andric 3905*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 3906*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 3907*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, bernoulli_distribution& __x) 3908*0b57cec5SDimitry Andric{ 3909*0b57cec5SDimitry Andric typedef bernoulli_distribution _Eng; 3910*0b57cec5SDimitry Andric typedef typename _Eng::param_type param_type; 3911*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__is); 3912*0b57cec5SDimitry Andric __is.flags(ios_base::dec | ios_base::skipws); 3913*0b57cec5SDimitry Andric double __p; 3914*0b57cec5SDimitry Andric __is >> __p; 3915*0b57cec5SDimitry Andric if (!__is.fail()) 3916*0b57cec5SDimitry Andric __x.param(param_type(__p)); 3917*0b57cec5SDimitry Andric return __is; 3918*0b57cec5SDimitry Andric} 3919*0b57cec5SDimitry Andric 3920*0b57cec5SDimitry Andric// binomial_distribution 3921*0b57cec5SDimitry Andric 3922*0b57cec5SDimitry Andrictemplate<class _IntType = int> 3923*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS binomial_distribution 3924*0b57cec5SDimitry Andric{ 3925*0b57cec5SDimitry Andricpublic: 3926*0b57cec5SDimitry Andric // types 3927*0b57cec5SDimitry Andric typedef _IntType result_type; 3928*0b57cec5SDimitry Andric 3929*0b57cec5SDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 3930*0b57cec5SDimitry Andric { 3931*0b57cec5SDimitry Andric result_type __t_; 3932*0b57cec5SDimitry Andric double __p_; 3933*0b57cec5SDimitry Andric double __pr_; 3934*0b57cec5SDimitry Andric double __odds_ratio_; 3935*0b57cec5SDimitry Andric result_type __r0_; 3936*0b57cec5SDimitry Andric public: 3937*0b57cec5SDimitry Andric typedef binomial_distribution distribution_type; 3938*0b57cec5SDimitry Andric 3939*0b57cec5SDimitry Andric explicit param_type(result_type __t = 1, double __p = 0.5); 3940*0b57cec5SDimitry Andric 3941*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3942*0b57cec5SDimitry Andric result_type t() const {return __t_;} 3943*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3944*0b57cec5SDimitry Andric double p() const {return __p_;} 3945*0b57cec5SDimitry Andric 3946*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 3947*0b57cec5SDimitry Andric bool operator==(const param_type& __x, const param_type& __y) 3948*0b57cec5SDimitry Andric {return __x.__t_ == __y.__t_ && __x.__p_ == __y.__p_;} 3949*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 3950*0b57cec5SDimitry Andric bool operator!=(const param_type& __x, const param_type& __y) 3951*0b57cec5SDimitry Andric {return !(__x == __y);} 3952*0b57cec5SDimitry Andric 3953*0b57cec5SDimitry Andric friend class binomial_distribution; 3954*0b57cec5SDimitry Andric }; 3955*0b57cec5SDimitry Andric 3956*0b57cec5SDimitry Andricprivate: 3957*0b57cec5SDimitry Andric param_type __p_; 3958*0b57cec5SDimitry Andric 3959*0b57cec5SDimitry Andricpublic: 3960*0b57cec5SDimitry Andric // constructors and reset functions 3961*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3962*0b57cec5SDimitry Andric explicit binomial_distribution(result_type __t = 1, double __p = 0.5) 3963*0b57cec5SDimitry Andric : __p_(param_type(__t, __p)) {} 3964*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3965*0b57cec5SDimitry Andric explicit binomial_distribution(const param_type& __p) : __p_(__p) {} 3966*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3967*0b57cec5SDimitry Andric void reset() {} 3968*0b57cec5SDimitry Andric 3969*0b57cec5SDimitry Andric // generating functions 3970*0b57cec5SDimitry Andric template<class _URNG> 3971*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3972*0b57cec5SDimitry Andric result_type operator()(_URNG& __g) 3973*0b57cec5SDimitry Andric {return (*this)(__g, __p_);} 3974*0b57cec5SDimitry Andric template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 3975*0b57cec5SDimitry Andric 3976*0b57cec5SDimitry Andric // property functions 3977*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3978*0b57cec5SDimitry Andric result_type t() const {return __p_.t();} 3979*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3980*0b57cec5SDimitry Andric double p() const {return __p_.p();} 3981*0b57cec5SDimitry Andric 3982*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3983*0b57cec5SDimitry Andric param_type param() const {return __p_;} 3984*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3985*0b57cec5SDimitry Andric void param(const param_type& __p) {__p_ = __p;} 3986*0b57cec5SDimitry Andric 3987*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3988*0b57cec5SDimitry Andric result_type min() const {return 0;} 3989*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3990*0b57cec5SDimitry Andric result_type max() const {return t();} 3991*0b57cec5SDimitry Andric 3992*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 3993*0b57cec5SDimitry Andric bool operator==(const binomial_distribution& __x, 3994*0b57cec5SDimitry Andric const binomial_distribution& __y) 3995*0b57cec5SDimitry Andric {return __x.__p_ == __y.__p_;} 3996*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 3997*0b57cec5SDimitry Andric bool operator!=(const binomial_distribution& __x, 3998*0b57cec5SDimitry Andric const binomial_distribution& __y) 3999*0b57cec5SDimitry Andric {return !(__x == __y);} 4000*0b57cec5SDimitry Andric}; 4001*0b57cec5SDimitry Andric 4002*0b57cec5SDimitry Andric#ifndef _LIBCPP_MSVCRT 4003*0b57cec5SDimitry Andricextern "C" double lgamma_r(double, int *); 4004*0b57cec5SDimitry Andric#endif 4005*0b57cec5SDimitry Andric 4006*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY double __libcpp_lgamma(double __d) { 4007*0b57cec5SDimitry Andric#if defined(_LIBCPP_MSVCRT) 4008*0b57cec5SDimitry Andric return lgamma(__d); 4009*0b57cec5SDimitry Andric#else 4010*0b57cec5SDimitry Andric int __sign; 4011*0b57cec5SDimitry Andric return lgamma_r(__d, &__sign); 4012*0b57cec5SDimitry Andric#endif 4013*0b57cec5SDimitry Andric} 4014*0b57cec5SDimitry Andric 4015*0b57cec5SDimitry Andrictemplate<class _IntType> 4016*0b57cec5SDimitry Andricbinomial_distribution<_IntType>::param_type::param_type(const result_type __t, const double __p) 4017*0b57cec5SDimitry Andric : __t_(__t), __p_(__p) 4018*0b57cec5SDimitry Andric{ 4019*0b57cec5SDimitry Andric if (0 < __p_ && __p_ < 1) 4020*0b57cec5SDimitry Andric { 4021*0b57cec5SDimitry Andric __r0_ = static_cast<result_type>((__t_ + 1) * __p_); 4022*0b57cec5SDimitry Andric __pr_ = _VSTD::exp(__libcpp_lgamma(__t_ + 1.) - 4023*0b57cec5SDimitry Andric __libcpp_lgamma(__r0_ + 1.) - 4024*0b57cec5SDimitry Andric __libcpp_lgamma(__t_ - __r0_ + 1.) + __r0_ * _VSTD::log(__p_) + 4025*0b57cec5SDimitry Andric (__t_ - __r0_) * _VSTD::log(1 - __p_)); 4026*0b57cec5SDimitry Andric __odds_ratio_ = __p_ / (1 - __p_); 4027*0b57cec5SDimitry Andric } 4028*0b57cec5SDimitry Andric} 4029*0b57cec5SDimitry Andric 4030*0b57cec5SDimitry Andric// Reference: Kemp, C.D. (1986). `A modal method for generating binomial 4031*0b57cec5SDimitry Andric// variables', Commun. Statist. - Theor. Meth. 15(3), 805-813. 4032*0b57cec5SDimitry Andrictemplate<class _IntType> 4033*0b57cec5SDimitry Andrictemplate<class _URNG> 4034*0b57cec5SDimitry Andric_IntType 4035*0b57cec5SDimitry Andricbinomial_distribution<_IntType>::operator()(_URNG& __g, const param_type& __pr) 4036*0b57cec5SDimitry Andric{ 4037*0b57cec5SDimitry Andric if (__pr.__t_ == 0 || __pr.__p_ == 0) 4038*0b57cec5SDimitry Andric return 0; 4039*0b57cec5SDimitry Andric if (__pr.__p_ == 1) 4040*0b57cec5SDimitry Andric return __pr.__t_; 4041*0b57cec5SDimitry Andric uniform_real_distribution<double> __gen; 4042*0b57cec5SDimitry Andric double __u = __gen(__g) - __pr.__pr_; 4043*0b57cec5SDimitry Andric if (__u < 0) 4044*0b57cec5SDimitry Andric return __pr.__r0_; 4045*0b57cec5SDimitry Andric double __pu = __pr.__pr_; 4046*0b57cec5SDimitry Andric double __pd = __pu; 4047*0b57cec5SDimitry Andric result_type __ru = __pr.__r0_; 4048*0b57cec5SDimitry Andric result_type __rd = __ru; 4049*0b57cec5SDimitry Andric while (true) 4050*0b57cec5SDimitry Andric { 4051*0b57cec5SDimitry Andric if (__rd >= 1) 4052*0b57cec5SDimitry Andric { 4053*0b57cec5SDimitry Andric __pd *= __rd / (__pr.__odds_ratio_ * (__pr.__t_ - __rd + 1)); 4054*0b57cec5SDimitry Andric __u -= __pd; 4055*0b57cec5SDimitry Andric if (__u < 0) 4056*0b57cec5SDimitry Andric return __rd - 1; 4057*0b57cec5SDimitry Andric } 4058*0b57cec5SDimitry Andric if ( __rd != 0 ) 4059*0b57cec5SDimitry Andric --__rd; 4060*0b57cec5SDimitry Andric ++__ru; 4061*0b57cec5SDimitry Andric if (__ru <= __pr.__t_) 4062*0b57cec5SDimitry Andric { 4063*0b57cec5SDimitry Andric __pu *= (__pr.__t_ - __ru + 1) * __pr.__odds_ratio_ / __ru; 4064*0b57cec5SDimitry Andric __u -= __pu; 4065*0b57cec5SDimitry Andric if (__u < 0) 4066*0b57cec5SDimitry Andric return __ru; 4067*0b57cec5SDimitry Andric } 4068*0b57cec5SDimitry Andric } 4069*0b57cec5SDimitry Andric} 4070*0b57cec5SDimitry Andric 4071*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _IntType> 4072*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 4073*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 4074*0b57cec5SDimitry Andric const binomial_distribution<_IntType>& __x) 4075*0b57cec5SDimitry Andric{ 4076*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__os); 4077*0b57cec5SDimitry Andric __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 4078*0b57cec5SDimitry Andric ios_base::scientific); 4079*0b57cec5SDimitry Andric _CharT __sp = __os.widen(' '); 4080*0b57cec5SDimitry Andric __os.fill(__sp); 4081*0b57cec5SDimitry Andric return __os << __x.t() << __sp << __x.p(); 4082*0b57cec5SDimitry Andric} 4083*0b57cec5SDimitry Andric 4084*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _IntType> 4085*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 4086*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 4087*0b57cec5SDimitry Andric binomial_distribution<_IntType>& __x) 4088*0b57cec5SDimitry Andric{ 4089*0b57cec5SDimitry Andric typedef binomial_distribution<_IntType> _Eng; 4090*0b57cec5SDimitry Andric typedef typename _Eng::result_type result_type; 4091*0b57cec5SDimitry Andric typedef typename _Eng::param_type param_type; 4092*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__is); 4093*0b57cec5SDimitry Andric __is.flags(ios_base::dec | ios_base::skipws); 4094*0b57cec5SDimitry Andric result_type __t; 4095*0b57cec5SDimitry Andric double __p; 4096*0b57cec5SDimitry Andric __is >> __t >> __p; 4097*0b57cec5SDimitry Andric if (!__is.fail()) 4098*0b57cec5SDimitry Andric __x.param(param_type(__t, __p)); 4099*0b57cec5SDimitry Andric return __is; 4100*0b57cec5SDimitry Andric} 4101*0b57cec5SDimitry Andric 4102*0b57cec5SDimitry Andric// exponential_distribution 4103*0b57cec5SDimitry Andric 4104*0b57cec5SDimitry Andrictemplate<class _RealType = double> 4105*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS exponential_distribution 4106*0b57cec5SDimitry Andric{ 4107*0b57cec5SDimitry Andricpublic: 4108*0b57cec5SDimitry Andric // types 4109*0b57cec5SDimitry Andric typedef _RealType result_type; 4110*0b57cec5SDimitry Andric 4111*0b57cec5SDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 4112*0b57cec5SDimitry Andric { 4113*0b57cec5SDimitry Andric result_type __lambda_; 4114*0b57cec5SDimitry Andric public: 4115*0b57cec5SDimitry Andric typedef exponential_distribution distribution_type; 4116*0b57cec5SDimitry Andric 4117*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4118*0b57cec5SDimitry Andric explicit param_type(result_type __lambda = 1) : __lambda_(__lambda) {} 4119*0b57cec5SDimitry Andric 4120*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4121*0b57cec5SDimitry Andric result_type lambda() const {return __lambda_;} 4122*0b57cec5SDimitry Andric 4123*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 4124*0b57cec5SDimitry Andric bool operator==(const param_type& __x, const param_type& __y) 4125*0b57cec5SDimitry Andric {return __x.__lambda_ == __y.__lambda_;} 4126*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 4127*0b57cec5SDimitry Andric bool operator!=(const param_type& __x, const param_type& __y) 4128*0b57cec5SDimitry Andric {return !(__x == __y);} 4129*0b57cec5SDimitry Andric }; 4130*0b57cec5SDimitry Andric 4131*0b57cec5SDimitry Andricprivate: 4132*0b57cec5SDimitry Andric param_type __p_; 4133*0b57cec5SDimitry Andric 4134*0b57cec5SDimitry Andricpublic: 4135*0b57cec5SDimitry Andric // constructors and reset functions 4136*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4137*0b57cec5SDimitry Andric explicit exponential_distribution(result_type __lambda = 1) 4138*0b57cec5SDimitry Andric : __p_(param_type(__lambda)) {} 4139*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4140*0b57cec5SDimitry Andric explicit exponential_distribution(const param_type& __p) : __p_(__p) {} 4141*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4142*0b57cec5SDimitry Andric void reset() {} 4143*0b57cec5SDimitry Andric 4144*0b57cec5SDimitry Andric // generating functions 4145*0b57cec5SDimitry Andric template<class _URNG> 4146*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4147*0b57cec5SDimitry Andric result_type operator()(_URNG& __g) 4148*0b57cec5SDimitry Andric {return (*this)(__g, __p_);} 4149*0b57cec5SDimitry Andric template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 4150*0b57cec5SDimitry Andric 4151*0b57cec5SDimitry Andric // property functions 4152*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4153*0b57cec5SDimitry Andric result_type lambda() const {return __p_.lambda();} 4154*0b57cec5SDimitry Andric 4155*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4156*0b57cec5SDimitry Andric param_type param() const {return __p_;} 4157*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4158*0b57cec5SDimitry Andric void param(const param_type& __p) {__p_ = __p;} 4159*0b57cec5SDimitry Andric 4160*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4161*0b57cec5SDimitry Andric result_type min() const {return 0;} 4162*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4163*0b57cec5SDimitry Andric result_type max() const {return numeric_limits<result_type>::infinity();} 4164*0b57cec5SDimitry Andric 4165*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 4166*0b57cec5SDimitry Andric bool operator==(const exponential_distribution& __x, 4167*0b57cec5SDimitry Andric const exponential_distribution& __y) 4168*0b57cec5SDimitry Andric {return __x.__p_ == __y.__p_;} 4169*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 4170*0b57cec5SDimitry Andric bool operator!=(const exponential_distribution& __x, 4171*0b57cec5SDimitry Andric const exponential_distribution& __y) 4172*0b57cec5SDimitry Andric {return !(__x == __y);} 4173*0b57cec5SDimitry Andric}; 4174*0b57cec5SDimitry Andric 4175*0b57cec5SDimitry Andrictemplate <class _RealType> 4176*0b57cec5SDimitry Andrictemplate<class _URNG> 4177*0b57cec5SDimitry Andric_RealType 4178*0b57cec5SDimitry Andricexponential_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 4179*0b57cec5SDimitry Andric{ 4180*0b57cec5SDimitry Andric return -_VSTD::log 4181*0b57cec5SDimitry Andric ( 4182*0b57cec5SDimitry Andric result_type(1) - 4183*0b57cec5SDimitry Andric _VSTD::generate_canonical<result_type, 4184*0b57cec5SDimitry Andric numeric_limits<result_type>::digits>(__g) 4185*0b57cec5SDimitry Andric ) 4186*0b57cec5SDimitry Andric / __p.lambda(); 4187*0b57cec5SDimitry Andric} 4188*0b57cec5SDimitry Andric 4189*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _RealType> 4190*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 4191*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 4192*0b57cec5SDimitry Andric const exponential_distribution<_RealType>& __x) 4193*0b57cec5SDimitry Andric{ 4194*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__os); 4195*0b57cec5SDimitry Andric __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 4196*0b57cec5SDimitry Andric ios_base::scientific); 4197*0b57cec5SDimitry Andric return __os << __x.lambda(); 4198*0b57cec5SDimitry Andric} 4199*0b57cec5SDimitry Andric 4200*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _RealType> 4201*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 4202*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 4203*0b57cec5SDimitry Andric exponential_distribution<_RealType>& __x) 4204*0b57cec5SDimitry Andric{ 4205*0b57cec5SDimitry Andric typedef exponential_distribution<_RealType> _Eng; 4206*0b57cec5SDimitry Andric typedef typename _Eng::result_type result_type; 4207*0b57cec5SDimitry Andric typedef typename _Eng::param_type param_type; 4208*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__is); 4209*0b57cec5SDimitry Andric __is.flags(ios_base::dec | ios_base::skipws); 4210*0b57cec5SDimitry Andric result_type __lambda; 4211*0b57cec5SDimitry Andric __is >> __lambda; 4212*0b57cec5SDimitry Andric if (!__is.fail()) 4213*0b57cec5SDimitry Andric __x.param(param_type(__lambda)); 4214*0b57cec5SDimitry Andric return __is; 4215*0b57cec5SDimitry Andric} 4216*0b57cec5SDimitry Andric 4217*0b57cec5SDimitry Andric// normal_distribution 4218*0b57cec5SDimitry Andric 4219*0b57cec5SDimitry Andrictemplate<class _RealType = double> 4220*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS normal_distribution 4221*0b57cec5SDimitry Andric{ 4222*0b57cec5SDimitry Andricpublic: 4223*0b57cec5SDimitry Andric // types 4224*0b57cec5SDimitry Andric typedef _RealType result_type; 4225*0b57cec5SDimitry Andric 4226*0b57cec5SDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 4227*0b57cec5SDimitry Andric { 4228*0b57cec5SDimitry Andric result_type __mean_; 4229*0b57cec5SDimitry Andric result_type __stddev_; 4230*0b57cec5SDimitry Andric public: 4231*0b57cec5SDimitry Andric typedef normal_distribution distribution_type; 4232*0b57cec5SDimitry Andric 4233*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4234*0b57cec5SDimitry Andric explicit param_type(result_type __mean = 0, result_type __stddev = 1) 4235*0b57cec5SDimitry Andric : __mean_(__mean), __stddev_(__stddev) {} 4236*0b57cec5SDimitry Andric 4237*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4238*0b57cec5SDimitry Andric result_type mean() const {return __mean_;} 4239*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4240*0b57cec5SDimitry Andric result_type stddev() const {return __stddev_;} 4241*0b57cec5SDimitry Andric 4242*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 4243*0b57cec5SDimitry Andric bool operator==(const param_type& __x, const param_type& __y) 4244*0b57cec5SDimitry Andric {return __x.__mean_ == __y.__mean_ && __x.__stddev_ == __y.__stddev_;} 4245*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 4246*0b57cec5SDimitry Andric bool operator!=(const param_type& __x, const param_type& __y) 4247*0b57cec5SDimitry Andric {return !(__x == __y);} 4248*0b57cec5SDimitry Andric }; 4249*0b57cec5SDimitry Andric 4250*0b57cec5SDimitry Andricprivate: 4251*0b57cec5SDimitry Andric param_type __p_; 4252*0b57cec5SDimitry Andric result_type _V_; 4253*0b57cec5SDimitry Andric bool _V_hot_; 4254*0b57cec5SDimitry Andric 4255*0b57cec5SDimitry Andricpublic: 4256*0b57cec5SDimitry Andric // constructors and reset functions 4257*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4258*0b57cec5SDimitry Andric explicit normal_distribution(result_type __mean = 0, result_type __stddev = 1) 4259*0b57cec5SDimitry Andric : __p_(param_type(__mean, __stddev)), _V_hot_(false) {} 4260*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4261*0b57cec5SDimitry Andric explicit normal_distribution(const param_type& __p) 4262*0b57cec5SDimitry Andric : __p_(__p), _V_hot_(false) {} 4263*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4264*0b57cec5SDimitry Andric void reset() {_V_hot_ = false;} 4265*0b57cec5SDimitry Andric 4266*0b57cec5SDimitry Andric // generating functions 4267*0b57cec5SDimitry Andric template<class _URNG> 4268*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4269*0b57cec5SDimitry Andric result_type operator()(_URNG& __g) 4270*0b57cec5SDimitry Andric {return (*this)(__g, __p_);} 4271*0b57cec5SDimitry Andric template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 4272*0b57cec5SDimitry Andric 4273*0b57cec5SDimitry Andric // property functions 4274*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4275*0b57cec5SDimitry Andric result_type mean() const {return __p_.mean();} 4276*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4277*0b57cec5SDimitry Andric result_type stddev() const {return __p_.stddev();} 4278*0b57cec5SDimitry Andric 4279*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4280*0b57cec5SDimitry Andric param_type param() const {return __p_;} 4281*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4282*0b57cec5SDimitry Andric void param(const param_type& __p) {__p_ = __p;} 4283*0b57cec5SDimitry Andric 4284*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4285*0b57cec5SDimitry Andric result_type min() const {return -numeric_limits<result_type>::infinity();} 4286*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4287*0b57cec5SDimitry Andric result_type max() const {return numeric_limits<result_type>::infinity();} 4288*0b57cec5SDimitry Andric 4289*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 4290*0b57cec5SDimitry Andric bool operator==(const normal_distribution& __x, 4291*0b57cec5SDimitry Andric const normal_distribution& __y) 4292*0b57cec5SDimitry Andric {return __x.__p_ == __y.__p_ && __x._V_hot_ == __y._V_hot_ && 4293*0b57cec5SDimitry Andric (!__x._V_hot_ || __x._V_ == __y._V_);} 4294*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 4295*0b57cec5SDimitry Andric bool operator!=(const normal_distribution& __x, 4296*0b57cec5SDimitry Andric const normal_distribution& __y) 4297*0b57cec5SDimitry Andric {return !(__x == __y);} 4298*0b57cec5SDimitry Andric 4299*0b57cec5SDimitry Andric template <class _CharT, class _Traits, class _RT> 4300*0b57cec5SDimitry Andric friend 4301*0b57cec5SDimitry Andric basic_ostream<_CharT, _Traits>& 4302*0b57cec5SDimitry Andric operator<<(basic_ostream<_CharT, _Traits>& __os, 4303*0b57cec5SDimitry Andric const normal_distribution<_RT>& __x); 4304*0b57cec5SDimitry Andric 4305*0b57cec5SDimitry Andric template <class _CharT, class _Traits, class _RT> 4306*0b57cec5SDimitry Andric friend 4307*0b57cec5SDimitry Andric basic_istream<_CharT, _Traits>& 4308*0b57cec5SDimitry Andric operator>>(basic_istream<_CharT, _Traits>& __is, 4309*0b57cec5SDimitry Andric normal_distribution<_RT>& __x); 4310*0b57cec5SDimitry Andric}; 4311*0b57cec5SDimitry Andric 4312*0b57cec5SDimitry Andrictemplate <class _RealType> 4313*0b57cec5SDimitry Andrictemplate<class _URNG> 4314*0b57cec5SDimitry Andric_RealType 4315*0b57cec5SDimitry Andricnormal_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 4316*0b57cec5SDimitry Andric{ 4317*0b57cec5SDimitry Andric result_type _Up; 4318*0b57cec5SDimitry Andric if (_V_hot_) 4319*0b57cec5SDimitry Andric { 4320*0b57cec5SDimitry Andric _V_hot_ = false; 4321*0b57cec5SDimitry Andric _Up = _V_; 4322*0b57cec5SDimitry Andric } 4323*0b57cec5SDimitry Andric else 4324*0b57cec5SDimitry Andric { 4325*0b57cec5SDimitry Andric uniform_real_distribution<result_type> _Uni(-1, 1); 4326*0b57cec5SDimitry Andric result_type __u; 4327*0b57cec5SDimitry Andric result_type __v; 4328*0b57cec5SDimitry Andric result_type __s; 4329*0b57cec5SDimitry Andric do 4330*0b57cec5SDimitry Andric { 4331*0b57cec5SDimitry Andric __u = _Uni(__g); 4332*0b57cec5SDimitry Andric __v = _Uni(__g); 4333*0b57cec5SDimitry Andric __s = __u * __u + __v * __v; 4334*0b57cec5SDimitry Andric } while (__s > 1 || __s == 0); 4335*0b57cec5SDimitry Andric result_type _Fp = _VSTD::sqrt(-2 * _VSTD::log(__s) / __s); 4336*0b57cec5SDimitry Andric _V_ = __v * _Fp; 4337*0b57cec5SDimitry Andric _V_hot_ = true; 4338*0b57cec5SDimitry Andric _Up = __u * _Fp; 4339*0b57cec5SDimitry Andric } 4340*0b57cec5SDimitry Andric return _Up * __p.stddev() + __p.mean(); 4341*0b57cec5SDimitry Andric} 4342*0b57cec5SDimitry Andric 4343*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _RT> 4344*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 4345*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 4346*0b57cec5SDimitry Andric const normal_distribution<_RT>& __x) 4347*0b57cec5SDimitry Andric{ 4348*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__os); 4349*0b57cec5SDimitry Andric __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 4350*0b57cec5SDimitry Andric ios_base::scientific); 4351*0b57cec5SDimitry Andric _CharT __sp = __os.widen(' '); 4352*0b57cec5SDimitry Andric __os.fill(__sp); 4353*0b57cec5SDimitry Andric __os << __x.mean() << __sp << __x.stddev() << __sp << __x._V_hot_; 4354*0b57cec5SDimitry Andric if (__x._V_hot_) 4355*0b57cec5SDimitry Andric __os << __sp << __x._V_; 4356*0b57cec5SDimitry Andric return __os; 4357*0b57cec5SDimitry Andric} 4358*0b57cec5SDimitry Andric 4359*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _RT> 4360*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 4361*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 4362*0b57cec5SDimitry Andric normal_distribution<_RT>& __x) 4363*0b57cec5SDimitry Andric{ 4364*0b57cec5SDimitry Andric typedef normal_distribution<_RT> _Eng; 4365*0b57cec5SDimitry Andric typedef typename _Eng::result_type result_type; 4366*0b57cec5SDimitry Andric typedef typename _Eng::param_type param_type; 4367*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__is); 4368*0b57cec5SDimitry Andric __is.flags(ios_base::dec | ios_base::skipws); 4369*0b57cec5SDimitry Andric result_type __mean; 4370*0b57cec5SDimitry Andric result_type __stddev; 4371*0b57cec5SDimitry Andric result_type _Vp = 0; 4372*0b57cec5SDimitry Andric bool _V_hot = false; 4373*0b57cec5SDimitry Andric __is >> __mean >> __stddev >> _V_hot; 4374*0b57cec5SDimitry Andric if (_V_hot) 4375*0b57cec5SDimitry Andric __is >> _Vp; 4376*0b57cec5SDimitry Andric if (!__is.fail()) 4377*0b57cec5SDimitry Andric { 4378*0b57cec5SDimitry Andric __x.param(param_type(__mean, __stddev)); 4379*0b57cec5SDimitry Andric __x._V_hot_ = _V_hot; 4380*0b57cec5SDimitry Andric __x._V_ = _Vp; 4381*0b57cec5SDimitry Andric } 4382*0b57cec5SDimitry Andric return __is; 4383*0b57cec5SDimitry Andric} 4384*0b57cec5SDimitry Andric 4385*0b57cec5SDimitry Andric// lognormal_distribution 4386*0b57cec5SDimitry Andric 4387*0b57cec5SDimitry Andrictemplate<class _RealType = double> 4388*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS lognormal_distribution 4389*0b57cec5SDimitry Andric{ 4390*0b57cec5SDimitry Andricpublic: 4391*0b57cec5SDimitry Andric // types 4392*0b57cec5SDimitry Andric typedef _RealType result_type; 4393*0b57cec5SDimitry Andric 4394*0b57cec5SDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 4395*0b57cec5SDimitry Andric { 4396*0b57cec5SDimitry Andric normal_distribution<result_type> __nd_; 4397*0b57cec5SDimitry Andric public: 4398*0b57cec5SDimitry Andric typedef lognormal_distribution distribution_type; 4399*0b57cec5SDimitry Andric 4400*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4401*0b57cec5SDimitry Andric explicit param_type(result_type __m = 0, result_type __s = 1) 4402*0b57cec5SDimitry Andric : __nd_(__m, __s) {} 4403*0b57cec5SDimitry Andric 4404*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4405*0b57cec5SDimitry Andric result_type m() const {return __nd_.mean();} 4406*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4407*0b57cec5SDimitry Andric result_type s() const {return __nd_.stddev();} 4408*0b57cec5SDimitry Andric 4409*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 4410*0b57cec5SDimitry Andric bool operator==(const param_type& __x, const param_type& __y) 4411*0b57cec5SDimitry Andric {return __x.__nd_ == __y.__nd_;} 4412*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 4413*0b57cec5SDimitry Andric bool operator!=(const param_type& __x, const param_type& __y) 4414*0b57cec5SDimitry Andric {return !(__x == __y);} 4415*0b57cec5SDimitry Andric friend class lognormal_distribution; 4416*0b57cec5SDimitry Andric 4417*0b57cec5SDimitry Andric template <class _CharT, class _Traits, class _RT> 4418*0b57cec5SDimitry Andric friend 4419*0b57cec5SDimitry Andric basic_ostream<_CharT, _Traits>& 4420*0b57cec5SDimitry Andric operator<<(basic_ostream<_CharT, _Traits>& __os, 4421*0b57cec5SDimitry Andric const lognormal_distribution<_RT>& __x); 4422*0b57cec5SDimitry Andric 4423*0b57cec5SDimitry Andric template <class _CharT, class _Traits, class _RT> 4424*0b57cec5SDimitry Andric friend 4425*0b57cec5SDimitry Andric basic_istream<_CharT, _Traits>& 4426*0b57cec5SDimitry Andric operator>>(basic_istream<_CharT, _Traits>& __is, 4427*0b57cec5SDimitry Andric lognormal_distribution<_RT>& __x); 4428*0b57cec5SDimitry Andric }; 4429*0b57cec5SDimitry Andric 4430*0b57cec5SDimitry Andricprivate: 4431*0b57cec5SDimitry Andric param_type __p_; 4432*0b57cec5SDimitry Andric 4433*0b57cec5SDimitry Andricpublic: 4434*0b57cec5SDimitry Andric // constructor and reset functions 4435*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4436*0b57cec5SDimitry Andric explicit lognormal_distribution(result_type __m = 0, result_type __s = 1) 4437*0b57cec5SDimitry Andric : __p_(param_type(__m, __s)) {} 4438*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4439*0b57cec5SDimitry Andric explicit lognormal_distribution(const param_type& __p) 4440*0b57cec5SDimitry Andric : __p_(__p) {} 4441*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4442*0b57cec5SDimitry Andric void reset() {__p_.__nd_.reset();} 4443*0b57cec5SDimitry Andric 4444*0b57cec5SDimitry Andric // generating functions 4445*0b57cec5SDimitry Andric template<class _URNG> 4446*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4447*0b57cec5SDimitry Andric result_type operator()(_URNG& __g) 4448*0b57cec5SDimitry Andric {return (*this)(__g, __p_);} 4449*0b57cec5SDimitry Andric template<class _URNG> 4450*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4451*0b57cec5SDimitry Andric result_type operator()(_URNG& __g, const param_type& __p) 4452*0b57cec5SDimitry Andric {return _VSTD::exp(const_cast<normal_distribution<result_type>&>(__p.__nd_)(__g));} 4453*0b57cec5SDimitry Andric 4454*0b57cec5SDimitry Andric // property functions 4455*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4456*0b57cec5SDimitry Andric result_type m() const {return __p_.m();} 4457*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4458*0b57cec5SDimitry Andric result_type s() const {return __p_.s();} 4459*0b57cec5SDimitry Andric 4460*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4461*0b57cec5SDimitry Andric param_type param() const {return __p_;} 4462*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4463*0b57cec5SDimitry Andric void param(const param_type& __p) {__p_ = __p;} 4464*0b57cec5SDimitry Andric 4465*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4466*0b57cec5SDimitry Andric result_type min() const {return 0;} 4467*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4468*0b57cec5SDimitry Andric result_type max() const {return numeric_limits<result_type>::infinity();} 4469*0b57cec5SDimitry Andric 4470*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 4471*0b57cec5SDimitry Andric bool operator==(const lognormal_distribution& __x, 4472*0b57cec5SDimitry Andric const lognormal_distribution& __y) 4473*0b57cec5SDimitry Andric {return __x.__p_ == __y.__p_;} 4474*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 4475*0b57cec5SDimitry Andric bool operator!=(const lognormal_distribution& __x, 4476*0b57cec5SDimitry Andric const lognormal_distribution& __y) 4477*0b57cec5SDimitry Andric {return !(__x == __y);} 4478*0b57cec5SDimitry Andric 4479*0b57cec5SDimitry Andric template <class _CharT, class _Traits, class _RT> 4480*0b57cec5SDimitry Andric friend 4481*0b57cec5SDimitry Andric basic_ostream<_CharT, _Traits>& 4482*0b57cec5SDimitry Andric operator<<(basic_ostream<_CharT, _Traits>& __os, 4483*0b57cec5SDimitry Andric const lognormal_distribution<_RT>& __x); 4484*0b57cec5SDimitry Andric 4485*0b57cec5SDimitry Andric template <class _CharT, class _Traits, class _RT> 4486*0b57cec5SDimitry Andric friend 4487*0b57cec5SDimitry Andric basic_istream<_CharT, _Traits>& 4488*0b57cec5SDimitry Andric operator>>(basic_istream<_CharT, _Traits>& __is, 4489*0b57cec5SDimitry Andric lognormal_distribution<_RT>& __x); 4490*0b57cec5SDimitry Andric}; 4491*0b57cec5SDimitry Andric 4492*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _RT> 4493*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 4494*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 4495*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 4496*0b57cec5SDimitry Andric const lognormal_distribution<_RT>& __x) 4497*0b57cec5SDimitry Andric{ 4498*0b57cec5SDimitry Andric return __os << __x.__p_.__nd_; 4499*0b57cec5SDimitry Andric} 4500*0b57cec5SDimitry Andric 4501*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _RT> 4502*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 4503*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 4504*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 4505*0b57cec5SDimitry Andric lognormal_distribution<_RT>& __x) 4506*0b57cec5SDimitry Andric{ 4507*0b57cec5SDimitry Andric return __is >> __x.__p_.__nd_; 4508*0b57cec5SDimitry Andric} 4509*0b57cec5SDimitry Andric 4510*0b57cec5SDimitry Andric// poisson_distribution 4511*0b57cec5SDimitry Andric 4512*0b57cec5SDimitry Andrictemplate<class _IntType = int> 4513*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS poisson_distribution 4514*0b57cec5SDimitry Andric{ 4515*0b57cec5SDimitry Andricpublic: 4516*0b57cec5SDimitry Andric // types 4517*0b57cec5SDimitry Andric typedef _IntType result_type; 4518*0b57cec5SDimitry Andric 4519*0b57cec5SDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 4520*0b57cec5SDimitry Andric { 4521*0b57cec5SDimitry Andric double __mean_; 4522*0b57cec5SDimitry Andric double __s_; 4523*0b57cec5SDimitry Andric double __d_; 4524*0b57cec5SDimitry Andric double __l_; 4525*0b57cec5SDimitry Andric double __omega_; 4526*0b57cec5SDimitry Andric double __c0_; 4527*0b57cec5SDimitry Andric double __c1_; 4528*0b57cec5SDimitry Andric double __c2_; 4529*0b57cec5SDimitry Andric double __c3_; 4530*0b57cec5SDimitry Andric double __c_; 4531*0b57cec5SDimitry Andric 4532*0b57cec5SDimitry Andric public: 4533*0b57cec5SDimitry Andric typedef poisson_distribution distribution_type; 4534*0b57cec5SDimitry Andric 4535*0b57cec5SDimitry Andric explicit param_type(double __mean = 1.0); 4536*0b57cec5SDimitry Andric 4537*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4538*0b57cec5SDimitry Andric double mean() const {return __mean_;} 4539*0b57cec5SDimitry Andric 4540*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 4541*0b57cec5SDimitry Andric bool operator==(const param_type& __x, const param_type& __y) 4542*0b57cec5SDimitry Andric {return __x.__mean_ == __y.__mean_;} 4543*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 4544*0b57cec5SDimitry Andric bool operator!=(const param_type& __x, const param_type& __y) 4545*0b57cec5SDimitry Andric {return !(__x == __y);} 4546*0b57cec5SDimitry Andric 4547*0b57cec5SDimitry Andric friend class poisson_distribution; 4548*0b57cec5SDimitry Andric }; 4549*0b57cec5SDimitry Andric 4550*0b57cec5SDimitry Andricprivate: 4551*0b57cec5SDimitry Andric param_type __p_; 4552*0b57cec5SDimitry Andric 4553*0b57cec5SDimitry Andricpublic: 4554*0b57cec5SDimitry Andric // constructors and reset functions 4555*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4556*0b57cec5SDimitry Andric explicit poisson_distribution(double __mean = 1.0) : __p_(__mean) {} 4557*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4558*0b57cec5SDimitry Andric explicit poisson_distribution(const param_type& __p) : __p_(__p) {} 4559*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4560*0b57cec5SDimitry Andric void reset() {} 4561*0b57cec5SDimitry Andric 4562*0b57cec5SDimitry Andric // generating functions 4563*0b57cec5SDimitry Andric template<class _URNG> 4564*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4565*0b57cec5SDimitry Andric result_type operator()(_URNG& __g) 4566*0b57cec5SDimitry Andric {return (*this)(__g, __p_);} 4567*0b57cec5SDimitry Andric template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 4568*0b57cec5SDimitry Andric 4569*0b57cec5SDimitry Andric // property functions 4570*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4571*0b57cec5SDimitry Andric double mean() const {return __p_.mean();} 4572*0b57cec5SDimitry Andric 4573*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4574*0b57cec5SDimitry Andric param_type param() const {return __p_;} 4575*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4576*0b57cec5SDimitry Andric void param(const param_type& __p) {__p_ = __p;} 4577*0b57cec5SDimitry Andric 4578*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4579*0b57cec5SDimitry Andric result_type min() const {return 0;} 4580*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4581*0b57cec5SDimitry Andric result_type max() const {return numeric_limits<result_type>::max();} 4582*0b57cec5SDimitry Andric 4583*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 4584*0b57cec5SDimitry Andric bool operator==(const poisson_distribution& __x, 4585*0b57cec5SDimitry Andric const poisson_distribution& __y) 4586*0b57cec5SDimitry Andric {return __x.__p_ == __y.__p_;} 4587*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 4588*0b57cec5SDimitry Andric bool operator!=(const poisson_distribution& __x, 4589*0b57cec5SDimitry Andric const poisson_distribution& __y) 4590*0b57cec5SDimitry Andric {return !(__x == __y);} 4591*0b57cec5SDimitry Andric}; 4592*0b57cec5SDimitry Andric 4593*0b57cec5SDimitry Andrictemplate<class _IntType> 4594*0b57cec5SDimitry Andricpoisson_distribution<_IntType>::param_type::param_type(double __mean) 4595*0b57cec5SDimitry Andric // According to the standard `inf` is a valid input, but it causes the 4596*0b57cec5SDimitry Andric // distribution to hang, so we replace it with the maximum representable 4597*0b57cec5SDimitry Andric // mean. 4598*0b57cec5SDimitry Andric : __mean_(isinf(__mean) ? numeric_limits<double>::max() : __mean) 4599*0b57cec5SDimitry Andric{ 4600*0b57cec5SDimitry Andric if (__mean_ < 10) 4601*0b57cec5SDimitry Andric { 4602*0b57cec5SDimitry Andric __s_ = 0; 4603*0b57cec5SDimitry Andric __d_ = 0; 4604*0b57cec5SDimitry Andric __l_ = _VSTD::exp(-__mean_); 4605*0b57cec5SDimitry Andric __omega_ = 0; 4606*0b57cec5SDimitry Andric __c3_ = 0; 4607*0b57cec5SDimitry Andric __c2_ = 0; 4608*0b57cec5SDimitry Andric __c1_ = 0; 4609*0b57cec5SDimitry Andric __c0_ = 0; 4610*0b57cec5SDimitry Andric __c_ = 0; 4611*0b57cec5SDimitry Andric } 4612*0b57cec5SDimitry Andric else 4613*0b57cec5SDimitry Andric { 4614*0b57cec5SDimitry Andric __s_ = _VSTD::sqrt(__mean_); 4615*0b57cec5SDimitry Andric __d_ = 6 * __mean_ * __mean_; 4616*0b57cec5SDimitry Andric __l_ = std::trunc(__mean_ - 1.1484); 4617*0b57cec5SDimitry Andric __omega_ = .3989423 / __s_; 4618*0b57cec5SDimitry Andric double __b1_ = .4166667E-1 / __mean_; 4619*0b57cec5SDimitry Andric double __b2_ = .3 * __b1_ * __b1_; 4620*0b57cec5SDimitry Andric __c3_ = .1428571 * __b1_ * __b2_; 4621*0b57cec5SDimitry Andric __c2_ = __b2_ - 15. * __c3_; 4622*0b57cec5SDimitry Andric __c1_ = __b1_ - 6. * __b2_ + 45. * __c3_; 4623*0b57cec5SDimitry Andric __c0_ = 1. - __b1_ + 3. * __b2_ - 15. * __c3_; 4624*0b57cec5SDimitry Andric __c_ = .1069 / __mean_; 4625*0b57cec5SDimitry Andric } 4626*0b57cec5SDimitry Andric} 4627*0b57cec5SDimitry Andric 4628*0b57cec5SDimitry Andrictemplate <class _IntType> 4629*0b57cec5SDimitry Andrictemplate<class _URNG> 4630*0b57cec5SDimitry Andric_IntType 4631*0b57cec5SDimitry Andricpoisson_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr) 4632*0b57cec5SDimitry Andric{ 4633*0b57cec5SDimitry Andric double __tx; 4634*0b57cec5SDimitry Andric uniform_real_distribution<double> __urd; 4635*0b57cec5SDimitry Andric if (__pr.__mean_ < 10) 4636*0b57cec5SDimitry Andric { 4637*0b57cec5SDimitry Andric __tx = 0; 4638*0b57cec5SDimitry Andric for (double __p = __urd(__urng); __p > __pr.__l_; ++__tx) 4639*0b57cec5SDimitry Andric __p *= __urd(__urng); 4640*0b57cec5SDimitry Andric } 4641*0b57cec5SDimitry Andric else 4642*0b57cec5SDimitry Andric { 4643*0b57cec5SDimitry Andric double __difmuk; 4644*0b57cec5SDimitry Andric double __g = __pr.__mean_ + __pr.__s_ * normal_distribution<double>()(__urng); 4645*0b57cec5SDimitry Andric double __u; 4646*0b57cec5SDimitry Andric if (__g > 0) 4647*0b57cec5SDimitry Andric { 4648*0b57cec5SDimitry Andric __tx = std::trunc(__g); 4649*0b57cec5SDimitry Andric if (__tx >= __pr.__l_) 4650*0b57cec5SDimitry Andric return std::__clamp_to_integral<result_type>(__tx); 4651*0b57cec5SDimitry Andric __difmuk = __pr.__mean_ - __tx; 4652*0b57cec5SDimitry Andric __u = __urd(__urng); 4653*0b57cec5SDimitry Andric if (__pr.__d_ * __u >= __difmuk * __difmuk * __difmuk) 4654*0b57cec5SDimitry Andric return std::__clamp_to_integral<result_type>(__tx); 4655*0b57cec5SDimitry Andric } 4656*0b57cec5SDimitry Andric exponential_distribution<double> __edist; 4657*0b57cec5SDimitry Andric for (bool __using_exp_dist = false; true; __using_exp_dist = true) 4658*0b57cec5SDimitry Andric { 4659*0b57cec5SDimitry Andric double __e; 4660*0b57cec5SDimitry Andric if (__using_exp_dist || __g <= 0) 4661*0b57cec5SDimitry Andric { 4662*0b57cec5SDimitry Andric double __t; 4663*0b57cec5SDimitry Andric do 4664*0b57cec5SDimitry Andric { 4665*0b57cec5SDimitry Andric __e = __edist(__urng); 4666*0b57cec5SDimitry Andric __u = __urd(__urng); 4667*0b57cec5SDimitry Andric __u += __u - 1; 4668*0b57cec5SDimitry Andric __t = 1.8 + (__u < 0 ? -__e : __e); 4669*0b57cec5SDimitry Andric } while (__t <= -.6744); 4670*0b57cec5SDimitry Andric __tx = std::trunc(__pr.__mean_ + __pr.__s_ * __t); 4671*0b57cec5SDimitry Andric __difmuk = __pr.__mean_ - __tx; 4672*0b57cec5SDimitry Andric __using_exp_dist = true; 4673*0b57cec5SDimitry Andric } 4674*0b57cec5SDimitry Andric double __px; 4675*0b57cec5SDimitry Andric double __py; 4676*0b57cec5SDimitry Andric if (__tx < 10 && __tx >= 0) 4677*0b57cec5SDimitry Andric { 4678*0b57cec5SDimitry Andric const double __fac[] = {1, 1, 2, 6, 24, 120, 720, 5040, 4679*0b57cec5SDimitry Andric 40320, 362880}; 4680*0b57cec5SDimitry Andric __px = -__pr.__mean_; 4681*0b57cec5SDimitry Andric __py = _VSTD::pow(__pr.__mean_, (double)__tx) / __fac[static_cast<int>(__tx)]; 4682*0b57cec5SDimitry Andric } 4683*0b57cec5SDimitry Andric else 4684*0b57cec5SDimitry Andric { 4685*0b57cec5SDimitry Andric double __del = .8333333E-1 / __tx; 4686*0b57cec5SDimitry Andric __del -= 4.8 * __del * __del * __del; 4687*0b57cec5SDimitry Andric double __v = __difmuk / __tx; 4688*0b57cec5SDimitry Andric if (_VSTD::abs(__v) > 0.25) 4689*0b57cec5SDimitry Andric __px = __tx * _VSTD::log(1 + __v) - __difmuk - __del; 4690*0b57cec5SDimitry Andric else 4691*0b57cec5SDimitry Andric __px = __tx * __v * __v * (((((((.1250060 * __v + -.1384794) * 4692*0b57cec5SDimitry Andric __v + .1421878) * __v + -.1661269) * __v + .2000118) * 4693*0b57cec5SDimitry Andric __v + -.2500068) * __v + .3333333) * __v + -.5) - __del; 4694*0b57cec5SDimitry Andric __py = .3989423 / _VSTD::sqrt(__tx); 4695*0b57cec5SDimitry Andric } 4696*0b57cec5SDimitry Andric double __r = (0.5 - __difmuk) / __pr.__s_; 4697*0b57cec5SDimitry Andric double __r2 = __r * __r; 4698*0b57cec5SDimitry Andric double __fx = -0.5 * __r2; 4699*0b57cec5SDimitry Andric double __fy = __pr.__omega_ * (((__pr.__c3_ * __r2 + __pr.__c2_) * 4700*0b57cec5SDimitry Andric __r2 + __pr.__c1_) * __r2 + __pr.__c0_); 4701*0b57cec5SDimitry Andric if (__using_exp_dist) 4702*0b57cec5SDimitry Andric { 4703*0b57cec5SDimitry Andric if (__pr.__c_ * _VSTD::abs(__u) <= __py * _VSTD::exp(__px + __e) - 4704*0b57cec5SDimitry Andric __fy * _VSTD::exp(__fx + __e)) 4705*0b57cec5SDimitry Andric break; 4706*0b57cec5SDimitry Andric } 4707*0b57cec5SDimitry Andric else 4708*0b57cec5SDimitry Andric { 4709*0b57cec5SDimitry Andric if (__fy - __u * __fy <= __py * _VSTD::exp(__px - __fx)) 4710*0b57cec5SDimitry Andric break; 4711*0b57cec5SDimitry Andric } 4712*0b57cec5SDimitry Andric } 4713*0b57cec5SDimitry Andric } 4714*0b57cec5SDimitry Andric return std::__clamp_to_integral<result_type>(__tx); 4715*0b57cec5SDimitry Andric} 4716*0b57cec5SDimitry Andric 4717*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _IntType> 4718*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 4719*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 4720*0b57cec5SDimitry Andric const poisson_distribution<_IntType>& __x) 4721*0b57cec5SDimitry Andric{ 4722*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__os); 4723*0b57cec5SDimitry Andric __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 4724*0b57cec5SDimitry Andric ios_base::scientific); 4725*0b57cec5SDimitry Andric return __os << __x.mean(); 4726*0b57cec5SDimitry Andric} 4727*0b57cec5SDimitry Andric 4728*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _IntType> 4729*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 4730*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 4731*0b57cec5SDimitry Andric poisson_distribution<_IntType>& __x) 4732*0b57cec5SDimitry Andric{ 4733*0b57cec5SDimitry Andric typedef poisson_distribution<_IntType> _Eng; 4734*0b57cec5SDimitry Andric typedef typename _Eng::param_type param_type; 4735*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__is); 4736*0b57cec5SDimitry Andric __is.flags(ios_base::dec | ios_base::skipws); 4737*0b57cec5SDimitry Andric double __mean; 4738*0b57cec5SDimitry Andric __is >> __mean; 4739*0b57cec5SDimitry Andric if (!__is.fail()) 4740*0b57cec5SDimitry Andric __x.param(param_type(__mean)); 4741*0b57cec5SDimitry Andric return __is; 4742*0b57cec5SDimitry Andric} 4743*0b57cec5SDimitry Andric 4744*0b57cec5SDimitry Andric// weibull_distribution 4745*0b57cec5SDimitry Andric 4746*0b57cec5SDimitry Andrictemplate<class _RealType = double> 4747*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS weibull_distribution 4748*0b57cec5SDimitry Andric{ 4749*0b57cec5SDimitry Andricpublic: 4750*0b57cec5SDimitry Andric // types 4751*0b57cec5SDimitry Andric typedef _RealType result_type; 4752*0b57cec5SDimitry Andric 4753*0b57cec5SDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 4754*0b57cec5SDimitry Andric { 4755*0b57cec5SDimitry Andric result_type __a_; 4756*0b57cec5SDimitry Andric result_type __b_; 4757*0b57cec5SDimitry Andric public: 4758*0b57cec5SDimitry Andric typedef weibull_distribution distribution_type; 4759*0b57cec5SDimitry Andric 4760*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4761*0b57cec5SDimitry Andric explicit param_type(result_type __a = 1, result_type __b = 1) 4762*0b57cec5SDimitry Andric : __a_(__a), __b_(__b) {} 4763*0b57cec5SDimitry Andric 4764*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4765*0b57cec5SDimitry Andric result_type a() const {return __a_;} 4766*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4767*0b57cec5SDimitry Andric result_type b() const {return __b_;} 4768*0b57cec5SDimitry Andric 4769*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 4770*0b57cec5SDimitry Andric bool operator==(const param_type& __x, const param_type& __y) 4771*0b57cec5SDimitry Andric {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} 4772*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 4773*0b57cec5SDimitry Andric bool operator!=(const param_type& __x, const param_type& __y) 4774*0b57cec5SDimitry Andric {return !(__x == __y);} 4775*0b57cec5SDimitry Andric }; 4776*0b57cec5SDimitry Andric 4777*0b57cec5SDimitry Andricprivate: 4778*0b57cec5SDimitry Andric param_type __p_; 4779*0b57cec5SDimitry Andric 4780*0b57cec5SDimitry Andricpublic: 4781*0b57cec5SDimitry Andric // constructor and reset functions 4782*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4783*0b57cec5SDimitry Andric explicit weibull_distribution(result_type __a = 1, result_type __b = 1) 4784*0b57cec5SDimitry Andric : __p_(param_type(__a, __b)) {} 4785*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4786*0b57cec5SDimitry Andric explicit weibull_distribution(const param_type& __p) 4787*0b57cec5SDimitry Andric : __p_(__p) {} 4788*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4789*0b57cec5SDimitry Andric void reset() {} 4790*0b57cec5SDimitry Andric 4791*0b57cec5SDimitry Andric // generating functions 4792*0b57cec5SDimitry Andric template<class _URNG> 4793*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4794*0b57cec5SDimitry Andric result_type operator()(_URNG& __g) 4795*0b57cec5SDimitry Andric {return (*this)(__g, __p_);} 4796*0b57cec5SDimitry Andric template<class _URNG> 4797*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4798*0b57cec5SDimitry Andric result_type operator()(_URNG& __g, const param_type& __p) 4799*0b57cec5SDimitry Andric {return __p.b() * 4800*0b57cec5SDimitry Andric _VSTD::pow(exponential_distribution<result_type>()(__g), 1/__p.a());} 4801*0b57cec5SDimitry Andric 4802*0b57cec5SDimitry Andric // property functions 4803*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4804*0b57cec5SDimitry Andric result_type a() const {return __p_.a();} 4805*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4806*0b57cec5SDimitry Andric result_type b() const {return __p_.b();} 4807*0b57cec5SDimitry Andric 4808*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4809*0b57cec5SDimitry Andric param_type param() const {return __p_;} 4810*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4811*0b57cec5SDimitry Andric void param(const param_type& __p) {__p_ = __p;} 4812*0b57cec5SDimitry Andric 4813*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4814*0b57cec5SDimitry Andric result_type min() const {return 0;} 4815*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4816*0b57cec5SDimitry Andric result_type max() const {return numeric_limits<result_type>::infinity();} 4817*0b57cec5SDimitry Andric 4818*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 4819*0b57cec5SDimitry Andric bool operator==(const weibull_distribution& __x, 4820*0b57cec5SDimitry Andric const weibull_distribution& __y) 4821*0b57cec5SDimitry Andric {return __x.__p_ == __y.__p_;} 4822*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 4823*0b57cec5SDimitry Andric bool operator!=(const weibull_distribution& __x, 4824*0b57cec5SDimitry Andric const weibull_distribution& __y) 4825*0b57cec5SDimitry Andric {return !(__x == __y);} 4826*0b57cec5SDimitry Andric}; 4827*0b57cec5SDimitry Andric 4828*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _RT> 4829*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 4830*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 4831*0b57cec5SDimitry Andric const weibull_distribution<_RT>& __x) 4832*0b57cec5SDimitry Andric{ 4833*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__os); 4834*0b57cec5SDimitry Andric __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 4835*0b57cec5SDimitry Andric ios_base::scientific); 4836*0b57cec5SDimitry Andric _CharT __sp = __os.widen(' '); 4837*0b57cec5SDimitry Andric __os.fill(__sp); 4838*0b57cec5SDimitry Andric __os << __x.a() << __sp << __x.b(); 4839*0b57cec5SDimitry Andric return __os; 4840*0b57cec5SDimitry Andric} 4841*0b57cec5SDimitry Andric 4842*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _RT> 4843*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 4844*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 4845*0b57cec5SDimitry Andric weibull_distribution<_RT>& __x) 4846*0b57cec5SDimitry Andric{ 4847*0b57cec5SDimitry Andric typedef weibull_distribution<_RT> _Eng; 4848*0b57cec5SDimitry Andric typedef typename _Eng::result_type result_type; 4849*0b57cec5SDimitry Andric typedef typename _Eng::param_type param_type; 4850*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__is); 4851*0b57cec5SDimitry Andric __is.flags(ios_base::dec | ios_base::skipws); 4852*0b57cec5SDimitry Andric result_type __a; 4853*0b57cec5SDimitry Andric result_type __b; 4854*0b57cec5SDimitry Andric __is >> __a >> __b; 4855*0b57cec5SDimitry Andric if (!__is.fail()) 4856*0b57cec5SDimitry Andric __x.param(param_type(__a, __b)); 4857*0b57cec5SDimitry Andric return __is; 4858*0b57cec5SDimitry Andric} 4859*0b57cec5SDimitry Andric 4860*0b57cec5SDimitry Andrictemplate<class _RealType = double> 4861*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS extreme_value_distribution 4862*0b57cec5SDimitry Andric{ 4863*0b57cec5SDimitry Andricpublic: 4864*0b57cec5SDimitry Andric // types 4865*0b57cec5SDimitry Andric typedef _RealType result_type; 4866*0b57cec5SDimitry Andric 4867*0b57cec5SDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 4868*0b57cec5SDimitry Andric { 4869*0b57cec5SDimitry Andric result_type __a_; 4870*0b57cec5SDimitry Andric result_type __b_; 4871*0b57cec5SDimitry Andric public: 4872*0b57cec5SDimitry Andric typedef extreme_value_distribution distribution_type; 4873*0b57cec5SDimitry Andric 4874*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4875*0b57cec5SDimitry Andric explicit param_type(result_type __a = 0, result_type __b = 1) 4876*0b57cec5SDimitry Andric : __a_(__a), __b_(__b) {} 4877*0b57cec5SDimitry Andric 4878*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4879*0b57cec5SDimitry Andric result_type a() const {return __a_;} 4880*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4881*0b57cec5SDimitry Andric result_type b() const {return __b_;} 4882*0b57cec5SDimitry Andric 4883*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 4884*0b57cec5SDimitry Andric bool operator==(const param_type& __x, const param_type& __y) 4885*0b57cec5SDimitry Andric {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} 4886*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 4887*0b57cec5SDimitry Andric bool operator!=(const param_type& __x, const param_type& __y) 4888*0b57cec5SDimitry Andric {return !(__x == __y);} 4889*0b57cec5SDimitry Andric }; 4890*0b57cec5SDimitry Andric 4891*0b57cec5SDimitry Andricprivate: 4892*0b57cec5SDimitry Andric param_type __p_; 4893*0b57cec5SDimitry Andric 4894*0b57cec5SDimitry Andricpublic: 4895*0b57cec5SDimitry Andric // constructor and reset functions 4896*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4897*0b57cec5SDimitry Andric explicit extreme_value_distribution(result_type __a = 0, result_type __b = 1) 4898*0b57cec5SDimitry Andric : __p_(param_type(__a, __b)) {} 4899*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4900*0b57cec5SDimitry Andric explicit extreme_value_distribution(const param_type& __p) 4901*0b57cec5SDimitry Andric : __p_(__p) {} 4902*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4903*0b57cec5SDimitry Andric void reset() {} 4904*0b57cec5SDimitry Andric 4905*0b57cec5SDimitry Andric // generating functions 4906*0b57cec5SDimitry Andric template<class _URNG> 4907*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4908*0b57cec5SDimitry Andric result_type operator()(_URNG& __g) 4909*0b57cec5SDimitry Andric {return (*this)(__g, __p_);} 4910*0b57cec5SDimitry Andric template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 4911*0b57cec5SDimitry Andric 4912*0b57cec5SDimitry Andric // property functions 4913*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4914*0b57cec5SDimitry Andric result_type a() const {return __p_.a();} 4915*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4916*0b57cec5SDimitry Andric result_type b() const {return __p_.b();} 4917*0b57cec5SDimitry Andric 4918*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4919*0b57cec5SDimitry Andric param_type param() const {return __p_;} 4920*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4921*0b57cec5SDimitry Andric void param(const param_type& __p) {__p_ = __p;} 4922*0b57cec5SDimitry Andric 4923*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4924*0b57cec5SDimitry Andric result_type min() const {return -numeric_limits<result_type>::infinity();} 4925*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4926*0b57cec5SDimitry Andric result_type max() const {return numeric_limits<result_type>::infinity();} 4927*0b57cec5SDimitry Andric 4928*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 4929*0b57cec5SDimitry Andric bool operator==(const extreme_value_distribution& __x, 4930*0b57cec5SDimitry Andric const extreme_value_distribution& __y) 4931*0b57cec5SDimitry Andric {return __x.__p_ == __y.__p_;} 4932*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 4933*0b57cec5SDimitry Andric bool operator!=(const extreme_value_distribution& __x, 4934*0b57cec5SDimitry Andric const extreme_value_distribution& __y) 4935*0b57cec5SDimitry Andric {return !(__x == __y);} 4936*0b57cec5SDimitry Andric}; 4937*0b57cec5SDimitry Andric 4938*0b57cec5SDimitry Andrictemplate<class _RealType> 4939*0b57cec5SDimitry Andrictemplate<class _URNG> 4940*0b57cec5SDimitry Andric_RealType 4941*0b57cec5SDimitry Andricextreme_value_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 4942*0b57cec5SDimitry Andric{ 4943*0b57cec5SDimitry Andric return __p.a() - __p.b() * 4944*0b57cec5SDimitry Andric _VSTD::log(-_VSTD::log(1-uniform_real_distribution<result_type>()(__g))); 4945*0b57cec5SDimitry Andric} 4946*0b57cec5SDimitry Andric 4947*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _RT> 4948*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 4949*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 4950*0b57cec5SDimitry Andric const extreme_value_distribution<_RT>& __x) 4951*0b57cec5SDimitry Andric{ 4952*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__os); 4953*0b57cec5SDimitry Andric __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 4954*0b57cec5SDimitry Andric ios_base::scientific); 4955*0b57cec5SDimitry Andric _CharT __sp = __os.widen(' '); 4956*0b57cec5SDimitry Andric __os.fill(__sp); 4957*0b57cec5SDimitry Andric __os << __x.a() << __sp << __x.b(); 4958*0b57cec5SDimitry Andric return __os; 4959*0b57cec5SDimitry Andric} 4960*0b57cec5SDimitry Andric 4961*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _RT> 4962*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 4963*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 4964*0b57cec5SDimitry Andric extreme_value_distribution<_RT>& __x) 4965*0b57cec5SDimitry Andric{ 4966*0b57cec5SDimitry Andric typedef extreme_value_distribution<_RT> _Eng; 4967*0b57cec5SDimitry Andric typedef typename _Eng::result_type result_type; 4968*0b57cec5SDimitry Andric typedef typename _Eng::param_type param_type; 4969*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__is); 4970*0b57cec5SDimitry Andric __is.flags(ios_base::dec | ios_base::skipws); 4971*0b57cec5SDimitry Andric result_type __a; 4972*0b57cec5SDimitry Andric result_type __b; 4973*0b57cec5SDimitry Andric __is >> __a >> __b; 4974*0b57cec5SDimitry Andric if (!__is.fail()) 4975*0b57cec5SDimitry Andric __x.param(param_type(__a, __b)); 4976*0b57cec5SDimitry Andric return __is; 4977*0b57cec5SDimitry Andric} 4978*0b57cec5SDimitry Andric 4979*0b57cec5SDimitry Andric// gamma_distribution 4980*0b57cec5SDimitry Andric 4981*0b57cec5SDimitry Andrictemplate<class _RealType = double> 4982*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS gamma_distribution 4983*0b57cec5SDimitry Andric{ 4984*0b57cec5SDimitry Andricpublic: 4985*0b57cec5SDimitry Andric // types 4986*0b57cec5SDimitry Andric typedef _RealType result_type; 4987*0b57cec5SDimitry Andric 4988*0b57cec5SDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 4989*0b57cec5SDimitry Andric { 4990*0b57cec5SDimitry Andric result_type __alpha_; 4991*0b57cec5SDimitry Andric result_type __beta_; 4992*0b57cec5SDimitry Andric public: 4993*0b57cec5SDimitry Andric typedef gamma_distribution distribution_type; 4994*0b57cec5SDimitry Andric 4995*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4996*0b57cec5SDimitry Andric explicit param_type(result_type __alpha = 1, result_type __beta = 1) 4997*0b57cec5SDimitry Andric : __alpha_(__alpha), __beta_(__beta) {} 4998*0b57cec5SDimitry Andric 4999*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5000*0b57cec5SDimitry Andric result_type alpha() const {return __alpha_;} 5001*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5002*0b57cec5SDimitry Andric result_type beta() const {return __beta_;} 5003*0b57cec5SDimitry Andric 5004*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5005*0b57cec5SDimitry Andric bool operator==(const param_type& __x, const param_type& __y) 5006*0b57cec5SDimitry Andric {return __x.__alpha_ == __y.__alpha_ && __x.__beta_ == __y.__beta_;} 5007*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5008*0b57cec5SDimitry Andric bool operator!=(const param_type& __x, const param_type& __y) 5009*0b57cec5SDimitry Andric {return !(__x == __y);} 5010*0b57cec5SDimitry Andric }; 5011*0b57cec5SDimitry Andric 5012*0b57cec5SDimitry Andricprivate: 5013*0b57cec5SDimitry Andric param_type __p_; 5014*0b57cec5SDimitry Andric 5015*0b57cec5SDimitry Andricpublic: 5016*0b57cec5SDimitry Andric // constructors and reset functions 5017*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5018*0b57cec5SDimitry Andric explicit gamma_distribution(result_type __alpha = 1, result_type __beta = 1) 5019*0b57cec5SDimitry Andric : __p_(param_type(__alpha, __beta)) {} 5020*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5021*0b57cec5SDimitry Andric explicit gamma_distribution(const param_type& __p) 5022*0b57cec5SDimitry Andric : __p_(__p) {} 5023*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5024*0b57cec5SDimitry Andric void reset() {} 5025*0b57cec5SDimitry Andric 5026*0b57cec5SDimitry Andric // generating functions 5027*0b57cec5SDimitry Andric template<class _URNG> 5028*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5029*0b57cec5SDimitry Andric result_type operator()(_URNG& __g) 5030*0b57cec5SDimitry Andric {return (*this)(__g, __p_);} 5031*0b57cec5SDimitry Andric template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 5032*0b57cec5SDimitry Andric 5033*0b57cec5SDimitry Andric // property functions 5034*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5035*0b57cec5SDimitry Andric result_type alpha() const {return __p_.alpha();} 5036*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5037*0b57cec5SDimitry Andric result_type beta() const {return __p_.beta();} 5038*0b57cec5SDimitry Andric 5039*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5040*0b57cec5SDimitry Andric param_type param() const {return __p_;} 5041*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5042*0b57cec5SDimitry Andric void param(const param_type& __p) {__p_ = __p;} 5043*0b57cec5SDimitry Andric 5044*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5045*0b57cec5SDimitry Andric result_type min() const {return 0;} 5046*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5047*0b57cec5SDimitry Andric result_type max() const {return numeric_limits<result_type>::infinity();} 5048*0b57cec5SDimitry Andric 5049*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5050*0b57cec5SDimitry Andric bool operator==(const gamma_distribution& __x, 5051*0b57cec5SDimitry Andric const gamma_distribution& __y) 5052*0b57cec5SDimitry Andric {return __x.__p_ == __y.__p_;} 5053*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5054*0b57cec5SDimitry Andric bool operator!=(const gamma_distribution& __x, 5055*0b57cec5SDimitry Andric const gamma_distribution& __y) 5056*0b57cec5SDimitry Andric {return !(__x == __y);} 5057*0b57cec5SDimitry Andric}; 5058*0b57cec5SDimitry Andric 5059*0b57cec5SDimitry Andrictemplate <class _RealType> 5060*0b57cec5SDimitry Andrictemplate<class _URNG> 5061*0b57cec5SDimitry Andric_RealType 5062*0b57cec5SDimitry Andricgamma_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 5063*0b57cec5SDimitry Andric{ 5064*0b57cec5SDimitry Andric result_type __a = __p.alpha(); 5065*0b57cec5SDimitry Andric uniform_real_distribution<result_type> __gen(0, 1); 5066*0b57cec5SDimitry Andric exponential_distribution<result_type> __egen; 5067*0b57cec5SDimitry Andric result_type __x; 5068*0b57cec5SDimitry Andric if (__a == 1) 5069*0b57cec5SDimitry Andric __x = __egen(__g); 5070*0b57cec5SDimitry Andric else if (__a > 1) 5071*0b57cec5SDimitry Andric { 5072*0b57cec5SDimitry Andric const result_type __b = __a - 1; 5073*0b57cec5SDimitry Andric const result_type __c = 3 * __a - result_type(0.75); 5074*0b57cec5SDimitry Andric while (true) 5075*0b57cec5SDimitry Andric { 5076*0b57cec5SDimitry Andric const result_type __u = __gen(__g); 5077*0b57cec5SDimitry Andric const result_type __v = __gen(__g); 5078*0b57cec5SDimitry Andric const result_type __w = __u * (1 - __u); 5079*0b57cec5SDimitry Andric if (__w != 0) 5080*0b57cec5SDimitry Andric { 5081*0b57cec5SDimitry Andric const result_type __y = _VSTD::sqrt(__c / __w) * 5082*0b57cec5SDimitry Andric (__u - result_type(0.5)); 5083*0b57cec5SDimitry Andric __x = __b + __y; 5084*0b57cec5SDimitry Andric if (__x >= 0) 5085*0b57cec5SDimitry Andric { 5086*0b57cec5SDimitry Andric const result_type __z = 64 * __w * __w * __w * __v * __v; 5087*0b57cec5SDimitry Andric if (__z <= 1 - 2 * __y * __y / __x) 5088*0b57cec5SDimitry Andric break; 5089*0b57cec5SDimitry Andric if (_VSTD::log(__z) <= 2 * (__b * _VSTD::log(__x / __b) - __y)) 5090*0b57cec5SDimitry Andric break; 5091*0b57cec5SDimitry Andric } 5092*0b57cec5SDimitry Andric } 5093*0b57cec5SDimitry Andric } 5094*0b57cec5SDimitry Andric } 5095*0b57cec5SDimitry Andric else // __a < 1 5096*0b57cec5SDimitry Andric { 5097*0b57cec5SDimitry Andric while (true) 5098*0b57cec5SDimitry Andric { 5099*0b57cec5SDimitry Andric const result_type __u = __gen(__g); 5100*0b57cec5SDimitry Andric const result_type __es = __egen(__g); 5101*0b57cec5SDimitry Andric if (__u <= 1 - __a) 5102*0b57cec5SDimitry Andric { 5103*0b57cec5SDimitry Andric __x = _VSTD::pow(__u, 1 / __a); 5104*0b57cec5SDimitry Andric if (__x <= __es) 5105*0b57cec5SDimitry Andric break; 5106*0b57cec5SDimitry Andric } 5107*0b57cec5SDimitry Andric else 5108*0b57cec5SDimitry Andric { 5109*0b57cec5SDimitry Andric const result_type __e = -_VSTD::log((1-__u)/__a); 5110*0b57cec5SDimitry Andric __x = _VSTD::pow(1 - __a + __a * __e, 1 / __a); 5111*0b57cec5SDimitry Andric if (__x <= __e + __es) 5112*0b57cec5SDimitry Andric break; 5113*0b57cec5SDimitry Andric } 5114*0b57cec5SDimitry Andric } 5115*0b57cec5SDimitry Andric } 5116*0b57cec5SDimitry Andric return __x * __p.beta(); 5117*0b57cec5SDimitry Andric} 5118*0b57cec5SDimitry Andric 5119*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _RT> 5120*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 5121*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 5122*0b57cec5SDimitry Andric const gamma_distribution<_RT>& __x) 5123*0b57cec5SDimitry Andric{ 5124*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__os); 5125*0b57cec5SDimitry Andric __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 5126*0b57cec5SDimitry Andric ios_base::scientific); 5127*0b57cec5SDimitry Andric _CharT __sp = __os.widen(' '); 5128*0b57cec5SDimitry Andric __os.fill(__sp); 5129*0b57cec5SDimitry Andric __os << __x.alpha() << __sp << __x.beta(); 5130*0b57cec5SDimitry Andric return __os; 5131*0b57cec5SDimitry Andric} 5132*0b57cec5SDimitry Andric 5133*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _RT> 5134*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 5135*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 5136*0b57cec5SDimitry Andric gamma_distribution<_RT>& __x) 5137*0b57cec5SDimitry Andric{ 5138*0b57cec5SDimitry Andric typedef gamma_distribution<_RT> _Eng; 5139*0b57cec5SDimitry Andric typedef typename _Eng::result_type result_type; 5140*0b57cec5SDimitry Andric typedef typename _Eng::param_type param_type; 5141*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__is); 5142*0b57cec5SDimitry Andric __is.flags(ios_base::dec | ios_base::skipws); 5143*0b57cec5SDimitry Andric result_type __alpha; 5144*0b57cec5SDimitry Andric result_type __beta; 5145*0b57cec5SDimitry Andric __is >> __alpha >> __beta; 5146*0b57cec5SDimitry Andric if (!__is.fail()) 5147*0b57cec5SDimitry Andric __x.param(param_type(__alpha, __beta)); 5148*0b57cec5SDimitry Andric return __is; 5149*0b57cec5SDimitry Andric} 5150*0b57cec5SDimitry Andric 5151*0b57cec5SDimitry Andric// negative_binomial_distribution 5152*0b57cec5SDimitry Andric 5153*0b57cec5SDimitry Andrictemplate<class _IntType = int> 5154*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS negative_binomial_distribution 5155*0b57cec5SDimitry Andric{ 5156*0b57cec5SDimitry Andricpublic: 5157*0b57cec5SDimitry Andric // types 5158*0b57cec5SDimitry Andric typedef _IntType result_type; 5159*0b57cec5SDimitry Andric 5160*0b57cec5SDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 5161*0b57cec5SDimitry Andric { 5162*0b57cec5SDimitry Andric result_type __k_; 5163*0b57cec5SDimitry Andric double __p_; 5164*0b57cec5SDimitry Andric public: 5165*0b57cec5SDimitry Andric typedef negative_binomial_distribution distribution_type; 5166*0b57cec5SDimitry Andric 5167*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5168*0b57cec5SDimitry Andric explicit param_type(result_type __k = 1, double __p = 0.5) 5169*0b57cec5SDimitry Andric : __k_(__k), __p_(__p) {} 5170*0b57cec5SDimitry Andric 5171*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5172*0b57cec5SDimitry Andric result_type k() const {return __k_;} 5173*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5174*0b57cec5SDimitry Andric double p() const {return __p_;} 5175*0b57cec5SDimitry Andric 5176*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5177*0b57cec5SDimitry Andric bool operator==(const param_type& __x, const param_type& __y) 5178*0b57cec5SDimitry Andric {return __x.__k_ == __y.__k_ && __x.__p_ == __y.__p_;} 5179*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5180*0b57cec5SDimitry Andric bool operator!=(const param_type& __x, const param_type& __y) 5181*0b57cec5SDimitry Andric {return !(__x == __y);} 5182*0b57cec5SDimitry Andric }; 5183*0b57cec5SDimitry Andric 5184*0b57cec5SDimitry Andricprivate: 5185*0b57cec5SDimitry Andric param_type __p_; 5186*0b57cec5SDimitry Andric 5187*0b57cec5SDimitry Andricpublic: 5188*0b57cec5SDimitry Andric // constructor and reset functions 5189*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5190*0b57cec5SDimitry Andric explicit negative_binomial_distribution(result_type __k = 1, double __p = 0.5) 5191*0b57cec5SDimitry Andric : __p_(__k, __p) {} 5192*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5193*0b57cec5SDimitry Andric explicit negative_binomial_distribution(const param_type& __p) : __p_(__p) {} 5194*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5195*0b57cec5SDimitry Andric void reset() {} 5196*0b57cec5SDimitry Andric 5197*0b57cec5SDimitry Andric // generating functions 5198*0b57cec5SDimitry Andric template<class _URNG> 5199*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5200*0b57cec5SDimitry Andric result_type operator()(_URNG& __g) 5201*0b57cec5SDimitry Andric {return (*this)(__g, __p_);} 5202*0b57cec5SDimitry Andric template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 5203*0b57cec5SDimitry Andric 5204*0b57cec5SDimitry Andric // property functions 5205*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5206*0b57cec5SDimitry Andric result_type k() const {return __p_.k();} 5207*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5208*0b57cec5SDimitry Andric double p() const {return __p_.p();} 5209*0b57cec5SDimitry Andric 5210*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5211*0b57cec5SDimitry Andric param_type param() const {return __p_;} 5212*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5213*0b57cec5SDimitry Andric void param(const param_type& __p) {__p_ = __p;} 5214*0b57cec5SDimitry Andric 5215*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5216*0b57cec5SDimitry Andric result_type min() const {return 0;} 5217*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5218*0b57cec5SDimitry Andric result_type max() const {return numeric_limits<result_type>::max();} 5219*0b57cec5SDimitry Andric 5220*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5221*0b57cec5SDimitry Andric bool operator==(const negative_binomial_distribution& __x, 5222*0b57cec5SDimitry Andric const negative_binomial_distribution& __y) 5223*0b57cec5SDimitry Andric {return __x.__p_ == __y.__p_;} 5224*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5225*0b57cec5SDimitry Andric bool operator!=(const negative_binomial_distribution& __x, 5226*0b57cec5SDimitry Andric const negative_binomial_distribution& __y) 5227*0b57cec5SDimitry Andric {return !(__x == __y);} 5228*0b57cec5SDimitry Andric}; 5229*0b57cec5SDimitry Andric 5230*0b57cec5SDimitry Andrictemplate <class _IntType> 5231*0b57cec5SDimitry Andrictemplate<class _URNG> 5232*0b57cec5SDimitry Andric_IntType 5233*0b57cec5SDimitry Andricnegative_binomial_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr) 5234*0b57cec5SDimitry Andric{ 5235*0b57cec5SDimitry Andric result_type __k = __pr.k(); 5236*0b57cec5SDimitry Andric double __p = __pr.p(); 5237*0b57cec5SDimitry Andric if (__k <= 21 * __p) 5238*0b57cec5SDimitry Andric { 5239*0b57cec5SDimitry Andric bernoulli_distribution __gen(__p); 5240*0b57cec5SDimitry Andric result_type __f = 0; 5241*0b57cec5SDimitry Andric result_type __s = 0; 5242*0b57cec5SDimitry Andric while (__s < __k) 5243*0b57cec5SDimitry Andric { 5244*0b57cec5SDimitry Andric if (__gen(__urng)) 5245*0b57cec5SDimitry Andric ++__s; 5246*0b57cec5SDimitry Andric else 5247*0b57cec5SDimitry Andric ++__f; 5248*0b57cec5SDimitry Andric } 5249*0b57cec5SDimitry Andric return __f; 5250*0b57cec5SDimitry Andric } 5251*0b57cec5SDimitry Andric return poisson_distribution<result_type>(gamma_distribution<double> 5252*0b57cec5SDimitry Andric (__k, (1-__p)/__p)(__urng))(__urng); 5253*0b57cec5SDimitry Andric} 5254*0b57cec5SDimitry Andric 5255*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _IntType> 5256*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 5257*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 5258*0b57cec5SDimitry Andric const negative_binomial_distribution<_IntType>& __x) 5259*0b57cec5SDimitry Andric{ 5260*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__os); 5261*0b57cec5SDimitry Andric __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 5262*0b57cec5SDimitry Andric ios_base::scientific); 5263*0b57cec5SDimitry Andric _CharT __sp = __os.widen(' '); 5264*0b57cec5SDimitry Andric __os.fill(__sp); 5265*0b57cec5SDimitry Andric return __os << __x.k() << __sp << __x.p(); 5266*0b57cec5SDimitry Andric} 5267*0b57cec5SDimitry Andric 5268*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _IntType> 5269*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 5270*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 5271*0b57cec5SDimitry Andric negative_binomial_distribution<_IntType>& __x) 5272*0b57cec5SDimitry Andric{ 5273*0b57cec5SDimitry Andric typedef negative_binomial_distribution<_IntType> _Eng; 5274*0b57cec5SDimitry Andric typedef typename _Eng::result_type result_type; 5275*0b57cec5SDimitry Andric typedef typename _Eng::param_type param_type; 5276*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__is); 5277*0b57cec5SDimitry Andric __is.flags(ios_base::dec | ios_base::skipws); 5278*0b57cec5SDimitry Andric result_type __k; 5279*0b57cec5SDimitry Andric double __p; 5280*0b57cec5SDimitry Andric __is >> __k >> __p; 5281*0b57cec5SDimitry Andric if (!__is.fail()) 5282*0b57cec5SDimitry Andric __x.param(param_type(__k, __p)); 5283*0b57cec5SDimitry Andric return __is; 5284*0b57cec5SDimitry Andric} 5285*0b57cec5SDimitry Andric 5286*0b57cec5SDimitry Andric// geometric_distribution 5287*0b57cec5SDimitry Andric 5288*0b57cec5SDimitry Andrictemplate<class _IntType = int> 5289*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS geometric_distribution 5290*0b57cec5SDimitry Andric{ 5291*0b57cec5SDimitry Andricpublic: 5292*0b57cec5SDimitry Andric // types 5293*0b57cec5SDimitry Andric typedef _IntType result_type; 5294*0b57cec5SDimitry Andric 5295*0b57cec5SDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 5296*0b57cec5SDimitry Andric { 5297*0b57cec5SDimitry Andric double __p_; 5298*0b57cec5SDimitry Andric public: 5299*0b57cec5SDimitry Andric typedef geometric_distribution distribution_type; 5300*0b57cec5SDimitry Andric 5301*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5302*0b57cec5SDimitry Andric explicit param_type(double __p = 0.5) : __p_(__p) {} 5303*0b57cec5SDimitry Andric 5304*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5305*0b57cec5SDimitry Andric double p() const {return __p_;} 5306*0b57cec5SDimitry Andric 5307*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5308*0b57cec5SDimitry Andric bool operator==(const param_type& __x, const param_type& __y) 5309*0b57cec5SDimitry Andric {return __x.__p_ == __y.__p_;} 5310*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5311*0b57cec5SDimitry Andric bool operator!=(const param_type& __x, const param_type& __y) 5312*0b57cec5SDimitry Andric {return !(__x == __y);} 5313*0b57cec5SDimitry Andric }; 5314*0b57cec5SDimitry Andric 5315*0b57cec5SDimitry Andricprivate: 5316*0b57cec5SDimitry Andric param_type __p_; 5317*0b57cec5SDimitry Andric 5318*0b57cec5SDimitry Andricpublic: 5319*0b57cec5SDimitry Andric // constructors and reset functions 5320*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5321*0b57cec5SDimitry Andric explicit geometric_distribution(double __p = 0.5) : __p_(__p) {} 5322*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5323*0b57cec5SDimitry Andric explicit geometric_distribution(const param_type& __p) : __p_(__p) {} 5324*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5325*0b57cec5SDimitry Andric void reset() {} 5326*0b57cec5SDimitry Andric 5327*0b57cec5SDimitry Andric // generating functions 5328*0b57cec5SDimitry Andric template<class _URNG> 5329*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5330*0b57cec5SDimitry Andric result_type operator()(_URNG& __g) 5331*0b57cec5SDimitry Andric {return (*this)(__g, __p_);} 5332*0b57cec5SDimitry Andric template<class _URNG> 5333*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5334*0b57cec5SDimitry Andric result_type operator()(_URNG& __g, const param_type& __p) 5335*0b57cec5SDimitry Andric {return negative_binomial_distribution<result_type>(1, __p.p())(__g);} 5336*0b57cec5SDimitry Andric 5337*0b57cec5SDimitry Andric // property functions 5338*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5339*0b57cec5SDimitry Andric double p() const {return __p_.p();} 5340*0b57cec5SDimitry Andric 5341*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5342*0b57cec5SDimitry Andric param_type param() const {return __p_;} 5343*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5344*0b57cec5SDimitry Andric void param(const param_type& __p) {__p_ = __p;} 5345*0b57cec5SDimitry Andric 5346*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5347*0b57cec5SDimitry Andric result_type min() const {return 0;} 5348*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5349*0b57cec5SDimitry Andric result_type max() const {return numeric_limits<result_type>::max();} 5350*0b57cec5SDimitry Andric 5351*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5352*0b57cec5SDimitry Andric bool operator==(const geometric_distribution& __x, 5353*0b57cec5SDimitry Andric const geometric_distribution& __y) 5354*0b57cec5SDimitry Andric {return __x.__p_ == __y.__p_;} 5355*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5356*0b57cec5SDimitry Andric bool operator!=(const geometric_distribution& __x, 5357*0b57cec5SDimitry Andric const geometric_distribution& __y) 5358*0b57cec5SDimitry Andric {return !(__x == __y);} 5359*0b57cec5SDimitry Andric}; 5360*0b57cec5SDimitry Andric 5361*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _IntType> 5362*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 5363*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 5364*0b57cec5SDimitry Andric const geometric_distribution<_IntType>& __x) 5365*0b57cec5SDimitry Andric{ 5366*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__os); 5367*0b57cec5SDimitry Andric __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 5368*0b57cec5SDimitry Andric ios_base::scientific); 5369*0b57cec5SDimitry Andric return __os << __x.p(); 5370*0b57cec5SDimitry Andric} 5371*0b57cec5SDimitry Andric 5372*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _IntType> 5373*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 5374*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 5375*0b57cec5SDimitry Andric geometric_distribution<_IntType>& __x) 5376*0b57cec5SDimitry Andric{ 5377*0b57cec5SDimitry Andric typedef geometric_distribution<_IntType> _Eng; 5378*0b57cec5SDimitry Andric typedef typename _Eng::param_type param_type; 5379*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__is); 5380*0b57cec5SDimitry Andric __is.flags(ios_base::dec | ios_base::skipws); 5381*0b57cec5SDimitry Andric double __p; 5382*0b57cec5SDimitry Andric __is >> __p; 5383*0b57cec5SDimitry Andric if (!__is.fail()) 5384*0b57cec5SDimitry Andric __x.param(param_type(__p)); 5385*0b57cec5SDimitry Andric return __is; 5386*0b57cec5SDimitry Andric} 5387*0b57cec5SDimitry Andric 5388*0b57cec5SDimitry Andric// chi_squared_distribution 5389*0b57cec5SDimitry Andric 5390*0b57cec5SDimitry Andrictemplate<class _RealType = double> 5391*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS chi_squared_distribution 5392*0b57cec5SDimitry Andric{ 5393*0b57cec5SDimitry Andricpublic: 5394*0b57cec5SDimitry Andric // types 5395*0b57cec5SDimitry Andric typedef _RealType result_type; 5396*0b57cec5SDimitry Andric 5397*0b57cec5SDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 5398*0b57cec5SDimitry Andric { 5399*0b57cec5SDimitry Andric result_type __n_; 5400*0b57cec5SDimitry Andric public: 5401*0b57cec5SDimitry Andric typedef chi_squared_distribution distribution_type; 5402*0b57cec5SDimitry Andric 5403*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5404*0b57cec5SDimitry Andric explicit param_type(result_type __n = 1) : __n_(__n) {} 5405*0b57cec5SDimitry Andric 5406*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5407*0b57cec5SDimitry Andric result_type n() const {return __n_;} 5408*0b57cec5SDimitry Andric 5409*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5410*0b57cec5SDimitry Andric bool operator==(const param_type& __x, const param_type& __y) 5411*0b57cec5SDimitry Andric {return __x.__n_ == __y.__n_;} 5412*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5413*0b57cec5SDimitry Andric bool operator!=(const param_type& __x, const param_type& __y) 5414*0b57cec5SDimitry Andric {return !(__x == __y);} 5415*0b57cec5SDimitry Andric }; 5416*0b57cec5SDimitry Andric 5417*0b57cec5SDimitry Andricprivate: 5418*0b57cec5SDimitry Andric param_type __p_; 5419*0b57cec5SDimitry Andric 5420*0b57cec5SDimitry Andricpublic: 5421*0b57cec5SDimitry Andric // constructor and reset functions 5422*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5423*0b57cec5SDimitry Andric explicit chi_squared_distribution(result_type __n = 1) 5424*0b57cec5SDimitry Andric : __p_(param_type(__n)) {} 5425*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5426*0b57cec5SDimitry Andric explicit chi_squared_distribution(const param_type& __p) 5427*0b57cec5SDimitry Andric : __p_(__p) {} 5428*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5429*0b57cec5SDimitry Andric void reset() {} 5430*0b57cec5SDimitry Andric 5431*0b57cec5SDimitry Andric // generating functions 5432*0b57cec5SDimitry Andric template<class _URNG> 5433*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5434*0b57cec5SDimitry Andric result_type operator()(_URNG& __g) 5435*0b57cec5SDimitry Andric {return (*this)(__g, __p_);} 5436*0b57cec5SDimitry Andric template<class _URNG> 5437*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5438*0b57cec5SDimitry Andric result_type operator()(_URNG& __g, const param_type& __p) 5439*0b57cec5SDimitry Andric {return gamma_distribution<result_type>(__p.n() / 2, 2)(__g);} 5440*0b57cec5SDimitry Andric 5441*0b57cec5SDimitry Andric // property functions 5442*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5443*0b57cec5SDimitry Andric result_type n() const {return __p_.n();} 5444*0b57cec5SDimitry Andric 5445*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5446*0b57cec5SDimitry Andric param_type param() const {return __p_;} 5447*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5448*0b57cec5SDimitry Andric void param(const param_type& __p) {__p_ = __p;} 5449*0b57cec5SDimitry Andric 5450*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5451*0b57cec5SDimitry Andric result_type min() const {return 0;} 5452*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5453*0b57cec5SDimitry Andric result_type max() const {return numeric_limits<result_type>::infinity();} 5454*0b57cec5SDimitry Andric 5455*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5456*0b57cec5SDimitry Andric bool operator==(const chi_squared_distribution& __x, 5457*0b57cec5SDimitry Andric const chi_squared_distribution& __y) 5458*0b57cec5SDimitry Andric {return __x.__p_ == __y.__p_;} 5459*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5460*0b57cec5SDimitry Andric bool operator!=(const chi_squared_distribution& __x, 5461*0b57cec5SDimitry Andric const chi_squared_distribution& __y) 5462*0b57cec5SDimitry Andric {return !(__x == __y);} 5463*0b57cec5SDimitry Andric}; 5464*0b57cec5SDimitry Andric 5465*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _RT> 5466*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 5467*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 5468*0b57cec5SDimitry Andric const chi_squared_distribution<_RT>& __x) 5469*0b57cec5SDimitry Andric{ 5470*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__os); 5471*0b57cec5SDimitry Andric __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 5472*0b57cec5SDimitry Andric ios_base::scientific); 5473*0b57cec5SDimitry Andric __os << __x.n(); 5474*0b57cec5SDimitry Andric return __os; 5475*0b57cec5SDimitry Andric} 5476*0b57cec5SDimitry Andric 5477*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _RT> 5478*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 5479*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 5480*0b57cec5SDimitry Andric chi_squared_distribution<_RT>& __x) 5481*0b57cec5SDimitry Andric{ 5482*0b57cec5SDimitry Andric typedef chi_squared_distribution<_RT> _Eng; 5483*0b57cec5SDimitry Andric typedef typename _Eng::result_type result_type; 5484*0b57cec5SDimitry Andric typedef typename _Eng::param_type param_type; 5485*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__is); 5486*0b57cec5SDimitry Andric __is.flags(ios_base::dec | ios_base::skipws); 5487*0b57cec5SDimitry Andric result_type __n; 5488*0b57cec5SDimitry Andric __is >> __n; 5489*0b57cec5SDimitry Andric if (!__is.fail()) 5490*0b57cec5SDimitry Andric __x.param(param_type(__n)); 5491*0b57cec5SDimitry Andric return __is; 5492*0b57cec5SDimitry Andric} 5493*0b57cec5SDimitry Andric 5494*0b57cec5SDimitry Andric// cauchy_distribution 5495*0b57cec5SDimitry Andric 5496*0b57cec5SDimitry Andrictemplate<class _RealType = double> 5497*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS cauchy_distribution 5498*0b57cec5SDimitry Andric{ 5499*0b57cec5SDimitry Andricpublic: 5500*0b57cec5SDimitry Andric // types 5501*0b57cec5SDimitry Andric typedef _RealType result_type; 5502*0b57cec5SDimitry Andric 5503*0b57cec5SDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 5504*0b57cec5SDimitry Andric { 5505*0b57cec5SDimitry Andric result_type __a_; 5506*0b57cec5SDimitry Andric result_type __b_; 5507*0b57cec5SDimitry Andric public: 5508*0b57cec5SDimitry Andric typedef cauchy_distribution distribution_type; 5509*0b57cec5SDimitry Andric 5510*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5511*0b57cec5SDimitry Andric explicit param_type(result_type __a = 0, result_type __b = 1) 5512*0b57cec5SDimitry Andric : __a_(__a), __b_(__b) {} 5513*0b57cec5SDimitry Andric 5514*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5515*0b57cec5SDimitry Andric result_type a() const {return __a_;} 5516*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5517*0b57cec5SDimitry Andric result_type b() const {return __b_;} 5518*0b57cec5SDimitry Andric 5519*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5520*0b57cec5SDimitry Andric bool operator==(const param_type& __x, const param_type& __y) 5521*0b57cec5SDimitry Andric {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} 5522*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5523*0b57cec5SDimitry Andric bool operator!=(const param_type& __x, const param_type& __y) 5524*0b57cec5SDimitry Andric {return !(__x == __y);} 5525*0b57cec5SDimitry Andric }; 5526*0b57cec5SDimitry Andric 5527*0b57cec5SDimitry Andricprivate: 5528*0b57cec5SDimitry Andric param_type __p_; 5529*0b57cec5SDimitry Andric 5530*0b57cec5SDimitry Andricpublic: 5531*0b57cec5SDimitry Andric // constructor and reset functions 5532*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5533*0b57cec5SDimitry Andric explicit cauchy_distribution(result_type __a = 0, result_type __b = 1) 5534*0b57cec5SDimitry Andric : __p_(param_type(__a, __b)) {} 5535*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5536*0b57cec5SDimitry Andric explicit cauchy_distribution(const param_type& __p) 5537*0b57cec5SDimitry Andric : __p_(__p) {} 5538*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5539*0b57cec5SDimitry Andric void reset() {} 5540*0b57cec5SDimitry Andric 5541*0b57cec5SDimitry Andric // generating functions 5542*0b57cec5SDimitry Andric template<class _URNG> 5543*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5544*0b57cec5SDimitry Andric result_type operator()(_URNG& __g) 5545*0b57cec5SDimitry Andric {return (*this)(__g, __p_);} 5546*0b57cec5SDimitry Andric template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p); 5547*0b57cec5SDimitry Andric 5548*0b57cec5SDimitry Andric // property functions 5549*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5550*0b57cec5SDimitry Andric result_type a() const {return __p_.a();} 5551*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5552*0b57cec5SDimitry Andric result_type b() const {return __p_.b();} 5553*0b57cec5SDimitry Andric 5554*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5555*0b57cec5SDimitry Andric param_type param() const {return __p_;} 5556*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5557*0b57cec5SDimitry Andric void param(const param_type& __p) {__p_ = __p;} 5558*0b57cec5SDimitry Andric 5559*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5560*0b57cec5SDimitry Andric result_type min() const {return -numeric_limits<result_type>::infinity();} 5561*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5562*0b57cec5SDimitry Andric result_type max() const {return numeric_limits<result_type>::infinity();} 5563*0b57cec5SDimitry Andric 5564*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5565*0b57cec5SDimitry Andric bool operator==(const cauchy_distribution& __x, 5566*0b57cec5SDimitry Andric const cauchy_distribution& __y) 5567*0b57cec5SDimitry Andric {return __x.__p_ == __y.__p_;} 5568*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5569*0b57cec5SDimitry Andric bool operator!=(const cauchy_distribution& __x, 5570*0b57cec5SDimitry Andric const cauchy_distribution& __y) 5571*0b57cec5SDimitry Andric {return !(__x == __y);} 5572*0b57cec5SDimitry Andric}; 5573*0b57cec5SDimitry Andric 5574*0b57cec5SDimitry Andrictemplate <class _RealType> 5575*0b57cec5SDimitry Andrictemplate<class _URNG> 5576*0b57cec5SDimitry Andricinline 5577*0b57cec5SDimitry Andric_RealType 5578*0b57cec5SDimitry Andriccauchy_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 5579*0b57cec5SDimitry Andric{ 5580*0b57cec5SDimitry Andric uniform_real_distribution<result_type> __gen; 5581*0b57cec5SDimitry Andric // purposefully let tan arg get as close to pi/2 as it wants, tan will return a finite 5582*0b57cec5SDimitry Andric return __p.a() + __p.b() * _VSTD::tan(3.1415926535897932384626433832795 * __gen(__g)); 5583*0b57cec5SDimitry Andric} 5584*0b57cec5SDimitry Andric 5585*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _RT> 5586*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 5587*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 5588*0b57cec5SDimitry Andric const cauchy_distribution<_RT>& __x) 5589*0b57cec5SDimitry Andric{ 5590*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__os); 5591*0b57cec5SDimitry Andric __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 5592*0b57cec5SDimitry Andric ios_base::scientific); 5593*0b57cec5SDimitry Andric _CharT __sp = __os.widen(' '); 5594*0b57cec5SDimitry Andric __os.fill(__sp); 5595*0b57cec5SDimitry Andric __os << __x.a() << __sp << __x.b(); 5596*0b57cec5SDimitry Andric return __os; 5597*0b57cec5SDimitry Andric} 5598*0b57cec5SDimitry Andric 5599*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _RT> 5600*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 5601*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 5602*0b57cec5SDimitry Andric cauchy_distribution<_RT>& __x) 5603*0b57cec5SDimitry Andric{ 5604*0b57cec5SDimitry Andric typedef cauchy_distribution<_RT> _Eng; 5605*0b57cec5SDimitry Andric typedef typename _Eng::result_type result_type; 5606*0b57cec5SDimitry Andric typedef typename _Eng::param_type param_type; 5607*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__is); 5608*0b57cec5SDimitry Andric __is.flags(ios_base::dec | ios_base::skipws); 5609*0b57cec5SDimitry Andric result_type __a; 5610*0b57cec5SDimitry Andric result_type __b; 5611*0b57cec5SDimitry Andric __is >> __a >> __b; 5612*0b57cec5SDimitry Andric if (!__is.fail()) 5613*0b57cec5SDimitry Andric __x.param(param_type(__a, __b)); 5614*0b57cec5SDimitry Andric return __is; 5615*0b57cec5SDimitry Andric} 5616*0b57cec5SDimitry Andric 5617*0b57cec5SDimitry Andric// fisher_f_distribution 5618*0b57cec5SDimitry Andric 5619*0b57cec5SDimitry Andrictemplate<class _RealType = double> 5620*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS fisher_f_distribution 5621*0b57cec5SDimitry Andric{ 5622*0b57cec5SDimitry Andricpublic: 5623*0b57cec5SDimitry Andric // types 5624*0b57cec5SDimitry Andric typedef _RealType result_type; 5625*0b57cec5SDimitry Andric 5626*0b57cec5SDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 5627*0b57cec5SDimitry Andric { 5628*0b57cec5SDimitry Andric result_type __m_; 5629*0b57cec5SDimitry Andric result_type __n_; 5630*0b57cec5SDimitry Andric public: 5631*0b57cec5SDimitry Andric typedef fisher_f_distribution distribution_type; 5632*0b57cec5SDimitry Andric 5633*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5634*0b57cec5SDimitry Andric explicit param_type(result_type __m = 1, result_type __n = 1) 5635*0b57cec5SDimitry Andric : __m_(__m), __n_(__n) {} 5636*0b57cec5SDimitry Andric 5637*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5638*0b57cec5SDimitry Andric result_type m() const {return __m_;} 5639*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5640*0b57cec5SDimitry Andric result_type n() const {return __n_;} 5641*0b57cec5SDimitry Andric 5642*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5643*0b57cec5SDimitry Andric bool operator==(const param_type& __x, const param_type& __y) 5644*0b57cec5SDimitry Andric {return __x.__m_ == __y.__m_ && __x.__n_ == __y.__n_;} 5645*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5646*0b57cec5SDimitry Andric bool operator!=(const param_type& __x, const param_type& __y) 5647*0b57cec5SDimitry Andric {return !(__x == __y);} 5648*0b57cec5SDimitry Andric }; 5649*0b57cec5SDimitry Andric 5650*0b57cec5SDimitry Andricprivate: 5651*0b57cec5SDimitry Andric param_type __p_; 5652*0b57cec5SDimitry Andric 5653*0b57cec5SDimitry Andricpublic: 5654*0b57cec5SDimitry Andric // constructor and reset functions 5655*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5656*0b57cec5SDimitry Andric explicit fisher_f_distribution(result_type __m = 1, result_type __n = 1) 5657*0b57cec5SDimitry Andric : __p_(param_type(__m, __n)) {} 5658*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5659*0b57cec5SDimitry Andric explicit fisher_f_distribution(const param_type& __p) 5660*0b57cec5SDimitry Andric : __p_(__p) {} 5661*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5662*0b57cec5SDimitry Andric void reset() {} 5663*0b57cec5SDimitry Andric 5664*0b57cec5SDimitry Andric // generating functions 5665*0b57cec5SDimitry Andric template<class _URNG> 5666*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5667*0b57cec5SDimitry Andric result_type operator()(_URNG& __g) 5668*0b57cec5SDimitry Andric {return (*this)(__g, __p_);} 5669*0b57cec5SDimitry Andric template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 5670*0b57cec5SDimitry Andric 5671*0b57cec5SDimitry Andric // property functions 5672*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5673*0b57cec5SDimitry Andric result_type m() const {return __p_.m();} 5674*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5675*0b57cec5SDimitry Andric result_type n() const {return __p_.n();} 5676*0b57cec5SDimitry Andric 5677*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5678*0b57cec5SDimitry Andric param_type param() const {return __p_;} 5679*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5680*0b57cec5SDimitry Andric void param(const param_type& __p) {__p_ = __p;} 5681*0b57cec5SDimitry Andric 5682*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5683*0b57cec5SDimitry Andric result_type min() const {return 0;} 5684*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5685*0b57cec5SDimitry Andric result_type max() const {return numeric_limits<result_type>::infinity();} 5686*0b57cec5SDimitry Andric 5687*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5688*0b57cec5SDimitry Andric bool operator==(const fisher_f_distribution& __x, 5689*0b57cec5SDimitry Andric const fisher_f_distribution& __y) 5690*0b57cec5SDimitry Andric {return __x.__p_ == __y.__p_;} 5691*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5692*0b57cec5SDimitry Andric bool operator!=(const fisher_f_distribution& __x, 5693*0b57cec5SDimitry Andric const fisher_f_distribution& __y) 5694*0b57cec5SDimitry Andric {return !(__x == __y);} 5695*0b57cec5SDimitry Andric}; 5696*0b57cec5SDimitry Andric 5697*0b57cec5SDimitry Andrictemplate <class _RealType> 5698*0b57cec5SDimitry Andrictemplate<class _URNG> 5699*0b57cec5SDimitry Andric_RealType 5700*0b57cec5SDimitry Andricfisher_f_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 5701*0b57cec5SDimitry Andric{ 5702*0b57cec5SDimitry Andric gamma_distribution<result_type> __gdm(__p.m() * result_type(.5)); 5703*0b57cec5SDimitry Andric gamma_distribution<result_type> __gdn(__p.n() * result_type(.5)); 5704*0b57cec5SDimitry Andric return __p.n() * __gdm(__g) / (__p.m() * __gdn(__g)); 5705*0b57cec5SDimitry Andric} 5706*0b57cec5SDimitry Andric 5707*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _RT> 5708*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 5709*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 5710*0b57cec5SDimitry Andric const fisher_f_distribution<_RT>& __x) 5711*0b57cec5SDimitry Andric{ 5712*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__os); 5713*0b57cec5SDimitry Andric __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 5714*0b57cec5SDimitry Andric ios_base::scientific); 5715*0b57cec5SDimitry Andric _CharT __sp = __os.widen(' '); 5716*0b57cec5SDimitry Andric __os.fill(__sp); 5717*0b57cec5SDimitry Andric __os << __x.m() << __sp << __x.n(); 5718*0b57cec5SDimitry Andric return __os; 5719*0b57cec5SDimitry Andric} 5720*0b57cec5SDimitry Andric 5721*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _RT> 5722*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 5723*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 5724*0b57cec5SDimitry Andric fisher_f_distribution<_RT>& __x) 5725*0b57cec5SDimitry Andric{ 5726*0b57cec5SDimitry Andric typedef fisher_f_distribution<_RT> _Eng; 5727*0b57cec5SDimitry Andric typedef typename _Eng::result_type result_type; 5728*0b57cec5SDimitry Andric typedef typename _Eng::param_type param_type; 5729*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__is); 5730*0b57cec5SDimitry Andric __is.flags(ios_base::dec | ios_base::skipws); 5731*0b57cec5SDimitry Andric result_type __m; 5732*0b57cec5SDimitry Andric result_type __n; 5733*0b57cec5SDimitry Andric __is >> __m >> __n; 5734*0b57cec5SDimitry Andric if (!__is.fail()) 5735*0b57cec5SDimitry Andric __x.param(param_type(__m, __n)); 5736*0b57cec5SDimitry Andric return __is; 5737*0b57cec5SDimitry Andric} 5738*0b57cec5SDimitry Andric 5739*0b57cec5SDimitry Andric// student_t_distribution 5740*0b57cec5SDimitry Andric 5741*0b57cec5SDimitry Andrictemplate<class _RealType = double> 5742*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS student_t_distribution 5743*0b57cec5SDimitry Andric{ 5744*0b57cec5SDimitry Andricpublic: 5745*0b57cec5SDimitry Andric // types 5746*0b57cec5SDimitry Andric typedef _RealType result_type; 5747*0b57cec5SDimitry Andric 5748*0b57cec5SDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 5749*0b57cec5SDimitry Andric { 5750*0b57cec5SDimitry Andric result_type __n_; 5751*0b57cec5SDimitry Andric public: 5752*0b57cec5SDimitry Andric typedef student_t_distribution distribution_type; 5753*0b57cec5SDimitry Andric 5754*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5755*0b57cec5SDimitry Andric explicit param_type(result_type __n = 1) : __n_(__n) {} 5756*0b57cec5SDimitry Andric 5757*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5758*0b57cec5SDimitry Andric result_type n() const {return __n_;} 5759*0b57cec5SDimitry Andric 5760*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5761*0b57cec5SDimitry Andric bool operator==(const param_type& __x, const param_type& __y) 5762*0b57cec5SDimitry Andric {return __x.__n_ == __y.__n_;} 5763*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5764*0b57cec5SDimitry Andric bool operator!=(const param_type& __x, const param_type& __y) 5765*0b57cec5SDimitry Andric {return !(__x == __y);} 5766*0b57cec5SDimitry Andric }; 5767*0b57cec5SDimitry Andric 5768*0b57cec5SDimitry Andricprivate: 5769*0b57cec5SDimitry Andric param_type __p_; 5770*0b57cec5SDimitry Andric normal_distribution<result_type> __nd_; 5771*0b57cec5SDimitry Andric 5772*0b57cec5SDimitry Andricpublic: 5773*0b57cec5SDimitry Andric // constructor and reset functions 5774*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5775*0b57cec5SDimitry Andric explicit student_t_distribution(result_type __n = 1) 5776*0b57cec5SDimitry Andric : __p_(param_type(__n)) {} 5777*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5778*0b57cec5SDimitry Andric explicit student_t_distribution(const param_type& __p) 5779*0b57cec5SDimitry Andric : __p_(__p) {} 5780*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5781*0b57cec5SDimitry Andric void reset() {__nd_.reset();} 5782*0b57cec5SDimitry Andric 5783*0b57cec5SDimitry Andric // generating functions 5784*0b57cec5SDimitry Andric template<class _URNG> 5785*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5786*0b57cec5SDimitry Andric result_type operator()(_URNG& __g) 5787*0b57cec5SDimitry Andric {return (*this)(__g, __p_);} 5788*0b57cec5SDimitry Andric template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 5789*0b57cec5SDimitry Andric 5790*0b57cec5SDimitry Andric // property functions 5791*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5792*0b57cec5SDimitry Andric result_type n() const {return __p_.n();} 5793*0b57cec5SDimitry Andric 5794*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5795*0b57cec5SDimitry Andric param_type param() const {return __p_;} 5796*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5797*0b57cec5SDimitry Andric void param(const param_type& __p) {__p_ = __p;} 5798*0b57cec5SDimitry Andric 5799*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5800*0b57cec5SDimitry Andric result_type min() const {return -numeric_limits<result_type>::infinity();} 5801*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5802*0b57cec5SDimitry Andric result_type max() const {return numeric_limits<result_type>::infinity();} 5803*0b57cec5SDimitry Andric 5804*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5805*0b57cec5SDimitry Andric bool operator==(const student_t_distribution& __x, 5806*0b57cec5SDimitry Andric const student_t_distribution& __y) 5807*0b57cec5SDimitry Andric {return __x.__p_ == __y.__p_;} 5808*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5809*0b57cec5SDimitry Andric bool operator!=(const student_t_distribution& __x, 5810*0b57cec5SDimitry Andric const student_t_distribution& __y) 5811*0b57cec5SDimitry Andric {return !(__x == __y);} 5812*0b57cec5SDimitry Andric}; 5813*0b57cec5SDimitry Andric 5814*0b57cec5SDimitry Andrictemplate <class _RealType> 5815*0b57cec5SDimitry Andrictemplate<class _URNG> 5816*0b57cec5SDimitry Andric_RealType 5817*0b57cec5SDimitry Andricstudent_t_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 5818*0b57cec5SDimitry Andric{ 5819*0b57cec5SDimitry Andric gamma_distribution<result_type> __gd(__p.n() * .5, 2); 5820*0b57cec5SDimitry Andric return __nd_(__g) * _VSTD::sqrt(__p.n()/__gd(__g)); 5821*0b57cec5SDimitry Andric} 5822*0b57cec5SDimitry Andric 5823*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _RT> 5824*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 5825*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 5826*0b57cec5SDimitry Andric const student_t_distribution<_RT>& __x) 5827*0b57cec5SDimitry Andric{ 5828*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__os); 5829*0b57cec5SDimitry Andric __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 5830*0b57cec5SDimitry Andric ios_base::scientific); 5831*0b57cec5SDimitry Andric __os << __x.n(); 5832*0b57cec5SDimitry Andric return __os; 5833*0b57cec5SDimitry Andric} 5834*0b57cec5SDimitry Andric 5835*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _RT> 5836*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 5837*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 5838*0b57cec5SDimitry Andric student_t_distribution<_RT>& __x) 5839*0b57cec5SDimitry Andric{ 5840*0b57cec5SDimitry Andric typedef student_t_distribution<_RT> _Eng; 5841*0b57cec5SDimitry Andric typedef typename _Eng::result_type result_type; 5842*0b57cec5SDimitry Andric typedef typename _Eng::param_type param_type; 5843*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__is); 5844*0b57cec5SDimitry Andric __is.flags(ios_base::dec | ios_base::skipws); 5845*0b57cec5SDimitry Andric result_type __n; 5846*0b57cec5SDimitry Andric __is >> __n; 5847*0b57cec5SDimitry Andric if (!__is.fail()) 5848*0b57cec5SDimitry Andric __x.param(param_type(__n)); 5849*0b57cec5SDimitry Andric return __is; 5850*0b57cec5SDimitry Andric} 5851*0b57cec5SDimitry Andric 5852*0b57cec5SDimitry Andric// discrete_distribution 5853*0b57cec5SDimitry Andric 5854*0b57cec5SDimitry Andrictemplate<class _IntType = int> 5855*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS discrete_distribution 5856*0b57cec5SDimitry Andric{ 5857*0b57cec5SDimitry Andricpublic: 5858*0b57cec5SDimitry Andric // types 5859*0b57cec5SDimitry Andric typedef _IntType result_type; 5860*0b57cec5SDimitry Andric 5861*0b57cec5SDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 5862*0b57cec5SDimitry Andric { 5863*0b57cec5SDimitry Andric vector<double> __p_; 5864*0b57cec5SDimitry Andric public: 5865*0b57cec5SDimitry Andric typedef discrete_distribution distribution_type; 5866*0b57cec5SDimitry Andric 5867*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5868*0b57cec5SDimitry Andric param_type() {} 5869*0b57cec5SDimitry Andric template<class _InputIterator> 5870*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5871*0b57cec5SDimitry Andric param_type(_InputIterator __f, _InputIterator __l) 5872*0b57cec5SDimitry Andric : __p_(__f, __l) {__init();} 5873*0b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 5874*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5875*0b57cec5SDimitry Andric param_type(initializer_list<double> __wl) 5876*0b57cec5SDimitry Andric : __p_(__wl.begin(), __wl.end()) {__init();} 5877*0b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 5878*0b57cec5SDimitry Andric template<class _UnaryOperation> 5879*0b57cec5SDimitry Andric param_type(size_t __nw, double __xmin, double __xmax, 5880*0b57cec5SDimitry Andric _UnaryOperation __fw); 5881*0b57cec5SDimitry Andric 5882*0b57cec5SDimitry Andric vector<double> probabilities() const; 5883*0b57cec5SDimitry Andric 5884*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5885*0b57cec5SDimitry Andric bool operator==(const param_type& __x, const param_type& __y) 5886*0b57cec5SDimitry Andric {return __x.__p_ == __y.__p_;} 5887*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5888*0b57cec5SDimitry Andric bool operator!=(const param_type& __x, const param_type& __y) 5889*0b57cec5SDimitry Andric {return !(__x == __y);} 5890*0b57cec5SDimitry Andric 5891*0b57cec5SDimitry Andric private: 5892*0b57cec5SDimitry Andric void __init(); 5893*0b57cec5SDimitry Andric 5894*0b57cec5SDimitry Andric friend class discrete_distribution; 5895*0b57cec5SDimitry Andric 5896*0b57cec5SDimitry Andric template <class _CharT, class _Traits, class _IT> 5897*0b57cec5SDimitry Andric friend 5898*0b57cec5SDimitry Andric basic_ostream<_CharT, _Traits>& 5899*0b57cec5SDimitry Andric operator<<(basic_ostream<_CharT, _Traits>& __os, 5900*0b57cec5SDimitry Andric const discrete_distribution<_IT>& __x); 5901*0b57cec5SDimitry Andric 5902*0b57cec5SDimitry Andric template <class _CharT, class _Traits, class _IT> 5903*0b57cec5SDimitry Andric friend 5904*0b57cec5SDimitry Andric basic_istream<_CharT, _Traits>& 5905*0b57cec5SDimitry Andric operator>>(basic_istream<_CharT, _Traits>& __is, 5906*0b57cec5SDimitry Andric discrete_distribution<_IT>& __x); 5907*0b57cec5SDimitry Andric }; 5908*0b57cec5SDimitry Andric 5909*0b57cec5SDimitry Andricprivate: 5910*0b57cec5SDimitry Andric param_type __p_; 5911*0b57cec5SDimitry Andric 5912*0b57cec5SDimitry Andricpublic: 5913*0b57cec5SDimitry Andric // constructor and reset functions 5914*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5915*0b57cec5SDimitry Andric discrete_distribution() {} 5916*0b57cec5SDimitry Andric template<class _InputIterator> 5917*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5918*0b57cec5SDimitry Andric discrete_distribution(_InputIterator __f, _InputIterator __l) 5919*0b57cec5SDimitry Andric : __p_(__f, __l) {} 5920*0b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 5921*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5922*0b57cec5SDimitry Andric discrete_distribution(initializer_list<double> __wl) 5923*0b57cec5SDimitry Andric : __p_(__wl) {} 5924*0b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 5925*0b57cec5SDimitry Andric template<class _UnaryOperation> 5926*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5927*0b57cec5SDimitry Andric discrete_distribution(size_t __nw, double __xmin, double __xmax, 5928*0b57cec5SDimitry Andric _UnaryOperation __fw) 5929*0b57cec5SDimitry Andric : __p_(__nw, __xmin, __xmax, __fw) {} 5930*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5931*0b57cec5SDimitry Andric explicit discrete_distribution(const param_type& __p) 5932*0b57cec5SDimitry Andric : __p_(__p) {} 5933*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5934*0b57cec5SDimitry Andric void reset() {} 5935*0b57cec5SDimitry Andric 5936*0b57cec5SDimitry Andric // generating functions 5937*0b57cec5SDimitry Andric template<class _URNG> 5938*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5939*0b57cec5SDimitry Andric result_type operator()(_URNG& __g) 5940*0b57cec5SDimitry Andric {return (*this)(__g, __p_);} 5941*0b57cec5SDimitry Andric template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 5942*0b57cec5SDimitry Andric 5943*0b57cec5SDimitry Andric // property functions 5944*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5945*0b57cec5SDimitry Andric vector<double> probabilities() const {return __p_.probabilities();} 5946*0b57cec5SDimitry Andric 5947*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5948*0b57cec5SDimitry Andric param_type param() const {return __p_;} 5949*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5950*0b57cec5SDimitry Andric void param(const param_type& __p) {__p_ = __p;} 5951*0b57cec5SDimitry Andric 5952*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5953*0b57cec5SDimitry Andric result_type min() const {return 0;} 5954*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5955*0b57cec5SDimitry Andric result_type max() const {return __p_.__p_.size();} 5956*0b57cec5SDimitry Andric 5957*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5958*0b57cec5SDimitry Andric bool operator==(const discrete_distribution& __x, 5959*0b57cec5SDimitry Andric const discrete_distribution& __y) 5960*0b57cec5SDimitry Andric {return __x.__p_ == __y.__p_;} 5961*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5962*0b57cec5SDimitry Andric bool operator!=(const discrete_distribution& __x, 5963*0b57cec5SDimitry Andric const discrete_distribution& __y) 5964*0b57cec5SDimitry Andric {return !(__x == __y);} 5965*0b57cec5SDimitry Andric 5966*0b57cec5SDimitry Andric template <class _CharT, class _Traits, class _IT> 5967*0b57cec5SDimitry Andric friend 5968*0b57cec5SDimitry Andric basic_ostream<_CharT, _Traits>& 5969*0b57cec5SDimitry Andric operator<<(basic_ostream<_CharT, _Traits>& __os, 5970*0b57cec5SDimitry Andric const discrete_distribution<_IT>& __x); 5971*0b57cec5SDimitry Andric 5972*0b57cec5SDimitry Andric template <class _CharT, class _Traits, class _IT> 5973*0b57cec5SDimitry Andric friend 5974*0b57cec5SDimitry Andric basic_istream<_CharT, _Traits>& 5975*0b57cec5SDimitry Andric operator>>(basic_istream<_CharT, _Traits>& __is, 5976*0b57cec5SDimitry Andric discrete_distribution<_IT>& __x); 5977*0b57cec5SDimitry Andric}; 5978*0b57cec5SDimitry Andric 5979*0b57cec5SDimitry Andrictemplate<class _IntType> 5980*0b57cec5SDimitry Andrictemplate<class _UnaryOperation> 5981*0b57cec5SDimitry Andricdiscrete_distribution<_IntType>::param_type::param_type(size_t __nw, 5982*0b57cec5SDimitry Andric double __xmin, 5983*0b57cec5SDimitry Andric double __xmax, 5984*0b57cec5SDimitry Andric _UnaryOperation __fw) 5985*0b57cec5SDimitry Andric{ 5986*0b57cec5SDimitry Andric if (__nw > 1) 5987*0b57cec5SDimitry Andric { 5988*0b57cec5SDimitry Andric __p_.reserve(__nw - 1); 5989*0b57cec5SDimitry Andric double __d = (__xmax - __xmin) / __nw; 5990*0b57cec5SDimitry Andric double __d2 = __d / 2; 5991*0b57cec5SDimitry Andric for (size_t __k = 0; __k < __nw; ++__k) 5992*0b57cec5SDimitry Andric __p_.push_back(__fw(__xmin + __k * __d + __d2)); 5993*0b57cec5SDimitry Andric __init(); 5994*0b57cec5SDimitry Andric } 5995*0b57cec5SDimitry Andric} 5996*0b57cec5SDimitry Andric 5997*0b57cec5SDimitry Andrictemplate<class _IntType> 5998*0b57cec5SDimitry Andricvoid 5999*0b57cec5SDimitry Andricdiscrete_distribution<_IntType>::param_type::__init() 6000*0b57cec5SDimitry Andric{ 6001*0b57cec5SDimitry Andric if (!__p_.empty()) 6002*0b57cec5SDimitry Andric { 6003*0b57cec5SDimitry Andric if (__p_.size() > 1) 6004*0b57cec5SDimitry Andric { 6005*0b57cec5SDimitry Andric double __s = _VSTD::accumulate(__p_.begin(), __p_.end(), 0.0); 6006*0b57cec5SDimitry Andric for (_VSTD::vector<double>::iterator __i = __p_.begin(), __e = __p_.end(); 6007*0b57cec5SDimitry Andric __i < __e; ++__i) 6008*0b57cec5SDimitry Andric *__i /= __s; 6009*0b57cec5SDimitry Andric vector<double> __t(__p_.size() - 1); 6010*0b57cec5SDimitry Andric _VSTD::partial_sum(__p_.begin(), __p_.end() - 1, __t.begin()); 6011*0b57cec5SDimitry Andric swap(__p_, __t); 6012*0b57cec5SDimitry Andric } 6013*0b57cec5SDimitry Andric else 6014*0b57cec5SDimitry Andric { 6015*0b57cec5SDimitry Andric __p_.clear(); 6016*0b57cec5SDimitry Andric __p_.shrink_to_fit(); 6017*0b57cec5SDimitry Andric } 6018*0b57cec5SDimitry Andric } 6019*0b57cec5SDimitry Andric} 6020*0b57cec5SDimitry Andric 6021*0b57cec5SDimitry Andrictemplate<class _IntType> 6022*0b57cec5SDimitry Andricvector<double> 6023*0b57cec5SDimitry Andricdiscrete_distribution<_IntType>::param_type::probabilities() const 6024*0b57cec5SDimitry Andric{ 6025*0b57cec5SDimitry Andric size_t __n = __p_.size(); 6026*0b57cec5SDimitry Andric _VSTD::vector<double> __p(__n+1); 6027*0b57cec5SDimitry Andric _VSTD::adjacent_difference(__p_.begin(), __p_.end(), __p.begin()); 6028*0b57cec5SDimitry Andric if (__n > 0) 6029*0b57cec5SDimitry Andric __p[__n] = 1 - __p_[__n-1]; 6030*0b57cec5SDimitry Andric else 6031*0b57cec5SDimitry Andric __p[0] = 1; 6032*0b57cec5SDimitry Andric return __p; 6033*0b57cec5SDimitry Andric} 6034*0b57cec5SDimitry Andric 6035*0b57cec5SDimitry Andrictemplate<class _IntType> 6036*0b57cec5SDimitry Andrictemplate<class _URNG> 6037*0b57cec5SDimitry Andric_IntType 6038*0b57cec5SDimitry Andricdiscrete_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p) 6039*0b57cec5SDimitry Andric{ 6040*0b57cec5SDimitry Andric uniform_real_distribution<double> __gen; 6041*0b57cec5SDimitry Andric return static_cast<_IntType>( 6042*0b57cec5SDimitry Andric _VSTD::upper_bound(__p.__p_.begin(), __p.__p_.end(), __gen(__g)) - 6043*0b57cec5SDimitry Andric __p.__p_.begin()); 6044*0b57cec5SDimitry Andric} 6045*0b57cec5SDimitry Andric 6046*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _IT> 6047*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 6048*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 6049*0b57cec5SDimitry Andric const discrete_distribution<_IT>& __x) 6050*0b57cec5SDimitry Andric{ 6051*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__os); 6052*0b57cec5SDimitry Andric __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 6053*0b57cec5SDimitry Andric ios_base::scientific); 6054*0b57cec5SDimitry Andric _CharT __sp = __os.widen(' '); 6055*0b57cec5SDimitry Andric __os.fill(__sp); 6056*0b57cec5SDimitry Andric size_t __n = __x.__p_.__p_.size(); 6057*0b57cec5SDimitry Andric __os << __n; 6058*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __n; ++__i) 6059*0b57cec5SDimitry Andric __os << __sp << __x.__p_.__p_[__i]; 6060*0b57cec5SDimitry Andric return __os; 6061*0b57cec5SDimitry Andric} 6062*0b57cec5SDimitry Andric 6063*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _IT> 6064*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 6065*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 6066*0b57cec5SDimitry Andric discrete_distribution<_IT>& __x) 6067*0b57cec5SDimitry Andric{ 6068*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__is); 6069*0b57cec5SDimitry Andric __is.flags(ios_base::dec | ios_base::skipws); 6070*0b57cec5SDimitry Andric size_t __n; 6071*0b57cec5SDimitry Andric __is >> __n; 6072*0b57cec5SDimitry Andric vector<double> __p(__n); 6073*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __n; ++__i) 6074*0b57cec5SDimitry Andric __is >> __p[__i]; 6075*0b57cec5SDimitry Andric if (!__is.fail()) 6076*0b57cec5SDimitry Andric swap(__x.__p_.__p_, __p); 6077*0b57cec5SDimitry Andric return __is; 6078*0b57cec5SDimitry Andric} 6079*0b57cec5SDimitry Andric 6080*0b57cec5SDimitry Andric// piecewise_constant_distribution 6081*0b57cec5SDimitry Andric 6082*0b57cec5SDimitry Andrictemplate<class _RealType = double> 6083*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS piecewise_constant_distribution 6084*0b57cec5SDimitry Andric{ 6085*0b57cec5SDimitry Andricpublic: 6086*0b57cec5SDimitry Andric // types 6087*0b57cec5SDimitry Andric typedef _RealType result_type; 6088*0b57cec5SDimitry Andric 6089*0b57cec5SDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 6090*0b57cec5SDimitry Andric { 6091*0b57cec5SDimitry Andric vector<result_type> __b_; 6092*0b57cec5SDimitry Andric vector<result_type> __densities_; 6093*0b57cec5SDimitry Andric vector<result_type> __areas_; 6094*0b57cec5SDimitry Andric public: 6095*0b57cec5SDimitry Andric typedef piecewise_constant_distribution distribution_type; 6096*0b57cec5SDimitry Andric 6097*0b57cec5SDimitry Andric param_type(); 6098*0b57cec5SDimitry Andric template<class _InputIteratorB, class _InputIteratorW> 6099*0b57cec5SDimitry Andric param_type(_InputIteratorB __fB, _InputIteratorB __lB, 6100*0b57cec5SDimitry Andric _InputIteratorW __fW); 6101*0b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 6102*0b57cec5SDimitry Andric template<class _UnaryOperation> 6103*0b57cec5SDimitry Andric param_type(initializer_list<result_type> __bl, _UnaryOperation __fw); 6104*0b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 6105*0b57cec5SDimitry Andric template<class _UnaryOperation> 6106*0b57cec5SDimitry Andric param_type(size_t __nw, result_type __xmin, result_type __xmax, 6107*0b57cec5SDimitry Andric _UnaryOperation __fw); 6108*0b57cec5SDimitry Andric param_type & operator=(const param_type& __rhs); 6109*0b57cec5SDimitry Andric 6110*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6111*0b57cec5SDimitry Andric vector<result_type> intervals() const {return __b_;} 6112*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6113*0b57cec5SDimitry Andric vector<result_type> densities() const {return __densities_;} 6114*0b57cec5SDimitry Andric 6115*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 6116*0b57cec5SDimitry Andric bool operator==(const param_type& __x, const param_type& __y) 6117*0b57cec5SDimitry Andric {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;} 6118*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 6119*0b57cec5SDimitry Andric bool operator!=(const param_type& __x, const param_type& __y) 6120*0b57cec5SDimitry Andric {return !(__x == __y);} 6121*0b57cec5SDimitry Andric 6122*0b57cec5SDimitry Andric private: 6123*0b57cec5SDimitry Andric void __init(); 6124*0b57cec5SDimitry Andric 6125*0b57cec5SDimitry Andric friend class piecewise_constant_distribution; 6126*0b57cec5SDimitry Andric 6127*0b57cec5SDimitry Andric template <class _CharT, class _Traits, class _RT> 6128*0b57cec5SDimitry Andric friend 6129*0b57cec5SDimitry Andric basic_ostream<_CharT, _Traits>& 6130*0b57cec5SDimitry Andric operator<<(basic_ostream<_CharT, _Traits>& __os, 6131*0b57cec5SDimitry Andric const piecewise_constant_distribution<_RT>& __x); 6132*0b57cec5SDimitry Andric 6133*0b57cec5SDimitry Andric template <class _CharT, class _Traits, class _RT> 6134*0b57cec5SDimitry Andric friend 6135*0b57cec5SDimitry Andric basic_istream<_CharT, _Traits>& 6136*0b57cec5SDimitry Andric operator>>(basic_istream<_CharT, _Traits>& __is, 6137*0b57cec5SDimitry Andric piecewise_constant_distribution<_RT>& __x); 6138*0b57cec5SDimitry Andric }; 6139*0b57cec5SDimitry Andric 6140*0b57cec5SDimitry Andricprivate: 6141*0b57cec5SDimitry Andric param_type __p_; 6142*0b57cec5SDimitry Andric 6143*0b57cec5SDimitry Andricpublic: 6144*0b57cec5SDimitry Andric // constructor and reset functions 6145*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6146*0b57cec5SDimitry Andric piecewise_constant_distribution() {} 6147*0b57cec5SDimitry Andric template<class _InputIteratorB, class _InputIteratorW> 6148*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6149*0b57cec5SDimitry Andric piecewise_constant_distribution(_InputIteratorB __fB, 6150*0b57cec5SDimitry Andric _InputIteratorB __lB, 6151*0b57cec5SDimitry Andric _InputIteratorW __fW) 6152*0b57cec5SDimitry Andric : __p_(__fB, __lB, __fW) {} 6153*0b57cec5SDimitry Andric 6154*0b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 6155*0b57cec5SDimitry Andric template<class _UnaryOperation> 6156*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6157*0b57cec5SDimitry Andric piecewise_constant_distribution(initializer_list<result_type> __bl, 6158*0b57cec5SDimitry Andric _UnaryOperation __fw) 6159*0b57cec5SDimitry Andric : __p_(__bl, __fw) {} 6160*0b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 6161*0b57cec5SDimitry Andric 6162*0b57cec5SDimitry Andric template<class _UnaryOperation> 6163*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6164*0b57cec5SDimitry Andric piecewise_constant_distribution(size_t __nw, result_type __xmin, 6165*0b57cec5SDimitry Andric result_type __xmax, _UnaryOperation __fw) 6166*0b57cec5SDimitry Andric : __p_(__nw, __xmin, __xmax, __fw) {} 6167*0b57cec5SDimitry Andric 6168*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6169*0b57cec5SDimitry Andric explicit piecewise_constant_distribution(const param_type& __p) 6170*0b57cec5SDimitry Andric : __p_(__p) {} 6171*0b57cec5SDimitry Andric 6172*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6173*0b57cec5SDimitry Andric void reset() {} 6174*0b57cec5SDimitry Andric 6175*0b57cec5SDimitry Andric // generating functions 6176*0b57cec5SDimitry Andric template<class _URNG> 6177*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6178*0b57cec5SDimitry Andric result_type operator()(_URNG& __g) 6179*0b57cec5SDimitry Andric {return (*this)(__g, __p_);} 6180*0b57cec5SDimitry Andric template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 6181*0b57cec5SDimitry Andric 6182*0b57cec5SDimitry Andric // property functions 6183*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6184*0b57cec5SDimitry Andric vector<result_type> intervals() const {return __p_.intervals();} 6185*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6186*0b57cec5SDimitry Andric vector<result_type> densities() const {return __p_.densities();} 6187*0b57cec5SDimitry Andric 6188*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6189*0b57cec5SDimitry Andric param_type param() const {return __p_;} 6190*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6191*0b57cec5SDimitry Andric void param(const param_type& __p) {__p_ = __p;} 6192*0b57cec5SDimitry Andric 6193*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6194*0b57cec5SDimitry Andric result_type min() const {return __p_.__b_.front();} 6195*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6196*0b57cec5SDimitry Andric result_type max() const {return __p_.__b_.back();} 6197*0b57cec5SDimitry Andric 6198*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 6199*0b57cec5SDimitry Andric bool operator==(const piecewise_constant_distribution& __x, 6200*0b57cec5SDimitry Andric const piecewise_constant_distribution& __y) 6201*0b57cec5SDimitry Andric {return __x.__p_ == __y.__p_;} 6202*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 6203*0b57cec5SDimitry Andric bool operator!=(const piecewise_constant_distribution& __x, 6204*0b57cec5SDimitry Andric const piecewise_constant_distribution& __y) 6205*0b57cec5SDimitry Andric {return !(__x == __y);} 6206*0b57cec5SDimitry Andric 6207*0b57cec5SDimitry Andric template <class _CharT, class _Traits, class _RT> 6208*0b57cec5SDimitry Andric friend 6209*0b57cec5SDimitry Andric basic_ostream<_CharT, _Traits>& 6210*0b57cec5SDimitry Andric operator<<(basic_ostream<_CharT, _Traits>& __os, 6211*0b57cec5SDimitry Andric const piecewise_constant_distribution<_RT>& __x); 6212*0b57cec5SDimitry Andric 6213*0b57cec5SDimitry Andric template <class _CharT, class _Traits, class _RT> 6214*0b57cec5SDimitry Andric friend 6215*0b57cec5SDimitry Andric basic_istream<_CharT, _Traits>& 6216*0b57cec5SDimitry Andric operator>>(basic_istream<_CharT, _Traits>& __is, 6217*0b57cec5SDimitry Andric piecewise_constant_distribution<_RT>& __x); 6218*0b57cec5SDimitry Andric}; 6219*0b57cec5SDimitry Andric 6220*0b57cec5SDimitry Andrictemplate<class _RealType> 6221*0b57cec5SDimitry Andrictypename piecewise_constant_distribution<_RealType>::param_type & 6222*0b57cec5SDimitry Andricpiecewise_constant_distribution<_RealType>::param_type::operator= 6223*0b57cec5SDimitry Andric (const param_type& __rhs) 6224*0b57cec5SDimitry Andric{ 6225*0b57cec5SDimitry Andric// These can throw 6226*0b57cec5SDimitry Andric __b_.reserve (__rhs.__b_.size ()); 6227*0b57cec5SDimitry Andric __densities_.reserve(__rhs.__densities_.size()); 6228*0b57cec5SDimitry Andric __areas_.reserve (__rhs.__areas_.size()); 6229*0b57cec5SDimitry Andric 6230*0b57cec5SDimitry Andric// These can not throw 6231*0b57cec5SDimitry Andric __b_ = __rhs.__b_; 6232*0b57cec5SDimitry Andric __densities_ = __rhs.__densities_; 6233*0b57cec5SDimitry Andric __areas_ = __rhs.__areas_; 6234*0b57cec5SDimitry Andric return *this; 6235*0b57cec5SDimitry Andric} 6236*0b57cec5SDimitry Andric 6237*0b57cec5SDimitry Andrictemplate<class _RealType> 6238*0b57cec5SDimitry Andricvoid 6239*0b57cec5SDimitry Andricpiecewise_constant_distribution<_RealType>::param_type::__init() 6240*0b57cec5SDimitry Andric{ 6241*0b57cec5SDimitry Andric // __densities_ contains non-normalized areas 6242*0b57cec5SDimitry Andric result_type __total_area = _VSTD::accumulate(__densities_.begin(), 6243*0b57cec5SDimitry Andric __densities_.end(), 6244*0b57cec5SDimitry Andric result_type()); 6245*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __densities_.size(); ++__i) 6246*0b57cec5SDimitry Andric __densities_[__i] /= __total_area; 6247*0b57cec5SDimitry Andric // __densities_ contains normalized areas 6248*0b57cec5SDimitry Andric __areas_.assign(__densities_.size(), result_type()); 6249*0b57cec5SDimitry Andric _VSTD::partial_sum(__densities_.begin(), __densities_.end() - 1, 6250*0b57cec5SDimitry Andric __areas_.begin() + 1); 6251*0b57cec5SDimitry Andric // __areas_ contains partial sums of normalized areas: [0, __densities_ - 1] 6252*0b57cec5SDimitry Andric __densities_.back() = 1 - __areas_.back(); // correct round off error 6253*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __densities_.size(); ++__i) 6254*0b57cec5SDimitry Andric __densities_[__i] /= (__b_[__i+1] - __b_[__i]); 6255*0b57cec5SDimitry Andric // __densities_ now contains __densities_ 6256*0b57cec5SDimitry Andric} 6257*0b57cec5SDimitry Andric 6258*0b57cec5SDimitry Andrictemplate<class _RealType> 6259*0b57cec5SDimitry Andricpiecewise_constant_distribution<_RealType>::param_type::param_type() 6260*0b57cec5SDimitry Andric : __b_(2), 6261*0b57cec5SDimitry Andric __densities_(1, 1.0), 6262*0b57cec5SDimitry Andric __areas_(1, 0.0) 6263*0b57cec5SDimitry Andric{ 6264*0b57cec5SDimitry Andric __b_[1] = 1; 6265*0b57cec5SDimitry Andric} 6266*0b57cec5SDimitry Andric 6267*0b57cec5SDimitry Andrictemplate<class _RealType> 6268*0b57cec5SDimitry Andrictemplate<class _InputIteratorB, class _InputIteratorW> 6269*0b57cec5SDimitry Andricpiecewise_constant_distribution<_RealType>::param_type::param_type( 6270*0b57cec5SDimitry Andric _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW) 6271*0b57cec5SDimitry Andric : __b_(__fB, __lB) 6272*0b57cec5SDimitry Andric{ 6273*0b57cec5SDimitry Andric if (__b_.size() < 2) 6274*0b57cec5SDimitry Andric { 6275*0b57cec5SDimitry Andric __b_.resize(2); 6276*0b57cec5SDimitry Andric __b_[0] = 0; 6277*0b57cec5SDimitry Andric __b_[1] = 1; 6278*0b57cec5SDimitry Andric __densities_.assign(1, 1.0); 6279*0b57cec5SDimitry Andric __areas_.assign(1, 0.0); 6280*0b57cec5SDimitry Andric } 6281*0b57cec5SDimitry Andric else 6282*0b57cec5SDimitry Andric { 6283*0b57cec5SDimitry Andric __densities_.reserve(__b_.size() - 1); 6284*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __b_.size() - 1; ++__i, ++__fW) 6285*0b57cec5SDimitry Andric __densities_.push_back(*__fW); 6286*0b57cec5SDimitry Andric __init(); 6287*0b57cec5SDimitry Andric } 6288*0b57cec5SDimitry Andric} 6289*0b57cec5SDimitry Andric 6290*0b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 6291*0b57cec5SDimitry Andric 6292*0b57cec5SDimitry Andrictemplate<class _RealType> 6293*0b57cec5SDimitry Andrictemplate<class _UnaryOperation> 6294*0b57cec5SDimitry Andricpiecewise_constant_distribution<_RealType>::param_type::param_type( 6295*0b57cec5SDimitry Andric initializer_list<result_type> __bl, _UnaryOperation __fw) 6296*0b57cec5SDimitry Andric : __b_(__bl.begin(), __bl.end()) 6297*0b57cec5SDimitry Andric{ 6298*0b57cec5SDimitry Andric if (__b_.size() < 2) 6299*0b57cec5SDimitry Andric { 6300*0b57cec5SDimitry Andric __b_.resize(2); 6301*0b57cec5SDimitry Andric __b_[0] = 0; 6302*0b57cec5SDimitry Andric __b_[1] = 1; 6303*0b57cec5SDimitry Andric __densities_.assign(1, 1.0); 6304*0b57cec5SDimitry Andric __areas_.assign(1, 0.0); 6305*0b57cec5SDimitry Andric } 6306*0b57cec5SDimitry Andric else 6307*0b57cec5SDimitry Andric { 6308*0b57cec5SDimitry Andric __densities_.reserve(__b_.size() - 1); 6309*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __b_.size() - 1; ++__i) 6310*0b57cec5SDimitry Andric __densities_.push_back(__fw((__b_[__i+1] + __b_[__i])*.5)); 6311*0b57cec5SDimitry Andric __init(); 6312*0b57cec5SDimitry Andric } 6313*0b57cec5SDimitry Andric} 6314*0b57cec5SDimitry Andric 6315*0b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 6316*0b57cec5SDimitry Andric 6317*0b57cec5SDimitry Andrictemplate<class _RealType> 6318*0b57cec5SDimitry Andrictemplate<class _UnaryOperation> 6319*0b57cec5SDimitry Andricpiecewise_constant_distribution<_RealType>::param_type::param_type( 6320*0b57cec5SDimitry Andric size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw) 6321*0b57cec5SDimitry Andric : __b_(__nw == 0 ? 2 : __nw + 1) 6322*0b57cec5SDimitry Andric{ 6323*0b57cec5SDimitry Andric size_t __n = __b_.size() - 1; 6324*0b57cec5SDimitry Andric result_type __d = (__xmax - __xmin) / __n; 6325*0b57cec5SDimitry Andric __densities_.reserve(__n); 6326*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __n; ++__i) 6327*0b57cec5SDimitry Andric { 6328*0b57cec5SDimitry Andric __b_[__i] = __xmin + __i * __d; 6329*0b57cec5SDimitry Andric __densities_.push_back(__fw(__b_[__i] + __d*.5)); 6330*0b57cec5SDimitry Andric } 6331*0b57cec5SDimitry Andric __b_[__n] = __xmax; 6332*0b57cec5SDimitry Andric __init(); 6333*0b57cec5SDimitry Andric} 6334*0b57cec5SDimitry Andric 6335*0b57cec5SDimitry Andrictemplate<class _RealType> 6336*0b57cec5SDimitry Andrictemplate<class _URNG> 6337*0b57cec5SDimitry Andric_RealType 6338*0b57cec5SDimitry Andricpiecewise_constant_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 6339*0b57cec5SDimitry Andric{ 6340*0b57cec5SDimitry Andric typedef uniform_real_distribution<result_type> _Gen; 6341*0b57cec5SDimitry Andric result_type __u = _Gen()(__g); 6342*0b57cec5SDimitry Andric ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(), 6343*0b57cec5SDimitry Andric __u) - __p.__areas_.begin() - 1; 6344*0b57cec5SDimitry Andric return (__u - __p.__areas_[__k]) / __p.__densities_[__k] + __p.__b_[__k]; 6345*0b57cec5SDimitry Andric} 6346*0b57cec5SDimitry Andric 6347*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _RT> 6348*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 6349*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 6350*0b57cec5SDimitry Andric const piecewise_constant_distribution<_RT>& __x) 6351*0b57cec5SDimitry Andric{ 6352*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__os); 6353*0b57cec5SDimitry Andric __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 6354*0b57cec5SDimitry Andric ios_base::scientific); 6355*0b57cec5SDimitry Andric _CharT __sp = __os.widen(' '); 6356*0b57cec5SDimitry Andric __os.fill(__sp); 6357*0b57cec5SDimitry Andric size_t __n = __x.__p_.__b_.size(); 6358*0b57cec5SDimitry Andric __os << __n; 6359*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __n; ++__i) 6360*0b57cec5SDimitry Andric __os << __sp << __x.__p_.__b_[__i]; 6361*0b57cec5SDimitry Andric __n = __x.__p_.__densities_.size(); 6362*0b57cec5SDimitry Andric __os << __sp << __n; 6363*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __n; ++__i) 6364*0b57cec5SDimitry Andric __os << __sp << __x.__p_.__densities_[__i]; 6365*0b57cec5SDimitry Andric __n = __x.__p_.__areas_.size(); 6366*0b57cec5SDimitry Andric __os << __sp << __n; 6367*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __n; ++__i) 6368*0b57cec5SDimitry Andric __os << __sp << __x.__p_.__areas_[__i]; 6369*0b57cec5SDimitry Andric return __os; 6370*0b57cec5SDimitry Andric} 6371*0b57cec5SDimitry Andric 6372*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _RT> 6373*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 6374*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 6375*0b57cec5SDimitry Andric piecewise_constant_distribution<_RT>& __x) 6376*0b57cec5SDimitry Andric{ 6377*0b57cec5SDimitry Andric typedef piecewise_constant_distribution<_RT> _Eng; 6378*0b57cec5SDimitry Andric typedef typename _Eng::result_type result_type; 6379*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__is); 6380*0b57cec5SDimitry Andric __is.flags(ios_base::dec | ios_base::skipws); 6381*0b57cec5SDimitry Andric size_t __n; 6382*0b57cec5SDimitry Andric __is >> __n; 6383*0b57cec5SDimitry Andric vector<result_type> __b(__n); 6384*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __n; ++__i) 6385*0b57cec5SDimitry Andric __is >> __b[__i]; 6386*0b57cec5SDimitry Andric __is >> __n; 6387*0b57cec5SDimitry Andric vector<result_type> __densities(__n); 6388*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __n; ++__i) 6389*0b57cec5SDimitry Andric __is >> __densities[__i]; 6390*0b57cec5SDimitry Andric __is >> __n; 6391*0b57cec5SDimitry Andric vector<result_type> __areas(__n); 6392*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __n; ++__i) 6393*0b57cec5SDimitry Andric __is >> __areas[__i]; 6394*0b57cec5SDimitry Andric if (!__is.fail()) 6395*0b57cec5SDimitry Andric { 6396*0b57cec5SDimitry Andric swap(__x.__p_.__b_, __b); 6397*0b57cec5SDimitry Andric swap(__x.__p_.__densities_, __densities); 6398*0b57cec5SDimitry Andric swap(__x.__p_.__areas_, __areas); 6399*0b57cec5SDimitry Andric } 6400*0b57cec5SDimitry Andric return __is; 6401*0b57cec5SDimitry Andric} 6402*0b57cec5SDimitry Andric 6403*0b57cec5SDimitry Andric// piecewise_linear_distribution 6404*0b57cec5SDimitry Andric 6405*0b57cec5SDimitry Andrictemplate<class _RealType = double> 6406*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS piecewise_linear_distribution 6407*0b57cec5SDimitry Andric{ 6408*0b57cec5SDimitry Andricpublic: 6409*0b57cec5SDimitry Andric // types 6410*0b57cec5SDimitry Andric typedef _RealType result_type; 6411*0b57cec5SDimitry Andric 6412*0b57cec5SDimitry Andric class _LIBCPP_TEMPLATE_VIS param_type 6413*0b57cec5SDimitry Andric { 6414*0b57cec5SDimitry Andric vector<result_type> __b_; 6415*0b57cec5SDimitry Andric vector<result_type> __densities_; 6416*0b57cec5SDimitry Andric vector<result_type> __areas_; 6417*0b57cec5SDimitry Andric public: 6418*0b57cec5SDimitry Andric typedef piecewise_linear_distribution distribution_type; 6419*0b57cec5SDimitry Andric 6420*0b57cec5SDimitry Andric param_type(); 6421*0b57cec5SDimitry Andric template<class _InputIteratorB, class _InputIteratorW> 6422*0b57cec5SDimitry Andric param_type(_InputIteratorB __fB, _InputIteratorB __lB, 6423*0b57cec5SDimitry Andric _InputIteratorW __fW); 6424*0b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 6425*0b57cec5SDimitry Andric template<class _UnaryOperation> 6426*0b57cec5SDimitry Andric param_type(initializer_list<result_type> __bl, _UnaryOperation __fw); 6427*0b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 6428*0b57cec5SDimitry Andric template<class _UnaryOperation> 6429*0b57cec5SDimitry Andric param_type(size_t __nw, result_type __xmin, result_type __xmax, 6430*0b57cec5SDimitry Andric _UnaryOperation __fw); 6431*0b57cec5SDimitry Andric param_type & operator=(const param_type& __rhs); 6432*0b57cec5SDimitry Andric 6433*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6434*0b57cec5SDimitry Andric vector<result_type> intervals() const {return __b_;} 6435*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6436*0b57cec5SDimitry Andric vector<result_type> densities() const {return __densities_;} 6437*0b57cec5SDimitry Andric 6438*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 6439*0b57cec5SDimitry Andric bool operator==(const param_type& __x, const param_type& __y) 6440*0b57cec5SDimitry Andric {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;} 6441*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 6442*0b57cec5SDimitry Andric bool operator!=(const param_type& __x, const param_type& __y) 6443*0b57cec5SDimitry Andric {return !(__x == __y);} 6444*0b57cec5SDimitry Andric 6445*0b57cec5SDimitry Andric private: 6446*0b57cec5SDimitry Andric void __init(); 6447*0b57cec5SDimitry Andric 6448*0b57cec5SDimitry Andric friend class piecewise_linear_distribution; 6449*0b57cec5SDimitry Andric 6450*0b57cec5SDimitry Andric template <class _CharT, class _Traits, class _RT> 6451*0b57cec5SDimitry Andric friend 6452*0b57cec5SDimitry Andric basic_ostream<_CharT, _Traits>& 6453*0b57cec5SDimitry Andric operator<<(basic_ostream<_CharT, _Traits>& __os, 6454*0b57cec5SDimitry Andric const piecewise_linear_distribution<_RT>& __x); 6455*0b57cec5SDimitry Andric 6456*0b57cec5SDimitry Andric template <class _CharT, class _Traits, class _RT> 6457*0b57cec5SDimitry Andric friend 6458*0b57cec5SDimitry Andric basic_istream<_CharT, _Traits>& 6459*0b57cec5SDimitry Andric operator>>(basic_istream<_CharT, _Traits>& __is, 6460*0b57cec5SDimitry Andric piecewise_linear_distribution<_RT>& __x); 6461*0b57cec5SDimitry Andric }; 6462*0b57cec5SDimitry Andric 6463*0b57cec5SDimitry Andricprivate: 6464*0b57cec5SDimitry Andric param_type __p_; 6465*0b57cec5SDimitry Andric 6466*0b57cec5SDimitry Andricpublic: 6467*0b57cec5SDimitry Andric // constructor and reset functions 6468*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6469*0b57cec5SDimitry Andric piecewise_linear_distribution() {} 6470*0b57cec5SDimitry Andric template<class _InputIteratorB, class _InputIteratorW> 6471*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6472*0b57cec5SDimitry Andric piecewise_linear_distribution(_InputIteratorB __fB, 6473*0b57cec5SDimitry Andric _InputIteratorB __lB, 6474*0b57cec5SDimitry Andric _InputIteratorW __fW) 6475*0b57cec5SDimitry Andric : __p_(__fB, __lB, __fW) {} 6476*0b57cec5SDimitry Andric 6477*0b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 6478*0b57cec5SDimitry Andric template<class _UnaryOperation> 6479*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6480*0b57cec5SDimitry Andric piecewise_linear_distribution(initializer_list<result_type> __bl, 6481*0b57cec5SDimitry Andric _UnaryOperation __fw) 6482*0b57cec5SDimitry Andric : __p_(__bl, __fw) {} 6483*0b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 6484*0b57cec5SDimitry Andric 6485*0b57cec5SDimitry Andric template<class _UnaryOperation> 6486*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6487*0b57cec5SDimitry Andric piecewise_linear_distribution(size_t __nw, result_type __xmin, 6488*0b57cec5SDimitry Andric result_type __xmax, _UnaryOperation __fw) 6489*0b57cec5SDimitry Andric : __p_(__nw, __xmin, __xmax, __fw) {} 6490*0b57cec5SDimitry Andric 6491*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6492*0b57cec5SDimitry Andric explicit piecewise_linear_distribution(const param_type& __p) 6493*0b57cec5SDimitry Andric : __p_(__p) {} 6494*0b57cec5SDimitry Andric 6495*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6496*0b57cec5SDimitry Andric void reset() {} 6497*0b57cec5SDimitry Andric 6498*0b57cec5SDimitry Andric // generating functions 6499*0b57cec5SDimitry Andric template<class _URNG> 6500*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6501*0b57cec5SDimitry Andric result_type operator()(_URNG& __g) 6502*0b57cec5SDimitry Andric {return (*this)(__g, __p_);} 6503*0b57cec5SDimitry Andric template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); 6504*0b57cec5SDimitry Andric 6505*0b57cec5SDimitry Andric // property functions 6506*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6507*0b57cec5SDimitry Andric vector<result_type> intervals() const {return __p_.intervals();} 6508*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6509*0b57cec5SDimitry Andric vector<result_type> densities() const {return __p_.densities();} 6510*0b57cec5SDimitry Andric 6511*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6512*0b57cec5SDimitry Andric param_type param() const {return __p_;} 6513*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6514*0b57cec5SDimitry Andric void param(const param_type& __p) {__p_ = __p;} 6515*0b57cec5SDimitry Andric 6516*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6517*0b57cec5SDimitry Andric result_type min() const {return __p_.__b_.front();} 6518*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6519*0b57cec5SDimitry Andric result_type max() const {return __p_.__b_.back();} 6520*0b57cec5SDimitry Andric 6521*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 6522*0b57cec5SDimitry Andric bool operator==(const piecewise_linear_distribution& __x, 6523*0b57cec5SDimitry Andric const piecewise_linear_distribution& __y) 6524*0b57cec5SDimitry Andric {return __x.__p_ == __y.__p_;} 6525*0b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 6526*0b57cec5SDimitry Andric bool operator!=(const piecewise_linear_distribution& __x, 6527*0b57cec5SDimitry Andric const piecewise_linear_distribution& __y) 6528*0b57cec5SDimitry Andric {return !(__x == __y);} 6529*0b57cec5SDimitry Andric 6530*0b57cec5SDimitry Andric template <class _CharT, class _Traits, class _RT> 6531*0b57cec5SDimitry Andric friend 6532*0b57cec5SDimitry Andric basic_ostream<_CharT, _Traits>& 6533*0b57cec5SDimitry Andric operator<<(basic_ostream<_CharT, _Traits>& __os, 6534*0b57cec5SDimitry Andric const piecewise_linear_distribution<_RT>& __x); 6535*0b57cec5SDimitry Andric 6536*0b57cec5SDimitry Andric template <class _CharT, class _Traits, class _RT> 6537*0b57cec5SDimitry Andric friend 6538*0b57cec5SDimitry Andric basic_istream<_CharT, _Traits>& 6539*0b57cec5SDimitry Andric operator>>(basic_istream<_CharT, _Traits>& __is, 6540*0b57cec5SDimitry Andric piecewise_linear_distribution<_RT>& __x); 6541*0b57cec5SDimitry Andric}; 6542*0b57cec5SDimitry Andric 6543*0b57cec5SDimitry Andrictemplate<class _RealType> 6544*0b57cec5SDimitry Andrictypename piecewise_linear_distribution<_RealType>::param_type & 6545*0b57cec5SDimitry Andricpiecewise_linear_distribution<_RealType>::param_type::operator= 6546*0b57cec5SDimitry Andric (const param_type& __rhs) 6547*0b57cec5SDimitry Andric{ 6548*0b57cec5SDimitry Andric// These can throw 6549*0b57cec5SDimitry Andric __b_.reserve (__rhs.__b_.size ()); 6550*0b57cec5SDimitry Andric __densities_.reserve(__rhs.__densities_.size()); 6551*0b57cec5SDimitry Andric __areas_.reserve (__rhs.__areas_.size()); 6552*0b57cec5SDimitry Andric 6553*0b57cec5SDimitry Andric// These can not throw 6554*0b57cec5SDimitry Andric __b_ = __rhs.__b_; 6555*0b57cec5SDimitry Andric __densities_ = __rhs.__densities_; 6556*0b57cec5SDimitry Andric __areas_ = __rhs.__areas_; 6557*0b57cec5SDimitry Andric return *this; 6558*0b57cec5SDimitry Andric} 6559*0b57cec5SDimitry Andric 6560*0b57cec5SDimitry Andric 6561*0b57cec5SDimitry Andrictemplate<class _RealType> 6562*0b57cec5SDimitry Andricvoid 6563*0b57cec5SDimitry Andricpiecewise_linear_distribution<_RealType>::param_type::__init() 6564*0b57cec5SDimitry Andric{ 6565*0b57cec5SDimitry Andric __areas_.assign(__densities_.size() - 1, result_type()); 6566*0b57cec5SDimitry Andric result_type _Sp = 0; 6567*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __areas_.size(); ++__i) 6568*0b57cec5SDimitry Andric { 6569*0b57cec5SDimitry Andric __areas_[__i] = (__densities_[__i+1] + __densities_[__i]) * 6570*0b57cec5SDimitry Andric (__b_[__i+1] - __b_[__i]) * .5; 6571*0b57cec5SDimitry Andric _Sp += __areas_[__i]; 6572*0b57cec5SDimitry Andric } 6573*0b57cec5SDimitry Andric for (size_t __i = __areas_.size(); __i > 1;) 6574*0b57cec5SDimitry Andric { 6575*0b57cec5SDimitry Andric --__i; 6576*0b57cec5SDimitry Andric __areas_[__i] = __areas_[__i-1] / _Sp; 6577*0b57cec5SDimitry Andric } 6578*0b57cec5SDimitry Andric __areas_[0] = 0; 6579*0b57cec5SDimitry Andric for (size_t __i = 1; __i < __areas_.size(); ++__i) 6580*0b57cec5SDimitry Andric __areas_[__i] += __areas_[__i-1]; 6581*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __densities_.size(); ++__i) 6582*0b57cec5SDimitry Andric __densities_[__i] /= _Sp; 6583*0b57cec5SDimitry Andric} 6584*0b57cec5SDimitry Andric 6585*0b57cec5SDimitry Andrictemplate<class _RealType> 6586*0b57cec5SDimitry Andricpiecewise_linear_distribution<_RealType>::param_type::param_type() 6587*0b57cec5SDimitry Andric : __b_(2), 6588*0b57cec5SDimitry Andric __densities_(2, 1.0), 6589*0b57cec5SDimitry Andric __areas_(1, 0.0) 6590*0b57cec5SDimitry Andric{ 6591*0b57cec5SDimitry Andric __b_[1] = 1; 6592*0b57cec5SDimitry Andric} 6593*0b57cec5SDimitry Andric 6594*0b57cec5SDimitry Andrictemplate<class _RealType> 6595*0b57cec5SDimitry Andrictemplate<class _InputIteratorB, class _InputIteratorW> 6596*0b57cec5SDimitry Andricpiecewise_linear_distribution<_RealType>::param_type::param_type( 6597*0b57cec5SDimitry Andric _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW) 6598*0b57cec5SDimitry Andric : __b_(__fB, __lB) 6599*0b57cec5SDimitry Andric{ 6600*0b57cec5SDimitry Andric if (__b_.size() < 2) 6601*0b57cec5SDimitry Andric { 6602*0b57cec5SDimitry Andric __b_.resize(2); 6603*0b57cec5SDimitry Andric __b_[0] = 0; 6604*0b57cec5SDimitry Andric __b_[1] = 1; 6605*0b57cec5SDimitry Andric __densities_.assign(2, 1.0); 6606*0b57cec5SDimitry Andric __areas_.assign(1, 0.0); 6607*0b57cec5SDimitry Andric } 6608*0b57cec5SDimitry Andric else 6609*0b57cec5SDimitry Andric { 6610*0b57cec5SDimitry Andric __densities_.reserve(__b_.size()); 6611*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __b_.size(); ++__i, ++__fW) 6612*0b57cec5SDimitry Andric __densities_.push_back(*__fW); 6613*0b57cec5SDimitry Andric __init(); 6614*0b57cec5SDimitry Andric } 6615*0b57cec5SDimitry Andric} 6616*0b57cec5SDimitry Andric 6617*0b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 6618*0b57cec5SDimitry Andric 6619*0b57cec5SDimitry Andrictemplate<class _RealType> 6620*0b57cec5SDimitry Andrictemplate<class _UnaryOperation> 6621*0b57cec5SDimitry Andricpiecewise_linear_distribution<_RealType>::param_type::param_type( 6622*0b57cec5SDimitry Andric initializer_list<result_type> __bl, _UnaryOperation __fw) 6623*0b57cec5SDimitry Andric : __b_(__bl.begin(), __bl.end()) 6624*0b57cec5SDimitry Andric{ 6625*0b57cec5SDimitry Andric if (__b_.size() < 2) 6626*0b57cec5SDimitry Andric { 6627*0b57cec5SDimitry Andric __b_.resize(2); 6628*0b57cec5SDimitry Andric __b_[0] = 0; 6629*0b57cec5SDimitry Andric __b_[1] = 1; 6630*0b57cec5SDimitry Andric __densities_.assign(2, 1.0); 6631*0b57cec5SDimitry Andric __areas_.assign(1, 0.0); 6632*0b57cec5SDimitry Andric } 6633*0b57cec5SDimitry Andric else 6634*0b57cec5SDimitry Andric { 6635*0b57cec5SDimitry Andric __densities_.reserve(__b_.size()); 6636*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __b_.size(); ++__i) 6637*0b57cec5SDimitry Andric __densities_.push_back(__fw(__b_[__i])); 6638*0b57cec5SDimitry Andric __init(); 6639*0b57cec5SDimitry Andric } 6640*0b57cec5SDimitry Andric} 6641*0b57cec5SDimitry Andric 6642*0b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 6643*0b57cec5SDimitry Andric 6644*0b57cec5SDimitry Andrictemplate<class _RealType> 6645*0b57cec5SDimitry Andrictemplate<class _UnaryOperation> 6646*0b57cec5SDimitry Andricpiecewise_linear_distribution<_RealType>::param_type::param_type( 6647*0b57cec5SDimitry Andric size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw) 6648*0b57cec5SDimitry Andric : __b_(__nw == 0 ? 2 : __nw + 1) 6649*0b57cec5SDimitry Andric{ 6650*0b57cec5SDimitry Andric size_t __n = __b_.size() - 1; 6651*0b57cec5SDimitry Andric result_type __d = (__xmax - __xmin) / __n; 6652*0b57cec5SDimitry Andric __densities_.reserve(__b_.size()); 6653*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __n; ++__i) 6654*0b57cec5SDimitry Andric { 6655*0b57cec5SDimitry Andric __b_[__i] = __xmin + __i * __d; 6656*0b57cec5SDimitry Andric __densities_.push_back(__fw(__b_[__i])); 6657*0b57cec5SDimitry Andric } 6658*0b57cec5SDimitry Andric __b_[__n] = __xmax; 6659*0b57cec5SDimitry Andric __densities_.push_back(__fw(__b_[__n])); 6660*0b57cec5SDimitry Andric __init(); 6661*0b57cec5SDimitry Andric} 6662*0b57cec5SDimitry Andric 6663*0b57cec5SDimitry Andrictemplate<class _RealType> 6664*0b57cec5SDimitry Andrictemplate<class _URNG> 6665*0b57cec5SDimitry Andric_RealType 6666*0b57cec5SDimitry Andricpiecewise_linear_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) 6667*0b57cec5SDimitry Andric{ 6668*0b57cec5SDimitry Andric typedef uniform_real_distribution<result_type> _Gen; 6669*0b57cec5SDimitry Andric result_type __u = _Gen()(__g); 6670*0b57cec5SDimitry Andric ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(), 6671*0b57cec5SDimitry Andric __u) - __p.__areas_.begin() - 1; 6672*0b57cec5SDimitry Andric __u -= __p.__areas_[__k]; 6673*0b57cec5SDimitry Andric const result_type __dk = __p.__densities_[__k]; 6674*0b57cec5SDimitry Andric const result_type __dk1 = __p.__densities_[__k+1]; 6675*0b57cec5SDimitry Andric const result_type __deltad = __dk1 - __dk; 6676*0b57cec5SDimitry Andric const result_type __bk = __p.__b_[__k]; 6677*0b57cec5SDimitry Andric if (__deltad == 0) 6678*0b57cec5SDimitry Andric return __u / __dk + __bk; 6679*0b57cec5SDimitry Andric const result_type __bk1 = __p.__b_[__k+1]; 6680*0b57cec5SDimitry Andric const result_type __deltab = __bk1 - __bk; 6681*0b57cec5SDimitry Andric return (__bk * __dk1 - __bk1 * __dk + 6682*0b57cec5SDimitry Andric _VSTD::sqrt(__deltab * (__deltab * __dk * __dk + 2 * __deltad * __u))) / 6683*0b57cec5SDimitry Andric __deltad; 6684*0b57cec5SDimitry Andric} 6685*0b57cec5SDimitry Andric 6686*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _RT> 6687*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 6688*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 6689*0b57cec5SDimitry Andric const piecewise_linear_distribution<_RT>& __x) 6690*0b57cec5SDimitry Andric{ 6691*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__os); 6692*0b57cec5SDimitry Andric __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | 6693*0b57cec5SDimitry Andric ios_base::scientific); 6694*0b57cec5SDimitry Andric _CharT __sp = __os.widen(' '); 6695*0b57cec5SDimitry Andric __os.fill(__sp); 6696*0b57cec5SDimitry Andric size_t __n = __x.__p_.__b_.size(); 6697*0b57cec5SDimitry Andric __os << __n; 6698*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __n; ++__i) 6699*0b57cec5SDimitry Andric __os << __sp << __x.__p_.__b_[__i]; 6700*0b57cec5SDimitry Andric __n = __x.__p_.__densities_.size(); 6701*0b57cec5SDimitry Andric __os << __sp << __n; 6702*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __n; ++__i) 6703*0b57cec5SDimitry Andric __os << __sp << __x.__p_.__densities_[__i]; 6704*0b57cec5SDimitry Andric __n = __x.__p_.__areas_.size(); 6705*0b57cec5SDimitry Andric __os << __sp << __n; 6706*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __n; ++__i) 6707*0b57cec5SDimitry Andric __os << __sp << __x.__p_.__areas_[__i]; 6708*0b57cec5SDimitry Andric return __os; 6709*0b57cec5SDimitry Andric} 6710*0b57cec5SDimitry Andric 6711*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _RT> 6712*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 6713*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 6714*0b57cec5SDimitry Andric piecewise_linear_distribution<_RT>& __x) 6715*0b57cec5SDimitry Andric{ 6716*0b57cec5SDimitry Andric typedef piecewise_linear_distribution<_RT> _Eng; 6717*0b57cec5SDimitry Andric typedef typename _Eng::result_type result_type; 6718*0b57cec5SDimitry Andric __save_flags<_CharT, _Traits> __lx(__is); 6719*0b57cec5SDimitry Andric __is.flags(ios_base::dec | ios_base::skipws); 6720*0b57cec5SDimitry Andric size_t __n; 6721*0b57cec5SDimitry Andric __is >> __n; 6722*0b57cec5SDimitry Andric vector<result_type> __b(__n); 6723*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __n; ++__i) 6724*0b57cec5SDimitry Andric __is >> __b[__i]; 6725*0b57cec5SDimitry Andric __is >> __n; 6726*0b57cec5SDimitry Andric vector<result_type> __densities(__n); 6727*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __n; ++__i) 6728*0b57cec5SDimitry Andric __is >> __densities[__i]; 6729*0b57cec5SDimitry Andric __is >> __n; 6730*0b57cec5SDimitry Andric vector<result_type> __areas(__n); 6731*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __n; ++__i) 6732*0b57cec5SDimitry Andric __is >> __areas[__i]; 6733*0b57cec5SDimitry Andric if (!__is.fail()) 6734*0b57cec5SDimitry Andric { 6735*0b57cec5SDimitry Andric swap(__x.__p_.__b_, __b); 6736*0b57cec5SDimitry Andric swap(__x.__p_.__densities_, __densities); 6737*0b57cec5SDimitry Andric swap(__x.__p_.__areas_, __areas); 6738*0b57cec5SDimitry Andric } 6739*0b57cec5SDimitry Andric return __is; 6740*0b57cec5SDimitry Andric} 6741*0b57cec5SDimitry Andric 6742*0b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 6743*0b57cec5SDimitry Andric 6744*0b57cec5SDimitry Andric_LIBCPP_POP_MACROS 6745*0b57cec5SDimitry Andric 6746*0b57cec5SDimitry Andric#endif // _LIBCPP_RANDOM 6747