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