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 namespace std
00032 {
00033 _GLIBCXX_BEGIN_NAMESPACE_TR1
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 namespace __detail
00048 {
00049 template<typename _UIntType, int __w,
00050 bool = __w < std::numeric_limits<_UIntType>::digits>
00051 struct _Shift
00052 { static const _UIntType __value = 0; };
00053
00054 template<typename _UIntType, int __w>
00055 struct _Shift<_UIntType, __w, true>
00056 { static const _UIntType __value = _UIntType(1) << __w; };
00057
00058 template<typename _Tp, _Tp __a, _Tp __c, _Tp __m, bool>
00059 struct _Mod;
00060
00061
00062
00063 template<typename _Tp, _Tp __a, _Tp __c, _Tp __m>
00064 inline _Tp
00065 __mod(_Tp __x)
00066 { return _Mod<_Tp, __a, __c, __m, __m == 0>::__calc(__x); }
00067
00068 typedef __gnu_cxx::__conditional_type<(sizeof(unsigned) == 4),
00069 unsigned, unsigned long>::__type _UInt32Type;
00070
00071
00072
00073
00074
00075 template<typename _Engine, typename _Distribution>
00076 struct _Adaptor
00077 {
00078 typedef typename remove_reference<_Engine>::type _BEngine;
00079 typedef typename _BEngine::result_type _Engine_result_type;
00080 typedef typename _Distribution::input_type result_type;
00081
00082 public:
00083 _Adaptor(const _Engine& __g)
00084 : _M_g(__g) { }
00085
00086 result_type
00087 min() const
00088 {
00089 result_type __return_value;
00090 if (is_integral<_Engine_result_type>::value
00091 && is_integral<result_type>::value)
00092 __return_value = _M_g.min();
00093 else
00094 __return_value = result_type(0);
00095 return __return_value;
00096 }
00097
00098 result_type
00099 max() const
00100 {
00101 result_type __return_value;
00102 if (is_integral<_Engine_result_type>::value
00103 && is_integral<result_type>::value)
00104 __return_value = _M_g.max();
00105 else if (!is_integral<result_type>::value)
00106 __return_value = result_type(1);
00107 else
00108 __return_value = std::numeric_limits<result_type>::max() - 1;
00109 return __return_value;
00110 }
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 result_type
00122 operator()()
00123 {
00124 result_type __return_value;
00125 if (is_integral<_Engine_result_type>::value
00126 && is_integral<result_type>::value)
00127 __return_value = _M_g();
00128 else if (!is_integral<_Engine_result_type>::value
00129 && !is_integral<result_type>::value)
00130 __return_value = result_type(_M_g() - _M_g.min())
00131 / result_type(_M_g.max() - _M_g.min());
00132 else if (is_integral<_Engine_result_type>::value
00133 && !is_integral<result_type>::value)
00134 __return_value = result_type(_M_g() - _M_g.min())
00135 / result_type(_M_g.max() - _M_g.min() + result_type(1));
00136 else
00137 __return_value = (((_M_g() - _M_g.min())
00138 / (_M_g.max() - _M_g.min()))
00139 * std::numeric_limits<result_type>::max());
00140 return __return_value;
00141 }
00142
00143 private:
00144 _Engine _M_g;
00145 };
00146
00147
00148 template<typename _Engine, typename _Distribution>
00149 struct _Adaptor<_Engine*, _Distribution>
00150 {
00151 typedef typename _Engine::result_type _Engine_result_type;
00152 typedef typename _Distribution::input_type result_type;
00153
00154 public:
00155 _Adaptor(_Engine* __g)
00156 : _M_g(__g) { }
00157
00158 result_type
00159 min() const
00160 {
00161 result_type __return_value;
00162 if (is_integral<_Engine_result_type>::value
00163 && is_integral<result_type>::value)
00164 __return_value = _M_g->min();
00165 else
00166 __return_value = result_type(0);
00167 return __return_value;
00168 }
00169
00170 result_type
00171 max() const
00172 {
00173 result_type __return_value;
00174 if (is_integral<_Engine_result_type>::value
00175 && is_integral<result_type>::value)
00176 __return_value = _M_g->max();
00177 else if (!is_integral<result_type>::value)
00178 __return_value = result_type(1);
00179 else
00180 __return_value = std::numeric_limits<result_type>::max() - 1;
00181 return __return_value;
00182 }
00183
00184 result_type
00185 operator()()
00186 {
00187 result_type __return_value;
00188 if (is_integral<_Engine_result_type>::value
00189 && is_integral<result_type>::value)
00190 __return_value = (*_M_g)();
00191 else if (!is_integral<_Engine_result_type>::value
00192 && !is_integral<result_type>::value)
00193 __return_value = result_type((*_M_g)() - _M_g->min())
00194 / result_type(_M_g->max() - _M_g->min());
00195 else if (is_integral<_Engine_result_type>::value
00196 && !is_integral<result_type>::value)
00197 __return_value = result_type((*_M_g)() - _M_g->min())
00198 / result_type(_M_g->max() - _M_g->min() + result_type(1));
00199 else
00200 __return_value = ((((*_M_g)() - _M_g->min())
00201 / (_M_g->max() - _M_g->min()))
00202 * std::numeric_limits<result_type>::max());
00203 return __return_value;
00204 }
00205
00206 private:
00207 _Engine* _M_g;
00208 };
00209 }
00210
00211
00212
00213
00214
00215
00216
00217 template<typename _Engine, typename _Dist>
00218 class variate_generator
00219 {
00220
00221 __glibcxx_class_requires(_Engine, _CopyConstructibleConcept)
00222
00223
00224
00225 public:
00226 typedef _Engine engine_type;
00227 typedef __detail::_Adaptor<_Engine, _Dist> engine_value_type;
00228 typedef _Dist distribution_type;
00229 typedef typename _Dist::result_type result_type;
00230
00231
00232 typedef typename __gnu_cxx::__enable_if<
00233 is_arithmetic<result_type>::value, result_type>::__type _IsValidType;
00234
00235
00236
00237
00238
00239
00240
00241
00242 variate_generator(engine_type __eng, distribution_type __dist)
00243 : _M_engine(__eng), _M_dist(__dist) { }
00244
00245
00246
00247
00248 result_type
00249 operator()()
00250 { return _M_dist(_M_engine); }
00251
00252
00253
00254
00255 template<typename _Tp>
00256 result_type
00257 operator()(_Tp __value)
00258 { return _M_dist(_M_engine, __value); }
00259
00260
00261
00262
00263
00264 engine_value_type&
00265 engine()
00266 { return _M_engine; }
00267
00268
00269
00270
00271
00272 const engine_value_type&
00273 engine() const
00274 { return _M_engine; }
00275
00276
00277
00278
00279 distribution_type&
00280 distribution()
00281 { return _M_dist; }
00282
00283
00284
00285
00286 const distribution_type&
00287 distribution() const
00288 { return _M_dist; }
00289
00290
00291
00292
00293 result_type
00294 min() const
00295 { return this->distribution().min(); }
00296
00297
00298
00299
00300 result_type
00301 max() const
00302 { return this->distribution().max(); }
00303
00304 private:
00305 engine_value_type _M_engine;
00306 distribution_type _M_dist;
00307 };
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345 template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
00346 class linear_congruential
00347 {
00348 __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept)
00349
00350
00351 public:
00352
00353 typedef _UIntType result_type;
00354
00355
00356 static const _UIntType multiplier = __a;
00357
00358 static const _UIntType increment = __c;
00359
00360 static const _UIntType modulus = __m;
00361
00362
00363
00364
00365
00366
00367
00368 explicit
00369 linear_congruential(unsigned long __x0 = 1)
00370 { this->seed(__x0); }
00371
00372
00373
00374
00375
00376
00377
00378 template<class _Gen>
00379 linear_congruential(_Gen& __g)
00380 { this->seed(__g); }
00381
00382
00383
00384
00385
00386
00387
00388 void
00389 seed(unsigned long __s = 1);
00390
00391
00392
00393
00394
00395
00396
00397 template<class _Gen>
00398 void
00399 seed(_Gen& __g)
00400 { seed(__g, typename is_fundamental<_Gen>::type()); }
00401
00402
00403
00404
00405
00406
00407
00408 result_type
00409 min() const
00410 { return (__detail::__mod<_UIntType, 1, 0, __m>(__c) == 0) ? 1 : 0; }
00411
00412
00413
00414
00415 result_type
00416 max() const
00417 { return __m - 1; }
00418
00419
00420
00421
00422 result_type
00423 operator()();
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434 friend bool
00435 operator==(const linear_congruential& __lhs,
00436 const linear_congruential& __rhs)
00437 { return __lhs._M_x == __rhs._M_x; }
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448 friend bool
00449 operator!=(const linear_congruential& __lhs,
00450 const linear_congruential& __rhs)
00451 { return !(__lhs == __rhs); }
00452
00453
00454
00455
00456
00457
00458
00459
00460 template<class _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
00461 _UIntType1 __m1,
00462 typename _CharT, typename _Traits>
00463 friend std::basic_ostream<_CharT, _Traits>&
00464 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
00465 const linear_congruential<_UIntType1, __a1, __c1,
00466 __m1>& __lcr);
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481 template<class _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
00482 _UIntType1 __m1,
00483 typename _CharT, typename _Traits>
00484 friend std::basic_istream<_CharT, _Traits>&
00485 operator>>(std::basic_istream<_CharT, _Traits>& __is,
00486 linear_congruential<_UIntType1, __a1, __c1, __m1>& __lcr);
00487
00488 private:
00489 template<class _Gen>
00490 void
00491 seed(_Gen& __g, true_type)
00492 { return seed(static_cast<unsigned long>(__g)); }
00493
00494 template<class _Gen>
00495 void
00496 seed(_Gen& __g, false_type);
00497
00498 _UIntType _M_x;
00499 };
00500
00501
00502
00503
00504 typedef linear_congruential<unsigned long, 16807, 0, 2147483647> minstd_rand0;
00505
00506
00507
00508
00509 typedef linear_congruential<unsigned long, 48271, 0, 2147483647> minstd_rand;
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537 template<class _UIntType, int __w, int __n, int __m, int __r,
00538 _UIntType __a, int __u, int __s, _UIntType __b, int __t,
00539 _UIntType __c, int __l>
00540 class mersenne_twister
00541 {
00542 __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept)
00543
00544 public:
00545
00546 typedef _UIntType result_type;
00547
00548
00549 static const int word_size = __w;
00550 static const int state_size = __n;
00551 static const int shift_size = __m;
00552 static const int mask_bits = __r;
00553 static const _UIntType parameter_a = __a;
00554 static const int output_u = __u;
00555 static const int output_s = __s;
00556 static const _UIntType output_b = __b;
00557 static const int output_t = __t;
00558 static const _UIntType output_c = __c;
00559 static const int output_l = __l;
00560
00561
00562 mersenne_twister()
00563 { seed(); }
00564
00565 explicit
00566 mersenne_twister(unsigned long __value)
00567 { seed(__value); }
00568
00569 template<class _Gen>
00570 mersenne_twister(_Gen& __g)
00571 { seed(__g); }
00572
00573 void
00574 seed()
00575 { seed(5489UL); }
00576
00577 void
00578 seed(unsigned long __value);
00579
00580 template<class _Gen>
00581 void
00582 seed(_Gen& __g)
00583 { seed(__g, typename is_fundamental<_Gen>::type()); }
00584
00585 result_type
00586 min() const
00587 { return 0; };
00588
00589 result_type
00590 max() const
00591 { return __detail::_Shift<_UIntType, __w>::__value - 1; }
00592
00593 result_type
00594 operator()();
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606 friend bool
00607 operator==(const mersenne_twister& __lhs,
00608 const mersenne_twister& __rhs)
00609 { return std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x); }
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621 friend bool
00622 operator!=(const mersenne_twister& __lhs,
00623 const mersenne_twister& __rhs)
00624 { return !(__lhs == __rhs); }
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636 template<class _UIntType1, int __w1, int __n1, int __m1, int __r1,
00637 _UIntType1 __a1, int __u1, int __s1, _UIntType1 __b1, int __t1,
00638 _UIntType1 __c1, int __l1,
00639 typename _CharT, typename _Traits>
00640 friend std::basic_ostream<_CharT, _Traits>&
00641 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
00642 const mersenne_twister<_UIntType1, __w1, __n1, __m1, __r1,
00643 __a1, __u1, __s1, __b1, __t1, __c1, __l1>& __x);
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655 template<class _UIntType1, int __w1, int __n1, int __m1, int __r1,
00656 _UIntType1 __a1, int __u1, int __s1, _UIntType1 __b1, int __t1,
00657 _UIntType1 __c1, int __l1,
00658 typename _CharT, typename _Traits>
00659 friend std::basic_istream<_CharT, _Traits>&
00660 operator>>(std::basic_istream<_CharT, _Traits>& __is,
00661 mersenne_twister<_UIntType1, __w1, __n1, __m1, __r1,
00662 __a1, __u1, __s1, __b1, __t1, __c1, __l1>& __x);
00663
00664 private:
00665 template<class _Gen>
00666 void
00667 seed(_Gen& __g, true_type)
00668 { return seed(static_cast<unsigned long>(__g)); }
00669
00670 template<class _Gen>
00671 void
00672 seed(_Gen& __g, false_type);
00673
00674 _UIntType _M_x[state_size];
00675 int _M_p;
00676 };
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686 typedef mersenne_twister<
00687 unsigned long, 32, 624, 397, 31,
00688 0x9908b0dful, 11, 7,
00689 0x9d2c5680ul, 15,
00690 0xefc60000ul, 18
00691 > mt19937;
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714 template<typename _IntType, _IntType __m, int __s, int __r>
00715 class subtract_with_carry
00716 {
00717 __glibcxx_class_requires(_IntType, _IntegerConcept)
00718
00719 public:
00720
00721 typedef _IntType result_type;
00722
00723
00724 static const _IntType modulus = __m;
00725 static const int long_lag = __r;
00726 static const int short_lag = __s;
00727
00728
00729
00730
00731
00732 subtract_with_carry()
00733 { this->seed(); }
00734
00735
00736
00737
00738
00739 explicit
00740 subtract_with_carry(unsigned long __value)
00741 { this->seed(__value); }
00742
00743
00744
00745
00746
00747
00748
00749 template<class _Gen>
00750 subtract_with_carry(_Gen& __g)
00751 { this->seed(__g); }
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764 void
00765 seed(unsigned long __value = 19780503);
00766
00767
00768
00769
00770
00771 template<class _Gen>
00772 void
00773 seed(_Gen& __g)
00774 { seed(__g, typename is_fundamental<_Gen>::type()); }
00775
00776
00777
00778
00779
00780 result_type
00781 min() const
00782 { return 0; }
00783
00784
00785
00786
00787
00788 result_type
00789 max() const
00790 { return this->modulus - 1; }
00791
00792
00793
00794
00795 result_type
00796 operator()();
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808 friend bool
00809 operator==(const subtract_with_carry& __lhs,
00810 const subtract_with_carry& __rhs)
00811 { return std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x); }
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823 friend bool
00824 operator!=(const subtract_with_carry& __lhs,
00825 const subtract_with_carry& __rhs)
00826 { return !(__lhs == __rhs); }
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838 template<typename _IntType1, _IntType1 __m1, int __s1, int __r1,
00839 typename _CharT, typename _Traits>
00840 friend std::basic_ostream<_CharT, _Traits>&
00841 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
00842 const subtract_with_carry<_IntType1, __m1, __s1,
00843 __r1>& __x);
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855 template<typename _IntType1, _IntType1 __m1, int __s1, int __r1,
00856 typename _CharT, typename _Traits>
00857 friend std::basic_istream<_CharT, _Traits>&
00858 operator>>(std::basic_istream<_CharT, _Traits>& __is,
00859 subtract_with_carry<_IntType1, __m1, __s1, __r1>& __x);
00860
00861 private:
00862 template<class _Gen>
00863 void
00864 seed(_Gen& __g, true_type)
00865 { return seed(static_cast<unsigned long>(__g)); }
00866
00867 template<class _Gen>
00868 void
00869 seed(_Gen& __g, false_type);
00870
00871 typedef typename __gnu_cxx::__add_unsigned<_IntType>::__type _UIntType;
00872
00873 _UIntType _M_x[long_lag];
00874 _UIntType _M_carry;
00875 int _M_p;
00876 };
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887 template<typename _RealType, int __w, int __s, int __r>
00888 class subtract_with_carry_01
00889 {
00890 public:
00891
00892 typedef _RealType result_type;
00893
00894
00895 static const int word_size = __w;
00896 static const int long_lag = __r;
00897 static const int short_lag = __s;
00898
00899
00900
00901
00902
00903 subtract_with_carry_01()
00904 {
00905 this->seed();
00906 _M_initialize_npows();
00907 }
00908
00909
00910
00911
00912
00913 explicit
00914 subtract_with_carry_01(unsigned long __value)
00915 {
00916 this->seed(__value);
00917 _M_initialize_npows();
00918 }
00919
00920
00921
00922
00923
00924
00925
00926 template<class _Gen>
00927 subtract_with_carry_01(_Gen& __g)
00928 {
00929 this->seed(__g);
00930 _M_initialize_npows();
00931 }
00932
00933
00934
00935
00936 void
00937 seed(unsigned long __value = 19780503);
00938
00939
00940
00941
00942
00943 template<class _Gen>
00944 void
00945 seed(_Gen& __g)
00946 { seed(__g, typename is_fundamental<_Gen>::type()); }
00947
00948
00949
00950
00951
00952 result_type
00953 min() const
00954 { return 0.0; }
00955
00956
00957
00958
00959
00960 result_type
00961 max() const
00962 { return 1.0; }
00963
00964
00965
00966
00967 result_type
00968 operator()();
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981 friend bool
00982 operator==(const subtract_with_carry_01& __lhs,
00983 const subtract_with_carry_01& __rhs)
00984 {
00985 for (int __i = 0; __i < long_lag; ++__i)
00986 if (!std::equal(__lhs._M_x[__i], __lhs._M_x[__i] + __n,
00987 __rhs._M_x[__i]))
00988 return false;
00989 return true;
00990 }
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004 friend bool
01005 operator!=(const subtract_with_carry_01& __lhs,
01006 const subtract_with_carry_01& __rhs)
01007 { return !(__lhs == __rhs); }
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019 template<typename _RealType1, int __w1, int __s1, int __r1,
01020 typename _CharT, typename _Traits>
01021 friend std::basic_ostream<_CharT, _Traits>&
01022 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
01023 const subtract_with_carry_01<_RealType1, __w1, __s1,
01024 __r1>& __x);
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036 template<typename _RealType1, int __w1, int __s1, int __r1,
01037 typename _CharT, typename _Traits>
01038 friend std::basic_istream<_CharT, _Traits>&
01039 operator>>(std::basic_istream<_CharT, _Traits>& __is,
01040 subtract_with_carry_01<_RealType1, __w1, __s1, __r1>& __x);
01041
01042 private:
01043 template<class _Gen>
01044 void
01045 seed(_Gen& __g, true_type)
01046 { return seed(static_cast<unsigned long>(__g)); }
01047
01048 template<class _Gen>
01049 void
01050 seed(_Gen& __g, false_type);
01051
01052 void
01053 _M_initialize_npows();
01054
01055 static const int __n = (__w + 31) / 32;
01056
01057 typedef __detail::_UInt32Type _UInt32Type;
01058 _UInt32Type _M_x[long_lag][__n];
01059 _RealType _M_npows[__n];
01060 _UInt32Type _M_carry;
01061 int _M_p;
01062 };
01063
01064 typedef subtract_with_carry_01<float, 24, 10, 24> ranlux_base_01;
01065
01066
01067
01068 typedef subtract_with_carry_01<double, 48, 5, 12> ranlux64_base_01;
01069
01070
01071
01072
01073
01074
01075
01076
01077 template<class _UniformRandomNumberGenerator, int __p, int __r>
01078 class discard_block
01079 {
01080
01081
01082
01083 public:
01084
01085 typedef _UniformRandomNumberGenerator base_type;
01086
01087 typedef typename base_type::result_type result_type;
01088
01089
01090 static const int block_size = __p;
01091 static const int used_block = __r;
01092
01093
01094
01095
01096
01097
01098 discard_block()
01099 : _M_n(0) { }
01100
01101
01102
01103
01104
01105
01106
01107 explicit
01108 discard_block(const base_type& __rng)
01109 : _M_b(__rng), _M_n(0) { }
01110
01111
01112
01113
01114
01115
01116
01117 explicit
01118 discard_block(unsigned long __s)
01119 : _M_b(__s), _M_n(0) { }
01120
01121
01122
01123
01124
01125
01126 template<class _Gen>
01127 discard_block(_Gen& __g)
01128 : _M_b(__g), _M_n(0) { }
01129
01130
01131
01132
01133
01134 void seed()
01135 {
01136 _M_b.seed();
01137 _M_n = 0;
01138 }
01139
01140
01141
01142
01143
01144
01145 template<class _Gen>
01146 void seed(_Gen& __g)
01147 {
01148 _M_b.seed(__g);
01149 _M_n = 0;
01150 }
01151
01152
01153
01154
01155 const base_type&
01156 base() const
01157 { return _M_b; }
01158
01159
01160
01161
01162 result_type
01163 min() const
01164 { return _M_b.min(); }
01165
01166
01167
01168
01169 result_type
01170 max() const
01171 { return _M_b.max(); }
01172
01173
01174
01175
01176 result_type
01177 operator()();
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189 friend bool
01190 operator==(const discard_block& __lhs, const discard_block& __rhs)
01191 { return (__lhs._M_b == __rhs._M_b) && (__lhs._M_n == __rhs._M_n); }
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201
01202
01203 friend bool
01204 operator!=(const discard_block& __lhs, const discard_block& __rhs)
01205 { return !(__lhs == __rhs); }
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217 template<class _UniformRandomNumberGenerator1, int __p1, int __r1,
01218 typename _CharT, typename _Traits>
01219 friend std::basic_ostream<_CharT, _Traits>&
01220 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
01221 const discard_block<_UniformRandomNumberGenerator1,
01222 __p1, __r1>& __x);
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234 template<class _UniformRandomNumberGenerator1, int __p1, int __r1,
01235 typename _CharT, typename _Traits>
01236 friend std::basic_istream<_CharT, _Traits>&
01237 operator>>(std::basic_istream<_CharT, _Traits>& __is,
01238 discard_block<_UniformRandomNumberGenerator1,
01239 __p1, __r1>& __x);
01240
01241 private:
01242 base_type _M_b;
01243 int _M_n;
01244 };
01245
01246
01247
01248
01249
01250 typedef discard_block<
01251 subtract_with_carry<unsigned long, (1UL << 24), 10, 24>,
01252 223,
01253 24
01254 > ranlux3;
01255
01256
01257
01258
01259 typedef discard_block<
01260 subtract_with_carry<unsigned long, (1UL << 24), 10, 24>,
01261 389,
01262 24
01263 > ranlux4;
01264
01265 typedef discard_block<
01266 subtract_with_carry_01<float, 24, 10, 24>,
01267 223,
01268 24
01269 > ranlux3_01;
01270
01271 typedef discard_block<
01272 subtract_with_carry_01<float, 24, 10, 24>,
01273 389,
01274 24
01275 > ranlux4_01;
01276
01277
01278
01279
01280
01281
01282 template<class _UniformRandomNumberGenerator1, int __s1,
01283 class _UniformRandomNumberGenerator2, int __s2>
01284 class xor_combine
01285 {
01286
01287
01288
01289
01290
01291 public:
01292
01293 typedef _UniformRandomNumberGenerator1 base1_type;
01294
01295 typedef _UniformRandomNumberGenerator2 base2_type;
01296
01297 private:
01298 typedef typename base1_type::result_type _Result_type1;
01299 typedef typename base2_type::result_type _Result_type2;
01300
01301 public:
01302
01303 typedef typename __gnu_cxx::__conditional_type<(sizeof(_Result_type1)
01304 > sizeof(_Result_type2)),
01305 _Result_type1, _Result_type2>::__type result_type;
01306
01307
01308 static const int shift1 = __s1;
01309 static const int shift2 = __s2;
01310
01311
01312 xor_combine()
01313 : _M_b1(), _M_b2()
01314 { _M_initialize_max(); }
01315
01316 xor_combine(const base1_type& __rng1, const base2_type& __rng2)
01317 : _M_b1(__rng1), _M_b2(__rng2)
01318 { _M_initialize_max(); }
01319
01320 xor_combine(unsigned long __s)
01321 : _M_b1(__s), _M_b2(__s + 1)
01322 { _M_initialize_max(); }
01323
01324 template<class _Gen>
01325 xor_combine(_Gen& __g)
01326 : _M_b1(__g), _M_b2(__g)
01327 { _M_initialize_max(); }
01328
01329 void
01330 seed()
01331 {
01332 _M_b1.seed();
01333 _M_b2.seed();
01334 }
01335
01336 template<class _Gen>
01337 void
01338 seed(_Gen& __g)
01339 {
01340 _M_b1.seed(__g);
01341 _M_b2.seed(__g);
01342 }
01343
01344 const base1_type&
01345 base1() const
01346 { return _M_b1; }
01347
01348 const base2_type&
01349 base2() const
01350 { return _M_b2; }
01351
01352 result_type
01353 min() const
01354 { return 0; }
01355
01356 result_type
01357 max() const
01358 { return _M_max; }
01359
01360
01361
01362
01363
01364 result_type
01365 operator()()
01366 {
01367 return ((result_type(_M_b1() - _M_b1.min()) << shift1)
01368 ^ (result_type(_M_b2() - _M_b2.min()) << shift2));
01369 }
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381 friend bool
01382 operator==(const xor_combine& __lhs, const xor_combine& __rhs)
01383 {
01384 return (__lhs.base1() == __rhs.base1())
01385 && (__lhs.base2() == __rhs.base2());
01386 }
01387
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398 friend bool
01399 operator!=(const xor_combine& __lhs, const xor_combine& __rhs)
01400 { return !(__lhs == __rhs); }
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412 template<class _UniformRandomNumberGenerator11, int __s11,
01413 class _UniformRandomNumberGenerator21, int __s21,
01414 typename _CharT, typename _Traits>
01415 friend std::basic_ostream<_CharT, _Traits>&
01416 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
01417 const xor_combine<_UniformRandomNumberGenerator11, __s11,
01418 _UniformRandomNumberGenerator21, __s21>& __x);
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430 template<class _UniformRandomNumberGenerator11, int __s11,
01431 class _UniformRandomNumberGenerator21, int __s21,
01432 typename _CharT, typename _Traits>
01433 friend std::basic_istream<_CharT, _Traits>&
01434 operator>>(std::basic_istream<_CharT, _Traits>& __is,
01435 xor_combine<_UniformRandomNumberGenerator11, __s11,
01436 _UniformRandomNumberGenerator21, __s21>& __x);
01437
01438 private:
01439 void
01440 _M_initialize_max();
01441
01442 result_type
01443 _M_initialize_max_aux(result_type, result_type, int);
01444
01445 base1_type _M_b1;
01446 base2_type _M_b2;
01447 result_type _M_max;
01448 };
01449
01450
01451
01452
01453
01454
01455 class random_device
01456 {
01457 public:
01458
01459 typedef unsigned int result_type;
01460
01461
01462
01463 #ifdef _GLIBCXX_USE_RANDOM_TR1
01464
01465 explicit
01466 random_device(const std::string& __token = "/dev/urandom")
01467 {
01468 if ((__token != "/dev/urandom" && __token != "/dev/random")
01469 || !(_M_file = std::fopen(__token.c_str(), "rb")))
01470 std::__throw_runtime_error(__N("random_device::"
01471 "random_device(const std::string&)"));
01472 }
01473
01474 ~random_device()
01475 { std::fclose(_M_file); }
01476
01477 #else
01478
01479 explicit
01480 random_device(const std::string& __token = "mt19937")
01481 : _M_mt(_M_strtoul(__token)) { }
01482
01483 private:
01484 static unsigned long
01485 _M_strtoul(const std::string& __str)
01486 {
01487 unsigned long __ret = 5489UL;
01488 if (__str != "mt19937")
01489 {
01490 const char* __nptr = __str.c_str();
01491 char* __endptr;
01492 __ret = std::strtoul(__nptr, &__endptr, 0);
01493 if (*__nptr == '\0' || *__endptr != '\0')
01494 std::__throw_runtime_error(__N("random_device::_M_strtoul"
01495 "(const std::string&)"));
01496 }
01497 return __ret;
01498 }
01499
01500 public:
01501
01502 #endif
01503
01504 result_type
01505 min() const
01506 { return std::numeric_limits<result_type>::min(); }
01507
01508 result_type
01509 max() const
01510 { return std::numeric_limits<result_type>::max(); }
01511
01512 double
01513 entropy() const
01514 { return 0.0; }
01515
01516 result_type
01517 operator()()
01518 {
01519 #ifdef _GLIBCXX_USE_RANDOM_TR1
01520 result_type __ret;
01521 std::fread(reinterpret_cast<void*>(&__ret), sizeof(result_type),
01522 1, _M_file);
01523 return __ret;
01524 #else
01525 return _M_mt();
01526 #endif
01527 }
01528
01529 private:
01530 random_device(const random_device&);
01531 void operator=(const random_device&);
01532
01533 #ifdef _GLIBCXX_USE_RANDOM_TR1
01534 FILE* _M_file;
01535 #else
01536 mt19937 _M_mt;
01537 #endif
01538 };
01539
01540
01541
01542
01543
01544
01545
01546
01547
01548
01549
01550
01551
01552
01553
01554
01555
01556
01557
01558
01559 template<typename _IntType = int>
01560 class uniform_int
01561 {
01562 __glibcxx_class_requires(_IntType, _IntegerConcept)
01563
01564 public:
01565
01566 typedef _IntType input_type;
01567
01568 typedef _IntType result_type;
01569
01570 public:
01571
01572
01573
01574 explicit
01575 uniform_int(_IntType __min = 0, _IntType __max = 9)
01576 : _M_min(__min), _M_max(__max)
01577 {
01578 _GLIBCXX_DEBUG_ASSERT(_M_min <= _M_max);
01579 }
01580
01581
01582
01583
01584 result_type
01585 min() const
01586 { return _M_min; }
01587
01588
01589
01590
01591 result_type
01592 max() const
01593 { return _M_max; }
01594
01595
01596
01597
01598
01599
01600 void
01601 reset() { }
01602
01603
01604
01605
01606
01607 template<typename _UniformRandomNumberGenerator>
01608 result_type
01609 operator()(_UniformRandomNumberGenerator& __urng)
01610 {
01611 typedef typename _UniformRandomNumberGenerator::result_type
01612 _UResult_type;
01613 return _M_call(__urng, _M_min, _M_max,
01614 typename is_integral<_UResult_type>::type());
01615 }
01616
01617
01618
01619
01620
01621
01622 template<typename _UniformRandomNumberGenerator>
01623 result_type
01624 operator()(_UniformRandomNumberGenerator& __urng, result_type __n)
01625 {
01626 typedef typename _UniformRandomNumberGenerator::result_type
01627 _UResult_type;
01628 return _M_call(__urng, 0, __n - 1,
01629 typename is_integral<_UResult_type>::type());
01630 }
01631
01632
01633
01634
01635
01636
01637
01638
01639
01640
01641
01642 template<typename _IntType1, typename _CharT, typename _Traits>
01643 friend std::basic_ostream<_CharT, _Traits>&
01644 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
01645 const uniform_int<_IntType1>& __x);
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656 template<typename _IntType1, typename _CharT, typename _Traits>
01657 friend std::basic_istream<_CharT, _Traits>&
01658 operator>>(std::basic_istream<_CharT, _Traits>& __is,
01659 uniform_int<_IntType1>& __x);
01660
01661 private:
01662 template<typename _UniformRandomNumberGenerator>
01663 result_type
01664 _M_call(_UniformRandomNumberGenerator& __urng,
01665 result_type __min, result_type __max, true_type);
01666
01667 template<typename _UniformRandomNumberGenerator>
01668 result_type
01669 _M_call(_UniformRandomNumberGenerator& __urng,
01670 result_type __min, result_type __max, false_type)
01671 {
01672 return result_type((__urng() - __urng.min())
01673 / (__urng.max() - __urng.min())
01674 * (__max - __min + 1)) + __min;
01675 }
01676
01677 _IntType _M_min;
01678 _IntType _M_max;
01679 };
01680
01681
01682
01683
01684
01685
01686
01687
01688 class bernoulli_distribution
01689 {
01690 public:
01691 typedef int input_type;
01692 typedef bool result_type;
01693
01694 public:
01695
01696
01697
01698
01699
01700
01701 explicit
01702 bernoulli_distribution(double __p = 0.5)
01703 : _M_p(__p)
01704 {
01705 _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0) && (_M_p <= 1.0));
01706 }
01707
01708
01709
01710
01711 double
01712 p() const
01713 { return _M_p; }
01714
01715
01716
01717
01718
01719
01720 void
01721 reset() { }
01722
01723
01724
01725
01726 template<class _UniformRandomNumberGenerator>
01727 result_type
01728 operator()(_UniformRandomNumberGenerator& __urng)
01729 {
01730 if ((__urng() - __urng.min()) < _M_p * (__urng.max() - __urng.min()))
01731 return true;
01732 return false;
01733 }
01734
01735
01736
01737
01738
01739
01740
01741
01742
01743
01744
01745 template<typename _CharT, typename _Traits>
01746 friend std::basic_ostream<_CharT, _Traits>&
01747 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
01748 const bernoulli_distribution& __x);
01749
01750
01751
01752
01753
01754
01755
01756
01757
01758
01759 template<typename _CharT, typename _Traits>
01760 friend std::basic_istream<_CharT, _Traits>&
01761 operator>>(std::basic_istream<_CharT, _Traits>& __is,
01762 bernoulli_distribution& __x)
01763 { return __is >> __x._M_p; }
01764
01765 private:
01766 double _M_p;
01767 };
01768
01769
01770
01771
01772
01773
01774
01775
01776
01777 template<typename _IntType = int, typename _RealType = double>
01778 class geometric_distribution
01779 {
01780 public:
01781
01782 typedef _RealType input_type;
01783 typedef _IntType result_type;
01784
01785
01786 explicit
01787 geometric_distribution(const _RealType& __p = _RealType(0.5))
01788 : _M_p(__p)
01789 {
01790 _GLIBCXX_DEBUG_ASSERT((_M_p > 0.0) && (_M_p < 1.0));
01791 _M_initialize();
01792 }
01793
01794
01795
01796
01797 _RealType
01798 p() const
01799 { return _M_p; }
01800
01801 void
01802 reset() { }
01803
01804 template<class _UniformRandomNumberGenerator>
01805 result_type
01806 operator()(_UniformRandomNumberGenerator& __urng);
01807
01808
01809
01810
01811
01812
01813
01814
01815
01816
01817
01818 template<typename _IntType1, typename _RealType1,
01819 typename _CharT, typename _Traits>
01820 friend std::basic_ostream<_CharT, _Traits>&
01821 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
01822 const geometric_distribution<_IntType1, _RealType1>& __x);
01823
01824
01825
01826
01827
01828
01829
01830
01831
01832
01833 template<typename _CharT, typename _Traits>
01834 friend std::basic_istream<_CharT, _Traits>&
01835 operator>>(std::basic_istream<_CharT, _Traits>& __is,
01836 geometric_distribution& __x)
01837 {
01838 __is >> __x._M_p;
01839 __x._M_initialize();
01840 return __is;
01841 }
01842
01843 private:
01844 void
01845 _M_initialize()
01846 { _M_log_p = std::log(_M_p); }
01847
01848 _RealType _M_p;
01849 _RealType _M_log_p;
01850 };
01851
01852
01853 template<typename _RealType>
01854 class normal_distribution;
01855
01856
01857
01858
01859
01860
01861
01862
01863 template<typename _IntType = int, typename _RealType = double>
01864 class poisson_distribution
01865 {
01866 public:
01867
01868 typedef _RealType input_type;
01869 typedef _IntType result_type;
01870
01871
01872 explicit
01873 poisson_distribution(const _RealType& __mean = _RealType(1))
01874 : _M_mean(__mean), _M_nd()
01875 {
01876 _GLIBCXX_DEBUG_ASSERT(_M_mean > 0.0);
01877 _M_initialize();
01878 }
01879
01880
01881
01882
01883 _RealType
01884 mean() const
01885 { return _M_mean; }
01886
01887 void
01888 reset()
01889 { _M_nd.reset(); }
01890
01891 template<class _UniformRandomNumberGenerator>
01892 result_type
01893 operator()(_UniformRandomNumberGenerator& __urng);
01894
01895
01896
01897
01898
01899
01900
01901
01902
01903
01904
01905 template<typename _IntType1, typename _RealType1,
01906 typename _CharT, typename _Traits>
01907 friend std::basic_ostream<_CharT, _Traits>&
01908 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
01909 const poisson_distribution<_IntType1, _RealType1>& __x);
01910
01911
01912
01913
01914
01915
01916
01917
01918
01919
01920 template<typename _IntType1, typename _RealType1,
01921 typename _CharT, typename _Traits>
01922 friend std::basic_istream<_CharT, _Traits>&
01923 operator>>(std::basic_istream<_CharT, _Traits>& __is,
01924 poisson_distribution<_IntType1, _RealType1>& __x);
01925
01926 private:
01927 void
01928 _M_initialize();
01929
01930
01931 normal_distribution<_RealType> _M_nd;
01932
01933 _RealType _M_mean;
01934
01935
01936 _RealType _M_lm_thr;
01937 #if _GLIBCXX_USE_C99_MATH_TR1
01938 _RealType _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb;
01939 #endif
01940 };
01941
01942
01943
01944
01945
01946
01947
01948
01949
01950 template<typename _IntType = int, typename _RealType = double>
01951 class binomial_distribution
01952 {
01953 public:
01954
01955 typedef _RealType input_type;
01956 typedef _IntType result_type;
01957
01958
01959 explicit
01960 binomial_distribution(_IntType __t = 1,
01961 const _RealType& __p = _RealType(0.5))
01962 : _M_t(__t), _M_p(__p), _M_nd()
01963 {
01964 _GLIBCXX_DEBUG_ASSERT((_M_t >= 0) && (_M_p >= 0.0) && (_M_p <= 1.0));
01965 _M_initialize();
01966 }
01967
01968
01969
01970
01971 _IntType
01972 t() const
01973 { return _M_t; }
01974
01975
01976
01977
01978 _RealType
01979 p() const
01980 { return _M_p; }
01981
01982 void
01983 reset()
01984 { _M_nd.reset(); }
01985
01986 template<class _UniformRandomNumberGenerator>
01987 result_type
01988 operator()(_UniformRandomNumberGenerator& __urng);
01989
01990
01991
01992
01993
01994
01995
01996
01997
01998
01999
02000 template<typename _IntType1, typename _RealType1,
02001 typename _CharT, typename _Traits>
02002 friend std::basic_ostream<_CharT, _Traits>&
02003 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
02004 const binomial_distribution<_IntType1, _RealType1>& __x);
02005
02006
02007
02008
02009
02010
02011
02012
02013
02014
02015 template<typename _IntType1, typename _RealType1,
02016 typename _CharT, typename _Traits>
02017 friend std::basic_istream<_CharT, _Traits>&
02018 operator>>(std::basic_istream<_CharT, _Traits>& __is,
02019 binomial_distribution<_IntType1, _RealType1>& __x);
02020
02021 private:
02022 void
02023 _M_initialize();
02024
02025 template<class _UniformRandomNumberGenerator>
02026 result_type
02027 _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t);
02028
02029
02030 normal_distribution<_RealType> _M_nd;
02031
02032 _RealType _M_q;
02033 #if _GLIBCXX_USE_C99_MATH_TR1
02034 _RealType _M_d1, _M_d2, _M_s1, _M_s2, _M_c,
02035 _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p;
02036 #endif
02037 _RealType _M_p;
02038 _IntType _M_t;
02039
02040 bool _M_easy;
02041 };
02042
02043
02044
02045
02046
02047
02048
02049
02050
02051
02052
02053
02054
02055
02056
02057
02058 template<typename _RealType = double>
02059 class uniform_real
02060 {
02061 public:
02062
02063 typedef _RealType input_type;
02064 typedef _RealType result_type;
02065
02066 public:
02067
02068
02069
02070
02071
02072
02073 explicit
02074 uniform_real(_RealType __min = _RealType(0),
02075 _RealType __max = _RealType(1))
02076 : _M_min(__min), _M_max(__max)
02077 {
02078 _GLIBCXX_DEBUG_ASSERT(_M_min <= _M_max);
02079 }
02080
02081 result_type
02082 min() const
02083 { return _M_min; }
02084
02085 result_type
02086 max() const
02087 { return _M_max; }
02088
02089 void
02090 reset() { }
02091
02092 template<class _UniformRandomNumberGenerator>
02093 result_type
02094 operator()(_UniformRandomNumberGenerator& __urng)
02095 { return (__urng() * (_M_max - _M_min)) + _M_min; }
02096
02097
02098
02099
02100
02101
02102
02103
02104
02105
02106
02107 template<typename _RealType1, typename _CharT, typename _Traits>
02108 friend std::basic_ostream<_CharT, _Traits>&
02109 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
02110 const uniform_real<_RealType1>& __x);
02111
02112
02113
02114
02115
02116
02117
02118
02119
02120
02121 template<typename _RealType1, typename _CharT, typename _Traits>
02122 friend std::basic_istream<_CharT, _Traits>&
02123 operator>>(std::basic_istream<_CharT, _Traits>& __is,
02124 uniform_real<_RealType1>& __x);
02125
02126 private:
02127 _RealType _M_min;
02128 _RealType _M_max;
02129 };
02130
02131
02132
02133
02134
02135
02136
02137
02138
02139
02140
02141
02142
02143
02144
02145
02146
02147 template<typename _RealType = double>
02148 class exponential_distribution
02149 {
02150 public:
02151
02152 typedef _RealType input_type;
02153 typedef _RealType result_type;
02154
02155 public:
02156
02157
02158
02159
02160 explicit
02161 exponential_distribution(const result_type& __lambda = result_type(1))
02162 : _M_lambda(__lambda)
02163 {
02164 _GLIBCXX_DEBUG_ASSERT(_M_lambda > 0);
02165 }
02166
02167
02168
02169
02170 _RealType
02171 lambda() const
02172 { return _M_lambda; }
02173
02174
02175
02176
02177
02178
02179 void
02180 reset() { }
02181
02182 template<class _UniformRandomNumberGenerator>
02183 result_type
02184 operator()(_UniformRandomNumberGenerator& __urng)
02185 { return -std::log(__urng()) / _M_lambda; }
02186
02187
02188
02189
02190
02191
02192
02193
02194
02195
02196
02197 template<typename _RealType1, typename _CharT, typename _Traits>
02198 friend std::basic_ostream<_CharT, _Traits>&
02199 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
02200 const exponential_distribution<_RealType1>& __x);
02201
02202
02203
02204
02205
02206
02207
02208
02209
02210
02211
02212 template<typename _CharT, typename _Traits>
02213 friend std::basic_istream<_CharT, _Traits>&
02214 operator>>(std::basic_istream<_CharT, _Traits>& __is,
02215 exponential_distribution& __x)
02216 { return __is >> __x._M_lambda; }
02217
02218 private:
02219 result_type _M_lambda;
02220 };
02221
02222
02223
02224
02225
02226
02227
02228
02229
02230 template<typename _RealType = double>
02231 class normal_distribution
02232 {
02233 public:
02234
02235 typedef _RealType input_type;
02236 typedef _RealType result_type;
02237
02238 public:
02239
02240
02241
02242
02243 explicit
02244 normal_distribution(const result_type& __mean = result_type(0),
02245 const result_type& __sigma = result_type(1))
02246 : _M_mean(__mean), _M_sigma(__sigma), _M_saved_available(false)
02247 {
02248 _GLIBCXX_DEBUG_ASSERT(_M_sigma > 0);
02249 }
02250
02251
02252
02253
02254 _RealType
02255 mean() const
02256 { return _M_mean; }
02257
02258
02259
02260
02261 _RealType
02262 sigma() const
02263 { return _M_sigma; }
02264
02265
02266
02267
02268 void
02269 reset()
02270 { _M_saved_available = false; }
02271
02272 template<class _UniformRandomNumberGenerator>
02273 result_type
02274 operator()(_UniformRandomNumberGenerator& __urng);
02275
02276
02277
02278
02279
02280
02281
02282
02283
02284
02285
02286 template<typename _RealType1, typename _CharT, typename _Traits>
02287 friend std::basic_ostream<_CharT, _Traits>&
02288 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
02289 const normal_distribution<_RealType1>& __x);
02290
02291
02292
02293
02294
02295
02296
02297
02298
02299
02300 template<typename _RealType1, typename _CharT, typename _Traits>
02301 friend std::basic_istream<_CharT, _Traits>&
02302 operator>>(std::basic_istream<_CharT, _Traits>& __is,
02303 normal_distribution<_RealType1>& __x);
02304
02305 private:
02306 result_type _M_mean;
02307 result_type _M_sigma;
02308 result_type _M_saved;
02309 bool _M_saved_available;
02310 };
02311
02312
02313
02314
02315
02316
02317
02318
02319 template<typename _RealType = double>
02320 class gamma_distribution
02321 {
02322 public:
02323
02324 typedef _RealType input_type;
02325 typedef _RealType result_type;
02326
02327 public:
02328
02329
02330
02331 explicit
02332 gamma_distribution(const result_type& __alpha_val = result_type(1))
02333 : _M_alpha(__alpha_val)
02334 {
02335 _GLIBCXX_DEBUG_ASSERT(_M_alpha > 0);
02336 _M_initialize();
02337 }
02338
02339
02340
02341
02342 _RealType
02343 alpha() const
02344 { return _M_alpha; }
02345
02346
02347
02348
02349 void
02350 reset() { }
02351
02352 template<class _UniformRandomNumberGenerator>
02353 result_type
02354 operator()(_UniformRandomNumberGenerator& __urng);
02355
02356
02357
02358
02359
02360
02361
02362
02363
02364
02365
02366 template<typename _RealType1, typename _CharT, typename _Traits>
02367 friend std::basic_ostream<_CharT, _Traits>&
02368 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
02369 const gamma_distribution<_RealType1>& __x);
02370
02371
02372
02373
02374
02375
02376
02377
02378
02379
02380 template<typename _CharT, typename _Traits>
02381 friend std::basic_istream<_CharT, _Traits>&
02382 operator>>(std::basic_istream<_CharT, _Traits>& __is,
02383 gamma_distribution& __x)
02384 {
02385 __is >> __x._M_alpha;
02386 __x._M_initialize();
02387 return __is;
02388 }
02389
02390 private:
02391 void
02392 _M_initialize();
02393
02394 result_type _M_alpha;
02395
02396
02397 result_type _M_l_d;
02398 };
02399
02400
02401
02402
02403
02404 _GLIBCXX_END_NAMESPACE_TR1
02405 }
02406
02407 #include <tr1_impl/random.tcc>