00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef _RANDOM_H
00032 #define _RANDOM_H 1
00033
00034 #include <vector>
00035
00036 namespace std _GLIBCXX_VISIBILITY(default)
00037 {
00038 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 template<typename _RealType, size_t __bits,
00056 typename _UniformRandomNumberGenerator>
00057 _RealType
00058 generate_canonical(_UniformRandomNumberGenerator& __g);
00059
00060 _GLIBCXX_END_NAMESPACE_VERSION
00061
00062
00063
00064
00065 namespace __detail
00066 {
00067 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00068
00069 template<typename _UIntType, size_t __w,
00070 bool = __w < static_cast<size_t>
00071 (std::numeric_limits<_UIntType>::digits)>
00072 struct _Shift
00073 { static const _UIntType __value = 0; };
00074
00075 template<typename _UIntType, size_t __w>
00076 struct _Shift<_UIntType, __w, true>
00077 { static const _UIntType __value = _UIntType(1) << __w; };
00078
00079 template<typename _Tp, _Tp __m, _Tp __a, _Tp __c, bool>
00080 struct _Mod;
00081
00082
00083
00084 template<typename _Tp, _Tp __m, _Tp __a = 1, _Tp __c = 0>
00085 inline _Tp
00086 __mod(_Tp __x)
00087 { return _Mod<_Tp, __m, __a, __c, __m == 0>::__calc(__x); }
00088
00089
00090
00091
00092
00093 template<typename _Engine, typename _DInputType>
00094 struct _Adaptor
00095 {
00096
00097 public:
00098 _Adaptor(_Engine& __g)
00099 : _M_g(__g) { }
00100
00101 _DInputType
00102 min() const
00103 { return _DInputType(0); }
00104
00105 _DInputType
00106 max() const
00107 { return _DInputType(1); }
00108
00109
00110
00111
00112
00113
00114 _DInputType
00115 operator()()
00116 {
00117 return std::generate_canonical<_DInputType,
00118 std::numeric_limits<_DInputType>::digits,
00119 _Engine>(_M_g);
00120 }
00121
00122 private:
00123 _Engine& _M_g;
00124 };
00125
00126 _GLIBCXX_END_NAMESPACE_VERSION
00127 }
00128
00129 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
00170 class linear_congruential_engine
00171 {
00172 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
00173 "substituting _UIntType not an unsigned integral type");
00174 static_assert(__m == 0u || (__a < __m && __c < __m),
00175 "template argument substituting __m out of bounds");
00176
00177 public:
00178
00179 typedef _UIntType result_type;
00180
00181
00182 static constexpr result_type multiplier = __a;
00183
00184 static constexpr result_type increment = __c;
00185
00186 static constexpr result_type modulus = __m;
00187 static constexpr result_type default_seed = 1u;
00188
00189
00190
00191
00192
00193
00194
00195
00196 explicit
00197 linear_congruential_engine(result_type __s = default_seed)
00198 { seed(__s); }
00199
00200
00201
00202
00203
00204
00205
00206 template<typename _Sseq, typename = typename
00207 std::enable_if<!std::is_same<_Sseq, linear_congruential_engine>::value>
00208 ::type>
00209 explicit
00210 linear_congruential_engine(_Sseq& __q)
00211 { seed(__q); }
00212
00213
00214
00215
00216
00217
00218
00219 void
00220 seed(result_type __s = default_seed);
00221
00222
00223
00224
00225
00226
00227
00228
00229 template<typename _Sseq>
00230 typename std::enable_if<std::is_class<_Sseq>::value>::type
00231 seed(_Sseq& __q);
00232
00233
00234
00235
00236
00237
00238
00239 static constexpr result_type
00240 min()
00241 { return __c == 0u ? 1u : 0u; }
00242
00243
00244
00245
00246 static constexpr result_type
00247 max()
00248 { return __m - 1u; }
00249
00250
00251
00252
00253 void
00254 discard(unsigned long long __z)
00255 {
00256 for (; __z != 0ULL; --__z)
00257 (*this)();
00258 }
00259
00260
00261
00262
00263 result_type
00264 operator()()
00265 {
00266 _M_x = __detail::__mod<_UIntType, __m, __a, __c>(_M_x);
00267 return _M_x;
00268 }
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281 friend bool
00282 operator==(const linear_congruential_engine& __lhs,
00283 const linear_congruential_engine& __rhs)
00284 { return __lhs._M_x == __rhs._M_x; }
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294 template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
00295 _UIntType1 __m1, typename _CharT, typename _Traits>
00296 friend std::basic_ostream<_CharT, _Traits>&
00297 operator<<(std::basic_ostream<_CharT, _Traits>&,
00298 const std::linear_congruential_engine<_UIntType1,
00299 __a1, __c1, __m1>&);
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314 template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
00315 _UIntType1 __m1, typename _CharT, typename _Traits>
00316 friend std::basic_istream<_CharT, _Traits>&
00317 operator>>(std::basic_istream<_CharT, _Traits>&,
00318 std::linear_congruential_engine<_UIntType1, __a1,
00319 __c1, __m1>&);
00320
00321 private:
00322 _UIntType _M_x;
00323 };
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336 template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
00337 inline bool
00338 operator!=(const std::linear_congruential_engine<_UIntType, __a,
00339 __c, __m>& __lhs,
00340 const std::linear_congruential_engine<_UIntType, __a,
00341 __c, __m>& __rhs)
00342 { return !(__lhs == __rhs); }
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370 template<typename _UIntType, size_t __w,
00371 size_t __n, size_t __m, size_t __r,
00372 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
00373 _UIntType __b, size_t __t,
00374 _UIntType __c, size_t __l, _UIntType __f>
00375 class mersenne_twister_engine
00376 {
00377 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
00378 "substituting _UIntType not an unsigned integral type");
00379 static_assert(1u <= __m && __m <= __n,
00380 "template argument substituting __m out of bounds");
00381 static_assert(__r <= __w, "template argument substituting "
00382 "__r out of bound");
00383 static_assert(__u <= __w, "template argument substituting "
00384 "__u out of bound");
00385 static_assert(__s <= __w, "template argument substituting "
00386 "__s out of bound");
00387 static_assert(__t <= __w, "template argument substituting "
00388 "__t out of bound");
00389 static_assert(__l <= __w, "template argument substituting "
00390 "__l out of bound");
00391 static_assert(__w <= std::numeric_limits<_UIntType>::digits,
00392 "template argument substituting __w out of bound");
00393 static_assert(__a <= (__detail::_Shift<_UIntType, __w>::__value - 1),
00394 "template argument substituting __a out of bound");
00395 static_assert(__b <= (__detail::_Shift<_UIntType, __w>::__value - 1),
00396 "template argument substituting __b out of bound");
00397 static_assert(__c <= (__detail::_Shift<_UIntType, __w>::__value - 1),
00398 "template argument substituting __c out of bound");
00399 static_assert(__d <= (__detail::_Shift<_UIntType, __w>::__value - 1),
00400 "template argument substituting __d out of bound");
00401 static_assert(__f <= (__detail::_Shift<_UIntType, __w>::__value - 1),
00402 "template argument substituting __f out of bound");
00403
00404 public:
00405
00406 typedef _UIntType result_type;
00407
00408
00409 static constexpr size_t word_size = __w;
00410 static constexpr size_t state_size = __n;
00411 static constexpr size_t shift_size = __m;
00412 static constexpr size_t mask_bits = __r;
00413 static constexpr result_type xor_mask = __a;
00414 static constexpr size_t tempering_u = __u;
00415 static constexpr result_type tempering_d = __d;
00416 static constexpr size_t tempering_s = __s;
00417 static constexpr result_type tempering_b = __b;
00418 static constexpr size_t tempering_t = __t;
00419 static constexpr result_type tempering_c = __c;
00420 static constexpr size_t tempering_l = __l;
00421 static constexpr result_type initialization_multiplier = __f;
00422 static constexpr result_type default_seed = 5489u;
00423
00424
00425 explicit
00426 mersenne_twister_engine(result_type __sd = default_seed)
00427 { seed(__sd); }
00428
00429
00430
00431
00432
00433
00434
00435 template<typename _Sseq, typename = typename
00436 std::enable_if<!std::is_same<_Sseq, mersenne_twister_engine>::value>
00437 ::type>
00438 explicit
00439 mersenne_twister_engine(_Sseq& __q)
00440 { seed(__q); }
00441
00442 void
00443 seed(result_type __sd = default_seed);
00444
00445 template<typename _Sseq>
00446 typename std::enable_if<std::is_class<_Sseq>::value>::type
00447 seed(_Sseq& __q);
00448
00449
00450
00451
00452 static constexpr result_type
00453 min()
00454 { return 0; };
00455
00456
00457
00458
00459 static constexpr result_type
00460 max()
00461 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
00462
00463
00464
00465
00466 void
00467 discard(unsigned long long __z)
00468 {
00469 for (; __z != 0ULL; --__z)
00470 (*this)();
00471 }
00472
00473 result_type
00474 operator()();
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488 friend bool
00489 operator==(const mersenne_twister_engine& __lhs,
00490 const mersenne_twister_engine& __rhs)
00491 { return std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x); }
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505 template<typename _UIntType1,
00506 size_t __w1, size_t __n1,
00507 size_t __m1, size_t __r1,
00508 _UIntType1 __a1, size_t __u1,
00509 _UIntType1 __d1, size_t __s1,
00510 _UIntType1 __b1, size_t __t1,
00511 _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
00512 typename _CharT, typename _Traits>
00513 friend std::basic_ostream<_CharT, _Traits>&
00514 operator<<(std::basic_ostream<_CharT, _Traits>&,
00515 const std::mersenne_twister_engine<_UIntType1, __w1, __n1,
00516 __m1, __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
00517 __l1, __f1>&);
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531 template<typename _UIntType1,
00532 size_t __w1, size_t __n1,
00533 size_t __m1, size_t __r1,
00534 _UIntType1 __a1, size_t __u1,
00535 _UIntType1 __d1, size_t __s1,
00536 _UIntType1 __b1, size_t __t1,
00537 _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
00538 typename _CharT, typename _Traits>
00539 friend std::basic_istream<_CharT, _Traits>&
00540 operator>>(std::basic_istream<_CharT, _Traits>&,
00541 std::mersenne_twister_engine<_UIntType1, __w1, __n1, __m1,
00542 __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
00543 __l1, __f1>&);
00544
00545 private:
00546 _UIntType _M_x[state_size];
00547 size_t _M_p;
00548 };
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562 template<typename _UIntType, size_t __w,
00563 size_t __n, size_t __m, size_t __r,
00564 _UIntType __a, size_t __u, _UIntType __d, size_t __s,
00565 _UIntType __b, size_t __t,
00566 _UIntType __c, size_t __l, _UIntType __f>
00567 inline bool
00568 operator!=(const std::mersenne_twister_engine<_UIntType, __w, __n, __m,
00569 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __lhs,
00570 const std::mersenne_twister_engine<_UIntType, __w, __n, __m,
00571 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __rhs)
00572 { return !(__lhs == __rhs); }
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594 template<typename _UIntType, size_t __w, size_t __s, size_t __r>
00595 class subtract_with_carry_engine
00596 {
00597 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
00598 "substituting _UIntType not an unsigned integral type");
00599 static_assert(0u < __s && __s < __r,
00600 "template argument substituting __s out of bounds");
00601 static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
00602 "template argument substituting __w out of bounds");
00603
00604 public:
00605
00606 typedef _UIntType result_type;
00607
00608
00609 static constexpr size_t word_size = __w;
00610 static constexpr size_t short_lag = __s;
00611 static constexpr size_t long_lag = __r;
00612 static constexpr result_type default_seed = 19780503u;
00613
00614
00615
00616
00617
00618 explicit
00619 subtract_with_carry_engine(result_type __sd = default_seed)
00620 { seed(__sd); }
00621
00622
00623
00624
00625
00626
00627
00628 template<typename _Sseq, typename = typename
00629 std::enable_if<!std::is_same<_Sseq, subtract_with_carry_engine>::value>
00630 ::type>
00631 explicit
00632 subtract_with_carry_engine(_Sseq& __q)
00633 { seed(__q); }
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647 void
00648 seed(result_type __sd = default_seed);
00649
00650
00651
00652
00653
00654 template<typename _Sseq>
00655 typename std::enable_if<std::is_class<_Sseq>::value>::type
00656 seed(_Sseq& __q);
00657
00658
00659
00660
00661
00662 static constexpr result_type
00663 min()
00664 { return 0; }
00665
00666
00667
00668
00669
00670 static constexpr result_type
00671 max()
00672 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
00673
00674
00675
00676
00677 void
00678 discard(unsigned long long __z)
00679 {
00680 for (; __z != 0ULL; --__z)
00681 (*this)();
00682 }
00683
00684
00685
00686
00687 result_type
00688 operator()();
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702 friend bool
00703 operator==(const subtract_with_carry_engine& __lhs,
00704 const subtract_with_carry_engine& __rhs)
00705 { return std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x); }
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719 template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
00720 typename _CharT, typename _Traits>
00721 friend std::basic_ostream<_CharT, _Traits>&
00722 operator<<(std::basic_ostream<_CharT, _Traits>&,
00723 const std::subtract_with_carry_engine<_UIntType1, __w1,
00724 __s1, __r1>&);
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738 template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
00739 typename _CharT, typename _Traits>
00740 friend std::basic_istream<_CharT, _Traits>&
00741 operator>>(std::basic_istream<_CharT, _Traits>&,
00742 std::subtract_with_carry_engine<_UIntType1, __w1,
00743 __s1, __r1>&);
00744
00745 private:
00746 _UIntType _M_x[long_lag];
00747 _UIntType _M_carry;
00748 size_t _M_p;
00749 };
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763 template<typename _UIntType, size_t __w, size_t __s, size_t __r>
00764 inline bool
00765 operator!=(const std::subtract_with_carry_engine<_UIntType, __w,
00766 __s, __r>& __lhs,
00767 const std::subtract_with_carry_engine<_UIntType, __w,
00768 __s, __r>& __rhs)
00769 { return !(__lhs == __rhs); }
00770
00771
00772
00773
00774
00775
00776
00777
00778 template<typename _RandomNumberEngine, size_t __p, size_t __r>
00779 class discard_block_engine
00780 {
00781 static_assert(1 <= __r && __r <= __p,
00782 "template argument substituting __r out of bounds");
00783
00784 public:
00785
00786 typedef typename _RandomNumberEngine::result_type result_type;
00787
00788
00789 static constexpr size_t block_size = __p;
00790 static constexpr size_t used_block = __r;
00791
00792
00793
00794
00795
00796
00797 discard_block_engine()
00798 : _M_b(), _M_n(0) { }
00799
00800
00801
00802
00803
00804
00805
00806 explicit
00807 discard_block_engine(const _RandomNumberEngine& __rne)
00808 : _M_b(__rne), _M_n(0) { }
00809
00810
00811
00812
00813
00814
00815
00816 explicit
00817 discard_block_engine(_RandomNumberEngine&& __rne)
00818 : _M_b(std::move(__rne)), _M_n(0) { }
00819
00820
00821
00822
00823
00824
00825
00826 explicit
00827 discard_block_engine(result_type __s)
00828 : _M_b(__s), _M_n(0) { }
00829
00830
00831
00832
00833
00834
00835 template<typename _Sseq, typename = typename
00836 std::enable_if<!std::is_same<_Sseq, discard_block_engine>::value
00837 && !std::is_same<_Sseq, _RandomNumberEngine>::value>
00838 ::type>
00839 explicit
00840 discard_block_engine(_Sseq& __q)
00841 : _M_b(__q), _M_n(0)
00842 { }
00843
00844
00845
00846
00847
00848 void
00849 seed()
00850 {
00851 _M_b.seed();
00852 _M_n = 0;
00853 }
00854
00855
00856
00857
00858
00859 void
00860 seed(result_type __s)
00861 {
00862 _M_b.seed(__s);
00863 _M_n = 0;
00864 }
00865
00866
00867
00868
00869
00870
00871 template<typename _Sseq>
00872 void
00873 seed(_Sseq& __q)
00874 {
00875 _M_b.seed(__q);
00876 _M_n = 0;
00877 }
00878
00879
00880
00881
00882
00883 const _RandomNumberEngine&
00884 base() const
00885 { return _M_b; }
00886
00887
00888
00889
00890 static constexpr result_type
00891 min()
00892 { return _RandomNumberEngine::min(); }
00893
00894
00895
00896
00897 static constexpr result_type
00898 max()
00899 { return _RandomNumberEngine::max(); }
00900
00901
00902
00903
00904 void
00905 discard(unsigned long long __z)
00906 {
00907 for (; __z != 0ULL; --__z)
00908 (*this)();
00909 }
00910
00911
00912
00913
00914 result_type
00915 operator()();
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928 friend bool
00929 operator==(const discard_block_engine& __lhs,
00930 const discard_block_engine& __rhs)
00931 { return __lhs._M_b == __rhs._M_b && __lhs._M_n == __rhs._M_n; }
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944 template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
00945 typename _CharT, typename _Traits>
00946 friend std::basic_ostream<_CharT, _Traits>&
00947 operator<<(std::basic_ostream<_CharT, _Traits>&,
00948 const std::discard_block_engine<_RandomNumberEngine1,
00949 __p1, __r1>&);
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962 template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
00963 typename _CharT, typename _Traits>
00964 friend std::basic_istream<_CharT, _Traits>&
00965 operator>>(std::basic_istream<_CharT, _Traits>&,
00966 std::discard_block_engine<_RandomNumberEngine1,
00967 __p1, __r1>&);
00968
00969 private:
00970 _RandomNumberEngine _M_b;
00971 size_t _M_n;
00972 };
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985 template<typename _RandomNumberEngine, size_t __p, size_t __r>
00986 inline bool
00987 operator!=(const std::discard_block_engine<_RandomNumberEngine, __p,
00988 __r>& __lhs,
00989 const std::discard_block_engine<_RandomNumberEngine, __p,
00990 __r>& __rhs)
00991 { return !(__lhs == __rhs); }
00992
00993
00994
00995
00996
00997
00998 template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
00999 class independent_bits_engine
01000 {
01001 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
01002 "substituting _UIntType not an unsigned integral type");
01003 static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
01004 "template argument substituting __w out of bounds");
01005
01006 public:
01007
01008 typedef _UIntType result_type;
01009
01010
01011
01012
01013
01014
01015 independent_bits_engine()
01016 : _M_b() { }
01017
01018
01019
01020
01021
01022
01023
01024 explicit
01025 independent_bits_engine(const _RandomNumberEngine& __rne)
01026 : _M_b(__rne) { }
01027
01028
01029
01030
01031
01032
01033
01034 explicit
01035 independent_bits_engine(_RandomNumberEngine&& __rne)
01036 : _M_b(std::move(__rne)) { }
01037
01038
01039
01040
01041
01042
01043
01044 explicit
01045 independent_bits_engine(result_type __s)
01046 : _M_b(__s) { }
01047
01048
01049
01050
01051
01052
01053 template<typename _Sseq, typename = typename
01054 std::enable_if<!std::is_same<_Sseq, independent_bits_engine>::value
01055 && !std::is_same<_Sseq, _RandomNumberEngine>::value>
01056 ::type>
01057 explicit
01058 independent_bits_engine(_Sseq& __q)
01059 : _M_b(__q)
01060 { }
01061
01062
01063
01064
01065
01066 void
01067 seed()
01068 { _M_b.seed(); }
01069
01070
01071
01072
01073
01074 void
01075 seed(result_type __s)
01076 { _M_b.seed(__s); }
01077
01078
01079
01080
01081
01082
01083 template<typename _Sseq>
01084 void
01085 seed(_Sseq& __q)
01086 { _M_b.seed(__q); }
01087
01088
01089
01090
01091
01092 const _RandomNumberEngine&
01093 base() const
01094 { return _M_b; }
01095
01096
01097
01098
01099 static constexpr result_type
01100 min()
01101 { return 0U; }
01102
01103
01104
01105
01106 static constexpr result_type
01107 max()
01108 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
01109
01110
01111
01112
01113 void
01114 discard(unsigned long long __z)
01115 {
01116 for (; __z != 0ULL; --__z)
01117 (*this)();
01118 }
01119
01120
01121
01122
01123 result_type
01124 operator()();
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138 friend bool
01139 operator==(const independent_bits_engine& __lhs,
01140 const independent_bits_engine& __rhs)
01141 { return __lhs._M_b == __rhs._M_b; }
01142
01143
01144
01145
01146
01147
01148
01149
01150
01151
01152
01153
01154
01155 template<typename _CharT, typename _Traits>
01156 friend std::basic_istream<_CharT, _Traits>&
01157 operator>>(std::basic_istream<_CharT, _Traits>& __is,
01158 std::independent_bits_engine<_RandomNumberEngine,
01159 __w, _UIntType>& __x)
01160 {
01161 __is >> __x._M_b;
01162 return __is;
01163 }
01164
01165 private:
01166 _RandomNumberEngine _M_b;
01167 };
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181 template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
01182 inline bool
01183 operator!=(const std::independent_bits_engine<_RandomNumberEngine, __w,
01184 _UIntType>& __lhs,
01185 const std::independent_bits_engine<_RandomNumberEngine, __w,
01186 _UIntType>& __rhs)
01187 { return !(__lhs == __rhs); }
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199 template<typename _RandomNumberEngine, size_t __w, typename _UIntType,
01200 typename _CharT, typename _Traits>
01201 std::basic_ostream<_CharT, _Traits>&
01202 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
01203 const std::independent_bits_engine<_RandomNumberEngine,
01204 __w, _UIntType>& __x)
01205 {
01206 __os << __x.base();
01207 return __os;
01208 }
01209
01210
01211
01212
01213
01214
01215
01216 template<typename _RandomNumberEngine, size_t __k>
01217 class shuffle_order_engine
01218 {
01219 static_assert(1u <= __k, "template argument substituting "
01220 "__k out of bound");
01221
01222 public:
01223
01224 typedef typename _RandomNumberEngine::result_type result_type;
01225
01226 static constexpr size_t table_size = __k;
01227
01228
01229
01230
01231
01232
01233 shuffle_order_engine()
01234 : _M_b()
01235 { _M_initialize(); }
01236
01237
01238
01239
01240
01241
01242
01243 explicit
01244 shuffle_order_engine(const _RandomNumberEngine& __rne)
01245 : _M_b(__rne)
01246 { _M_initialize(); }
01247
01248
01249
01250
01251
01252
01253
01254 explicit
01255 shuffle_order_engine(_RandomNumberEngine&& __rne)
01256 : _M_b(std::move(__rne))
01257 { _M_initialize(); }
01258
01259
01260
01261
01262
01263
01264
01265 explicit
01266 shuffle_order_engine(result_type __s)
01267 : _M_b(__s)
01268 { _M_initialize(); }
01269
01270
01271
01272
01273
01274
01275 template<typename _Sseq, typename = typename
01276 std::enable_if<!std::is_same<_Sseq, shuffle_order_engine>::value
01277 && !std::is_same<_Sseq, _RandomNumberEngine>::value>
01278 ::type>
01279 explicit
01280 shuffle_order_engine(_Sseq& __q)
01281 : _M_b(__q)
01282 { _M_initialize(); }
01283
01284
01285
01286
01287
01288 void
01289 seed()
01290 {
01291 _M_b.seed();
01292 _M_initialize();
01293 }
01294
01295
01296
01297
01298
01299 void
01300 seed(result_type __s)
01301 {
01302 _M_b.seed(__s);
01303 _M_initialize();
01304 }
01305
01306
01307
01308
01309
01310
01311 template<typename _Sseq>
01312 void
01313 seed(_Sseq& __q)
01314 {
01315 _M_b.seed(__q);
01316 _M_initialize();
01317 }
01318
01319
01320
01321
01322 const _RandomNumberEngine&
01323 base() const
01324 { return _M_b; }
01325
01326
01327
01328
01329 static constexpr result_type
01330 min()
01331 { return _RandomNumberEngine::min(); }
01332
01333
01334
01335
01336 static constexpr result_type
01337 max()
01338 { return _RandomNumberEngine::max(); }
01339
01340
01341
01342
01343 void
01344 discard(unsigned long long __z)
01345 {
01346 for (; __z != 0ULL; --__z)
01347 (*this)();
01348 }
01349
01350
01351
01352
01353 result_type
01354 operator()();
01355
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367 friend bool
01368 operator==(const shuffle_order_engine& __lhs,
01369 const shuffle_order_engine& __rhs)
01370 { return __lhs._M_b == __rhs._M_b; }
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383 template<typename _RandomNumberEngine1, size_t __k1,
01384 typename _CharT, typename _Traits>
01385 friend std::basic_ostream<_CharT, _Traits>&
01386 operator<<(std::basic_ostream<_CharT, _Traits>&,
01387 const std::shuffle_order_engine<_RandomNumberEngine1,
01388 __k1>&);
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401 template<typename _RandomNumberEngine1, size_t __k1,
01402 typename _CharT, typename _Traits>
01403 friend std::basic_istream<_CharT, _Traits>&
01404 operator>>(std::basic_istream<_CharT, _Traits>&,
01405 std::shuffle_order_engine<_RandomNumberEngine1, __k1>&);
01406
01407 private:
01408 void _M_initialize()
01409 {
01410 for (size_t __i = 0; __i < __k; ++__i)
01411 _M_v[__i] = _M_b();
01412 _M_y = _M_b();
01413 }
01414
01415 _RandomNumberEngine _M_b;
01416 result_type _M_v[__k];
01417 result_type _M_y;
01418 };
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431 template<typename _RandomNumberEngine, size_t __k>
01432 inline bool
01433 operator!=(const std::shuffle_order_engine<_RandomNumberEngine,
01434 __k>& __lhs,
01435 const std::shuffle_order_engine<_RandomNumberEngine,
01436 __k>& __rhs)
01437 { return !(__lhs == __rhs); }
01438
01439
01440
01441
01442
01443 typedef linear_congruential_engine<uint_fast32_t, 16807UL, 0UL, 2147483647UL>
01444 minstd_rand0;
01445
01446
01447
01448
01449 typedef linear_congruential_engine<uint_fast32_t, 48271UL, 0UL, 2147483647UL>
01450 minstd_rand;
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460 typedef mersenne_twister_engine<
01461 uint_fast32_t,
01462 32, 624, 397, 31,
01463 0x9908b0dfUL, 11,
01464 0xffffffffUL, 7,
01465 0x9d2c5680UL, 15,
01466 0xefc60000UL, 18, 1812433253UL> mt19937;
01467
01468
01469
01470
01471 typedef mersenne_twister_engine<
01472 uint_fast64_t,
01473 64, 312, 156, 31,
01474 0xb5026f5aa96619e9ULL, 29,
01475 0x5555555555555555ULL, 17,
01476 0x71d67fffeda60000ULL, 37,
01477 0xfff7eee000000000ULL, 43,
01478 6364136223846793005ULL> mt19937_64;
01479
01480 typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>
01481 ranlux24_base;
01482
01483 typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>
01484 ranlux48_base;
01485
01486 typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24;
01487
01488 typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48;
01489
01490 typedef shuffle_order_engine<minstd_rand0, 256> knuth_b;
01491
01492 typedef minstd_rand0 default_random_engine;
01493
01494
01495
01496
01497
01498 class random_device
01499 {
01500 public:
01501
01502 typedef unsigned int result_type;
01503
01504
01505
01506 #ifdef _GLIBCXX_USE_RANDOM_TR1
01507
01508 explicit
01509 random_device(const std::string& __token = "/dev/urandom")
01510 {
01511 if ((__token != "/dev/urandom" && __token != "/dev/random")
01512 || !(_M_file = std::fopen(__token.c_str(), "rb")))
01513 std::__throw_runtime_error(__N("random_device::"
01514 "random_device(const std::string&)"));
01515 }
01516
01517 ~random_device()
01518 { std::fclose(_M_file); }
01519
01520 #else
01521
01522 explicit
01523 random_device(const std::string& __token = "mt19937")
01524 : _M_mt(_M_strtoul(__token)) { }
01525
01526 private:
01527 static unsigned long
01528 _M_strtoul(const std::string& __str)
01529 {
01530 unsigned long __ret = 5489UL;
01531 if (__str != "mt19937")
01532 {
01533 const char* __nptr = __str.c_str();
01534 char* __endptr;
01535 __ret = std::strtoul(__nptr, &__endptr, 0);
01536 if (*__nptr == '\0' || *__endptr != '\0')
01537 std::__throw_runtime_error(__N("random_device::_M_strtoul"
01538 "(const std::string&)"));
01539 }
01540 return __ret;
01541 }
01542
01543 public:
01544
01545 #endif
01546
01547 result_type
01548 min() const
01549 { return std::numeric_limits<result_type>::min(); }
01550
01551 result_type
01552 max() const
01553 { return std::numeric_limits<result_type>::max(); }
01554
01555 double
01556 entropy() const
01557 { return 0.0; }
01558
01559 result_type
01560 operator()()
01561 {
01562 #ifdef _GLIBCXX_USE_RANDOM_TR1
01563 result_type __ret;
01564 std::fread(reinterpret_cast<void*>(&__ret), sizeof(result_type),
01565 1, _M_file);
01566 return __ret;
01567 #else
01568 return _M_mt();
01569 #endif
01570 }
01571
01572
01573 random_device(const random_device&) = delete;
01574 void operator=(const random_device&) = delete;
01575
01576 private:
01577
01578 #ifdef _GLIBCXX_USE_RANDOM_TR1
01579 FILE* _M_file;
01580 #else
01581 mt19937 _M_mt;
01582 #endif
01583 };
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601
01602
01603
01604 template<typename _IntType = int>
01605 class uniform_int_distribution
01606 {
01607 static_assert(std::is_integral<_IntType>::value,
01608 "template argument not an integral type");
01609
01610 public:
01611
01612 typedef _IntType result_type;
01613
01614 struct param_type
01615 {
01616 typedef uniform_int_distribution<_IntType> distribution_type;
01617
01618 explicit
01619 param_type(_IntType __a = 0,
01620 _IntType __b = std::numeric_limits<_IntType>::max())
01621 : _M_a(__a), _M_b(__b)
01622 {
01623 _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b);
01624 }
01625
01626 result_type
01627 a() const
01628 { return _M_a; }
01629
01630 result_type
01631 b() const
01632 { return _M_b; }
01633
01634 friend bool
01635 operator==(const param_type& __p1, const param_type& __p2)
01636 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
01637
01638 private:
01639 _IntType _M_a;
01640 _IntType _M_b;
01641 };
01642
01643 public:
01644
01645
01646
01647 explicit
01648 uniform_int_distribution(_IntType __a = 0,
01649 _IntType __b = std::numeric_limits<_IntType>::max())
01650 : _M_param(__a, __b)
01651 { }
01652
01653 explicit
01654 uniform_int_distribution(const param_type& __p)
01655 : _M_param(__p)
01656 { }
01657
01658
01659
01660
01661
01662
01663 void
01664 reset() { }
01665
01666 result_type
01667 a() const
01668 { return _M_param.a(); }
01669
01670 result_type
01671 b() const
01672 { return _M_param.b(); }
01673
01674
01675
01676
01677 param_type
01678 param() const
01679 { return _M_param; }
01680
01681
01682
01683
01684
01685 void
01686 param(const param_type& __param)
01687 { _M_param = __param; }
01688
01689
01690
01691
01692 result_type
01693 min() const
01694 { return this->a(); }
01695
01696
01697
01698
01699 result_type
01700 max() const
01701 { return this->b(); }
01702
01703
01704
01705
01706 template<typename _UniformRandomNumberGenerator>
01707 result_type
01708 operator()(_UniformRandomNumberGenerator& __urng)
01709 { return this->operator()(__urng, this->param()); }
01710
01711 template<typename _UniformRandomNumberGenerator>
01712 result_type
01713 operator()(_UniformRandomNumberGenerator& __urng,
01714 const param_type& __p);
01715
01716 param_type _M_param;
01717 };
01718
01719
01720
01721
01722
01723 template<typename _IntType>
01724 inline bool
01725 operator==(const std::uniform_int_distribution<_IntType>& __d1,
01726 const std::uniform_int_distribution<_IntType>& __d2)
01727 { return __d1.param() == __d2.param(); }
01728
01729
01730
01731
01732
01733 template<typename _IntType>
01734 inline bool
01735 operator!=(const std::uniform_int_distribution<_IntType>& __d1,
01736 const std::uniform_int_distribution<_IntType>& __d2)
01737 { return !(__d1 == __d2); }
01738
01739
01740
01741
01742
01743
01744
01745
01746
01747
01748
01749 template<typename _IntType, typename _CharT, typename _Traits>
01750 std::basic_ostream<_CharT, _Traits>&
01751 operator<<(std::basic_ostream<_CharT, _Traits>&,
01752 const std::uniform_int_distribution<_IntType>&);
01753
01754
01755
01756
01757
01758
01759
01760
01761
01762
01763 template<typename _IntType, typename _CharT, typename _Traits>
01764 std::basic_istream<_CharT, _Traits>&
01765 operator>>(std::basic_istream<_CharT, _Traits>&,
01766 std::uniform_int_distribution<_IntType>&);
01767
01768
01769
01770
01771
01772
01773
01774
01775
01776 template<typename _RealType = double>
01777 class uniform_real_distribution
01778 {
01779 static_assert(std::is_floating_point<_RealType>::value,
01780 "template argument not a floating point type");
01781
01782 public:
01783
01784 typedef _RealType result_type;
01785
01786 struct param_type
01787 {
01788 typedef uniform_real_distribution<_RealType> distribution_type;
01789
01790 explicit
01791 param_type(_RealType __a = _RealType(0),
01792 _RealType __b = _RealType(1))
01793 : _M_a(__a), _M_b(__b)
01794 {
01795 _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b);
01796 }
01797
01798 result_type
01799 a() const
01800 { return _M_a; }
01801
01802 result_type
01803 b() const
01804 { return _M_b; }
01805
01806 friend bool
01807 operator==(const param_type& __p1, const param_type& __p2)
01808 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
01809
01810 private:
01811 _RealType _M_a;
01812 _RealType _M_b;
01813 };
01814
01815 public:
01816
01817
01818
01819
01820
01821
01822 explicit
01823 uniform_real_distribution(_RealType __a = _RealType(0),
01824 _RealType __b = _RealType(1))
01825 : _M_param(__a, __b)
01826 { }
01827
01828 explicit
01829 uniform_real_distribution(const param_type& __p)
01830 : _M_param(__p)
01831 { }
01832
01833
01834
01835
01836
01837
01838 void
01839 reset() { }
01840
01841 result_type
01842 a() const
01843 { return _M_param.a(); }
01844
01845 result_type
01846 b() const
01847 { return _M_param.b(); }
01848
01849
01850
01851
01852 param_type
01853 param() const
01854 { return _M_param; }
01855
01856
01857
01858
01859
01860 void
01861 param(const param_type& __param)
01862 { _M_param = __param; }
01863
01864
01865
01866
01867 result_type
01868 min() const
01869 { return this->a(); }
01870
01871
01872
01873
01874 result_type
01875 max() const
01876 { return this->b(); }
01877
01878
01879
01880
01881 template<typename _UniformRandomNumberGenerator>
01882 result_type
01883 operator()(_UniformRandomNumberGenerator& __urng)
01884 { return this->operator()(__urng, this->param()); }
01885
01886 template<typename _UniformRandomNumberGenerator>
01887 result_type
01888 operator()(_UniformRandomNumberGenerator& __urng,
01889 const param_type& __p)
01890 {
01891 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
01892 __aurng(__urng);
01893 return (__aurng() * (__p.b() - __p.a())) + __p.a();
01894 }
01895
01896 private:
01897 param_type _M_param;
01898 };
01899
01900
01901
01902
01903
01904 template<typename _IntType>
01905 inline bool
01906 operator==(const std::uniform_real_distribution<_IntType>& __d1,
01907 const std::uniform_real_distribution<_IntType>& __d2)
01908 { return __d1.param() == __d2.param(); }
01909
01910
01911
01912
01913
01914 template<typename _IntType>
01915 inline bool
01916 operator!=(const std::uniform_real_distribution<_IntType>& __d1,
01917 const std::uniform_real_distribution<_IntType>& __d2)
01918 { return !(__d1 == __d2); }
01919
01920
01921
01922
01923
01924
01925
01926
01927
01928
01929
01930 template<typename _RealType, typename _CharT, typename _Traits>
01931 std::basic_ostream<_CharT, _Traits>&
01932 operator<<(std::basic_ostream<_CharT, _Traits>&,
01933 const std::uniform_real_distribution<_RealType>&);
01934
01935
01936
01937
01938
01939
01940
01941
01942
01943
01944 template<typename _RealType, typename _CharT, typename _Traits>
01945 std::basic_istream<_CharT, _Traits>&
01946 operator>>(std::basic_istream<_CharT, _Traits>&,
01947 std::uniform_real_distribution<_RealType>&);
01948
01949
01950
01951
01952
01953
01954
01955
01956
01957
01958
01959
01960
01961
01962
01963
01964
01965
01966 template<typename _RealType = double>
01967 class normal_distribution
01968 {
01969 static_assert(std::is_floating_point<_RealType>::value,
01970 "template argument not a floating point type");
01971
01972 public:
01973
01974 typedef _RealType result_type;
01975
01976 struct param_type
01977 {
01978 typedef normal_distribution<_RealType> distribution_type;
01979
01980 explicit
01981 param_type(_RealType __mean = _RealType(0),
01982 _RealType __stddev = _RealType(1))
01983 : _M_mean(__mean), _M_stddev(__stddev)
01984 {
01985 _GLIBCXX_DEBUG_ASSERT(_M_stddev > _RealType(0));
01986 }
01987
01988 _RealType
01989 mean() const
01990 { return _M_mean; }
01991
01992 _RealType
01993 stddev() const
01994 { return _M_stddev; }
01995
01996 friend bool
01997 operator==(const param_type& __p1, const param_type& __p2)
01998 { return (__p1._M_mean == __p2._M_mean
01999 && __p1._M_stddev == __p2._M_stddev); }
02000
02001 private:
02002 _RealType _M_mean;
02003 _RealType _M_stddev;
02004 };
02005
02006 public:
02007
02008
02009
02010
02011 explicit
02012 normal_distribution(result_type __mean = result_type(0),
02013 result_type __stddev = result_type(1))
02014 : _M_param(__mean, __stddev), _M_saved_available(false)
02015 { }
02016
02017 explicit
02018 normal_distribution(const param_type& __p)
02019 : _M_param(__p), _M_saved_available(false)
02020 { }
02021
02022
02023
02024
02025 void
02026 reset()
02027 { _M_saved_available = false; }
02028
02029
02030
02031
02032 _RealType
02033 mean() const
02034 { return _M_param.mean(); }
02035
02036
02037
02038
02039 _RealType
02040 stddev() const
02041 { return _M_param.stddev(); }
02042
02043
02044
02045
02046 param_type
02047 param() const
02048 { return _M_param; }
02049
02050
02051
02052
02053
02054 void
02055 param(const param_type& __param)
02056 { _M_param = __param; }
02057
02058
02059
02060
02061 result_type
02062 min() const
02063 { return std::numeric_limits<result_type>::min(); }
02064
02065
02066
02067
02068 result_type
02069 max() const
02070 { return std::numeric_limits<result_type>::max(); }
02071
02072
02073
02074
02075 template<typename _UniformRandomNumberGenerator>
02076 result_type
02077 operator()(_UniformRandomNumberGenerator& __urng)
02078 { return this->operator()(__urng, this->param()); }
02079
02080 template<typename _UniformRandomNumberGenerator>
02081 result_type
02082 operator()(_UniformRandomNumberGenerator& __urng,
02083 const param_type& __p);
02084
02085
02086
02087
02088
02089
02090 template<typename _RealType1>
02091 friend bool
02092 operator==(const std::normal_distribution<_RealType1>& __d1,
02093 const std::normal_distribution<_RealType1>& __d2);
02094
02095
02096
02097
02098
02099
02100
02101
02102
02103
02104
02105 template<typename _RealType1, typename _CharT, typename _Traits>
02106 friend std::basic_ostream<_CharT, _Traits>&
02107 operator<<(std::basic_ostream<_CharT, _Traits>&,
02108 const std::normal_distribution<_RealType1>&);
02109
02110
02111
02112
02113
02114
02115
02116
02117
02118
02119
02120 template<typename _RealType1, typename _CharT, typename _Traits>
02121 friend std::basic_istream<_CharT, _Traits>&
02122 operator>>(std::basic_istream<_CharT, _Traits>&,
02123 std::normal_distribution<_RealType1>&);
02124
02125 private:
02126 param_type _M_param;
02127 result_type _M_saved;
02128 bool _M_saved_available;
02129 };
02130
02131
02132
02133
02134 template<typename _RealType>
02135 inline bool
02136 operator!=(const std::normal_distribution<_RealType>& __d1,
02137 const std::normal_distribution<_RealType>& __d2)
02138 { return !(__d1 == __d2); }
02139
02140
02141
02142
02143
02144
02145
02146
02147
02148
02149
02150 template<typename _RealType = double>
02151 class lognormal_distribution
02152 {
02153 static_assert(std::is_floating_point<_RealType>::value,
02154 "template argument not a floating point type");
02155
02156 public:
02157
02158 typedef _RealType result_type;
02159
02160 struct param_type
02161 {
02162 typedef lognormal_distribution<_RealType> distribution_type;
02163
02164 explicit
02165 param_type(_RealType __m = _RealType(0),
02166 _RealType __s = _RealType(1))
02167 : _M_m(__m), _M_s(__s)
02168 { }
02169
02170 _RealType
02171 m() const
02172 { return _M_m; }
02173
02174 _RealType
02175 s() const
02176 { return _M_s; }
02177
02178 friend bool
02179 operator==(const param_type& __p1, const param_type& __p2)
02180 { return __p1._M_m == __p2._M_m && __p1._M_s == __p2._M_s; }
02181
02182 private:
02183 _RealType _M_m;
02184 _RealType _M_s;
02185 };
02186
02187 explicit
02188 lognormal_distribution(_RealType __m = _RealType(0),
02189 _RealType __s = _RealType(1))
02190 : _M_param(__m, __s), _M_nd()
02191 { }
02192
02193 explicit
02194 lognormal_distribution(const param_type& __p)
02195 : _M_param(__p), _M_nd()
02196 { }
02197
02198
02199
02200
02201 void
02202 reset()
02203 { _M_nd.reset(); }
02204
02205
02206
02207
02208 _RealType
02209 m() const
02210 { return _M_param.m(); }
02211
02212 _RealType
02213 s() const
02214 { return _M_param.s(); }
02215
02216
02217
02218
02219 param_type
02220 param() const
02221 { return _M_param; }
02222
02223
02224
02225
02226
02227 void
02228 param(const param_type& __param)
02229 { _M_param = __param; }
02230
02231
02232
02233
02234 result_type
02235 min() const
02236 { return result_type(0); }
02237
02238
02239
02240
02241 result_type
02242 max() const
02243 { return std::numeric_limits<result_type>::max(); }
02244
02245
02246
02247
02248 template<typename _UniformRandomNumberGenerator>
02249 result_type
02250 operator()(_UniformRandomNumberGenerator& __urng)
02251 { return this->operator()(__urng, this->param()); }
02252
02253 template<typename _UniformRandomNumberGenerator>
02254 result_type
02255 operator()(_UniformRandomNumberGenerator& __urng,
02256 const param_type& __p)
02257 { return std::exp(__p.s() * _M_nd(__urng) + __p.m()); }
02258
02259
02260
02261
02262
02263
02264 template<typename _RealType1>
02265 friend bool
02266 operator==(const std::lognormal_distribution<_RealType1>& __d1,
02267 const std::lognormal_distribution<_RealType1>& __d2)
02268 { return (__d1.param() == __d2.param()
02269 && __d1._M_nd == __d2._M_nd); }
02270
02271
02272
02273
02274
02275
02276
02277
02278
02279
02280
02281 template<typename _RealType1, typename _CharT, typename _Traits>
02282 friend std::basic_ostream<_CharT, _Traits>&
02283 operator<<(std::basic_ostream<_CharT, _Traits>&,
02284 const std::lognormal_distribution<_RealType1>&);
02285
02286
02287
02288
02289
02290
02291
02292
02293
02294
02295
02296 template<typename _RealType1, typename _CharT, typename _Traits>
02297 friend std::basic_istream<_CharT, _Traits>&
02298 operator>>(std::basic_istream<_CharT, _Traits>&,
02299 std::lognormal_distribution<_RealType1>&);
02300
02301 private:
02302 param_type _M_param;
02303
02304 std::normal_distribution<result_type> _M_nd;
02305 };
02306
02307
02308
02309
02310 template<typename _RealType>
02311 inline bool
02312 operator!=(const std::lognormal_distribution<_RealType>& __d1,
02313 const std::lognormal_distribution<_RealType>& __d2)
02314 { return !(__d1 == __d2); }
02315
02316
02317
02318
02319
02320
02321
02322
02323
02324
02325
02326 template<typename _RealType = double>
02327 class gamma_distribution
02328 {
02329 static_assert(std::is_floating_point<_RealType>::value,
02330 "template argument not a floating point type");
02331
02332 public:
02333
02334 typedef _RealType result_type;
02335
02336 struct param_type
02337 {
02338 typedef gamma_distribution<_RealType> distribution_type;
02339 friend class gamma_distribution<_RealType>;
02340
02341 explicit
02342 param_type(_RealType __alpha_val = _RealType(1),
02343 _RealType __beta_val = _RealType(1))
02344 : _M_alpha(__alpha_val), _M_beta(__beta_val)
02345 {
02346 _GLIBCXX_DEBUG_ASSERT(_M_alpha > _RealType(0));
02347 _M_initialize();
02348 }
02349
02350 _RealType
02351 alpha() const
02352 { return _M_alpha; }
02353
02354 _RealType
02355 beta() const
02356 { return _M_beta; }
02357
02358 friend bool
02359 operator==(const param_type& __p1, const param_type& __p2)
02360 { return (__p1._M_alpha == __p2._M_alpha
02361 && __p1._M_beta == __p2._M_beta); }
02362
02363 private:
02364 void
02365 _M_initialize();
02366
02367 _RealType _M_alpha;
02368 _RealType _M_beta;
02369
02370 _RealType _M_malpha, _M_a2;
02371 };
02372
02373 public:
02374
02375
02376
02377
02378 explicit
02379 gamma_distribution(_RealType __alpha_val = _RealType(1),
02380 _RealType __beta_val = _RealType(1))
02381 : _M_param(__alpha_val, __beta_val), _M_nd()
02382 { }
02383
02384 explicit
02385 gamma_distribution(const param_type& __p)
02386 : _M_param(__p), _M_nd()
02387 { }
02388
02389
02390
02391
02392 void
02393 reset()
02394 { _M_nd.reset(); }
02395
02396
02397
02398
02399 _RealType
02400 alpha() const
02401 { return _M_param.alpha(); }
02402
02403
02404
02405
02406 _RealType
02407 beta() const
02408 { return _M_param.beta(); }
02409
02410
02411
02412
02413 param_type
02414 param() const
02415 { return _M_param; }
02416
02417
02418
02419
02420
02421 void
02422 param(const param_type& __param)
02423 { _M_param = __param; }
02424
02425
02426
02427
02428 result_type
02429 min() const
02430 { return result_type(0); }
02431
02432
02433
02434
02435 result_type
02436 max() const
02437 { return std::numeric_limits<result_type>::max(); }
02438
02439
02440
02441
02442 template<typename _UniformRandomNumberGenerator>
02443 result_type
02444 operator()(_UniformRandomNumberGenerator& __urng)
02445 { return this->operator()(__urng, this->param()); }
02446
02447 template<typename _UniformRandomNumberGenerator>
02448 result_type
02449 operator()(_UniformRandomNumberGenerator& __urng,
02450 const param_type& __p);
02451
02452
02453
02454
02455
02456
02457 template<typename _RealType1>
02458 friend bool
02459 operator==(const std::gamma_distribution<_RealType1>& __d1,
02460 const std::gamma_distribution<_RealType1>& __d2)
02461 { return (__d1.param() == __d2.param()
02462 && __d1._M_nd == __d2._M_nd); }
02463
02464
02465
02466
02467
02468
02469
02470
02471
02472
02473
02474 template<typename _RealType1, typename _CharT, typename _Traits>
02475 friend std::basic_ostream<_CharT, _Traits>&
02476 operator<<(std::basic_ostream<_CharT, _Traits>&,
02477 const std::gamma_distribution<_RealType1>&);
02478
02479
02480
02481
02482
02483
02484
02485
02486
02487
02488 template<typename _RealType1, typename _CharT, typename _Traits>
02489 friend std::basic_istream<_CharT, _Traits>&
02490 operator>>(std::basic_istream<_CharT, _Traits>&,
02491 std::gamma_distribution<_RealType1>&);
02492
02493 private:
02494 param_type _M_param;
02495
02496 std::normal_distribution<result_type> _M_nd;
02497 };
02498
02499
02500
02501
02502 template<typename _RealType>
02503 inline bool
02504 operator!=(const std::gamma_distribution<_RealType>& __d1,
02505 const std::gamma_distribution<_RealType>& __d2)
02506 { return !(__d1 == __d2); }
02507
02508
02509
02510
02511
02512
02513
02514
02515 template<typename _RealType = double>
02516 class chi_squared_distribution
02517 {
02518 static_assert(std::is_floating_point<_RealType>::value,
02519 "template argument not a floating point type");
02520
02521 public:
02522
02523 typedef _RealType result_type;
02524
02525 struct param_type
02526 {
02527 typedef chi_squared_distribution<_RealType> distribution_type;
02528
02529 explicit
02530 param_type(_RealType __n = _RealType(1))
02531 : _M_n(__n)
02532 { }
02533
02534 _RealType
02535 n() const
02536 { return _M_n; }
02537
02538 friend bool
02539 operator==(const param_type& __p1, const param_type& __p2)
02540 { return __p1._M_n == __p2._M_n; }
02541
02542 private:
02543 _RealType _M_n;
02544 };
02545
02546 explicit
02547 chi_squared_distribution(_RealType __n = _RealType(1))
02548 : _M_param(__n), _M_gd(__n / 2)
02549 { }
02550
02551 explicit
02552 chi_squared_distribution(const param_type& __p)
02553 : _M_param(__p), _M_gd(__p.n() / 2)
02554 { }
02555
02556
02557
02558
02559 void
02560 reset()
02561 { _M_gd.reset(); }
02562
02563
02564
02565
02566 _RealType
02567 n() const
02568 { return _M_param.n(); }
02569
02570
02571
02572
02573 param_type
02574 param() const
02575 { return _M_param; }
02576
02577
02578
02579
02580
02581 void
02582 param(const param_type& __param)
02583 { _M_param = __param; }
02584
02585
02586
02587
02588 result_type
02589 min() const
02590 { return result_type(0); }
02591
02592
02593
02594
02595 result_type
02596 max() const
02597 { return std::numeric_limits<result_type>::max(); }
02598
02599
02600
02601
02602 template<typename _UniformRandomNumberGenerator>
02603 result_type
02604 operator()(_UniformRandomNumberGenerator& __urng)
02605 { return 2 * _M_gd(__urng); }
02606
02607 template<typename _UniformRandomNumberGenerator>
02608 result_type
02609 operator()(_UniformRandomNumberGenerator& __urng,
02610 const param_type& __p)
02611 {
02612 typedef typename std::gamma_distribution<result_type>::param_type
02613 param_type;
02614 return 2 * _M_gd(__urng, param_type(__p.n() / 2));
02615 }
02616
02617
02618
02619
02620
02621
02622 template<typename _RealType1>
02623 friend bool
02624 operator==(const std::chi_squared_distribution<_RealType1>& __d1,
02625 const std::chi_squared_distribution<_RealType1>& __d2)
02626 { return __d1.param() == __d2.param() && __d1._M_gd == __d2._M_gd; }
02627
02628
02629
02630
02631
02632
02633
02634
02635
02636
02637
02638 template<typename _RealType1, typename _CharT, typename _Traits>
02639 friend std::basic_ostream<_CharT, _Traits>&
02640 operator<<(std::basic_ostream<_CharT, _Traits>&,
02641 const std::chi_squared_distribution<_RealType1>&);
02642
02643
02644
02645
02646
02647
02648
02649
02650
02651
02652
02653 template<typename _RealType1, typename _CharT, typename _Traits>
02654 friend std::basic_istream<_CharT, _Traits>&
02655 operator>>(std::basic_istream<_CharT, _Traits>&,
02656 std::chi_squared_distribution<_RealType1>&);
02657
02658 private:
02659 param_type _M_param;
02660
02661 std::gamma_distribution<result_type> _M_gd;
02662 };
02663
02664
02665
02666
02667 template<typename _RealType>
02668 inline bool
02669 operator!=(const std::chi_squared_distribution<_RealType>& __d1,
02670 const std::chi_squared_distribution<_RealType>& __d2)
02671 { return !(__d1 == __d2); }
02672
02673
02674
02675
02676
02677
02678
02679
02680 template<typename _RealType = double>
02681 class cauchy_distribution
02682 {
02683 static_assert(std::is_floating_point<_RealType>::value,
02684 "template argument not a floating point type");
02685
02686 public:
02687
02688 typedef _RealType result_type;
02689
02690 struct param_type
02691 {
02692 typedef cauchy_distribution<_RealType> distribution_type;
02693
02694 explicit
02695 param_type(_RealType __a = _RealType(0),
02696 _RealType __b = _RealType(1))
02697 : _M_a(__a), _M_b(__b)
02698 { }
02699
02700 _RealType
02701 a() const
02702 { return _M_a; }
02703
02704 _RealType
02705 b() const
02706 { return _M_b; }
02707
02708 friend bool
02709 operator==(const param_type& __p1, const param_type& __p2)
02710 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
02711
02712 private:
02713 _RealType _M_a;
02714 _RealType _M_b;
02715 };
02716
02717 explicit
02718 cauchy_distribution(_RealType __a = _RealType(0),
02719 _RealType __b = _RealType(1))
02720 : _M_param(__a, __b)
02721 { }
02722
02723 explicit
02724 cauchy_distribution(const param_type& __p)
02725 : _M_param(__p)
02726 { }
02727
02728
02729
02730
02731 void
02732 reset()
02733 { }
02734
02735
02736
02737
02738 _RealType
02739 a() const
02740 { return _M_param.a(); }
02741
02742 _RealType
02743 b() const
02744 { return _M_param.b(); }
02745
02746
02747
02748
02749 param_type
02750 param() const
02751 { return _M_param; }
02752
02753
02754
02755
02756
02757 void
02758 param(const param_type& __param)
02759 { _M_param = __param; }
02760
02761
02762
02763
02764 result_type
02765 min() const
02766 { return std::numeric_limits<result_type>::min(); }
02767
02768
02769
02770
02771 result_type
02772 max() const
02773 { return std::numeric_limits<result_type>::max(); }
02774
02775
02776
02777
02778 template<typename _UniformRandomNumberGenerator>
02779 result_type
02780 operator()(_UniformRandomNumberGenerator& __urng)
02781 { return this->operator()(__urng, this->param()); }
02782
02783 template<typename _UniformRandomNumberGenerator>
02784 result_type
02785 operator()(_UniformRandomNumberGenerator& __urng,
02786 const param_type& __p);
02787
02788 private:
02789 param_type _M_param;
02790 };
02791
02792
02793
02794
02795
02796 template<typename _RealType>
02797 inline bool
02798 operator==(const std::cauchy_distribution<_RealType>& __d1,
02799 const std::cauchy_distribution<_RealType>& __d2)
02800 { return __d1.param() == __d2.param(); }
02801
02802
02803
02804
02805
02806 template<typename _RealType>
02807 inline bool
02808 operator!=(const std::cauchy_distribution<_RealType>& __d1,
02809 const std::cauchy_distribution<_RealType>& __d2)
02810 { return !(__d1 == __d2); }
02811
02812
02813
02814
02815
02816
02817
02818
02819
02820
02821
02822 template<typename _RealType, typename _CharT, typename _Traits>
02823 std::basic_ostream<_CharT, _Traits>&
02824 operator<<(std::basic_ostream<_CharT, _Traits>&,
02825 const std::cauchy_distribution<_RealType>&);
02826
02827
02828
02829
02830
02831
02832
02833
02834
02835
02836
02837 template<typename _RealType, typename _CharT, typename _Traits>
02838 std::basic_istream<_CharT, _Traits>&
02839 operator>>(std::basic_istream<_CharT, _Traits>&,
02840 std::cauchy_distribution<_RealType>&);
02841
02842
02843
02844
02845
02846
02847
02848
02849
02850
02851
02852
02853 template<typename _RealType = double>
02854 class fisher_f_distribution
02855 {
02856 static_assert(std::is_floating_point<_RealType>::value,
02857 "template argument not a floating point type");
02858
02859 public:
02860
02861 typedef _RealType result_type;
02862
02863 struct param_type
02864 {
02865 typedef fisher_f_distribution<_RealType> distribution_type;
02866
02867 explicit
02868 param_type(_RealType __m = _RealType(1),
02869 _RealType __n = _RealType(1))
02870 : _M_m(__m), _M_n(__n)
02871 { }
02872
02873 _RealType
02874 m() const
02875 { return _M_m; }
02876
02877 _RealType
02878 n() const
02879 { return _M_n; }
02880
02881 friend bool
02882 operator==(const param_type& __p1, const param_type& __p2)
02883 { return __p1._M_m == __p2._M_m && __p1._M_n == __p2._M_n; }
02884
02885 private:
02886 _RealType _M_m;
02887 _RealType _M_n;
02888 };
02889
02890 explicit
02891 fisher_f_distribution(_RealType __m = _RealType(1),
02892 _RealType __n = _RealType(1))
02893 : _M_param(__m, __n), _M_gd_x(__m / 2), _M_gd_y(__n / 2)
02894 { }
02895
02896 explicit
02897 fisher_f_distribution(const param_type& __p)
02898 : _M_param(__p), _M_gd_x(__p.m() / 2), _M_gd_y(__p.n() / 2)
02899 { }
02900
02901
02902
02903
02904 void
02905 reset()
02906 {
02907 _M_gd_x.reset();
02908 _M_gd_y.reset();
02909 }
02910
02911
02912
02913
02914 _RealType
02915 m() const
02916 { return _M_param.m(); }
02917
02918 _RealType
02919 n() const
02920 { return _M_param.n(); }
02921
02922
02923
02924
02925 param_type
02926 param() const
02927 { return _M_param; }
02928
02929
02930
02931
02932
02933 void
02934 param(const param_type& __param)
02935 { _M_param = __param; }
02936
02937
02938
02939
02940 result_type
02941 min() const
02942 { return result_type(0); }
02943
02944
02945
02946
02947 result_type
02948 max() const
02949 { return std::numeric_limits<result_type>::max(); }
02950
02951
02952
02953
02954 template<typename _UniformRandomNumberGenerator>
02955 result_type
02956 operator()(_UniformRandomNumberGenerator& __urng)
02957 { return (_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()); }
02958
02959 template<typename _UniformRandomNumberGenerator>
02960 result_type
02961 operator()(_UniformRandomNumberGenerator& __urng,
02962 const param_type& __p)
02963 {
02964 typedef typename std::gamma_distribution<result_type>::param_type
02965 param_type;
02966 return ((_M_gd_x(__urng, param_type(__p.m() / 2)) * n())
02967 / (_M_gd_y(__urng, param_type(__p.n() / 2)) * m()));
02968 }
02969
02970
02971
02972
02973
02974
02975 template<typename _RealType1>
02976 friend bool
02977 operator==(const std::fisher_f_distribution<_RealType1>& __d1,
02978 const std::fisher_f_distribution<_RealType1>& __d2)
02979 { return (__d1.param() == __d2.param()
02980 && __d1._M_gd_x == __d2._M_gd_x
02981 && __d1._M_gd_y == __d2._M_gd_y); }
02982
02983
02984
02985
02986
02987
02988
02989
02990
02991
02992
02993 template<typename _RealType1, typename _CharT, typename _Traits>
02994 friend std::basic_ostream<_CharT, _Traits>&
02995 operator<<(std::basic_ostream<_CharT, _Traits>&,
02996 const std::fisher_f_distribution<_RealType1>&);
02997
02998
02999
03000
03001
03002
03003
03004
03005
03006
03007
03008 template<typename _RealType1, typename _CharT, typename _Traits>
03009 friend std::basic_istream<_CharT, _Traits>&
03010 operator>>(std::basic_istream<_CharT, _Traits>&,
03011 std::fisher_f_distribution<_RealType1>&);
03012
03013 private:
03014 param_type _M_param;
03015
03016 std::gamma_distribution<result_type> _M_gd_x, _M_gd_y;
03017 };
03018
03019
03020
03021
03022 template<typename _RealType>
03023 inline bool
03024 operator!=(const std::fisher_f_distribution<_RealType>& __d1,
03025 const std::fisher_f_distribution<_RealType>& __d2)
03026 { return !(__d1 == __d2); }
03027
03028
03029
03030
03031
03032
03033
03034
03035
03036
03037 template<typename _RealType = double>
03038 class student_t_distribution
03039 {
03040 static_assert(std::is_floating_point<_RealType>::value,
03041 "template argument not a floating point type");
03042
03043 public:
03044
03045 typedef _RealType result_type;
03046
03047 struct param_type
03048 {
03049 typedef student_t_distribution<_RealType> distribution_type;
03050
03051 explicit
03052 param_type(_RealType __n = _RealType(1))
03053 : _M_n(__n)
03054 { }
03055
03056 _RealType
03057 n() const
03058 { return _M_n; }
03059
03060 friend bool
03061 operator==(const param_type& __p1, const param_type& __p2)
03062 { return __p1._M_n == __p2._M_n; }
03063
03064 private:
03065 _RealType _M_n;
03066 };
03067
03068 explicit
03069 student_t_distribution(_RealType __n = _RealType(1))
03070 : _M_param(__n), _M_nd(), _M_gd(__n / 2, 2)
03071 { }
03072
03073 explicit
03074 student_t_distribution(const param_type& __p)
03075 : _M_param(__p), _M_nd(), _M_gd(__p.n() / 2, 2)
03076 { }
03077
03078
03079
03080
03081 void
03082 reset()
03083 {
03084 _M_nd.reset();
03085 _M_gd.reset();
03086 }
03087
03088
03089
03090
03091 _RealType
03092 n() const
03093 { return _M_param.n(); }
03094
03095
03096
03097
03098 param_type
03099 param() const
03100 { return _M_param; }
03101
03102
03103
03104
03105
03106 void
03107 param(const param_type& __param)
03108 { _M_param = __param; }
03109
03110
03111
03112
03113 result_type
03114 min() const
03115 { return std::numeric_limits<result_type>::min(); }
03116
03117
03118
03119
03120 result_type
03121 max() const
03122 { return std::numeric_limits<result_type>::max(); }
03123
03124
03125
03126
03127 template<typename _UniformRandomNumberGenerator>
03128 result_type
03129 operator()(_UniformRandomNumberGenerator& __urng)
03130 { return _M_nd(__urng) * std::sqrt(n() / _M_gd(__urng)); }
03131
03132 template<typename _UniformRandomNumberGenerator>
03133 result_type
03134 operator()(_UniformRandomNumberGenerator& __urng,
03135 const param_type& __p)
03136 {
03137 typedef typename std::gamma_distribution<result_type>::param_type
03138 param_type;
03139
03140 const result_type __g = _M_gd(__urng, param_type(__p.n() / 2, 2));
03141 return _M_nd(__urng) * std::sqrt(__p.n() / __g);
03142 }
03143
03144
03145
03146
03147
03148
03149 template<typename _RealType1>
03150 friend bool
03151 operator==(const std::student_t_distribution<_RealType1>& __d1,
03152 const std::student_t_distribution<_RealType1>& __d2)
03153 { return (__d1.param() == __d2.param()
03154 && __d1._M_nd == __d2._M_nd && __d1._M_gd == __d2._M_gd); }
03155
03156
03157
03158
03159
03160
03161
03162
03163
03164
03165
03166 template<typename _RealType1, typename _CharT, typename _Traits>
03167 friend std::basic_ostream<_CharT, _Traits>&
03168 operator<<(std::basic_ostream<_CharT, _Traits>&,
03169 const std::student_t_distribution<_RealType1>&);
03170
03171
03172
03173
03174
03175
03176
03177
03178
03179
03180
03181 template<typename _RealType1, typename _CharT, typename _Traits>
03182 friend std::basic_istream<_CharT, _Traits>&
03183 operator>>(std::basic_istream<_CharT, _Traits>&,
03184 std::student_t_distribution<_RealType1>&);
03185
03186 private:
03187 param_type _M_param;
03188
03189 std::normal_distribution<result_type> _M_nd;
03190 std::gamma_distribution<result_type> _M_gd;
03191 };
03192
03193
03194
03195
03196 template<typename _RealType>
03197 inline bool
03198 operator!=(const std::student_t_distribution<_RealType>& __d1,
03199 const std::student_t_distribution<_RealType>& __d2)
03200 { return !(__d1 == __d2); }
03201
03202
03203
03204
03205
03206
03207
03208
03209
03210
03211
03212
03213
03214
03215
03216
03217 class bernoulli_distribution
03218 {
03219 public:
03220
03221 typedef bool result_type;
03222
03223 struct param_type
03224 {
03225 typedef bernoulli_distribution distribution_type;
03226
03227 explicit
03228 param_type(double __p = 0.5)
03229 : _M_p(__p)
03230 {
03231 _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0) && (_M_p <= 1.0));
03232 }
03233
03234 double
03235 p() const
03236 { return _M_p; }
03237
03238 friend bool
03239 operator==(const param_type& __p1, const param_type& __p2)
03240 { return __p1._M_p == __p2._M_p; }
03241
03242 private:
03243 double _M_p;
03244 };
03245
03246 public:
03247
03248
03249
03250
03251
03252
03253 explicit
03254 bernoulli_distribution(double __p = 0.5)
03255 : _M_param(__p)
03256 { }
03257
03258 explicit
03259 bernoulli_distribution(const param_type& __p)
03260 : _M_param(__p)
03261 { }
03262
03263
03264
03265
03266
03267
03268 void
03269 reset() { }
03270
03271
03272
03273
03274 double
03275 p() const
03276 { return _M_param.p(); }
03277
03278
03279
03280
03281 param_type
03282 param() const
03283 { return _M_param; }
03284
03285
03286
03287
03288
03289 void
03290 param(const param_type& __param)
03291 { _M_param = __param; }
03292
03293
03294
03295
03296 result_type
03297 min() const
03298 { return std::numeric_limits<result_type>::min(); }
03299
03300
03301
03302
03303 result_type
03304 max() const
03305 { return std::numeric_limits<result_type>::max(); }
03306
03307
03308
03309
03310 template<typename _UniformRandomNumberGenerator>
03311 result_type
03312 operator()(_UniformRandomNumberGenerator& __urng)
03313 { return this->operator()(__urng, this->param()); }
03314
03315 template<typename _UniformRandomNumberGenerator>
03316 result_type
03317 operator()(_UniformRandomNumberGenerator& __urng,
03318 const param_type& __p)
03319 {
03320 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
03321 __aurng(__urng);
03322 if ((__aurng() - __aurng.min())
03323 < __p.p() * (__aurng.max() - __aurng.min()))
03324 return true;
03325 return false;
03326 }
03327
03328 private:
03329 param_type _M_param;
03330 };
03331
03332
03333
03334
03335
03336 inline bool
03337 operator==(const std::bernoulli_distribution& __d1,
03338 const std::bernoulli_distribution& __d2)
03339 { return __d1.param() == __d2.param(); }
03340
03341
03342
03343
03344
03345 inline bool
03346 operator!=(const std::bernoulli_distribution& __d1,
03347 const std::bernoulli_distribution& __d2)
03348 { return !(__d1 == __d2); }
03349
03350
03351
03352
03353
03354
03355
03356
03357
03358
03359
03360 template<typename _CharT, typename _Traits>
03361 std::basic_ostream<_CharT, _Traits>&
03362 operator<<(std::basic_ostream<_CharT, _Traits>&,
03363 const std::bernoulli_distribution&);
03364
03365
03366
03367
03368
03369
03370
03371
03372
03373
03374 template<typename _CharT, typename _Traits>
03375 std::basic_istream<_CharT, _Traits>&
03376 operator>>(std::basic_istream<_CharT, _Traits>& __is,
03377 std::bernoulli_distribution& __x)
03378 {
03379 double __p;
03380 __is >> __p;
03381 __x.param(bernoulli_distribution::param_type(__p));
03382 return __is;
03383 }
03384
03385
03386
03387
03388
03389
03390
03391
03392
03393 template<typename _IntType = int>
03394 class binomial_distribution
03395 {
03396 static_assert(std::is_integral<_IntType>::value,
03397 "template argument not an integral type");
03398
03399 public:
03400
03401 typedef _IntType result_type;
03402
03403 struct param_type
03404 {
03405 typedef binomial_distribution<_IntType> distribution_type;
03406 friend class binomial_distribution<_IntType>;
03407
03408 explicit
03409 param_type(_IntType __t = _IntType(1), double __p = 0.5)
03410 : _M_t(__t), _M_p(__p)
03411 {
03412 _GLIBCXX_DEBUG_ASSERT((_M_t >= _IntType(0))
03413 && (_M_p >= 0.0)
03414 && (_M_p <= 1.0));
03415 _M_initialize();
03416 }
03417
03418 _IntType
03419 t() const
03420 { return _M_t; }
03421
03422 double
03423 p() const
03424 { return _M_p; }
03425
03426 friend bool
03427 operator==(const param_type& __p1, const param_type& __p2)
03428 { return __p1._M_t == __p2._M_t && __p1._M_p == __p2._M_p; }
03429
03430 private:
03431 void
03432 _M_initialize();
03433
03434 _IntType _M_t;
03435 double _M_p;
03436
03437 double _M_q;
03438 #if _GLIBCXX_USE_C99_MATH_TR1
03439 double _M_d1, _M_d2, _M_s1, _M_s2, _M_c,
03440 _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p;
03441 #endif
03442 bool _M_easy;
03443 };
03444
03445
03446 explicit
03447 binomial_distribution(_IntType __t = _IntType(1),
03448 double __p = 0.5)
03449 : _M_param(__t, __p), _M_nd()
03450 { }
03451
03452 explicit
03453 binomial_distribution(const param_type& __p)
03454 : _M_param(__p), _M_nd()
03455 { }
03456
03457
03458
03459
03460 void
03461 reset()
03462 { _M_nd.reset(); }
03463
03464
03465
03466
03467 _IntType
03468 t() const
03469 { return _M_param.t(); }
03470
03471
03472
03473
03474 double
03475 p() const
03476 { return _M_param.p(); }
03477
03478
03479
03480
03481 param_type
03482 param() const
03483 { return _M_param; }
03484
03485
03486
03487
03488
03489 void
03490 param(const param_type& __param)
03491 { _M_param = __param; }
03492
03493
03494
03495
03496 result_type
03497 min() const
03498 { return 0; }
03499
03500
03501
03502
03503 result_type
03504 max() const
03505 { return _M_param.t(); }
03506
03507
03508
03509
03510 template<typename _UniformRandomNumberGenerator>
03511 result_type
03512 operator()(_UniformRandomNumberGenerator& __urng)
03513 { return this->operator()(__urng, this->param()); }
03514
03515 template<typename _UniformRandomNumberGenerator>
03516 result_type
03517 operator()(_UniformRandomNumberGenerator& __urng,
03518 const param_type& __p);
03519
03520
03521
03522
03523
03524
03525 template<typename _IntType1>
03526 friend bool
03527 operator==(const std::binomial_distribution<_IntType1>& __d1,
03528 const std::binomial_distribution<_IntType1>& __d2)
03529 #ifdef _GLIBCXX_USE_C99_MATH_TR1
03530 { return __d1.param() == __d2.param() && __d1._M_nd == __d2._M_nd; }
03531 #else
03532 { return __d1.param() == __d2.param(); }
03533 #endif
03534
03535
03536
03537
03538
03539
03540
03541
03542
03543
03544
03545 template<typename _IntType1,
03546 typename _CharT, typename _Traits>
03547 friend std::basic_ostream<_CharT, _Traits>&
03548 operator<<(std::basic_ostream<_CharT, _Traits>&,
03549 const std::binomial_distribution<_IntType1>&);
03550
03551
03552
03553
03554
03555
03556
03557
03558
03559
03560
03561 template<typename _IntType1,
03562 typename _CharT, typename _Traits>
03563 friend std::basic_istream<_CharT, _Traits>&
03564 operator>>(std::basic_istream<_CharT, _Traits>&,
03565 std::binomial_distribution<_IntType1>&);
03566
03567 private:
03568 template<typename _UniformRandomNumberGenerator>
03569 result_type
03570 _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t);
03571
03572 param_type _M_param;
03573
03574
03575 std::normal_distribution<double> _M_nd;
03576 };
03577
03578
03579
03580
03581 template<typename _IntType>
03582 inline bool
03583 operator!=(const std::binomial_distribution<_IntType>& __d1,
03584 const std::binomial_distribution<_IntType>& __d2)
03585 { return !(__d1 == __d2); }
03586
03587
03588
03589
03590
03591
03592
03593
03594
03595 template<typename _IntType = int>
03596 class geometric_distribution
03597 {
03598 static_assert(std::is_integral<_IntType>::value,
03599 "template argument not an integral type");
03600
03601 public:
03602
03603 typedef _IntType result_type;
03604
03605 struct param_type
03606 {
03607 typedef geometric_distribution<_IntType> distribution_type;
03608 friend class geometric_distribution<_IntType>;
03609
03610 explicit
03611 param_type(double __p = 0.5)
03612 : _M_p(__p)
03613 {
03614 _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0)
03615 && (_M_p <= 1.0));
03616 _M_initialize();
03617 }
03618
03619 double
03620 p() const
03621 { return _M_p; }
03622
03623 friend bool
03624 operator==(const param_type& __p1, const param_type& __p2)
03625 { return __p1._M_p == __p2._M_p; }
03626
03627 private:
03628 void
03629 _M_initialize()
03630 { _M_log_p = std::log(_M_p); }
03631
03632 double _M_p;
03633
03634 double _M_log_p;
03635 };
03636
03637
03638 explicit
03639 geometric_distribution(double __p = 0.5)
03640 : _M_param(__p)
03641 { }
03642
03643 explicit
03644 geometric_distribution(const param_type& __p)
03645 : _M_param(__p)
03646 { }
03647
03648
03649
03650
03651
03652
03653 void
03654 reset() { }
03655
03656
03657
03658
03659 double
03660 p() const
03661 { return _M_param.p(); }
03662
03663
03664
03665
03666 param_type
03667 param() const
03668 { return _M_param; }
03669
03670
03671
03672
03673
03674 void
03675 param(const param_type& __param)
03676 { _M_param = __param; }
03677
03678
03679
03680
03681 result_type
03682 min() const
03683 { return 0; }
03684
03685
03686
03687
03688 result_type
03689 max() const
03690 { return std::numeric_limits<result_type>::max(); }
03691
03692
03693
03694
03695 template<typename _UniformRandomNumberGenerator>
03696 result_type
03697 operator()(_UniformRandomNumberGenerator& __urng)
03698 { return this->operator()(__urng, this->param()); }
03699
03700 template<typename _UniformRandomNumberGenerator>
03701 result_type
03702 operator()(_UniformRandomNumberGenerator& __urng,
03703 const param_type& __p);
03704
03705 private:
03706 param_type _M_param;
03707 };
03708
03709
03710
03711
03712
03713 template<typename _IntType>
03714 inline bool
03715 operator==(const std::geometric_distribution<_IntType>& __d1,
03716 const std::geometric_distribution<_IntType>& __d2)
03717 { return __d1.param() == __d2.param(); }
03718
03719
03720
03721
03722
03723 template<typename _IntType>
03724 inline bool
03725 operator!=(const std::geometric_distribution<_IntType>& __d1,
03726 const std::geometric_distribution<_IntType>& __d2)
03727 { return !(__d1 == __d2); }
03728
03729
03730
03731
03732
03733
03734
03735
03736
03737
03738
03739 template<typename _IntType,
03740 typename _CharT, typename _Traits>
03741 std::basic_ostream<_CharT, _Traits>&
03742 operator<<(std::basic_ostream<_CharT, _Traits>&,
03743 const std::geometric_distribution<_IntType>&);
03744
03745
03746
03747
03748
03749
03750
03751
03752
03753
03754 template<typename _IntType,
03755 typename _CharT, typename _Traits>
03756 std::basic_istream<_CharT, _Traits>&
03757 operator>>(std::basic_istream<_CharT, _Traits>&,
03758 std::geometric_distribution<_IntType>&);
03759
03760
03761
03762
03763
03764
03765
03766
03767
03768 template<typename _IntType = int>
03769 class negative_binomial_distribution
03770 {
03771 static_assert(std::is_integral<_IntType>::value,
03772 "template argument not an integral type");
03773
03774 public:
03775
03776 typedef _IntType result_type;
03777
03778 struct param_type
03779 {
03780 typedef negative_binomial_distribution<_IntType> distribution_type;
03781
03782 explicit
03783 param_type(_IntType __k = 1, double __p = 0.5)
03784 : _M_k(__k), _M_p(__p)
03785 { }
03786
03787 _IntType
03788 k() const
03789 { return _M_k; }
03790
03791 double
03792 p() const
03793 { return _M_p; }
03794
03795 friend bool
03796 operator==(const param_type& __p1, const param_type& __p2)
03797 { return __p1._M_k == __p2._M_k && __p1._M_p == __p2._M_p; }
03798
03799 private:
03800 _IntType _M_k;
03801 double _M_p;
03802 };
03803
03804 explicit
03805 negative_binomial_distribution(_IntType __k = 1, double __p = 0.5)
03806 : _M_param(__k, __p), _M_gd(__k, __p / (1.0 - __p))
03807 { }
03808
03809 explicit
03810 negative_binomial_distribution(const param_type& __p)
03811 : _M_param(__p), _M_gd(__p.k(), __p.p() / (1.0 - __p.p()))
03812 { }
03813
03814
03815
03816
03817 void
03818 reset()
03819 { _M_gd.reset(); }
03820
03821
03822
03823
03824 _IntType
03825 k() const
03826 { return _M_param.k(); }
03827
03828
03829
03830
03831 double
03832 p() const
03833 { return _M_param.p(); }
03834
03835
03836
03837
03838 param_type
03839 param() const
03840 { return _M_param; }
03841
03842
03843
03844
03845
03846 void
03847 param(const param_type& __param)
03848 { _M_param = __param; }
03849
03850
03851
03852
03853 result_type
03854 min() const
03855 { return result_type(0); }
03856
03857
03858
03859
03860 result_type
03861 max() const
03862 { return std::numeric_limits<result_type>::max(); }
03863
03864
03865
03866
03867 template<typename _UniformRandomNumberGenerator>
03868 result_type
03869 operator()(_UniformRandomNumberGenerator& __urng);
03870
03871 template<typename _UniformRandomNumberGenerator>
03872 result_type
03873 operator()(_UniformRandomNumberGenerator& __urng,
03874 const param_type& __p);
03875
03876
03877
03878
03879
03880
03881 template<typename _IntType1>
03882 friend bool
03883 operator==(const std::negative_binomial_distribution<_IntType1>& __d1,
03884 const std::negative_binomial_distribution<_IntType1>& __d2)
03885 { return __d1.param() == __d2.param() && __d1._M_gd == __d2._M_gd; }
03886
03887
03888
03889
03890
03891
03892
03893
03894
03895
03896
03897
03898 template<typename _IntType1, typename _CharT, typename _Traits>
03899 friend std::basic_ostream<_CharT, _Traits>&
03900 operator<<(std::basic_ostream<_CharT, _Traits>&,
03901 const std::negative_binomial_distribution<_IntType1>&);
03902
03903
03904
03905
03906
03907
03908
03909
03910
03911
03912
03913 template<typename _IntType1, typename _CharT, typename _Traits>
03914 friend std::basic_istream<_CharT, _Traits>&
03915 operator>>(std::basic_istream<_CharT, _Traits>&,
03916 std::negative_binomial_distribution<_IntType1>&);
03917
03918 private:
03919 param_type _M_param;
03920
03921 std::gamma_distribution<double> _M_gd;
03922 };
03923
03924
03925
03926
03927 template<typename _IntType>
03928 inline bool
03929 operator!=(const std::negative_binomial_distribution<_IntType>& __d1,
03930 const std::negative_binomial_distribution<_IntType>& __d2)
03931 { return !(__d1 == __d2); }
03932
03933
03934
03935
03936
03937
03938
03939
03940
03941
03942
03943
03944
03945
03946
03947
03948
03949 template<typename _IntType = int>
03950 class poisson_distribution
03951 {
03952 static_assert(std::is_integral<_IntType>::value,
03953 "template argument not an integral type");
03954
03955 public:
03956
03957 typedef _IntType result_type;
03958
03959 struct param_type
03960 {
03961 typedef poisson_distribution<_IntType> distribution_type;
03962 friend class poisson_distribution<_IntType>;
03963
03964 explicit
03965 param_type(double __mean = 1.0)
03966 : _M_mean(__mean)
03967 {
03968 _GLIBCXX_DEBUG_ASSERT(_M_mean > 0.0);
03969 _M_initialize();
03970 }
03971
03972 double
03973 mean() const
03974 { return _M_mean; }
03975
03976 friend bool
03977 operator==(const param_type& __p1, const param_type& __p2)
03978 { return __p1._M_mean == __p2._M_mean; }
03979
03980 private:
03981
03982 void
03983 _M_initialize();
03984
03985 double _M_mean;
03986
03987 double _M_lm_thr;
03988 #if _GLIBCXX_USE_C99_MATH_TR1
03989 double _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb;
03990 #endif
03991 };
03992
03993
03994 explicit
03995 poisson_distribution(double __mean = 1.0)
03996 : _M_param(__mean), _M_nd()
03997 { }
03998
03999 explicit
04000 poisson_distribution(const param_type& __p)
04001 : _M_param(__p), _M_nd()
04002 { }
04003
04004
04005
04006
04007 void
04008 reset()
04009 { _M_nd.reset(); }
04010
04011
04012
04013
04014 double
04015 mean() const
04016 { return _M_param.mean(); }
04017
04018
04019
04020
04021 param_type
04022 param() const
04023 { return _M_param; }
04024
04025
04026
04027
04028
04029 void
04030 param(const param_type& __param)
04031 { _M_param = __param; }
04032
04033
04034
04035
04036 result_type
04037 min() const
04038 { return 0; }
04039
04040
04041
04042
04043 result_type
04044 max() const
04045 { return std::numeric_limits<result_type>::max(); }
04046
04047
04048
04049
04050 template<typename _UniformRandomNumberGenerator>
04051 result_type
04052 operator()(_UniformRandomNumberGenerator& __urng)
04053 { return this->operator()(__urng, this->param()); }
04054
04055 template<typename _UniformRandomNumberGenerator>
04056 result_type
04057 operator()(_UniformRandomNumberGenerator& __urng,
04058 const param_type& __p);
04059
04060
04061
04062
04063
04064
04065 template<typename _IntType1>
04066 friend bool
04067 operator==(const std::poisson_distribution<_IntType1>& __d1,
04068 const std::poisson_distribution<_IntType1>& __d2)
04069 #ifdef _GLIBCXX_USE_C99_MATH_TR1
04070 { return __d1.param() == __d2.param() && __d1._M_nd == __d2._M_nd; }
04071 #else
04072 { return __d1.param() == __d2.param(); }
04073 #endif
04074
04075
04076
04077
04078
04079
04080
04081
04082
04083
04084
04085 template<typename _IntType1, typename _CharT, typename _Traits>
04086 friend std::basic_ostream<_CharT, _Traits>&
04087 operator<<(std::basic_ostream<_CharT, _Traits>&,
04088 const std::poisson_distribution<_IntType1>&);
04089
04090
04091
04092
04093
04094
04095
04096
04097
04098
04099
04100 template<typename _IntType1, typename _CharT, typename _Traits>
04101 friend std::basic_istream<_CharT, _Traits>&
04102 operator>>(std::basic_istream<_CharT, _Traits>&,
04103 std::poisson_distribution<_IntType1>&);
04104
04105 private:
04106 param_type _M_param;
04107
04108
04109 std::normal_distribution<double> _M_nd;
04110 };
04111
04112
04113
04114
04115 template<typename _IntType>
04116 inline bool
04117 operator!=(const std::poisson_distribution<_IntType>& __d1,
04118 const std::poisson_distribution<_IntType>& __d2)
04119 { return !(__d1 == __d2); }
04120
04121
04122
04123
04124
04125
04126
04127
04128
04129
04130
04131
04132
04133
04134
04135
04136
04137 template<typename _RealType = double>
04138 class exponential_distribution
04139 {
04140 static_assert(std::is_floating_point<_RealType>::value,
04141 "template argument not a floating point type");
04142
04143 public:
04144
04145 typedef _RealType result_type;
04146
04147 struct param_type
04148 {
04149 typedef exponential_distribution<_RealType> distribution_type;
04150
04151 explicit
04152 param_type(_RealType __lambda = _RealType(1))
04153 : _M_lambda(__lambda)
04154 {
04155 _GLIBCXX_DEBUG_ASSERT(_M_lambda > _RealType(0));
04156 }
04157
04158 _RealType
04159 lambda() const
04160 { return _M_lambda; }
04161
04162 friend bool
04163 operator==(const param_type& __p1, const param_type& __p2)
04164 { return __p1._M_lambda == __p2._M_lambda; }
04165
04166 private:
04167 _RealType _M_lambda;
04168 };
04169
04170 public:
04171
04172
04173
04174
04175 explicit
04176 exponential_distribution(const result_type& __lambda = result_type(1))
04177 : _M_param(__lambda)
04178 { }
04179
04180 explicit
04181 exponential_distribution(const param_type& __p)
04182 : _M_param(__p)
04183 { }
04184
04185
04186
04187
04188
04189
04190 void
04191 reset() { }
04192
04193
04194
04195
04196 _RealType
04197 lambda() const
04198 { return _M_param.lambda(); }
04199
04200
04201
04202
04203 param_type
04204 param() const
04205 { return _M_param; }
04206
04207
04208
04209
04210
04211 void
04212 param(const param_type& __param)
04213 { _M_param = __param; }
04214
04215
04216
04217
04218 result_type
04219 min() const
04220 { return result_type(0); }
04221
04222
04223
04224
04225 result_type
04226 max() const
04227 { return std::numeric_limits<result_type>::max(); }
04228
04229
04230
04231
04232 template<typename _UniformRandomNumberGenerator>
04233 result_type
04234 operator()(_UniformRandomNumberGenerator& __urng)
04235 { return this->operator()(__urng, this->param()); }
04236
04237 template<typename _UniformRandomNumberGenerator>
04238 result_type
04239 operator()(_UniformRandomNumberGenerator& __urng,
04240 const param_type& __p)
04241 {
04242 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
04243 __aurng(__urng);
04244 return -std::log(__aurng()) / __p.lambda();
04245 }
04246
04247 private:
04248 param_type _M_param;
04249 };
04250
04251
04252
04253
04254
04255 template<typename _RealType>
04256 inline bool
04257 operator==(const std::exponential_distribution<_RealType>& __d1,
04258 const std::exponential_distribution<_RealType>& __d2)
04259 { return __d1.param() == __d2.param(); }
04260
04261
04262
04263
04264
04265 template<typename _RealType>
04266 inline bool
04267 operator!=(const std::exponential_distribution<_RealType>& __d1,
04268 const std::exponential_distribution<_RealType>& __d2)
04269 { return !(__d1 == __d2); }
04270
04271
04272
04273
04274
04275
04276
04277
04278
04279
04280
04281 template<typename _RealType, typename _CharT, typename _Traits>
04282 std::basic_ostream<_CharT, _Traits>&
04283 operator<<(std::basic_ostream<_CharT, _Traits>&,
04284 const std::exponential_distribution<_RealType>&);
04285
04286
04287
04288
04289
04290
04291
04292
04293
04294
04295
04296 template<typename _RealType, typename _CharT, typename _Traits>
04297 std::basic_istream<_CharT, _Traits>&
04298 operator>>(std::basic_istream<_CharT, _Traits>&,
04299 std::exponential_distribution<_RealType>&);
04300
04301
04302
04303
04304
04305
04306
04307
04308
04309
04310
04311 template<typename _RealType = double>
04312 class weibull_distribution
04313 {
04314 static_assert(std::is_floating_point<_RealType>::value,
04315 "template argument not a floating point type");
04316
04317 public:
04318
04319 typedef _RealType result_type;
04320
04321 struct param_type
04322 {
04323 typedef weibull_distribution<_RealType> distribution_type;
04324
04325 explicit
04326 param_type(_RealType __a = _RealType(1),
04327 _RealType __b = _RealType(1))
04328 : _M_a(__a), _M_b(__b)
04329 { }
04330
04331 _RealType
04332 a() const
04333 { return _M_a; }
04334
04335 _RealType
04336 b() const
04337 { return _M_b; }
04338
04339 friend bool
04340 operator==(const param_type& __p1, const param_type& __p2)
04341 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
04342
04343 private:
04344 _RealType _M_a;
04345 _RealType _M_b;
04346 };
04347
04348 explicit
04349 weibull_distribution(_RealType __a = _RealType(1),
04350 _RealType __b = _RealType(1))
04351 : _M_param(__a, __b)
04352 { }
04353
04354 explicit
04355 weibull_distribution(const param_type& __p)
04356 : _M_param(__p)
04357 { }
04358
04359
04360
04361
04362 void
04363 reset()
04364 { }
04365
04366
04367
04368
04369 _RealType
04370 a() const
04371 { return _M_param.a(); }
04372
04373
04374
04375
04376 _RealType
04377 b() const
04378 { return _M_param.b(); }
04379
04380
04381
04382
04383 param_type
04384 param() const
04385 { return _M_param; }
04386
04387
04388
04389
04390
04391 void
04392 param(const param_type& __param)
04393 { _M_param = __param; }
04394
04395
04396
04397
04398 result_type
04399 min() const
04400 { return result_type(0); }
04401
04402
04403
04404
04405 result_type
04406 max() const
04407 { return std::numeric_limits<result_type>::max(); }
04408
04409
04410
04411
04412 template<typename _UniformRandomNumberGenerator>
04413 result_type
04414 operator()(_UniformRandomNumberGenerator& __urng)
04415 { return this->operator()(__urng, this->param()); }
04416
04417 template<typename _UniformRandomNumberGenerator>
04418 result_type
04419 operator()(_UniformRandomNumberGenerator& __urng,
04420 const param_type& __p);
04421
04422 private:
04423 param_type _M_param;
04424 };
04425
04426
04427
04428
04429
04430 template<typename _RealType>
04431 inline bool
04432 operator==(const std::weibull_distribution<_RealType>& __d1,
04433 const std::weibull_distribution<_RealType>& __d2)
04434 { return __d1.param() == __d2.param(); }
04435
04436
04437
04438
04439
04440 template<typename _RealType>
04441 inline bool
04442 operator!=(const std::weibull_distribution<_RealType>& __d1,
04443 const std::weibull_distribution<_RealType>& __d2)
04444 { return !(__d1 == __d2); }
04445
04446
04447
04448
04449
04450
04451
04452
04453
04454
04455
04456 template<typename _RealType, typename _CharT, typename _Traits>
04457 std::basic_ostream<_CharT, _Traits>&
04458 operator<<(std::basic_ostream<_CharT, _Traits>&,
04459 const std::weibull_distribution<_RealType>&);
04460
04461
04462
04463
04464
04465
04466
04467
04468
04469
04470
04471 template<typename _RealType, typename _CharT, typename _Traits>
04472 std::basic_istream<_CharT, _Traits>&
04473 operator>>(std::basic_istream<_CharT, _Traits>&,
04474 std::weibull_distribution<_RealType>&);
04475
04476
04477
04478
04479
04480
04481
04482
04483
04484
04485
04486 template<typename _RealType = double>
04487 class extreme_value_distribution
04488 {
04489 static_assert(std::is_floating_point<_RealType>::value,
04490 "template argument not a floating point type");
04491
04492 public:
04493
04494 typedef _RealType result_type;
04495
04496 struct param_type
04497 {
04498 typedef extreme_value_distribution<_RealType> distribution_type;
04499
04500 explicit
04501 param_type(_RealType __a = _RealType(0),
04502 _RealType __b = _RealType(1))
04503 : _M_a(__a), _M_b(__b)
04504 { }
04505
04506 _RealType
04507 a() const
04508 { return _M_a; }
04509
04510 _RealType
04511 b() const
04512 { return _M_b; }
04513
04514 friend bool
04515 operator==(const param_type& __p1, const param_type& __p2)
04516 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
04517
04518 private:
04519 _RealType _M_a;
04520 _RealType _M_b;
04521 };
04522
04523 explicit
04524 extreme_value_distribution(_RealType __a = _RealType(0),
04525 _RealType __b = _RealType(1))
04526 : _M_param(__a, __b)
04527 { }
04528
04529 explicit
04530 extreme_value_distribution(const param_type& __p)
04531 : _M_param(__p)
04532 { }
04533
04534
04535
04536
04537 void
04538 reset()
04539 { }
04540
04541
04542
04543
04544 _RealType
04545 a() const
04546 { return _M_param.a(); }
04547
04548
04549
04550
04551 _RealType
04552 b() const
04553 { return _M_param.b(); }
04554
04555
04556
04557
04558 param_type
04559 param() const
04560 { return _M_param; }
04561
04562
04563
04564
04565
04566 void
04567 param(const param_type& __param)
04568 { _M_param = __param; }
04569
04570
04571
04572
04573 result_type
04574 min() const
04575 { return std::numeric_limits<result_type>::min(); }
04576
04577
04578
04579
04580 result_type
04581 max() const
04582 { return std::numeric_limits<result_type>::max(); }
04583
04584
04585
04586
04587 template<typename _UniformRandomNumberGenerator>
04588 result_type
04589 operator()(_UniformRandomNumberGenerator& __urng)
04590 { return this->operator()(__urng, this->param()); }
04591
04592 template<typename _UniformRandomNumberGenerator>
04593 result_type
04594 operator()(_UniformRandomNumberGenerator& __urng,
04595 const param_type& __p);
04596
04597 private:
04598 param_type _M_param;
04599 };
04600
04601
04602
04603
04604
04605 template<typename _RealType>
04606 inline bool
04607 operator==(const std::extreme_value_distribution<_RealType>& __d1,
04608 const std::extreme_value_distribution<_RealType>& __d2)
04609 { return __d1.param() == __d2.param(); }
04610
04611
04612
04613
04614
04615 template<typename _RealType>
04616 inline bool
04617 operator!=(const std::extreme_value_distribution<_RealType>& __d1,
04618 const std::extreme_value_distribution<_RealType>& __d2)
04619 { return !(__d1 == __d2); }
04620
04621
04622
04623
04624
04625
04626
04627
04628
04629
04630
04631 template<typename _RealType, typename _CharT, typename _Traits>
04632 std::basic_ostream<_CharT, _Traits>&
04633 operator<<(std::basic_ostream<_CharT, _Traits>&,
04634 const std::extreme_value_distribution<_RealType>&);
04635
04636
04637
04638
04639
04640
04641
04642
04643
04644
04645
04646 template<typename _RealType, typename _CharT, typename _Traits>
04647 std::basic_istream<_CharT, _Traits>&
04648 operator>>(std::basic_istream<_CharT, _Traits>&,
04649 std::extreme_value_distribution<_RealType>&);
04650
04651
04652
04653
04654
04655
04656
04657
04658 template<typename _IntType = int>
04659 class discrete_distribution
04660 {
04661 static_assert(std::is_integral<_IntType>::value,
04662 "template argument not an integral type");
04663
04664 public:
04665
04666 typedef _IntType result_type;
04667
04668 struct param_type
04669 {
04670 typedef discrete_distribution<_IntType> distribution_type;
04671 friend class discrete_distribution<_IntType>;
04672
04673 param_type()
04674 : _M_prob(), _M_cp()
04675 { }
04676
04677 template<typename _InputIterator>
04678 param_type(_InputIterator __wbegin,
04679 _InputIterator __wend)
04680 : _M_prob(__wbegin, __wend), _M_cp()
04681 { _M_initialize(); }
04682
04683 param_type(initializer_list<double> __wil)
04684 : _M_prob(__wil.begin(), __wil.end()), _M_cp()
04685 { _M_initialize(); }
04686
04687 template<typename _Func>
04688 param_type(size_t __nw, double __xmin, double __xmax,
04689 _Func __fw);
04690
04691
04692 param_type(const param_type&) = default;
04693 param_type& operator=(const param_type&) = default;
04694
04695 std::vector<double>
04696 probabilities() const
04697 { return _M_prob.empty() ? std::vector<double>(1, 1.0) : _M_prob; }
04698
04699 friend bool
04700 operator==(const param_type& __p1, const param_type& __p2)
04701 { return __p1._M_prob == __p2._M_prob; }
04702
04703 private:
04704 void
04705 _M_initialize();
04706
04707 std::vector<double> _M_prob;
04708 std::vector<double> _M_cp;
04709 };
04710
04711 discrete_distribution()
04712 : _M_param()
04713 { }
04714
04715 template<typename _InputIterator>
04716 discrete_distribution(_InputIterator __wbegin,
04717 _InputIterator __wend)
04718 : _M_param(__wbegin, __wend)
04719 { }
04720
04721 discrete_distribution(initializer_list<double> __wl)
04722 : _M_param(__wl)
04723 { }
04724
04725 template<typename _Func>
04726 discrete_distribution(size_t __nw, double __xmin, double __xmax,
04727 _Func __fw)
04728 : _M_param(__nw, __xmin, __xmax, __fw)
04729 { }
04730
04731 explicit
04732 discrete_distribution(const param_type& __p)
04733 : _M_param(__p)
04734 { }
04735
04736
04737
04738
04739 void
04740 reset()
04741 { }
04742
04743
04744
04745
04746 std::vector<double>
04747 probabilities() const
04748 {
04749 return _M_param._M_prob.empty()
04750 ? std::vector<double>(1, 1.0) : _M_param._M_prob;
04751 }
04752
04753
04754
04755
04756 param_type
04757 param() const
04758 { return _M_param; }
04759
04760
04761
04762
04763
04764 void
04765 param(const param_type& __param)
04766 { _M_param = __param; }
04767
04768
04769
04770
04771 result_type
04772 min() const
04773 { return result_type(0); }
04774
04775
04776
04777
04778 result_type
04779 max() const
04780 {
04781 return _M_param._M_prob.empty()
04782 ? result_type(0) : result_type(_M_param._M_prob.size() - 1);
04783 }
04784
04785
04786
04787
04788 template<typename _UniformRandomNumberGenerator>
04789 result_type
04790 operator()(_UniformRandomNumberGenerator& __urng)
04791 { return this->operator()(__urng, this->param()); }
04792
04793 template<typename _UniformRandomNumberGenerator>
04794 result_type
04795 operator()(_UniformRandomNumberGenerator& __urng,
04796 const param_type& __p);
04797
04798
04799
04800
04801
04802
04803
04804
04805
04806
04807
04808 template<typename _IntType1, typename _CharT, typename _Traits>
04809 friend std::basic_ostream<_CharT, _Traits>&
04810 operator<<(std::basic_ostream<_CharT, _Traits>&,
04811 const std::discrete_distribution<_IntType1>&);
04812
04813
04814
04815
04816
04817
04818
04819
04820
04821
04822
04823
04824 template<typename _IntType1, typename _CharT, typename _Traits>
04825 friend std::basic_istream<_CharT, _Traits>&
04826 operator>>(std::basic_istream<_CharT, _Traits>&,
04827 std::discrete_distribution<_IntType1>&);
04828
04829 private:
04830 param_type _M_param;
04831 };
04832
04833
04834
04835
04836
04837 template<typename _IntType>
04838 inline bool
04839 operator==(const std::discrete_distribution<_IntType>& __d1,
04840 const std::discrete_distribution<_IntType>& __d2)
04841 { return __d1.param() == __d2.param(); }
04842
04843
04844
04845
04846
04847 template<typename _IntType>
04848 inline bool
04849 operator!=(const std::discrete_distribution<_IntType>& __d1,
04850 const std::discrete_distribution<_IntType>& __d2)
04851 { return !(__d1 == __d2); }
04852
04853
04854
04855
04856
04857
04858
04859
04860 template<typename _RealType = double>
04861 class piecewise_constant_distribution
04862 {
04863 static_assert(std::is_floating_point<_RealType>::value,
04864 "template argument not a floating point type");
04865
04866 public:
04867
04868 typedef _RealType result_type;
04869
04870 struct param_type
04871 {
04872 typedef piecewise_constant_distribution<_RealType> distribution_type;
04873 friend class piecewise_constant_distribution<_RealType>;
04874
04875 param_type()
04876 : _M_int(), _M_den(), _M_cp()
04877 { }
04878
04879 template<typename _InputIteratorB, typename _InputIteratorW>
04880 param_type(_InputIteratorB __bfirst,
04881 _InputIteratorB __bend,
04882 _InputIteratorW __wbegin);
04883
04884 template<typename _Func>
04885 param_type(initializer_list<_RealType> __bi, _Func __fw);
04886
04887 template<typename _Func>
04888 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
04889 _Func __fw);
04890
04891
04892 param_type(const param_type&) = default;
04893 param_type& operator=(const param_type&) = default;
04894
04895 std::vector<_RealType>
04896 intervals() const
04897 {
04898 if (_M_int.empty())
04899 {
04900 std::vector<_RealType> __tmp(2);
04901 __tmp[1] = _RealType(1);
04902 return __tmp;
04903 }
04904 else
04905 return _M_int;
04906 }
04907
04908 std::vector<double>
04909 densities() const
04910 { return _M_den.empty() ? std::vector<double>(1, 1.0) : _M_den; }
04911
04912 friend bool
04913 operator==(const param_type& __p1, const param_type& __p2)
04914 { return __p1._M_int == __p2._M_int && __p1._M_den == __p2._M_den; }
04915
04916 private:
04917 void
04918 _M_initialize();
04919
04920 std::vector<_RealType> _M_int;
04921 std::vector<double> _M_den;
04922 std::vector<double> _M_cp;
04923 };
04924
04925 explicit
04926 piecewise_constant_distribution()
04927 : _M_param()
04928 { }
04929
04930 template<typename _InputIteratorB, typename _InputIteratorW>
04931 piecewise_constant_distribution(_InputIteratorB __bfirst,
04932 _InputIteratorB __bend,
04933 _InputIteratorW __wbegin)
04934 : _M_param(__bfirst, __bend, __wbegin)
04935 { }
04936
04937 template<typename _Func>
04938 piecewise_constant_distribution(initializer_list<_RealType> __bl,
04939 _Func __fw)
04940 : _M_param(__bl, __fw)
04941 { }
04942
04943 template<typename _Func>
04944 piecewise_constant_distribution(size_t __nw,
04945 _RealType __xmin, _RealType __xmax,
04946 _Func __fw)
04947 : _M_param(__nw, __xmin, __xmax, __fw)
04948 { }
04949
04950 explicit
04951 piecewise_constant_distribution(const param_type& __p)
04952 : _M_param(__p)
04953 { }
04954
04955
04956
04957
04958 void
04959 reset()
04960 { }
04961
04962
04963
04964
04965 std::vector<_RealType>
04966 intervals() const
04967 {
04968 if (_M_param._M_int.empty())
04969 {
04970 std::vector<_RealType> __tmp(2);
04971 __tmp[1] = _RealType(1);
04972 return __tmp;
04973 }
04974 else
04975 return _M_param._M_int;
04976 }
04977
04978
04979
04980
04981 std::vector<double>
04982 densities() const
04983 {
04984 return _M_param._M_den.empty()
04985 ? std::vector<double>(1, 1.0) : _M_param._M_den;
04986 }
04987
04988
04989
04990
04991 param_type
04992 param() const
04993 { return _M_param; }
04994
04995
04996
04997
04998
04999 void
05000 param(const param_type& __param)
05001 { _M_param = __param; }
05002
05003
05004
05005
05006 result_type
05007 min() const
05008 {
05009 return _M_param._M_int.empty()
05010 ? result_type(0) : _M_param._M_int.front();
05011 }
05012
05013
05014
05015
05016 result_type
05017 max() const
05018 {
05019 return _M_param._M_int.empty()
05020 ? result_type(1) : _M_param._M_int.back();
05021 }
05022
05023
05024
05025
05026 template<typename _UniformRandomNumberGenerator>
05027 result_type
05028 operator()(_UniformRandomNumberGenerator& __urng)
05029 { return this->operator()(__urng, this->param()); }
05030
05031 template<typename _UniformRandomNumberGenerator>
05032 result_type
05033 operator()(_UniformRandomNumberGenerator& __urng,
05034 const param_type& __p);
05035
05036
05037
05038
05039
05040
05041
05042
05043
05044
05045
05046
05047 template<typename _RealType1, typename _CharT, typename _Traits>
05048 friend std::basic_ostream<_CharT, _Traits>&
05049 operator<<(std::basic_ostream<_CharT, _Traits>&,
05050 const std::piecewise_constant_distribution<_RealType1>&);
05051
05052
05053
05054
05055
05056
05057
05058
05059
05060
05061
05062
05063 template<typename _RealType1, typename _CharT, typename _Traits>
05064 friend std::basic_istream<_CharT, _Traits>&
05065 operator>>(std::basic_istream<_CharT, _Traits>&,
05066 std::piecewise_constant_distribution<_RealType1>&);
05067
05068 private:
05069 param_type _M_param;
05070 };
05071
05072
05073
05074
05075
05076 template<typename _RealType>
05077 inline bool
05078 operator==(const std::piecewise_constant_distribution<_RealType>& __d1,
05079 const std::piecewise_constant_distribution<_RealType>& __d2)
05080 { return __d1.param() == __d2.param(); }
05081
05082
05083
05084
05085
05086 template<typename _RealType>
05087 inline bool
05088 operator!=(const std::piecewise_constant_distribution<_RealType>& __d1,
05089 const std::piecewise_constant_distribution<_RealType>& __d2)
05090 { return !(__d1 == __d2); }
05091
05092
05093
05094
05095
05096
05097
05098
05099 template<typename _RealType = double>
05100 class piecewise_linear_distribution
05101 {
05102 static_assert(std::is_floating_point<_RealType>::value,
05103 "template argument not a floating point type");
05104
05105 public:
05106
05107 typedef _RealType result_type;
05108
05109 struct param_type
05110 {
05111 typedef piecewise_linear_distribution<_RealType> distribution_type;
05112 friend class piecewise_linear_distribution<_RealType>;
05113
05114 param_type()
05115 : _M_int(), _M_den(), _M_cp(), _M_m()
05116 { }
05117
05118 template<typename _InputIteratorB, typename _InputIteratorW>
05119 param_type(_InputIteratorB __bfirst,
05120 _InputIteratorB __bend,
05121 _InputIteratorW __wbegin);
05122
05123 template<typename _Func>
05124 param_type(initializer_list<_RealType> __bl, _Func __fw);
05125
05126 template<typename _Func>
05127 param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
05128 _Func __fw);
05129
05130
05131 param_type(const param_type&) = default;
05132 param_type& operator=(const param_type&) = default;
05133
05134 std::vector<_RealType>
05135 intervals() const
05136 {
05137 if (_M_int.empty())
05138 {
05139 std::vector<_RealType> __tmp(2);
05140 __tmp[1] = _RealType(1);
05141 return __tmp;
05142 }
05143 else
05144 return _M_int;
05145 }
05146
05147 std::vector<double>
05148 densities() const
05149 { return _M_den.empty() ? std::vector<double>(2, 1.0) : _M_den; }
05150
05151 friend bool
05152 operator==(const param_type& __p1, const param_type& __p2)
05153 { return (__p1._M_int == __p2._M_int
05154 && __p1._M_den == __p2._M_den); }
05155
05156 private:
05157 void
05158 _M_initialize();
05159
05160 std::vector<_RealType> _M_int;
05161 std::vector<double> _M_den;
05162 std::vector<double> _M_cp;
05163 std::vector<double> _M_m;
05164 };
05165
05166 explicit
05167 piecewise_linear_distribution()
05168 : _M_param()
05169 { }
05170
05171 template<typename _InputIteratorB, typename _InputIteratorW>
05172 piecewise_linear_distribution(_InputIteratorB __bfirst,
05173 _InputIteratorB __bend,
05174 _InputIteratorW __wbegin)
05175 : _M_param(__bfirst, __bend, __wbegin)
05176 { }
05177
05178 template<typename _Func>
05179 piecewise_linear_distribution(initializer_list<_RealType> __bl,
05180 _Func __fw)
05181 : _M_param(__bl, __fw)
05182 { }
05183
05184 template<typename _Func>
05185 piecewise_linear_distribution(size_t __nw,
05186 _RealType __xmin, _RealType __xmax,
05187 _Func __fw)
05188 : _M_param(__nw, __xmin, __xmax, __fw)
05189 { }
05190
05191 explicit
05192 piecewise_linear_distribution(const param_type& __p)
05193 : _M_param(__p)
05194 { }
05195
05196
05197
05198
05199 void
05200 reset()
05201 { }
05202
05203
05204
05205
05206 std::vector<_RealType>
05207 intervals() const
05208 {
05209 if (_M_param._M_int.empty())
05210 {
05211 std::vector<_RealType> __tmp(2);
05212 __tmp[1] = _RealType(1);
05213 return __tmp;
05214 }
05215 else
05216 return _M_param._M_int;
05217 }
05218
05219
05220
05221
05222
05223 std::vector<double>
05224 densities() const
05225 {
05226 return _M_param._M_den.empty()
05227 ? std::vector<double>(2, 1.0) : _M_param._M_den;
05228 }
05229
05230
05231
05232
05233 param_type
05234 param() const
05235 { return _M_param; }
05236
05237
05238
05239
05240
05241 void
05242 param(const param_type& __param)
05243 { _M_param = __param; }
05244
05245
05246
05247
05248 result_type
05249 min() const
05250 {
05251 return _M_param._M_int.empty()
05252 ? result_type(0) : _M_param._M_int.front();
05253 }
05254
05255
05256
05257
05258 result_type
05259 max() const
05260 {
05261 return _M_param._M_int.empty()
05262 ? result_type(1) : _M_param._M_int.back();
05263 }
05264
05265
05266
05267
05268 template<typename _UniformRandomNumberGenerator>
05269 result_type
05270 operator()(_UniformRandomNumberGenerator& __urng)
05271 { return this->operator()(__urng, this->param()); }
05272
05273 template<typename _UniformRandomNumberGenerator>
05274 result_type
05275 operator()(_UniformRandomNumberGenerator& __urng,
05276 const param_type& __p);
05277
05278
05279
05280
05281
05282
05283
05284
05285
05286
05287
05288
05289 template<typename _RealType1, typename _CharT, typename _Traits>
05290 friend std::basic_ostream<_CharT, _Traits>&
05291 operator<<(std::basic_ostream<_CharT, _Traits>&,
05292 const std::piecewise_linear_distribution<_RealType1>&);
05293
05294
05295
05296
05297
05298
05299
05300
05301
05302
05303
05304
05305 template<typename _RealType1, typename _CharT, typename _Traits>
05306 friend std::basic_istream<_CharT, _Traits>&
05307 operator>>(std::basic_istream<_CharT, _Traits>&,
05308 std::piecewise_linear_distribution<_RealType1>&);
05309
05310 private:
05311 param_type _M_param;
05312 };
05313
05314
05315
05316
05317
05318 template<typename _RealType>
05319 inline bool
05320 operator==(const std::piecewise_linear_distribution<_RealType>& __d1,
05321 const std::piecewise_linear_distribution<_RealType>& __d2)
05322 { return __d1.param() == __d2.param(); }
05323
05324
05325
05326
05327
05328 template<typename _RealType>
05329 inline bool
05330 operator!=(const std::piecewise_linear_distribution<_RealType>& __d1,
05331 const std::piecewise_linear_distribution<_RealType>& __d2)
05332 { return !(__d1 == __d2); }
05333
05334
05335
05336
05337
05338
05339
05340
05341
05342
05343
05344
05345
05346
05347
05348
05349 class seed_seq
05350 {
05351
05352 public:
05353
05354 typedef uint_least32_t result_type;
05355
05356
05357 seed_seq()
05358 : _M_v()
05359 { }
05360
05361 template<typename _IntType>
05362 seed_seq(std::initializer_list<_IntType> il);
05363
05364 template<typename _InputIterator>
05365 seed_seq(_InputIterator __begin, _InputIterator __end);
05366
05367
05368 template<typename _RandomAccessIterator>
05369 void
05370 generate(_RandomAccessIterator __begin, _RandomAccessIterator __end);
05371
05372
05373 size_t size() const
05374 { return _M_v.size(); }
05375
05376 template<typename OutputIterator>
05377 void
05378 param(OutputIterator __dest) const
05379 { std::copy(_M_v.begin(), _M_v.end(), __dest); }
05380
05381 private:
05382
05383 std::vector<result_type> _M_v;
05384 };
05385
05386
05387
05388
05389
05390 _GLIBCXX_END_NAMESPACE_VERSION
05391 }
05392
05393 #endif