random 110 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867
  1. // Random number extensions -*- C++ -*-
  2. // Copyright (C) 2012-2019 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file ext/random
  21. * This file is a GNU extension to the Standard C++ Library.
  22. */
  23. #ifndef _EXT_RANDOM
  24. #define _EXT_RANDOM 1
  25. #pragma GCC system_header
  26. #if __cplusplus < 201103L
  27. # include <bits/c++0x_warning.h>
  28. #else
  29. #include <random>
  30. #include <algorithm>
  31. #include <array>
  32. #include <ext/cmath>
  33. #ifdef __SSE2__
  34. # include <emmintrin.h>
  35. #endif
  36. #if defined(_GLIBCXX_USE_C99_STDINT_TR1) && defined(UINT32_C)
  37. namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
  38. {
  39. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  40. #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
  41. /* Mersenne twister implementation optimized for vector operations.
  42. *
  43. * Reference: http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/
  44. */
  45. template<typename _UIntType, size_t __m,
  46. size_t __pos1, size_t __sl1, size_t __sl2,
  47. size_t __sr1, size_t __sr2,
  48. uint32_t __msk1, uint32_t __msk2,
  49. uint32_t __msk3, uint32_t __msk4,
  50. uint32_t __parity1, uint32_t __parity2,
  51. uint32_t __parity3, uint32_t __parity4>
  52. class simd_fast_mersenne_twister_engine
  53. {
  54. static_assert(std::is_unsigned<_UIntType>::value, "template argument "
  55. "substituting _UIntType not an unsigned integral type");
  56. static_assert(__sr1 < 32, "first right shift too large");
  57. static_assert(__sr2 < 16, "second right shift too large");
  58. static_assert(__sl1 < 32, "first left shift too large");
  59. static_assert(__sl2 < 16, "second left shift too large");
  60. public:
  61. typedef _UIntType result_type;
  62. private:
  63. static constexpr size_t m_w = sizeof(result_type) * 8;
  64. static constexpr size_t _M_nstate = __m / 128 + 1;
  65. static constexpr size_t _M_nstate32 = _M_nstate * 4;
  66. static_assert(std::is_unsigned<_UIntType>::value, "template argument "
  67. "substituting _UIntType not an unsigned integral type");
  68. static_assert(__pos1 < _M_nstate, "POS1 not smaller than state size");
  69. static_assert(16 % sizeof(_UIntType) == 0,
  70. "UIntType size must divide 16");
  71. template<typename _Sseq>
  72. using _If_seed_seq
  73. = typename std::enable_if<std::__detail::__is_seed_seq<
  74. _Sseq, simd_fast_mersenne_twister_engine, result_type>::value
  75. >::type;
  76. public:
  77. static constexpr size_t state_size = _M_nstate * (16
  78. / sizeof(result_type));
  79. static constexpr result_type default_seed = 5489u;
  80. // constructors and member functions
  81. simd_fast_mersenne_twister_engine()
  82. : simd_fast_mersenne_twister_engine(default_seed)
  83. { }
  84. explicit
  85. simd_fast_mersenne_twister_engine(result_type __sd)
  86. { seed(__sd); }
  87. template<typename _Sseq, typename = _If_seed_seq<_Sseq>>
  88. explicit
  89. simd_fast_mersenne_twister_engine(_Sseq& __q)
  90. { seed(__q); }
  91. void
  92. seed(result_type __sd = default_seed);
  93. template<typename _Sseq>
  94. _If_seed_seq<_Sseq>
  95. seed(_Sseq& __q);
  96. static constexpr result_type
  97. min()
  98. { return 0; }
  99. static constexpr result_type
  100. max()
  101. { return std::numeric_limits<result_type>::max(); }
  102. void
  103. discard(unsigned long long __z);
  104. result_type
  105. operator()()
  106. {
  107. if (__builtin_expect(_M_pos >= state_size, 0))
  108. _M_gen_rand();
  109. return _M_stateT[_M_pos++];
  110. }
  111. template<typename _UIntType_2, size_t __m_2,
  112. size_t __pos1_2, size_t __sl1_2, size_t __sl2_2,
  113. size_t __sr1_2, size_t __sr2_2,
  114. uint32_t __msk1_2, uint32_t __msk2_2,
  115. uint32_t __msk3_2, uint32_t __msk4_2,
  116. uint32_t __parity1_2, uint32_t __parity2_2,
  117. uint32_t __parity3_2, uint32_t __parity4_2>
  118. friend bool
  119. operator==(const simd_fast_mersenne_twister_engine<_UIntType_2,
  120. __m_2, __pos1_2, __sl1_2, __sl2_2, __sr1_2, __sr2_2,
  121. __msk1_2, __msk2_2, __msk3_2, __msk4_2,
  122. __parity1_2, __parity2_2, __parity3_2, __parity4_2>& __lhs,
  123. const simd_fast_mersenne_twister_engine<_UIntType_2,
  124. __m_2, __pos1_2, __sl1_2, __sl2_2, __sr1_2, __sr2_2,
  125. __msk1_2, __msk2_2, __msk3_2, __msk4_2,
  126. __parity1_2, __parity2_2, __parity3_2, __parity4_2>& __rhs);
  127. template<typename _UIntType_2, size_t __m_2,
  128. size_t __pos1_2, size_t __sl1_2, size_t __sl2_2,
  129. size_t __sr1_2, size_t __sr2_2,
  130. uint32_t __msk1_2, uint32_t __msk2_2,
  131. uint32_t __msk3_2, uint32_t __msk4_2,
  132. uint32_t __parity1_2, uint32_t __parity2_2,
  133. uint32_t __parity3_2, uint32_t __parity4_2,
  134. typename _CharT, typename _Traits>
  135. friend std::basic_ostream<_CharT, _Traits>&
  136. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  137. const __gnu_cxx::simd_fast_mersenne_twister_engine
  138. <_UIntType_2,
  139. __m_2, __pos1_2, __sl1_2, __sl2_2, __sr1_2, __sr2_2,
  140. __msk1_2, __msk2_2, __msk3_2, __msk4_2,
  141. __parity1_2, __parity2_2, __parity3_2, __parity4_2>& __x);
  142. template<typename _UIntType_2, size_t __m_2,
  143. size_t __pos1_2, size_t __sl1_2, size_t __sl2_2,
  144. size_t __sr1_2, size_t __sr2_2,
  145. uint32_t __msk1_2, uint32_t __msk2_2,
  146. uint32_t __msk3_2, uint32_t __msk4_2,
  147. uint32_t __parity1_2, uint32_t __parity2_2,
  148. uint32_t __parity3_2, uint32_t __parity4_2,
  149. typename _CharT, typename _Traits>
  150. friend std::basic_istream<_CharT, _Traits>&
  151. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  152. __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType_2,
  153. __m_2, __pos1_2, __sl1_2, __sl2_2, __sr1_2, __sr2_2,
  154. __msk1_2, __msk2_2, __msk3_2, __msk4_2,
  155. __parity1_2, __parity2_2, __parity3_2, __parity4_2>& __x);
  156. private:
  157. union
  158. {
  159. #ifdef __SSE2__
  160. __m128i _M_state[_M_nstate];
  161. #endif
  162. #ifdef __ARM_NEON
  163. #ifdef __aarch64__
  164. __Uint32x4_t _M_state[_M_nstate];
  165. #endif
  166. #endif
  167. uint32_t _M_state32[_M_nstate32];
  168. result_type _M_stateT[state_size];
  169. } __attribute__ ((__aligned__ (16)));
  170. size_t _M_pos;
  171. void _M_gen_rand(void);
  172. void _M_period_certification();
  173. };
  174. template<typename _UIntType, size_t __m,
  175. size_t __pos1, size_t __sl1, size_t __sl2,
  176. size_t __sr1, size_t __sr2,
  177. uint32_t __msk1, uint32_t __msk2,
  178. uint32_t __msk3, uint32_t __msk4,
  179. uint32_t __parity1, uint32_t __parity2,
  180. uint32_t __parity3, uint32_t __parity4>
  181. inline bool
  182. operator!=(const __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType,
  183. __m, __pos1, __sl1, __sl2, __sr1, __sr2, __msk1, __msk2, __msk3,
  184. __msk4, __parity1, __parity2, __parity3, __parity4>& __lhs,
  185. const __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType,
  186. __m, __pos1, __sl1, __sl2, __sr1, __sr2, __msk1, __msk2, __msk3,
  187. __msk4, __parity1, __parity2, __parity3, __parity4>& __rhs)
  188. { return !(__lhs == __rhs); }
  189. /* Definitions for the SIMD-oriented Fast Mersenne Twister as defined
  190. * in the C implementation by Daito and Matsumoto, as both a 32-bit
  191. * and 64-bit version.
  192. */
  193. typedef simd_fast_mersenne_twister_engine<uint32_t, 607, 2,
  194. 15, 3, 13, 3,
  195. 0xfdff37ffU, 0xef7f3f7dU,
  196. 0xff777b7dU, 0x7ff7fb2fU,
  197. 0x00000001U, 0x00000000U,
  198. 0x00000000U, 0x5986f054U>
  199. sfmt607;
  200. typedef simd_fast_mersenne_twister_engine<uint64_t, 607, 2,
  201. 15, 3, 13, 3,
  202. 0xfdff37ffU, 0xef7f3f7dU,
  203. 0xff777b7dU, 0x7ff7fb2fU,
  204. 0x00000001U, 0x00000000U,
  205. 0x00000000U, 0x5986f054U>
  206. sfmt607_64;
  207. typedef simd_fast_mersenne_twister_engine<uint32_t, 1279, 7,
  208. 14, 3, 5, 1,
  209. 0xf7fefffdU, 0x7fefcfffU,
  210. 0xaff3ef3fU, 0xb5ffff7fU,
  211. 0x00000001U, 0x00000000U,
  212. 0x00000000U, 0x20000000U>
  213. sfmt1279;
  214. typedef simd_fast_mersenne_twister_engine<uint64_t, 1279, 7,
  215. 14, 3, 5, 1,
  216. 0xf7fefffdU, 0x7fefcfffU,
  217. 0xaff3ef3fU, 0xb5ffff7fU,
  218. 0x00000001U, 0x00000000U,
  219. 0x00000000U, 0x20000000U>
  220. sfmt1279_64;
  221. typedef simd_fast_mersenne_twister_engine<uint32_t, 2281, 12,
  222. 19, 1, 5, 1,
  223. 0xbff7ffbfU, 0xfdfffffeU,
  224. 0xf7ffef7fU, 0xf2f7cbbfU,
  225. 0x00000001U, 0x00000000U,
  226. 0x00000000U, 0x41dfa600U>
  227. sfmt2281;
  228. typedef simd_fast_mersenne_twister_engine<uint64_t, 2281, 12,
  229. 19, 1, 5, 1,
  230. 0xbff7ffbfU, 0xfdfffffeU,
  231. 0xf7ffef7fU, 0xf2f7cbbfU,
  232. 0x00000001U, 0x00000000U,
  233. 0x00000000U, 0x41dfa600U>
  234. sfmt2281_64;
  235. typedef simd_fast_mersenne_twister_engine<uint32_t, 4253, 17,
  236. 20, 1, 7, 1,
  237. 0x9f7bffffU, 0x9fffff5fU,
  238. 0x3efffffbU, 0xfffff7bbU,
  239. 0xa8000001U, 0xaf5390a3U,
  240. 0xb740b3f8U, 0x6c11486dU>
  241. sfmt4253;
  242. typedef simd_fast_mersenne_twister_engine<uint64_t, 4253, 17,
  243. 20, 1, 7, 1,
  244. 0x9f7bffffU, 0x9fffff5fU,
  245. 0x3efffffbU, 0xfffff7bbU,
  246. 0xa8000001U, 0xaf5390a3U,
  247. 0xb740b3f8U, 0x6c11486dU>
  248. sfmt4253_64;
  249. typedef simd_fast_mersenne_twister_engine<uint32_t, 11213, 68,
  250. 14, 3, 7, 3,
  251. 0xeffff7fbU, 0xffffffefU,
  252. 0xdfdfbfffU, 0x7fffdbfdU,
  253. 0x00000001U, 0x00000000U,
  254. 0xe8148000U, 0xd0c7afa3U>
  255. sfmt11213;
  256. typedef simd_fast_mersenne_twister_engine<uint64_t, 11213, 68,
  257. 14, 3, 7, 3,
  258. 0xeffff7fbU, 0xffffffefU,
  259. 0xdfdfbfffU, 0x7fffdbfdU,
  260. 0x00000001U, 0x00000000U,
  261. 0xe8148000U, 0xd0c7afa3U>
  262. sfmt11213_64;
  263. typedef simd_fast_mersenne_twister_engine<uint32_t, 19937, 122,
  264. 18, 1, 11, 1,
  265. 0xdfffffefU, 0xddfecb7fU,
  266. 0xbffaffffU, 0xbffffff6U,
  267. 0x00000001U, 0x00000000U,
  268. 0x00000000U, 0x13c9e684U>
  269. sfmt19937;
  270. typedef simd_fast_mersenne_twister_engine<uint64_t, 19937, 122,
  271. 18, 1, 11, 1,
  272. 0xdfffffefU, 0xddfecb7fU,
  273. 0xbffaffffU, 0xbffffff6U,
  274. 0x00000001U, 0x00000000U,
  275. 0x00000000U, 0x13c9e684U>
  276. sfmt19937_64;
  277. typedef simd_fast_mersenne_twister_engine<uint32_t, 44497, 330,
  278. 5, 3, 9, 3,
  279. 0xeffffffbU, 0xdfbebfffU,
  280. 0xbfbf7befU, 0x9ffd7bffU,
  281. 0x00000001U, 0x00000000U,
  282. 0xa3ac4000U, 0xecc1327aU>
  283. sfmt44497;
  284. typedef simd_fast_mersenne_twister_engine<uint64_t, 44497, 330,
  285. 5, 3, 9, 3,
  286. 0xeffffffbU, 0xdfbebfffU,
  287. 0xbfbf7befU, 0x9ffd7bffU,
  288. 0x00000001U, 0x00000000U,
  289. 0xa3ac4000U, 0xecc1327aU>
  290. sfmt44497_64;
  291. typedef simd_fast_mersenne_twister_engine<uint32_t, 86243, 366,
  292. 6, 7, 19, 1,
  293. 0xfdbffbffU, 0xbff7ff3fU,
  294. 0xfd77efffU, 0xbf9ff3ffU,
  295. 0x00000001U, 0x00000000U,
  296. 0x00000000U, 0xe9528d85U>
  297. sfmt86243;
  298. typedef simd_fast_mersenne_twister_engine<uint64_t, 86243, 366,
  299. 6, 7, 19, 1,
  300. 0xfdbffbffU, 0xbff7ff3fU,
  301. 0xfd77efffU, 0xbf9ff3ffU,
  302. 0x00000001U, 0x00000000U,
  303. 0x00000000U, 0xe9528d85U>
  304. sfmt86243_64;
  305. typedef simd_fast_mersenne_twister_engine<uint32_t, 132049, 110,
  306. 19, 1, 21, 1,
  307. 0xffffbb5fU, 0xfb6ebf95U,
  308. 0xfffefffaU, 0xcff77fffU,
  309. 0x00000001U, 0x00000000U,
  310. 0xcb520000U, 0xc7e91c7dU>
  311. sfmt132049;
  312. typedef simd_fast_mersenne_twister_engine<uint64_t, 132049, 110,
  313. 19, 1, 21, 1,
  314. 0xffffbb5fU, 0xfb6ebf95U,
  315. 0xfffefffaU, 0xcff77fffU,
  316. 0x00000001U, 0x00000000U,
  317. 0xcb520000U, 0xc7e91c7dU>
  318. sfmt132049_64;
  319. typedef simd_fast_mersenne_twister_engine<uint32_t, 216091, 627,
  320. 11, 3, 10, 1,
  321. 0xbff7bff7U, 0xbfffffffU,
  322. 0xbffffa7fU, 0xffddfbfbU,
  323. 0xf8000001U, 0x89e80709U,
  324. 0x3bd2b64bU, 0x0c64b1e4U>
  325. sfmt216091;
  326. typedef simd_fast_mersenne_twister_engine<uint64_t, 216091, 627,
  327. 11, 3, 10, 1,
  328. 0xbff7bff7U, 0xbfffffffU,
  329. 0xbffffa7fU, 0xffddfbfbU,
  330. 0xf8000001U, 0x89e80709U,
  331. 0x3bd2b64bU, 0x0c64b1e4U>
  332. sfmt216091_64;
  333. #endif // __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
  334. /**
  335. * @brief A beta continuous distribution for random numbers.
  336. *
  337. * The formula for the beta probability density function is:
  338. * @f[
  339. * p(x|\alpha,\beta) = \frac{1}{B(\alpha,\beta)}
  340. * x^{\alpha - 1} (1 - x)^{\beta - 1}
  341. * @f]
  342. */
  343. template<typename _RealType = double>
  344. class beta_distribution
  345. {
  346. static_assert(std::is_floating_point<_RealType>::value,
  347. "template argument not a floating point type");
  348. public:
  349. /** The type of the range of the distribution. */
  350. typedef _RealType result_type;
  351. /** Parameter type. */
  352. struct param_type
  353. {
  354. typedef beta_distribution<_RealType> distribution_type;
  355. friend class beta_distribution<_RealType>;
  356. param_type() : param_type(1) { }
  357. explicit
  358. param_type(_RealType __alpha_val, _RealType __beta_val = _RealType(1))
  359. : _M_alpha(__alpha_val), _M_beta(__beta_val)
  360. {
  361. __glibcxx_assert(_M_alpha > _RealType(0));
  362. __glibcxx_assert(_M_beta > _RealType(0));
  363. }
  364. _RealType
  365. alpha() const
  366. { return _M_alpha; }
  367. _RealType
  368. beta() const
  369. { return _M_beta; }
  370. friend bool
  371. operator==(const param_type& __p1, const param_type& __p2)
  372. { return (__p1._M_alpha == __p2._M_alpha
  373. && __p1._M_beta == __p2._M_beta); }
  374. friend bool
  375. operator!=(const param_type& __p1, const param_type& __p2)
  376. { return !(__p1 == __p2); }
  377. private:
  378. void
  379. _M_initialize();
  380. _RealType _M_alpha;
  381. _RealType _M_beta;
  382. };
  383. public:
  384. beta_distribution() : beta_distribution(1.0) { }
  385. /**
  386. * @brief Constructs a beta distribution with parameters
  387. * @f$\alpha@f$ and @f$\beta@f$.
  388. */
  389. explicit
  390. beta_distribution(_RealType __alpha_val,
  391. _RealType __beta_val = _RealType(1))
  392. : _M_param(__alpha_val, __beta_val)
  393. { }
  394. explicit
  395. beta_distribution(const param_type& __p)
  396. : _M_param(__p)
  397. { }
  398. /**
  399. * @brief Resets the distribution state.
  400. */
  401. void
  402. reset()
  403. { }
  404. /**
  405. * @brief Returns the @f$\alpha@f$ of the distribution.
  406. */
  407. _RealType
  408. alpha() const
  409. { return _M_param.alpha(); }
  410. /**
  411. * @brief Returns the @f$\beta@f$ of the distribution.
  412. */
  413. _RealType
  414. beta() const
  415. { return _M_param.beta(); }
  416. /**
  417. * @brief Returns the parameter set of the distribution.
  418. */
  419. param_type
  420. param() const
  421. { return _M_param; }
  422. /**
  423. * @brief Sets the parameter set of the distribution.
  424. * @param __param The new parameter set of the distribution.
  425. */
  426. void
  427. param(const param_type& __param)
  428. { _M_param = __param; }
  429. /**
  430. * @brief Returns the greatest lower bound value of the distribution.
  431. */
  432. result_type
  433. min() const
  434. { return result_type(0); }
  435. /**
  436. * @brief Returns the least upper bound value of the distribution.
  437. */
  438. result_type
  439. max() const
  440. { return result_type(1); }
  441. /**
  442. * @brief Generating functions.
  443. */
  444. template<typename _UniformRandomNumberGenerator>
  445. result_type
  446. operator()(_UniformRandomNumberGenerator& __urng)
  447. { return this->operator()(__urng, _M_param); }
  448. template<typename _UniformRandomNumberGenerator>
  449. result_type
  450. operator()(_UniformRandomNumberGenerator& __urng,
  451. const param_type& __p);
  452. template<typename _ForwardIterator,
  453. typename _UniformRandomNumberGenerator>
  454. void
  455. __generate(_ForwardIterator __f, _ForwardIterator __t,
  456. _UniformRandomNumberGenerator& __urng)
  457. { this->__generate(__f, __t, __urng, _M_param); }
  458. template<typename _ForwardIterator,
  459. typename _UniformRandomNumberGenerator>
  460. void
  461. __generate(_ForwardIterator __f, _ForwardIterator __t,
  462. _UniformRandomNumberGenerator& __urng,
  463. const param_type& __p)
  464. { this->__generate_impl(__f, __t, __urng, __p); }
  465. template<typename _UniformRandomNumberGenerator>
  466. void
  467. __generate(result_type* __f, result_type* __t,
  468. _UniformRandomNumberGenerator& __urng,
  469. const param_type& __p)
  470. { this->__generate_impl(__f, __t, __urng, __p); }
  471. /**
  472. * @brief Return true if two beta distributions have the same
  473. * parameters and the sequences that would be generated
  474. * are equal.
  475. */
  476. friend bool
  477. operator==(const beta_distribution& __d1,
  478. const beta_distribution& __d2)
  479. { return __d1._M_param == __d2._M_param; }
  480. /**
  481. * @brief Inserts a %beta_distribution random number distribution
  482. * @p __x into the output stream @p __os.
  483. *
  484. * @param __os An output stream.
  485. * @param __x A %beta_distribution random number distribution.
  486. *
  487. * @returns The output stream with the state of @p __x inserted or in
  488. * an error state.
  489. */
  490. template<typename _RealType1, typename _CharT, typename _Traits>
  491. friend std::basic_ostream<_CharT, _Traits>&
  492. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  493. const __gnu_cxx::beta_distribution<_RealType1>& __x);
  494. /**
  495. * @brief Extracts a %beta_distribution random number distribution
  496. * @p __x from the input stream @p __is.
  497. *
  498. * @param __is An input stream.
  499. * @param __x A %beta_distribution random number generator engine.
  500. *
  501. * @returns The input stream with @p __x extracted or in an error state.
  502. */
  503. template<typename _RealType1, typename _CharT, typename _Traits>
  504. friend std::basic_istream<_CharT, _Traits>&
  505. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  506. __gnu_cxx::beta_distribution<_RealType1>& __x);
  507. private:
  508. template<typename _ForwardIterator,
  509. typename _UniformRandomNumberGenerator>
  510. void
  511. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  512. _UniformRandomNumberGenerator& __urng,
  513. const param_type& __p);
  514. param_type _M_param;
  515. };
  516. /**
  517. * @brief Return true if two beta distributions are different.
  518. */
  519. template<typename _RealType>
  520. inline bool
  521. operator!=(const __gnu_cxx::beta_distribution<_RealType>& __d1,
  522. const __gnu_cxx::beta_distribution<_RealType>& __d2)
  523. { return !(__d1 == __d2); }
  524. /**
  525. * @brief A multi-variate normal continuous distribution for random numbers.
  526. *
  527. * The formula for the normal probability density function is
  528. * @f[
  529. * p(\overrightarrow{x}|\overrightarrow{\mu },\Sigma) =
  530. * \frac{1}{\sqrt{(2\pi )^k\det(\Sigma))}}
  531. * e^{-\frac{1}{2}(\overrightarrow{x}-\overrightarrow{\mu})^\text{T}
  532. * \Sigma ^{-1}(\overrightarrow{x}-\overrightarrow{\mu})}
  533. * @f]
  534. *
  535. * where @f$\overrightarrow{x}@f$ and @f$\overrightarrow{\mu}@f$ are
  536. * vectors of dimension @f$k@f$ and @f$\Sigma@f$ is the covariance
  537. * matrix (which must be positive-definite).
  538. */
  539. template<std::size_t _Dimen, typename _RealType = double>
  540. class normal_mv_distribution
  541. {
  542. static_assert(std::is_floating_point<_RealType>::value,
  543. "template argument not a floating point type");
  544. static_assert(_Dimen != 0, "dimension is zero");
  545. public:
  546. /** The type of the range of the distribution. */
  547. typedef std::array<_RealType, _Dimen> result_type;
  548. /** Parameter type. */
  549. class param_type
  550. {
  551. static constexpr size_t _M_t_size = _Dimen * (_Dimen + 1) / 2;
  552. public:
  553. typedef normal_mv_distribution<_Dimen, _RealType> distribution_type;
  554. friend class normal_mv_distribution<_Dimen, _RealType>;
  555. param_type()
  556. {
  557. std::fill(_M_mean.begin(), _M_mean.end(), _RealType(0));
  558. auto __it = _M_t.begin();
  559. for (size_t __i = 0; __i < _Dimen; ++__i)
  560. {
  561. std::fill_n(__it, __i, _RealType(0));
  562. __it += __i;
  563. *__it++ = _RealType(1);
  564. }
  565. }
  566. template<typename _ForwardIterator1, typename _ForwardIterator2>
  567. param_type(_ForwardIterator1 __meanbegin,
  568. _ForwardIterator1 __meanend,
  569. _ForwardIterator2 __varcovbegin,
  570. _ForwardIterator2 __varcovend)
  571. {
  572. __glibcxx_function_requires(_ForwardIteratorConcept<
  573. _ForwardIterator1>)
  574. __glibcxx_function_requires(_ForwardIteratorConcept<
  575. _ForwardIterator2>)
  576. _GLIBCXX_DEBUG_ASSERT(std::distance(__meanbegin, __meanend)
  577. <= _Dimen);
  578. const auto __dist = std::distance(__varcovbegin, __varcovend);
  579. _GLIBCXX_DEBUG_ASSERT(__dist == _Dimen * _Dimen
  580. || __dist == _Dimen * (_Dimen + 1) / 2
  581. || __dist == _Dimen);
  582. if (__dist == _Dimen * _Dimen)
  583. _M_init_full(__meanbegin, __meanend, __varcovbegin, __varcovend);
  584. else if (__dist == _Dimen * (_Dimen + 1) / 2)
  585. _M_init_lower(__meanbegin, __meanend, __varcovbegin, __varcovend);
  586. else
  587. {
  588. __glibcxx_assert(__dist == _Dimen);
  589. _M_init_diagonal(__meanbegin, __meanend,
  590. __varcovbegin, __varcovend);
  591. }
  592. }
  593. param_type(std::initializer_list<_RealType> __mean,
  594. std::initializer_list<_RealType> __varcov)
  595. {
  596. _GLIBCXX_DEBUG_ASSERT(__mean.size() <= _Dimen);
  597. _GLIBCXX_DEBUG_ASSERT(__varcov.size() == _Dimen * _Dimen
  598. || __varcov.size() == _Dimen * (_Dimen + 1) / 2
  599. || __varcov.size() == _Dimen);
  600. if (__varcov.size() == _Dimen * _Dimen)
  601. _M_init_full(__mean.begin(), __mean.end(),
  602. __varcov.begin(), __varcov.end());
  603. else if (__varcov.size() == _Dimen * (_Dimen + 1) / 2)
  604. _M_init_lower(__mean.begin(), __mean.end(),
  605. __varcov.begin(), __varcov.end());
  606. else
  607. {
  608. __glibcxx_assert(__varcov.size() == _Dimen);
  609. _M_init_diagonal(__mean.begin(), __mean.end(),
  610. __varcov.begin(), __varcov.end());
  611. }
  612. }
  613. std::array<_RealType, _Dimen>
  614. mean() const
  615. { return _M_mean; }
  616. std::array<_RealType, _M_t_size>
  617. varcov() const
  618. { return _M_t; }
  619. friend bool
  620. operator==(const param_type& __p1, const param_type& __p2)
  621. { return __p1._M_mean == __p2._M_mean && __p1._M_t == __p2._M_t; }
  622. friend bool
  623. operator!=(const param_type& __p1, const param_type& __p2)
  624. { return !(__p1 == __p2); }
  625. private:
  626. template <typename _InputIterator1, typename _InputIterator2>
  627. void _M_init_full(_InputIterator1 __meanbegin,
  628. _InputIterator1 __meanend,
  629. _InputIterator2 __varcovbegin,
  630. _InputIterator2 __varcovend);
  631. template <typename _InputIterator1, typename _InputIterator2>
  632. void _M_init_lower(_InputIterator1 __meanbegin,
  633. _InputIterator1 __meanend,
  634. _InputIterator2 __varcovbegin,
  635. _InputIterator2 __varcovend);
  636. template <typename _InputIterator1, typename _InputIterator2>
  637. void _M_init_diagonal(_InputIterator1 __meanbegin,
  638. _InputIterator1 __meanend,
  639. _InputIterator2 __varbegin,
  640. _InputIterator2 __varend);
  641. std::array<_RealType, _Dimen> _M_mean;
  642. std::array<_RealType, _M_t_size> _M_t;
  643. };
  644. public:
  645. normal_mv_distribution()
  646. : _M_param(), _M_nd()
  647. { }
  648. template<typename _ForwardIterator1, typename _ForwardIterator2>
  649. normal_mv_distribution(_ForwardIterator1 __meanbegin,
  650. _ForwardIterator1 __meanend,
  651. _ForwardIterator2 __varcovbegin,
  652. _ForwardIterator2 __varcovend)
  653. : _M_param(__meanbegin, __meanend, __varcovbegin, __varcovend),
  654. _M_nd()
  655. { }
  656. normal_mv_distribution(std::initializer_list<_RealType> __mean,
  657. std::initializer_list<_RealType> __varcov)
  658. : _M_param(__mean, __varcov), _M_nd()
  659. { }
  660. explicit
  661. normal_mv_distribution(const param_type& __p)
  662. : _M_param(__p), _M_nd()
  663. { }
  664. /**
  665. * @brief Resets the distribution state.
  666. */
  667. void
  668. reset()
  669. { _M_nd.reset(); }
  670. /**
  671. * @brief Returns the mean of the distribution.
  672. */
  673. result_type
  674. mean() const
  675. { return _M_param.mean(); }
  676. /**
  677. * @brief Returns the compact form of the variance/covariance
  678. * matrix of the distribution.
  679. */
  680. std::array<_RealType, _Dimen * (_Dimen + 1) / 2>
  681. varcov() const
  682. { return _M_param.varcov(); }
  683. /**
  684. * @brief Returns the parameter set of the distribution.
  685. */
  686. param_type
  687. param() const
  688. { return _M_param; }
  689. /**
  690. * @brief Sets the parameter set of the distribution.
  691. * @param __param The new parameter set of the distribution.
  692. */
  693. void
  694. param(const param_type& __param)
  695. { _M_param = __param; }
  696. /**
  697. * @brief Returns the greatest lower bound value of the distribution.
  698. */
  699. result_type
  700. min() const
  701. { result_type __res;
  702. __res.fill(std::numeric_limits<_RealType>::lowest());
  703. return __res; }
  704. /**
  705. * @brief Returns the least upper bound value of the distribution.
  706. */
  707. result_type
  708. max() const
  709. { result_type __res;
  710. __res.fill(std::numeric_limits<_RealType>::max());
  711. return __res; }
  712. /**
  713. * @brief Generating functions.
  714. */
  715. template<typename _UniformRandomNumberGenerator>
  716. result_type
  717. operator()(_UniformRandomNumberGenerator& __urng)
  718. { return this->operator()(__urng, _M_param); }
  719. template<typename _UniformRandomNumberGenerator>
  720. result_type
  721. operator()(_UniformRandomNumberGenerator& __urng,
  722. const param_type& __p);
  723. template<typename _ForwardIterator,
  724. typename _UniformRandomNumberGenerator>
  725. void
  726. __generate(_ForwardIterator __f, _ForwardIterator __t,
  727. _UniformRandomNumberGenerator& __urng)
  728. { return this->__generate_impl(__f, __t, __urng, _M_param); }
  729. template<typename _ForwardIterator,
  730. typename _UniformRandomNumberGenerator>
  731. void
  732. __generate(_ForwardIterator __f, _ForwardIterator __t,
  733. _UniformRandomNumberGenerator& __urng,
  734. const param_type& __p)
  735. { return this->__generate_impl(__f, __t, __urng, __p); }
  736. /**
  737. * @brief Return true if two multi-variant normal distributions have
  738. * the same parameters and the sequences that would
  739. * be generated are equal.
  740. */
  741. template<size_t _Dimen1, typename _RealType1>
  742. friend bool
  743. operator==(const
  744. __gnu_cxx::normal_mv_distribution<_Dimen1, _RealType1>&
  745. __d1,
  746. const
  747. __gnu_cxx::normal_mv_distribution<_Dimen1, _RealType1>&
  748. __d2);
  749. /**
  750. * @brief Inserts a %normal_mv_distribution random number distribution
  751. * @p __x into the output stream @p __os.
  752. *
  753. * @param __os An output stream.
  754. * @param __x A %normal_mv_distribution random number distribution.
  755. *
  756. * @returns The output stream with the state of @p __x inserted or in
  757. * an error state.
  758. */
  759. template<size_t _Dimen1, typename _RealType1,
  760. typename _CharT, typename _Traits>
  761. friend std::basic_ostream<_CharT, _Traits>&
  762. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  763. const
  764. __gnu_cxx::normal_mv_distribution<_Dimen1, _RealType1>&
  765. __x);
  766. /**
  767. * @brief Extracts a %normal_mv_distribution random number distribution
  768. * @p __x from the input stream @p __is.
  769. *
  770. * @param __is An input stream.
  771. * @param __x A %normal_mv_distribution random number generator engine.
  772. *
  773. * @returns The input stream with @p __x extracted or in an error
  774. * state.
  775. */
  776. template<size_t _Dimen1, typename _RealType1,
  777. typename _CharT, typename _Traits>
  778. friend std::basic_istream<_CharT, _Traits>&
  779. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  780. __gnu_cxx::normal_mv_distribution<_Dimen1, _RealType1>&
  781. __x);
  782. private:
  783. template<typename _ForwardIterator,
  784. typename _UniformRandomNumberGenerator>
  785. void
  786. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  787. _UniformRandomNumberGenerator& __urng,
  788. const param_type& __p);
  789. param_type _M_param;
  790. std::normal_distribution<_RealType> _M_nd;
  791. };
  792. /**
  793. * @brief Return true if two multi-variate normal distributions are
  794. * different.
  795. */
  796. template<size_t _Dimen, typename _RealType>
  797. inline bool
  798. operator!=(const __gnu_cxx::normal_mv_distribution<_Dimen, _RealType>&
  799. __d1,
  800. const __gnu_cxx::normal_mv_distribution<_Dimen, _RealType>&
  801. __d2)
  802. { return !(__d1 == __d2); }
  803. /**
  804. * @brief A Rice continuous distribution for random numbers.
  805. *
  806. * The formula for the Rice probability density function is
  807. * @f[
  808. * p(x|\nu,\sigma) = \frac{x}{\sigma^2}
  809. * \exp\left(-\frac{x^2+\nu^2}{2\sigma^2}\right)
  810. * I_0\left(\frac{x \nu}{\sigma^2}\right)
  811. * @f]
  812. * where @f$I_0(z)@f$ is the modified Bessel function of the first kind
  813. * of order 0 and @f$\nu >= 0@f$ and @f$\sigma > 0@f$.
  814. *
  815. * <table border=1 cellpadding=10 cellspacing=0>
  816. * <caption align=top>Distribution Statistics</caption>
  817. * <tr><td>Mean</td><td>@f$\sqrt{\pi/2}L_{1/2}(-\nu^2/2\sigma^2)@f$</td></tr>
  818. * <tr><td>Variance</td><td>@f$2\sigma^2 + \nu^2
  819. * + (\pi\sigma^2/2)L^2_{1/2}(-\nu^2/2\sigma^2)@f$</td></tr>
  820. * <tr><td>Range</td><td>@f$[0, \infty)@f$</td></tr>
  821. * </table>
  822. * where @f$L_{1/2}(x)@f$ is the Laguerre polynomial of order 1/2.
  823. */
  824. template<typename _RealType = double>
  825. class
  826. rice_distribution
  827. {
  828. static_assert(std::is_floating_point<_RealType>::value,
  829. "template argument not a floating point type");
  830. public:
  831. /** The type of the range of the distribution. */
  832. typedef _RealType result_type;
  833. /** Parameter type. */
  834. struct param_type
  835. {
  836. typedef rice_distribution<result_type> distribution_type;
  837. param_type() : param_type(0) { }
  838. param_type(result_type __nu_val,
  839. result_type __sigma_val = result_type(1))
  840. : _M_nu(__nu_val), _M_sigma(__sigma_val)
  841. {
  842. __glibcxx_assert(_M_nu >= result_type(0));
  843. __glibcxx_assert(_M_sigma > result_type(0));
  844. }
  845. result_type
  846. nu() const
  847. { return _M_nu; }
  848. result_type
  849. sigma() const
  850. { return _M_sigma; }
  851. friend bool
  852. operator==(const param_type& __p1, const param_type& __p2)
  853. { return __p1._M_nu == __p2._M_nu && __p1._M_sigma == __p2._M_sigma; }
  854. friend bool
  855. operator!=(const param_type& __p1, const param_type& __p2)
  856. { return !(__p1 == __p2); }
  857. private:
  858. void _M_initialize();
  859. result_type _M_nu;
  860. result_type _M_sigma;
  861. };
  862. /**
  863. * @brief Constructors.
  864. * @{
  865. */
  866. rice_distribution() : rice_distribution(0) { }
  867. explicit
  868. rice_distribution(result_type __nu_val,
  869. result_type __sigma_val = result_type(1))
  870. : _M_param(__nu_val, __sigma_val),
  871. _M_ndx(__nu_val, __sigma_val),
  872. _M_ndy(result_type(0), __sigma_val)
  873. { }
  874. explicit
  875. rice_distribution(const param_type& __p)
  876. : _M_param(__p),
  877. _M_ndx(__p.nu(), __p.sigma()),
  878. _M_ndy(result_type(0), __p.sigma())
  879. { }
  880. // @}
  881. /**
  882. * @brief Resets the distribution state.
  883. */
  884. void
  885. reset()
  886. {
  887. _M_ndx.reset();
  888. _M_ndy.reset();
  889. }
  890. /**
  891. * @brief Return the parameters of the distribution.
  892. */
  893. result_type
  894. nu() const
  895. { return _M_param.nu(); }
  896. result_type
  897. sigma() const
  898. { return _M_param.sigma(); }
  899. /**
  900. * @brief Returns the parameter set of the distribution.
  901. */
  902. param_type
  903. param() const
  904. { return _M_param; }
  905. /**
  906. * @brief Sets the parameter set of the distribution.
  907. * @param __param The new parameter set of the distribution.
  908. */
  909. void
  910. param(const param_type& __param)
  911. { _M_param = __param; }
  912. /**
  913. * @brief Returns the greatest lower bound value of the distribution.
  914. */
  915. result_type
  916. min() const
  917. { return result_type(0); }
  918. /**
  919. * @brief Returns the least upper bound value of the distribution.
  920. */
  921. result_type
  922. max() const
  923. { return std::numeric_limits<result_type>::max(); }
  924. /**
  925. * @brief Generating functions.
  926. */
  927. template<typename _UniformRandomNumberGenerator>
  928. result_type
  929. operator()(_UniformRandomNumberGenerator& __urng)
  930. {
  931. result_type __x = this->_M_ndx(__urng);
  932. result_type __y = this->_M_ndy(__urng);
  933. #if _GLIBCXX_USE_C99_MATH_TR1
  934. return std::hypot(__x, __y);
  935. #else
  936. return std::sqrt(__x * __x + __y * __y);
  937. #endif
  938. }
  939. template<typename _UniformRandomNumberGenerator>
  940. result_type
  941. operator()(_UniformRandomNumberGenerator& __urng,
  942. const param_type& __p)
  943. {
  944. typename std::normal_distribution<result_type>::param_type
  945. __px(__p.nu(), __p.sigma()), __py(result_type(0), __p.sigma());
  946. result_type __x = this->_M_ndx(__px, __urng);
  947. result_type __y = this->_M_ndy(__py, __urng);
  948. #if _GLIBCXX_USE_C99_MATH_TR1
  949. return std::hypot(__x, __y);
  950. #else
  951. return std::sqrt(__x * __x + __y * __y);
  952. #endif
  953. }
  954. template<typename _ForwardIterator,
  955. typename _UniformRandomNumberGenerator>
  956. void
  957. __generate(_ForwardIterator __f, _ForwardIterator __t,
  958. _UniformRandomNumberGenerator& __urng)
  959. { this->__generate(__f, __t, __urng, _M_param); }
  960. template<typename _ForwardIterator,
  961. typename _UniformRandomNumberGenerator>
  962. void
  963. __generate(_ForwardIterator __f, _ForwardIterator __t,
  964. _UniformRandomNumberGenerator& __urng,
  965. const param_type& __p)
  966. { this->__generate_impl(__f, __t, __urng, __p); }
  967. template<typename _UniformRandomNumberGenerator>
  968. void
  969. __generate(result_type* __f, result_type* __t,
  970. _UniformRandomNumberGenerator& __urng,
  971. const param_type& __p)
  972. { this->__generate_impl(__f, __t, __urng, __p); }
  973. /**
  974. * @brief Return true if two Rice distributions have
  975. * the same parameters and the sequences that would
  976. * be generated are equal.
  977. */
  978. friend bool
  979. operator==(const rice_distribution& __d1,
  980. const rice_distribution& __d2)
  981. { return (__d1._M_param == __d2._M_param
  982. && __d1._M_ndx == __d2._M_ndx
  983. && __d1._M_ndy == __d2._M_ndy); }
  984. /**
  985. * @brief Inserts a %rice_distribution random number distribution
  986. * @p __x into the output stream @p __os.
  987. *
  988. * @param __os An output stream.
  989. * @param __x A %rice_distribution random number distribution.
  990. *
  991. * @returns The output stream with the state of @p __x inserted or in
  992. * an error state.
  993. */
  994. template<typename _RealType1, typename _CharT, typename _Traits>
  995. friend std::basic_ostream<_CharT, _Traits>&
  996. operator<<(std::basic_ostream<_CharT, _Traits>&,
  997. const rice_distribution<_RealType1>&);
  998. /**
  999. * @brief Extracts a %rice_distribution random number distribution
  1000. * @p __x from the input stream @p __is.
  1001. *
  1002. * @param __is An input stream.
  1003. * @param __x A %rice_distribution random number
  1004. * generator engine.
  1005. *
  1006. * @returns The input stream with @p __x extracted or in an error state.
  1007. */
  1008. template<typename _RealType1, typename _CharT, typename _Traits>
  1009. friend std::basic_istream<_CharT, _Traits>&
  1010. operator>>(std::basic_istream<_CharT, _Traits>&,
  1011. rice_distribution<_RealType1>&);
  1012. private:
  1013. template<typename _ForwardIterator,
  1014. typename _UniformRandomNumberGenerator>
  1015. void
  1016. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  1017. _UniformRandomNumberGenerator& __urng,
  1018. const param_type& __p);
  1019. param_type _M_param;
  1020. std::normal_distribution<result_type> _M_ndx;
  1021. std::normal_distribution<result_type> _M_ndy;
  1022. };
  1023. /**
  1024. * @brief Return true if two Rice distributions are not equal.
  1025. */
  1026. template<typename _RealType1>
  1027. inline bool
  1028. operator!=(const rice_distribution<_RealType1>& __d1,
  1029. const rice_distribution<_RealType1>& __d2)
  1030. { return !(__d1 == __d2); }
  1031. /**
  1032. * @brief A Nakagami continuous distribution for random numbers.
  1033. *
  1034. * The formula for the Nakagami probability density function is
  1035. * @f[
  1036. * p(x|\mu,\omega) = \frac{2\mu^\mu}{\Gamma(\mu)\omega^\mu}
  1037. * x^{2\mu-1}e^{-\mu x / \omega}
  1038. * @f]
  1039. * where @f$\Gamma(z)@f$ is the gamma function and @f$\mu >= 0.5@f$
  1040. * and @f$\omega > 0@f$.
  1041. */
  1042. template<typename _RealType = double>
  1043. class
  1044. nakagami_distribution
  1045. {
  1046. static_assert(std::is_floating_point<_RealType>::value,
  1047. "template argument not a floating point type");
  1048. public:
  1049. /** The type of the range of the distribution. */
  1050. typedef _RealType result_type;
  1051. /** Parameter type. */
  1052. struct param_type
  1053. {
  1054. typedef nakagami_distribution<result_type> distribution_type;
  1055. param_type() : param_type(1) { }
  1056. param_type(result_type __mu_val,
  1057. result_type __omega_val = result_type(1))
  1058. : _M_mu(__mu_val), _M_omega(__omega_val)
  1059. {
  1060. __glibcxx_assert(_M_mu >= result_type(0.5L));
  1061. __glibcxx_assert(_M_omega > result_type(0));
  1062. }
  1063. result_type
  1064. mu() const
  1065. { return _M_mu; }
  1066. result_type
  1067. omega() const
  1068. { return _M_omega; }
  1069. friend bool
  1070. operator==(const param_type& __p1, const param_type& __p2)
  1071. { return __p1._M_mu == __p2._M_mu && __p1._M_omega == __p2._M_omega; }
  1072. friend bool
  1073. operator!=(const param_type& __p1, const param_type& __p2)
  1074. { return !(__p1 == __p2); }
  1075. private:
  1076. void _M_initialize();
  1077. result_type _M_mu;
  1078. result_type _M_omega;
  1079. };
  1080. /**
  1081. * @brief Constructors.
  1082. * @{
  1083. */
  1084. nakagami_distribution() : nakagami_distribution(1) { }
  1085. explicit
  1086. nakagami_distribution(result_type __mu_val,
  1087. result_type __omega_val = result_type(1))
  1088. : _M_param(__mu_val, __omega_val),
  1089. _M_gd(__mu_val, __omega_val / __mu_val)
  1090. { }
  1091. explicit
  1092. nakagami_distribution(const param_type& __p)
  1093. : _M_param(__p),
  1094. _M_gd(__p.mu(), __p.omega() / __p.mu())
  1095. { }
  1096. // @}
  1097. /**
  1098. * @brief Resets the distribution state.
  1099. */
  1100. void
  1101. reset()
  1102. { _M_gd.reset(); }
  1103. /**
  1104. * @brief Return the parameters of the distribution.
  1105. */
  1106. result_type
  1107. mu() const
  1108. { return _M_param.mu(); }
  1109. result_type
  1110. omega() const
  1111. { return _M_param.omega(); }
  1112. /**
  1113. * @brief Returns the parameter set of the distribution.
  1114. */
  1115. param_type
  1116. param() const
  1117. { return _M_param; }
  1118. /**
  1119. * @brief Sets the parameter set of the distribution.
  1120. * @param __param The new parameter set of the distribution.
  1121. */
  1122. void
  1123. param(const param_type& __param)
  1124. { _M_param = __param; }
  1125. /**
  1126. * @brief Returns the greatest lower bound value of the distribution.
  1127. */
  1128. result_type
  1129. min() const
  1130. { return result_type(0); }
  1131. /**
  1132. * @brief Returns the least upper bound value of the distribution.
  1133. */
  1134. result_type
  1135. max() const
  1136. { return std::numeric_limits<result_type>::max(); }
  1137. /**
  1138. * @brief Generating functions.
  1139. */
  1140. template<typename _UniformRandomNumberGenerator>
  1141. result_type
  1142. operator()(_UniformRandomNumberGenerator& __urng)
  1143. { return std::sqrt(this->_M_gd(__urng)); }
  1144. template<typename _UniformRandomNumberGenerator>
  1145. result_type
  1146. operator()(_UniformRandomNumberGenerator& __urng,
  1147. const param_type& __p)
  1148. {
  1149. typename std::gamma_distribution<result_type>::param_type
  1150. __pg(__p.mu(), __p.omega() / __p.mu());
  1151. return std::sqrt(this->_M_gd(__pg, __urng));
  1152. }
  1153. template<typename _ForwardIterator,
  1154. typename _UniformRandomNumberGenerator>
  1155. void
  1156. __generate(_ForwardIterator __f, _ForwardIterator __t,
  1157. _UniformRandomNumberGenerator& __urng)
  1158. { this->__generate(__f, __t, __urng, _M_param); }
  1159. template<typename _ForwardIterator,
  1160. typename _UniformRandomNumberGenerator>
  1161. void
  1162. __generate(_ForwardIterator __f, _ForwardIterator __t,
  1163. _UniformRandomNumberGenerator& __urng,
  1164. const param_type& __p)
  1165. { this->__generate_impl(__f, __t, __urng, __p); }
  1166. template<typename _UniformRandomNumberGenerator>
  1167. void
  1168. __generate(result_type* __f, result_type* __t,
  1169. _UniformRandomNumberGenerator& __urng,
  1170. const param_type& __p)
  1171. { this->__generate_impl(__f, __t, __urng, __p); }
  1172. /**
  1173. * @brief Return true if two Nakagami distributions have
  1174. * the same parameters and the sequences that would
  1175. * be generated are equal.
  1176. */
  1177. friend bool
  1178. operator==(const nakagami_distribution& __d1,
  1179. const nakagami_distribution& __d2)
  1180. { return (__d1._M_param == __d2._M_param
  1181. && __d1._M_gd == __d2._M_gd); }
  1182. /**
  1183. * @brief Inserts a %nakagami_distribution random number distribution
  1184. * @p __x into the output stream @p __os.
  1185. *
  1186. * @param __os An output stream.
  1187. * @param __x A %nakagami_distribution random number distribution.
  1188. *
  1189. * @returns The output stream with the state of @p __x inserted or in
  1190. * an error state.
  1191. */
  1192. template<typename _RealType1, typename _CharT, typename _Traits>
  1193. friend std::basic_ostream<_CharT, _Traits>&
  1194. operator<<(std::basic_ostream<_CharT, _Traits>&,
  1195. const nakagami_distribution<_RealType1>&);
  1196. /**
  1197. * @brief Extracts a %nakagami_distribution random number distribution
  1198. * @p __x from the input stream @p __is.
  1199. *
  1200. * @param __is An input stream.
  1201. * @param __x A %nakagami_distribution random number
  1202. * generator engine.
  1203. *
  1204. * @returns The input stream with @p __x extracted or in an error state.
  1205. */
  1206. template<typename _RealType1, typename _CharT, typename _Traits>
  1207. friend std::basic_istream<_CharT, _Traits>&
  1208. operator>>(std::basic_istream<_CharT, _Traits>&,
  1209. nakagami_distribution<_RealType1>&);
  1210. private:
  1211. template<typename _ForwardIterator,
  1212. typename _UniformRandomNumberGenerator>
  1213. void
  1214. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  1215. _UniformRandomNumberGenerator& __urng,
  1216. const param_type& __p);
  1217. param_type _M_param;
  1218. std::gamma_distribution<result_type> _M_gd;
  1219. };
  1220. /**
  1221. * @brief Return true if two Nakagami distributions are not equal.
  1222. */
  1223. template<typename _RealType>
  1224. inline bool
  1225. operator!=(const nakagami_distribution<_RealType>& __d1,
  1226. const nakagami_distribution<_RealType>& __d2)
  1227. { return !(__d1 == __d2); }
  1228. /**
  1229. * @brief A Pareto continuous distribution for random numbers.
  1230. *
  1231. * The formula for the Pareto cumulative probability function is
  1232. * @f[
  1233. * P(x|\alpha,\mu) = 1 - \left(\frac{\mu}{x}\right)^\alpha
  1234. * @f]
  1235. * The formula for the Pareto probability density function is
  1236. * @f[
  1237. * p(x|\alpha,\mu) = \frac{\alpha + 1}{\mu}
  1238. * \left(\frac{\mu}{x}\right)^{\alpha + 1}
  1239. * @f]
  1240. * where @f$x >= \mu@f$ and @f$\mu > 0@f$, @f$\alpha > 0@f$.
  1241. *
  1242. * <table border=1 cellpadding=10 cellspacing=0>
  1243. * <caption align=top>Distribution Statistics</caption>
  1244. * <tr><td>Mean</td><td>@f$\alpha \mu / (\alpha - 1)@f$
  1245. * for @f$\alpha > 1@f$</td></tr>
  1246. * <tr><td>Variance</td><td>@f$\alpha \mu^2 / [(\alpha - 1)^2(\alpha - 2)]@f$
  1247. * for @f$\alpha > 2@f$</td></tr>
  1248. * <tr><td>Range</td><td>@f$[\mu, \infty)@f$</td></tr>
  1249. * </table>
  1250. */
  1251. template<typename _RealType = double>
  1252. class
  1253. pareto_distribution
  1254. {
  1255. static_assert(std::is_floating_point<_RealType>::value,
  1256. "template argument not a floating point type");
  1257. public:
  1258. /** The type of the range of the distribution. */
  1259. typedef _RealType result_type;
  1260. /** Parameter type. */
  1261. struct param_type
  1262. {
  1263. typedef pareto_distribution<result_type> distribution_type;
  1264. param_type() : param_type(1) { }
  1265. param_type(result_type __alpha_val,
  1266. result_type __mu_val = result_type(1))
  1267. : _M_alpha(__alpha_val), _M_mu(__mu_val)
  1268. {
  1269. __glibcxx_assert(_M_alpha > result_type(0));
  1270. __glibcxx_assert(_M_mu > result_type(0));
  1271. }
  1272. result_type
  1273. alpha() const
  1274. { return _M_alpha; }
  1275. result_type
  1276. mu() const
  1277. { return _M_mu; }
  1278. friend bool
  1279. operator==(const param_type& __p1, const param_type& __p2)
  1280. { return __p1._M_alpha == __p2._M_alpha && __p1._M_mu == __p2._M_mu; }
  1281. friend bool
  1282. operator!=(const param_type& __p1, const param_type& __p2)
  1283. { return !(__p1 == __p2); }
  1284. private:
  1285. void _M_initialize();
  1286. result_type _M_alpha;
  1287. result_type _M_mu;
  1288. };
  1289. /**
  1290. * @brief Constructors.
  1291. * @{
  1292. */
  1293. pareto_distribution() : pareto_distribution(1) { }
  1294. explicit
  1295. pareto_distribution(result_type __alpha_val,
  1296. result_type __mu_val = result_type(1))
  1297. : _M_param(__alpha_val, __mu_val),
  1298. _M_ud()
  1299. { }
  1300. explicit
  1301. pareto_distribution(const param_type& __p)
  1302. : _M_param(__p),
  1303. _M_ud()
  1304. { }
  1305. // @}
  1306. /**
  1307. * @brief Resets the distribution state.
  1308. */
  1309. void
  1310. reset()
  1311. {
  1312. _M_ud.reset();
  1313. }
  1314. /**
  1315. * @brief Return the parameters of the distribution.
  1316. */
  1317. result_type
  1318. alpha() const
  1319. { return _M_param.alpha(); }
  1320. result_type
  1321. mu() const
  1322. { return _M_param.mu(); }
  1323. /**
  1324. * @brief Returns the parameter set of the distribution.
  1325. */
  1326. param_type
  1327. param() const
  1328. { return _M_param; }
  1329. /**
  1330. * @brief Sets the parameter set of the distribution.
  1331. * @param __param The new parameter set of the distribution.
  1332. */
  1333. void
  1334. param(const param_type& __param)
  1335. { _M_param = __param; }
  1336. /**
  1337. * @brief Returns the greatest lower bound value of the distribution.
  1338. */
  1339. result_type
  1340. min() const
  1341. { return this->mu(); }
  1342. /**
  1343. * @brief Returns the least upper bound value of the distribution.
  1344. */
  1345. result_type
  1346. max() const
  1347. { return std::numeric_limits<result_type>::max(); }
  1348. /**
  1349. * @brief Generating functions.
  1350. */
  1351. template<typename _UniformRandomNumberGenerator>
  1352. result_type
  1353. operator()(_UniformRandomNumberGenerator& __urng)
  1354. {
  1355. return this->mu() * std::pow(this->_M_ud(__urng),
  1356. -result_type(1) / this->alpha());
  1357. }
  1358. template<typename _UniformRandomNumberGenerator>
  1359. result_type
  1360. operator()(_UniformRandomNumberGenerator& __urng,
  1361. const param_type& __p)
  1362. {
  1363. return __p.mu() * std::pow(this->_M_ud(__urng),
  1364. -result_type(1) / __p.alpha());
  1365. }
  1366. template<typename _ForwardIterator,
  1367. typename _UniformRandomNumberGenerator>
  1368. void
  1369. __generate(_ForwardIterator __f, _ForwardIterator __t,
  1370. _UniformRandomNumberGenerator& __urng)
  1371. { this->__generate(__f, __t, __urng, _M_param); }
  1372. template<typename _ForwardIterator,
  1373. typename _UniformRandomNumberGenerator>
  1374. void
  1375. __generate(_ForwardIterator __f, _ForwardIterator __t,
  1376. _UniformRandomNumberGenerator& __urng,
  1377. const param_type& __p)
  1378. { this->__generate_impl(__f, __t, __urng, __p); }
  1379. template<typename _UniformRandomNumberGenerator>
  1380. void
  1381. __generate(result_type* __f, result_type* __t,
  1382. _UniformRandomNumberGenerator& __urng,
  1383. const param_type& __p)
  1384. { this->__generate_impl(__f, __t, __urng, __p); }
  1385. /**
  1386. * @brief Return true if two Pareto distributions have
  1387. * the same parameters and the sequences that would
  1388. * be generated are equal.
  1389. */
  1390. friend bool
  1391. operator==(const pareto_distribution& __d1,
  1392. const pareto_distribution& __d2)
  1393. { return (__d1._M_param == __d2._M_param
  1394. && __d1._M_ud == __d2._M_ud); }
  1395. /**
  1396. * @brief Inserts a %pareto_distribution random number distribution
  1397. * @p __x into the output stream @p __os.
  1398. *
  1399. * @param __os An output stream.
  1400. * @param __x A %pareto_distribution random number distribution.
  1401. *
  1402. * @returns The output stream with the state of @p __x inserted or in
  1403. * an error state.
  1404. */
  1405. template<typename _RealType1, typename _CharT, typename _Traits>
  1406. friend std::basic_ostream<_CharT, _Traits>&
  1407. operator<<(std::basic_ostream<_CharT, _Traits>&,
  1408. const pareto_distribution<_RealType1>&);
  1409. /**
  1410. * @brief Extracts a %pareto_distribution random number distribution
  1411. * @p __x from the input stream @p __is.
  1412. *
  1413. * @param __is An input stream.
  1414. * @param __x A %pareto_distribution random number
  1415. * generator engine.
  1416. *
  1417. * @returns The input stream with @p __x extracted or in an error state.
  1418. */
  1419. template<typename _RealType1, typename _CharT, typename _Traits>
  1420. friend std::basic_istream<_CharT, _Traits>&
  1421. operator>>(std::basic_istream<_CharT, _Traits>&,
  1422. pareto_distribution<_RealType1>&);
  1423. private:
  1424. template<typename _ForwardIterator,
  1425. typename _UniformRandomNumberGenerator>
  1426. void
  1427. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  1428. _UniformRandomNumberGenerator& __urng,
  1429. const param_type& __p);
  1430. param_type _M_param;
  1431. std::uniform_real_distribution<result_type> _M_ud;
  1432. };
  1433. /**
  1434. * @brief Return true if two Pareto distributions are not equal.
  1435. */
  1436. template<typename _RealType>
  1437. inline bool
  1438. operator!=(const pareto_distribution<_RealType>& __d1,
  1439. const pareto_distribution<_RealType>& __d2)
  1440. { return !(__d1 == __d2); }
  1441. /**
  1442. * @brief A K continuous distribution for random numbers.
  1443. *
  1444. * The formula for the K probability density function is
  1445. * @f[
  1446. * p(x|\lambda, \mu, \nu) = \frac{2}{x}
  1447. * \left(\frac{\lambda\nu x}{\mu}\right)^{\frac{\lambda + \nu}{2}}
  1448. * \frac{1}{\Gamma(\lambda)\Gamma(\nu)}
  1449. * K_{\nu - \lambda}\left(2\sqrt{\frac{\lambda\nu x}{\mu}}\right)
  1450. * @f]
  1451. * where @f$I_0(z)@f$ is the modified Bessel function of the second kind
  1452. * of order @f$\nu - \lambda@f$ and @f$\lambda > 0@f$, @f$\mu > 0@f$
  1453. * and @f$\nu > 0@f$.
  1454. *
  1455. * <table border=1 cellpadding=10 cellspacing=0>
  1456. * <caption align=top>Distribution Statistics</caption>
  1457. * <tr><td>Mean</td><td>@f$\mu@f$</td></tr>
  1458. * <tr><td>Variance</td><td>@f$\mu^2\frac{\lambda + \nu + 1}{\lambda\nu}@f$</td></tr>
  1459. * <tr><td>Range</td><td>@f$[0, \infty)@f$</td></tr>
  1460. * </table>
  1461. */
  1462. template<typename _RealType = double>
  1463. class
  1464. k_distribution
  1465. {
  1466. static_assert(std::is_floating_point<_RealType>::value,
  1467. "template argument not a floating point type");
  1468. public:
  1469. /** The type of the range of the distribution. */
  1470. typedef _RealType result_type;
  1471. /** Parameter type. */
  1472. struct param_type
  1473. {
  1474. typedef k_distribution<result_type> distribution_type;
  1475. param_type() : param_type(1) { }
  1476. param_type(result_type __lambda_val,
  1477. result_type __mu_val = result_type(1),
  1478. result_type __nu_val = result_type(1))
  1479. : _M_lambda(__lambda_val), _M_mu(__mu_val), _M_nu(__nu_val)
  1480. {
  1481. __glibcxx_assert(_M_lambda > result_type(0));
  1482. __glibcxx_assert(_M_mu > result_type(0));
  1483. __glibcxx_assert(_M_nu > result_type(0));
  1484. }
  1485. result_type
  1486. lambda() const
  1487. { return _M_lambda; }
  1488. result_type
  1489. mu() const
  1490. { return _M_mu; }
  1491. result_type
  1492. nu() const
  1493. { return _M_nu; }
  1494. friend bool
  1495. operator==(const param_type& __p1, const param_type& __p2)
  1496. {
  1497. return __p1._M_lambda == __p2._M_lambda
  1498. && __p1._M_mu == __p2._M_mu
  1499. && __p1._M_nu == __p2._M_nu;
  1500. }
  1501. friend bool
  1502. operator!=(const param_type& __p1, const param_type& __p2)
  1503. { return !(__p1 == __p2); }
  1504. private:
  1505. void _M_initialize();
  1506. result_type _M_lambda;
  1507. result_type _M_mu;
  1508. result_type _M_nu;
  1509. };
  1510. /**
  1511. * @brief Constructors.
  1512. * @{
  1513. */
  1514. k_distribution() : k_distribution(1) { }
  1515. explicit
  1516. k_distribution(result_type __lambda_val,
  1517. result_type __mu_val = result_type(1),
  1518. result_type __nu_val = result_type(1))
  1519. : _M_param(__lambda_val, __mu_val, __nu_val),
  1520. _M_gd1(__lambda_val, result_type(1) / __lambda_val),
  1521. _M_gd2(__nu_val, __mu_val / __nu_val)
  1522. { }
  1523. explicit
  1524. k_distribution(const param_type& __p)
  1525. : _M_param(__p),
  1526. _M_gd1(__p.lambda(), result_type(1) / __p.lambda()),
  1527. _M_gd2(__p.nu(), __p.mu() / __p.nu())
  1528. { }
  1529. // @}
  1530. /**
  1531. * @brief Resets the distribution state.
  1532. */
  1533. void
  1534. reset()
  1535. {
  1536. _M_gd1.reset();
  1537. _M_gd2.reset();
  1538. }
  1539. /**
  1540. * @brief Return the parameters of the distribution.
  1541. */
  1542. result_type
  1543. lambda() const
  1544. { return _M_param.lambda(); }
  1545. result_type
  1546. mu() const
  1547. { return _M_param.mu(); }
  1548. result_type
  1549. nu() const
  1550. { return _M_param.nu(); }
  1551. /**
  1552. * @brief Returns the parameter set of the distribution.
  1553. */
  1554. param_type
  1555. param() const
  1556. { return _M_param; }
  1557. /**
  1558. * @brief Sets the parameter set of the distribution.
  1559. * @param __param The new parameter set of the distribution.
  1560. */
  1561. void
  1562. param(const param_type& __param)
  1563. { _M_param = __param; }
  1564. /**
  1565. * @brief Returns the greatest lower bound value of the distribution.
  1566. */
  1567. result_type
  1568. min() const
  1569. { return result_type(0); }
  1570. /**
  1571. * @brief Returns the least upper bound value of the distribution.
  1572. */
  1573. result_type
  1574. max() const
  1575. { return std::numeric_limits<result_type>::max(); }
  1576. /**
  1577. * @brief Generating functions.
  1578. */
  1579. template<typename _UniformRandomNumberGenerator>
  1580. result_type
  1581. operator()(_UniformRandomNumberGenerator&);
  1582. template<typename _UniformRandomNumberGenerator>
  1583. result_type
  1584. operator()(_UniformRandomNumberGenerator&, const param_type&);
  1585. template<typename _ForwardIterator,
  1586. typename _UniformRandomNumberGenerator>
  1587. void
  1588. __generate(_ForwardIterator __f, _ForwardIterator __t,
  1589. _UniformRandomNumberGenerator& __urng)
  1590. { this->__generate(__f, __t, __urng, _M_param); }
  1591. template<typename _ForwardIterator,
  1592. typename _UniformRandomNumberGenerator>
  1593. void
  1594. __generate(_ForwardIterator __f, _ForwardIterator __t,
  1595. _UniformRandomNumberGenerator& __urng,
  1596. const param_type& __p)
  1597. { this->__generate_impl(__f, __t, __urng, __p); }
  1598. template<typename _UniformRandomNumberGenerator>
  1599. void
  1600. __generate(result_type* __f, result_type* __t,
  1601. _UniformRandomNumberGenerator& __urng,
  1602. const param_type& __p)
  1603. { this->__generate_impl(__f, __t, __urng, __p); }
  1604. /**
  1605. * @brief Return true if two K distributions have
  1606. * the same parameters and the sequences that would
  1607. * be generated are equal.
  1608. */
  1609. friend bool
  1610. operator==(const k_distribution& __d1,
  1611. const k_distribution& __d2)
  1612. { return (__d1._M_param == __d2._M_param
  1613. && __d1._M_gd1 == __d2._M_gd1
  1614. && __d1._M_gd2 == __d2._M_gd2); }
  1615. /**
  1616. * @brief Inserts a %k_distribution random number distribution
  1617. * @p __x into the output stream @p __os.
  1618. *
  1619. * @param __os An output stream.
  1620. * @param __x A %k_distribution random number distribution.
  1621. *
  1622. * @returns The output stream with the state of @p __x inserted or in
  1623. * an error state.
  1624. */
  1625. template<typename _RealType1, typename _CharT, typename _Traits>
  1626. friend std::basic_ostream<_CharT, _Traits>&
  1627. operator<<(std::basic_ostream<_CharT, _Traits>&,
  1628. const k_distribution<_RealType1>&);
  1629. /**
  1630. * @brief Extracts a %k_distribution random number distribution
  1631. * @p __x from the input stream @p __is.
  1632. *
  1633. * @param __is An input stream.
  1634. * @param __x A %k_distribution random number
  1635. * generator engine.
  1636. *
  1637. * @returns The input stream with @p __x extracted or in an error state.
  1638. */
  1639. template<typename _RealType1, typename _CharT, typename _Traits>
  1640. friend std::basic_istream<_CharT, _Traits>&
  1641. operator>>(std::basic_istream<_CharT, _Traits>&,
  1642. k_distribution<_RealType1>&);
  1643. private:
  1644. template<typename _ForwardIterator,
  1645. typename _UniformRandomNumberGenerator>
  1646. void
  1647. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  1648. _UniformRandomNumberGenerator& __urng,
  1649. const param_type& __p);
  1650. param_type _M_param;
  1651. std::gamma_distribution<result_type> _M_gd1;
  1652. std::gamma_distribution<result_type> _M_gd2;
  1653. };
  1654. /**
  1655. * @brief Return true if two K distributions are not equal.
  1656. */
  1657. template<typename _RealType>
  1658. inline bool
  1659. operator!=(const k_distribution<_RealType>& __d1,
  1660. const k_distribution<_RealType>& __d2)
  1661. { return !(__d1 == __d2); }
  1662. /**
  1663. * @brief An arcsine continuous distribution for random numbers.
  1664. *
  1665. * The formula for the arcsine probability density function is
  1666. * @f[
  1667. * p(x|a,b) = \frac{1}{\pi \sqrt{(x - a)(b - x)}}
  1668. * @f]
  1669. * where @f$x >= a@f$ and @f$x <= b@f$.
  1670. *
  1671. * <table border=1 cellpadding=10 cellspacing=0>
  1672. * <caption align=top>Distribution Statistics</caption>
  1673. * <tr><td>Mean</td><td>@f$ (a + b) / 2 @f$</td></tr>
  1674. * <tr><td>Variance</td><td>@f$ (b - a)^2 / 8 @f$</td></tr>
  1675. * <tr><td>Range</td><td>@f$[a, b]@f$</td></tr>
  1676. * </table>
  1677. */
  1678. template<typename _RealType = double>
  1679. class
  1680. arcsine_distribution
  1681. {
  1682. static_assert(std::is_floating_point<_RealType>::value,
  1683. "template argument not a floating point type");
  1684. public:
  1685. /** The type of the range of the distribution. */
  1686. typedef _RealType result_type;
  1687. /** Parameter type. */
  1688. struct param_type
  1689. {
  1690. typedef arcsine_distribution<result_type> distribution_type;
  1691. param_type() : param_type(0) { }
  1692. param_type(result_type __a, result_type __b = result_type(1))
  1693. : _M_a(__a), _M_b(__b)
  1694. {
  1695. __glibcxx_assert(_M_a <= _M_b);
  1696. }
  1697. result_type
  1698. a() const
  1699. { return _M_a; }
  1700. result_type
  1701. b() const
  1702. { return _M_b; }
  1703. friend bool
  1704. operator==(const param_type& __p1, const param_type& __p2)
  1705. { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
  1706. friend bool
  1707. operator!=(const param_type& __p1, const param_type& __p2)
  1708. { return !(__p1 == __p2); }
  1709. private:
  1710. void _M_initialize();
  1711. result_type _M_a;
  1712. result_type _M_b;
  1713. };
  1714. /**
  1715. * @brief Constructors.
  1716. * :{
  1717. */
  1718. arcsine_distribution() : arcsine_distribution(0) { }
  1719. explicit
  1720. arcsine_distribution(result_type __a, result_type __b = result_type(1))
  1721. : _M_param(__a, __b),
  1722. _M_ud(-1.5707963267948966192313216916397514L,
  1723. +1.5707963267948966192313216916397514L)
  1724. { }
  1725. explicit
  1726. arcsine_distribution(const param_type& __p)
  1727. : _M_param(__p),
  1728. _M_ud(-1.5707963267948966192313216916397514L,
  1729. +1.5707963267948966192313216916397514L)
  1730. { }
  1731. // @}
  1732. /**
  1733. * @brief Resets the distribution state.
  1734. */
  1735. void
  1736. reset()
  1737. { _M_ud.reset(); }
  1738. /**
  1739. * @brief Return the parameters of the distribution.
  1740. */
  1741. result_type
  1742. a() const
  1743. { return _M_param.a(); }
  1744. result_type
  1745. b() const
  1746. { return _M_param.b(); }
  1747. /**
  1748. * @brief Returns the parameter set of the distribution.
  1749. */
  1750. param_type
  1751. param() const
  1752. { return _M_param; }
  1753. /**
  1754. * @brief Sets the parameter set of the distribution.
  1755. * @param __param The new parameter set of the distribution.
  1756. */
  1757. void
  1758. param(const param_type& __param)
  1759. { _M_param = __param; }
  1760. /**
  1761. * @brief Returns the greatest lower bound value of the distribution.
  1762. */
  1763. result_type
  1764. min() const
  1765. { return this->a(); }
  1766. /**
  1767. * @brief Returns the least upper bound value of the distribution.
  1768. */
  1769. result_type
  1770. max() const
  1771. { return this->b(); }
  1772. /**
  1773. * @brief Generating functions.
  1774. */
  1775. template<typename _UniformRandomNumberGenerator>
  1776. result_type
  1777. operator()(_UniformRandomNumberGenerator& __urng)
  1778. {
  1779. result_type __x = std::sin(this->_M_ud(__urng));
  1780. return (__x * (this->b() - this->a())
  1781. + this->a() + this->b()) / result_type(2);
  1782. }
  1783. template<typename _UniformRandomNumberGenerator>
  1784. result_type
  1785. operator()(_UniformRandomNumberGenerator& __urng,
  1786. const param_type& __p)
  1787. {
  1788. result_type __x = std::sin(this->_M_ud(__urng));
  1789. return (__x * (__p.b() - __p.a())
  1790. + __p.a() + __p.b()) / result_type(2);
  1791. }
  1792. template<typename _ForwardIterator,
  1793. typename _UniformRandomNumberGenerator>
  1794. void
  1795. __generate(_ForwardIterator __f, _ForwardIterator __t,
  1796. _UniformRandomNumberGenerator& __urng)
  1797. { this->__generate(__f, __t, __urng, _M_param); }
  1798. template<typename _ForwardIterator,
  1799. typename _UniformRandomNumberGenerator>
  1800. void
  1801. __generate(_ForwardIterator __f, _ForwardIterator __t,
  1802. _UniformRandomNumberGenerator& __urng,
  1803. const param_type& __p)
  1804. { this->__generate_impl(__f, __t, __urng, __p); }
  1805. template<typename _UniformRandomNumberGenerator>
  1806. void
  1807. __generate(result_type* __f, result_type* __t,
  1808. _UniformRandomNumberGenerator& __urng,
  1809. const param_type& __p)
  1810. { this->__generate_impl(__f, __t, __urng, __p); }
  1811. /**
  1812. * @brief Return true if two arcsine distributions have
  1813. * the same parameters and the sequences that would
  1814. * be generated are equal.
  1815. */
  1816. friend bool
  1817. operator==(const arcsine_distribution& __d1,
  1818. const arcsine_distribution& __d2)
  1819. { return (__d1._M_param == __d2._M_param
  1820. && __d1._M_ud == __d2._M_ud); }
  1821. /**
  1822. * @brief Inserts a %arcsine_distribution random number distribution
  1823. * @p __x into the output stream @p __os.
  1824. *
  1825. * @param __os An output stream.
  1826. * @param __x A %arcsine_distribution random number distribution.
  1827. *
  1828. * @returns The output stream with the state of @p __x inserted or in
  1829. * an error state.
  1830. */
  1831. template<typename _RealType1, typename _CharT, typename _Traits>
  1832. friend std::basic_ostream<_CharT, _Traits>&
  1833. operator<<(std::basic_ostream<_CharT, _Traits>&,
  1834. const arcsine_distribution<_RealType1>&);
  1835. /**
  1836. * @brief Extracts a %arcsine_distribution random number distribution
  1837. * @p __x from the input stream @p __is.
  1838. *
  1839. * @param __is An input stream.
  1840. * @param __x A %arcsine_distribution random number
  1841. * generator engine.
  1842. *
  1843. * @returns The input stream with @p __x extracted or in an error state.
  1844. */
  1845. template<typename _RealType1, typename _CharT, typename _Traits>
  1846. friend std::basic_istream<_CharT, _Traits>&
  1847. operator>>(std::basic_istream<_CharT, _Traits>&,
  1848. arcsine_distribution<_RealType1>&);
  1849. private:
  1850. template<typename _ForwardIterator,
  1851. typename _UniformRandomNumberGenerator>
  1852. void
  1853. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  1854. _UniformRandomNumberGenerator& __urng,
  1855. const param_type& __p);
  1856. param_type _M_param;
  1857. std::uniform_real_distribution<result_type> _M_ud;
  1858. };
  1859. /**
  1860. * @brief Return true if two arcsine distributions are not equal.
  1861. */
  1862. template<typename _RealType>
  1863. inline bool
  1864. operator!=(const arcsine_distribution<_RealType>& __d1,
  1865. const arcsine_distribution<_RealType>& __d2)
  1866. { return !(__d1 == __d2); }
  1867. /**
  1868. * @brief A Hoyt continuous distribution for random numbers.
  1869. *
  1870. * The formula for the Hoyt probability density function is
  1871. * @f[
  1872. * p(x|q,\omega) = \frac{(1 + q^2)x}{q\omega}
  1873. * \exp\left(-\frac{(1 + q^2)^2 x^2}{4 q^2 \omega}\right)
  1874. * I_0\left(\frac{(1 - q^4) x^2}{4 q^2 \omega}\right)
  1875. * @f]
  1876. * where @f$I_0(z)@f$ is the modified Bessel function of the first kind
  1877. * of order 0 and @f$0 < q < 1@f$.
  1878. *
  1879. * <table border=1 cellpadding=10 cellspacing=0>
  1880. * <caption align=top>Distribution Statistics</caption>
  1881. * <tr><td>Mean</td><td>@f$ \sqrt{\frac{2}{\pi}} \sqrt{\frac{\omega}{1 + q^2}}
  1882. * E(1 - q^2) @f$</td></tr>
  1883. * <tr><td>Variance</td><td>@f$ \omega \left(1 - \frac{2E^2(1 - q^2)}
  1884. * {\pi (1 + q^2)}\right) @f$</td></tr>
  1885. * <tr><td>Range</td><td>@f$[0, \infty)@f$</td></tr>
  1886. * </table>
  1887. * where @f$E(x)@f$ is the elliptic function of the second kind.
  1888. */
  1889. template<typename _RealType = double>
  1890. class
  1891. hoyt_distribution
  1892. {
  1893. static_assert(std::is_floating_point<_RealType>::value,
  1894. "template argument not a floating point type");
  1895. public:
  1896. /** The type of the range of the distribution. */
  1897. typedef _RealType result_type;
  1898. /** Parameter type. */
  1899. struct param_type
  1900. {
  1901. typedef hoyt_distribution<result_type> distribution_type;
  1902. param_type() : param_type(0.5) { }
  1903. param_type(result_type __q, result_type __omega = result_type(1))
  1904. : _M_q(__q), _M_omega(__omega)
  1905. {
  1906. __glibcxx_assert(_M_q > result_type(0));
  1907. __glibcxx_assert(_M_q < result_type(1));
  1908. }
  1909. result_type
  1910. q() const
  1911. { return _M_q; }
  1912. result_type
  1913. omega() const
  1914. { return _M_omega; }
  1915. friend bool
  1916. operator==(const param_type& __p1, const param_type& __p2)
  1917. { return __p1._M_q == __p2._M_q && __p1._M_omega == __p2._M_omega; }
  1918. friend bool
  1919. operator!=(const param_type& __p1, const param_type& __p2)
  1920. { return !(__p1 == __p2); }
  1921. private:
  1922. void _M_initialize();
  1923. result_type _M_q;
  1924. result_type _M_omega;
  1925. };
  1926. /**
  1927. * @brief Constructors.
  1928. * @{
  1929. */
  1930. hoyt_distribution() : hoyt_distribution(0.5) { }
  1931. explicit
  1932. hoyt_distribution(result_type __q, result_type __omega = result_type(1))
  1933. : _M_param(__q, __omega),
  1934. _M_ad(result_type(0.5L) * (result_type(1) + __q * __q),
  1935. result_type(0.5L) * (result_type(1) + __q * __q)
  1936. / (__q * __q)),
  1937. _M_ed(result_type(1))
  1938. { }
  1939. explicit
  1940. hoyt_distribution(const param_type& __p)
  1941. : _M_param(__p),
  1942. _M_ad(result_type(0.5L) * (result_type(1) + __p.q() * __p.q()),
  1943. result_type(0.5L) * (result_type(1) + __p.q() * __p.q())
  1944. / (__p.q() * __p.q())),
  1945. _M_ed(result_type(1))
  1946. { }
  1947. /**
  1948. * @brief Resets the distribution state.
  1949. */
  1950. void
  1951. reset()
  1952. {
  1953. _M_ad.reset();
  1954. _M_ed.reset();
  1955. }
  1956. /**
  1957. * @brief Return the parameters of the distribution.
  1958. */
  1959. result_type
  1960. q() const
  1961. { return _M_param.q(); }
  1962. result_type
  1963. omega() const
  1964. { return _M_param.omega(); }
  1965. /**
  1966. * @brief Returns the parameter set of the distribution.
  1967. */
  1968. param_type
  1969. param() const
  1970. { return _M_param; }
  1971. /**
  1972. * @brief Sets the parameter set of the distribution.
  1973. * @param __param The new parameter set of the distribution.
  1974. */
  1975. void
  1976. param(const param_type& __param)
  1977. { _M_param = __param; }
  1978. /**
  1979. * @brief Returns the greatest lower bound value of the distribution.
  1980. */
  1981. result_type
  1982. min() const
  1983. { return result_type(0); }
  1984. /**
  1985. * @brief Returns the least upper bound value of the distribution.
  1986. */
  1987. result_type
  1988. max() const
  1989. { return std::numeric_limits<result_type>::max(); }
  1990. /**
  1991. * @brief Generating functions.
  1992. */
  1993. template<typename _UniformRandomNumberGenerator>
  1994. result_type
  1995. operator()(_UniformRandomNumberGenerator& __urng);
  1996. template<typename _UniformRandomNumberGenerator>
  1997. result_type
  1998. operator()(_UniformRandomNumberGenerator& __urng,
  1999. const param_type& __p);
  2000. template<typename _ForwardIterator,
  2001. typename _UniformRandomNumberGenerator>
  2002. void
  2003. __generate(_ForwardIterator __f, _ForwardIterator __t,
  2004. _UniformRandomNumberGenerator& __urng)
  2005. { this->__generate(__f, __t, __urng, _M_param); }
  2006. template<typename _ForwardIterator,
  2007. typename _UniformRandomNumberGenerator>
  2008. void
  2009. __generate(_ForwardIterator __f, _ForwardIterator __t,
  2010. _UniformRandomNumberGenerator& __urng,
  2011. const param_type& __p)
  2012. { this->__generate_impl(__f, __t, __urng, __p); }
  2013. template<typename _UniformRandomNumberGenerator>
  2014. void
  2015. __generate(result_type* __f, result_type* __t,
  2016. _UniformRandomNumberGenerator& __urng,
  2017. const param_type& __p)
  2018. { this->__generate_impl(__f, __t, __urng, __p); }
  2019. /**
  2020. * @brief Return true if two Hoyt distributions have
  2021. * the same parameters and the sequences that would
  2022. * be generated are equal.
  2023. */
  2024. friend bool
  2025. operator==(const hoyt_distribution& __d1,
  2026. const hoyt_distribution& __d2)
  2027. { return (__d1._M_param == __d2._M_param
  2028. && __d1._M_ad == __d2._M_ad
  2029. && __d1._M_ed == __d2._M_ed); }
  2030. /**
  2031. * @brief Inserts a %hoyt_distribution random number distribution
  2032. * @p __x into the output stream @p __os.
  2033. *
  2034. * @param __os An output stream.
  2035. * @param __x A %hoyt_distribution random number distribution.
  2036. *
  2037. * @returns The output stream with the state of @p __x inserted or in
  2038. * an error state.
  2039. */
  2040. template<typename _RealType1, typename _CharT, typename _Traits>
  2041. friend std::basic_ostream<_CharT, _Traits>&
  2042. operator<<(std::basic_ostream<_CharT, _Traits>&,
  2043. const hoyt_distribution<_RealType1>&);
  2044. /**
  2045. * @brief Extracts a %hoyt_distribution random number distribution
  2046. * @p __x from the input stream @p __is.
  2047. *
  2048. * @param __is An input stream.
  2049. * @param __x A %hoyt_distribution random number
  2050. * generator engine.
  2051. *
  2052. * @returns The input stream with @p __x extracted or in an error state.
  2053. */
  2054. template<typename _RealType1, typename _CharT, typename _Traits>
  2055. friend std::basic_istream<_CharT, _Traits>&
  2056. operator>>(std::basic_istream<_CharT, _Traits>&,
  2057. hoyt_distribution<_RealType1>&);
  2058. private:
  2059. template<typename _ForwardIterator,
  2060. typename _UniformRandomNumberGenerator>
  2061. void
  2062. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  2063. _UniformRandomNumberGenerator& __urng,
  2064. const param_type& __p);
  2065. param_type _M_param;
  2066. __gnu_cxx::arcsine_distribution<result_type> _M_ad;
  2067. std::exponential_distribution<result_type> _M_ed;
  2068. };
  2069. /**
  2070. * @brief Return true if two Hoyt distributions are not equal.
  2071. */
  2072. template<typename _RealType>
  2073. inline bool
  2074. operator!=(const hoyt_distribution<_RealType>& __d1,
  2075. const hoyt_distribution<_RealType>& __d2)
  2076. { return !(__d1 == __d2); }
  2077. /**
  2078. * @brief A triangular distribution for random numbers.
  2079. *
  2080. * The formula for the triangular probability density function is
  2081. * @f[
  2082. * / 0 for x < a
  2083. * p(x|a,b,c) = | \frac{2(x-a)}{(c-a)(b-a)} for a <= x <= b
  2084. * | \frac{2(c-x)}{(c-a)(c-b)} for b < x <= c
  2085. * \ 0 for c < x
  2086. * @f]
  2087. *
  2088. * <table border=1 cellpadding=10 cellspacing=0>
  2089. * <caption align=top>Distribution Statistics</caption>
  2090. * <tr><td>Mean</td><td>@f$ \frac{a+b+c}{2} @f$</td></tr>
  2091. * <tr><td>Variance</td><td>@f$ \frac{a^2+b^2+c^2-ab-ac-bc}
  2092. * {18}@f$</td></tr>
  2093. * <tr><td>Range</td><td>@f$[a, c]@f$</td></tr>
  2094. * </table>
  2095. */
  2096. template<typename _RealType = double>
  2097. class triangular_distribution
  2098. {
  2099. static_assert(std::is_floating_point<_RealType>::value,
  2100. "template argument not a floating point type");
  2101. public:
  2102. /** The type of the range of the distribution. */
  2103. typedef _RealType result_type;
  2104. /** Parameter type. */
  2105. struct param_type
  2106. {
  2107. friend class triangular_distribution<_RealType>;
  2108. param_type() : param_type(0) { }
  2109. explicit
  2110. param_type(_RealType __a,
  2111. _RealType __b = _RealType(0.5),
  2112. _RealType __c = _RealType(1))
  2113. : _M_a(__a), _M_b(__b), _M_c(__c)
  2114. {
  2115. __glibcxx_assert(_M_a <= _M_b);
  2116. __glibcxx_assert(_M_b <= _M_c);
  2117. __glibcxx_assert(_M_a < _M_c);
  2118. _M_r_ab = (_M_b - _M_a) / (_M_c - _M_a);
  2119. _M_f_ab_ac = (_M_b - _M_a) * (_M_c - _M_a);
  2120. _M_f_bc_ac = (_M_c - _M_b) * (_M_c - _M_a);
  2121. }
  2122. _RealType
  2123. a() const
  2124. { return _M_a; }
  2125. _RealType
  2126. b() const
  2127. { return _M_b; }
  2128. _RealType
  2129. c() const
  2130. { return _M_c; }
  2131. friend bool
  2132. operator==(const param_type& __p1, const param_type& __p2)
  2133. {
  2134. return (__p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b
  2135. && __p1._M_c == __p2._M_c);
  2136. }
  2137. friend bool
  2138. operator!=(const param_type& __p1, const param_type& __p2)
  2139. { return !(__p1 == __p2); }
  2140. private:
  2141. _RealType _M_a;
  2142. _RealType _M_b;
  2143. _RealType _M_c;
  2144. _RealType _M_r_ab;
  2145. _RealType _M_f_ab_ac;
  2146. _RealType _M_f_bc_ac;
  2147. };
  2148. triangular_distribution() : triangular_distribution(0.0) { }
  2149. /**
  2150. * @brief Constructs a triangle distribution with parameters
  2151. * @f$ a @f$, @f$ b @f$ and @f$ c @f$.
  2152. */
  2153. explicit
  2154. triangular_distribution(result_type __a,
  2155. result_type __b = result_type(0.5),
  2156. result_type __c = result_type(1))
  2157. : _M_param(__a, __b, __c)
  2158. { }
  2159. explicit
  2160. triangular_distribution(const param_type& __p)
  2161. : _M_param(__p)
  2162. { }
  2163. /**
  2164. * @brief Resets the distribution state.
  2165. */
  2166. void
  2167. reset()
  2168. { }
  2169. /**
  2170. * @brief Returns the @f$ a @f$ of the distribution.
  2171. */
  2172. result_type
  2173. a() const
  2174. { return _M_param.a(); }
  2175. /**
  2176. * @brief Returns the @f$ b @f$ of the distribution.
  2177. */
  2178. result_type
  2179. b() const
  2180. { return _M_param.b(); }
  2181. /**
  2182. * @brief Returns the @f$ c @f$ of the distribution.
  2183. */
  2184. result_type
  2185. c() const
  2186. { return _M_param.c(); }
  2187. /**
  2188. * @brief Returns the parameter set of the distribution.
  2189. */
  2190. param_type
  2191. param() const
  2192. { return _M_param; }
  2193. /**
  2194. * @brief Sets the parameter set of the distribution.
  2195. * @param __param The new parameter set of the distribution.
  2196. */
  2197. void
  2198. param(const param_type& __param)
  2199. { _M_param = __param; }
  2200. /**
  2201. * @brief Returns the greatest lower bound value of the distribution.
  2202. */
  2203. result_type
  2204. min() const
  2205. { return _M_param._M_a; }
  2206. /**
  2207. * @brief Returns the least upper bound value of the distribution.
  2208. */
  2209. result_type
  2210. max() const
  2211. { return _M_param._M_c; }
  2212. /**
  2213. * @brief Generating functions.
  2214. */
  2215. template<typename _UniformRandomNumberGenerator>
  2216. result_type
  2217. operator()(_UniformRandomNumberGenerator& __urng)
  2218. { return this->operator()(__urng, _M_param); }
  2219. template<typename _UniformRandomNumberGenerator>
  2220. result_type
  2221. operator()(_UniformRandomNumberGenerator& __urng,
  2222. const param_type& __p)
  2223. {
  2224. std::__detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
  2225. __aurng(__urng);
  2226. result_type __rnd = __aurng();
  2227. if (__rnd <= __p._M_r_ab)
  2228. return __p.a() + std::sqrt(__rnd * __p._M_f_ab_ac);
  2229. else
  2230. return __p.c() - std::sqrt((result_type(1) - __rnd)
  2231. * __p._M_f_bc_ac);
  2232. }
  2233. template<typename _ForwardIterator,
  2234. typename _UniformRandomNumberGenerator>
  2235. void
  2236. __generate(_ForwardIterator __f, _ForwardIterator __t,
  2237. _UniformRandomNumberGenerator& __urng)
  2238. { this->__generate(__f, __t, __urng, _M_param); }
  2239. template<typename _ForwardIterator,
  2240. typename _UniformRandomNumberGenerator>
  2241. void
  2242. __generate(_ForwardIterator __f, _ForwardIterator __t,
  2243. _UniformRandomNumberGenerator& __urng,
  2244. const param_type& __p)
  2245. { this->__generate_impl(__f, __t, __urng, __p); }
  2246. template<typename _UniformRandomNumberGenerator>
  2247. void
  2248. __generate(result_type* __f, result_type* __t,
  2249. _UniformRandomNumberGenerator& __urng,
  2250. const param_type& __p)
  2251. { this->__generate_impl(__f, __t, __urng, __p); }
  2252. /**
  2253. * @brief Return true if two triangle distributions have the same
  2254. * parameters and the sequences that would be generated
  2255. * are equal.
  2256. */
  2257. friend bool
  2258. operator==(const triangular_distribution& __d1,
  2259. const triangular_distribution& __d2)
  2260. { return __d1._M_param == __d2._M_param; }
  2261. /**
  2262. * @brief Inserts a %triangular_distribution random number distribution
  2263. * @p __x into the output stream @p __os.
  2264. *
  2265. * @param __os An output stream.
  2266. * @param __x A %triangular_distribution random number distribution.
  2267. *
  2268. * @returns The output stream with the state of @p __x inserted or in
  2269. * an error state.
  2270. */
  2271. template<typename _RealType1, typename _CharT, typename _Traits>
  2272. friend std::basic_ostream<_CharT, _Traits>&
  2273. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  2274. const __gnu_cxx::triangular_distribution<_RealType1>& __x);
  2275. /**
  2276. * @brief Extracts a %triangular_distribution random number distribution
  2277. * @p __x from the input stream @p __is.
  2278. *
  2279. * @param __is An input stream.
  2280. * @param __x A %triangular_distribution random number generator engine.
  2281. *
  2282. * @returns The input stream with @p __x extracted or in an error state.
  2283. */
  2284. template<typename _RealType1, typename _CharT, typename _Traits>
  2285. friend std::basic_istream<_CharT, _Traits>&
  2286. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  2287. __gnu_cxx::triangular_distribution<_RealType1>& __x);
  2288. private:
  2289. template<typename _ForwardIterator,
  2290. typename _UniformRandomNumberGenerator>
  2291. void
  2292. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  2293. _UniformRandomNumberGenerator& __urng,
  2294. const param_type& __p);
  2295. param_type _M_param;
  2296. };
  2297. /**
  2298. * @brief Return true if two triangle distributions are different.
  2299. */
  2300. template<typename _RealType>
  2301. inline bool
  2302. operator!=(const __gnu_cxx::triangular_distribution<_RealType>& __d1,
  2303. const __gnu_cxx::triangular_distribution<_RealType>& __d2)
  2304. { return !(__d1 == __d2); }
  2305. /**
  2306. * @brief A von Mises distribution for random numbers.
  2307. *
  2308. * The formula for the von Mises probability density function is
  2309. * @f[
  2310. * p(x|\mu,\kappa) = \frac{e^{\kappa \cos(x-\mu)}}
  2311. * {2\pi I_0(\kappa)}
  2312. * @f]
  2313. *
  2314. * The generating functions use the method according to:
  2315. *
  2316. * D. J. Best and N. I. Fisher, 1979. "Efficient Simulation of the
  2317. * von Mises Distribution", Journal of the Royal Statistical Society.
  2318. * Series C (Applied Statistics), Vol. 28, No. 2, pp. 152-157.
  2319. *
  2320. * <table border=1 cellpadding=10 cellspacing=0>
  2321. * <caption align=top>Distribution Statistics</caption>
  2322. * <tr><td>Mean</td><td>@f$ \mu @f$</td></tr>
  2323. * <tr><td>Variance</td><td>@f$ 1-I_1(\kappa)/I_0(\kappa) @f$</td></tr>
  2324. * <tr><td>Range</td><td>@f$[-\pi, \pi]@f$</td></tr>
  2325. * </table>
  2326. */
  2327. template<typename _RealType = double>
  2328. class von_mises_distribution
  2329. {
  2330. static_assert(std::is_floating_point<_RealType>::value,
  2331. "template argument not a floating point type");
  2332. public:
  2333. /** The type of the range of the distribution. */
  2334. typedef _RealType result_type;
  2335. /** Parameter type. */
  2336. struct param_type
  2337. {
  2338. friend class von_mises_distribution<_RealType>;
  2339. param_type() : param_type(0) { }
  2340. explicit
  2341. param_type(_RealType __mu, _RealType __kappa = _RealType(1))
  2342. : _M_mu(__mu), _M_kappa(__kappa)
  2343. {
  2344. const _RealType __pi = __gnu_cxx::__math_constants<_RealType>::__pi;
  2345. __glibcxx_assert(_M_mu >= -__pi && _M_mu <= __pi);
  2346. __glibcxx_assert(_M_kappa >= _RealType(0));
  2347. auto __tau = std::sqrt(_RealType(4) * _M_kappa * _M_kappa
  2348. + _RealType(1)) + _RealType(1);
  2349. auto __rho = ((__tau - std::sqrt(_RealType(2) * __tau))
  2350. / (_RealType(2) * _M_kappa));
  2351. _M_r = (_RealType(1) + __rho * __rho) / (_RealType(2) * __rho);
  2352. }
  2353. _RealType
  2354. mu() const
  2355. { return _M_mu; }
  2356. _RealType
  2357. kappa() const
  2358. { return _M_kappa; }
  2359. friend bool
  2360. operator==(const param_type& __p1, const param_type& __p2)
  2361. { return __p1._M_mu == __p2._M_mu && __p1._M_kappa == __p2._M_kappa; }
  2362. friend bool
  2363. operator!=(const param_type& __p1, const param_type& __p2)
  2364. { return !(__p1 == __p2); }
  2365. private:
  2366. _RealType _M_mu;
  2367. _RealType _M_kappa;
  2368. _RealType _M_r;
  2369. };
  2370. von_mises_distribution() : von_mises_distribution(0.0) { }
  2371. /**
  2372. * @brief Constructs a von Mises distribution with parameters
  2373. * @f$\mu@f$ and @f$\kappa@f$.
  2374. */
  2375. explicit
  2376. von_mises_distribution(result_type __mu,
  2377. result_type __kappa = result_type(1))
  2378. : _M_param(__mu, __kappa)
  2379. { }
  2380. explicit
  2381. von_mises_distribution(const param_type& __p)
  2382. : _M_param(__p)
  2383. { }
  2384. /**
  2385. * @brief Resets the distribution state.
  2386. */
  2387. void
  2388. reset()
  2389. { }
  2390. /**
  2391. * @brief Returns the @f$ \mu @f$ of the distribution.
  2392. */
  2393. result_type
  2394. mu() const
  2395. { return _M_param.mu(); }
  2396. /**
  2397. * @brief Returns the @f$ \kappa @f$ of the distribution.
  2398. */
  2399. result_type
  2400. kappa() const
  2401. { return _M_param.kappa(); }
  2402. /**
  2403. * @brief Returns the parameter set of the distribution.
  2404. */
  2405. param_type
  2406. param() const
  2407. { return _M_param; }
  2408. /**
  2409. * @brief Sets the parameter set of the distribution.
  2410. * @param __param The new parameter set of the distribution.
  2411. */
  2412. void
  2413. param(const param_type& __param)
  2414. { _M_param = __param; }
  2415. /**
  2416. * @brief Returns the greatest lower bound value of the distribution.
  2417. */
  2418. result_type
  2419. min() const
  2420. {
  2421. return -__gnu_cxx::__math_constants<result_type>::__pi;
  2422. }
  2423. /**
  2424. * @brief Returns the least upper bound value of the distribution.
  2425. */
  2426. result_type
  2427. max() const
  2428. {
  2429. return __gnu_cxx::__math_constants<result_type>::__pi;
  2430. }
  2431. /**
  2432. * @brief Generating functions.
  2433. */
  2434. template<typename _UniformRandomNumberGenerator>
  2435. result_type
  2436. operator()(_UniformRandomNumberGenerator& __urng)
  2437. { return this->operator()(__urng, _M_param); }
  2438. template<typename _UniformRandomNumberGenerator>
  2439. result_type
  2440. operator()(_UniformRandomNumberGenerator& __urng,
  2441. const param_type& __p);
  2442. template<typename _ForwardIterator,
  2443. typename _UniformRandomNumberGenerator>
  2444. void
  2445. __generate(_ForwardIterator __f, _ForwardIterator __t,
  2446. _UniformRandomNumberGenerator& __urng)
  2447. { this->__generate(__f, __t, __urng, _M_param); }
  2448. template<typename _ForwardIterator,
  2449. typename _UniformRandomNumberGenerator>
  2450. void
  2451. __generate(_ForwardIterator __f, _ForwardIterator __t,
  2452. _UniformRandomNumberGenerator& __urng,
  2453. const param_type& __p)
  2454. { this->__generate_impl(__f, __t, __urng, __p); }
  2455. template<typename _UniformRandomNumberGenerator>
  2456. void
  2457. __generate(result_type* __f, result_type* __t,
  2458. _UniformRandomNumberGenerator& __urng,
  2459. const param_type& __p)
  2460. { this->__generate_impl(__f, __t, __urng, __p); }
  2461. /**
  2462. * @brief Return true if two von Mises distributions have the same
  2463. * parameters and the sequences that would be generated
  2464. * are equal.
  2465. */
  2466. friend bool
  2467. operator==(const von_mises_distribution& __d1,
  2468. const von_mises_distribution& __d2)
  2469. { return __d1._M_param == __d2._M_param; }
  2470. /**
  2471. * @brief Inserts a %von_mises_distribution random number distribution
  2472. * @p __x into the output stream @p __os.
  2473. *
  2474. * @param __os An output stream.
  2475. * @param __x A %von_mises_distribution random number distribution.
  2476. *
  2477. * @returns The output stream with the state of @p __x inserted or in
  2478. * an error state.
  2479. */
  2480. template<typename _RealType1, typename _CharT, typename _Traits>
  2481. friend std::basic_ostream<_CharT, _Traits>&
  2482. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  2483. const __gnu_cxx::von_mises_distribution<_RealType1>& __x);
  2484. /**
  2485. * @brief Extracts a %von_mises_distribution random number distribution
  2486. * @p __x from the input stream @p __is.
  2487. *
  2488. * @param __is An input stream.
  2489. * @param __x A %von_mises_distribution random number generator engine.
  2490. *
  2491. * @returns The input stream with @p __x extracted or in an error state.
  2492. */
  2493. template<typename _RealType1, typename _CharT, typename _Traits>
  2494. friend std::basic_istream<_CharT, _Traits>&
  2495. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  2496. __gnu_cxx::von_mises_distribution<_RealType1>& __x);
  2497. private:
  2498. template<typename _ForwardIterator,
  2499. typename _UniformRandomNumberGenerator>
  2500. void
  2501. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  2502. _UniformRandomNumberGenerator& __urng,
  2503. const param_type& __p);
  2504. param_type _M_param;
  2505. };
  2506. /**
  2507. * @brief Return true if two von Mises distributions are different.
  2508. */
  2509. template<typename _RealType>
  2510. inline bool
  2511. operator!=(const __gnu_cxx::von_mises_distribution<_RealType>& __d1,
  2512. const __gnu_cxx::von_mises_distribution<_RealType>& __d2)
  2513. { return !(__d1 == __d2); }
  2514. /**
  2515. * @brief A discrete hypergeometric random number distribution.
  2516. *
  2517. * The hypergeometric distribution is a discrete probability distribution
  2518. * that describes the probability of @p k successes in @p n draws @a without
  2519. * replacement from a finite population of size @p N containing exactly @p K
  2520. * successes.
  2521. *
  2522. * The formula for the hypergeometric probability density function is
  2523. * @f[
  2524. * p(k|N,K,n) = \frac{\binom{K}{k} \binom{N-K}{n-k}}{\binom{N}{n}}
  2525. * @f]
  2526. * where @f$N@f$ is the total population of the distribution,
  2527. * @f$K@f$ is the total population of the distribution.
  2528. *
  2529. * <table border=1 cellpadding=10 cellspacing=0>
  2530. * <caption align=top>Distribution Statistics</caption>
  2531. * <tr><td>Mean</td><td>@f$ n\frac{K}{N} @f$</td></tr>
  2532. * <tr><td>Variance</td><td>@f$ n\frac{K}{N}\frac{N-K}{N}\frac{N-n}{N-1}
  2533. * @f$</td></tr>
  2534. * <tr><td>Range</td><td>@f$[max(0, n+K-N), min(K, n)]@f$</td></tr>
  2535. * </table>
  2536. */
  2537. template<typename _UIntType = unsigned int>
  2538. class hypergeometric_distribution
  2539. {
  2540. static_assert(std::is_unsigned<_UIntType>::value, "template argument "
  2541. "substituting _UIntType not an unsigned integral type");
  2542. public:
  2543. /** The type of the range of the distribution. */
  2544. typedef _UIntType result_type;
  2545. /** Parameter type. */
  2546. struct param_type
  2547. {
  2548. typedef hypergeometric_distribution<_UIntType> distribution_type;
  2549. friend class hypergeometric_distribution<_UIntType>;
  2550. param_type() : param_type(10) { }
  2551. explicit
  2552. param_type(result_type __N, result_type __K = 5,
  2553. result_type __n = 1)
  2554. : _M_N{__N}, _M_K{__K}, _M_n{__n}
  2555. {
  2556. __glibcxx_assert(_M_N >= _M_K);
  2557. __glibcxx_assert(_M_N >= _M_n);
  2558. }
  2559. result_type
  2560. total_size() const
  2561. { return _M_N; }
  2562. result_type
  2563. successful_size() const
  2564. { return _M_K; }
  2565. result_type
  2566. unsuccessful_size() const
  2567. { return _M_N - _M_K; }
  2568. result_type
  2569. total_draws() const
  2570. { return _M_n; }
  2571. friend bool
  2572. operator==(const param_type& __p1, const param_type& __p2)
  2573. { return (__p1._M_N == __p2._M_N)
  2574. && (__p1._M_K == __p2._M_K)
  2575. && (__p1._M_n == __p2._M_n); }
  2576. friend bool
  2577. operator!=(const param_type& __p1, const param_type& __p2)
  2578. { return !(__p1 == __p2); }
  2579. private:
  2580. result_type _M_N;
  2581. result_type _M_K;
  2582. result_type _M_n;
  2583. };
  2584. // constructors and member functions
  2585. hypergeometric_distribution() : hypergeometric_distribution(10) { }
  2586. explicit
  2587. hypergeometric_distribution(result_type __N, result_type __K = 5,
  2588. result_type __n = 1)
  2589. : _M_param{__N, __K, __n}
  2590. { }
  2591. explicit
  2592. hypergeometric_distribution(const param_type& __p)
  2593. : _M_param{__p}
  2594. { }
  2595. /**
  2596. * @brief Resets the distribution state.
  2597. */
  2598. void
  2599. reset()
  2600. { }
  2601. /**
  2602. * @brief Returns the distribution parameter @p N,
  2603. * the total number of items.
  2604. */
  2605. result_type
  2606. total_size() const
  2607. { return this->_M_param.total_size(); }
  2608. /**
  2609. * @brief Returns the distribution parameter @p K,
  2610. * the total number of successful items.
  2611. */
  2612. result_type
  2613. successful_size() const
  2614. { return this->_M_param.successful_size(); }
  2615. /**
  2616. * @brief Returns the total number of unsuccessful items @f$ N - K @f$.
  2617. */
  2618. result_type
  2619. unsuccessful_size() const
  2620. { return this->_M_param.unsuccessful_size(); }
  2621. /**
  2622. * @brief Returns the distribution parameter @p n,
  2623. * the total number of draws.
  2624. */
  2625. result_type
  2626. total_draws() const
  2627. { return this->_M_param.total_draws(); }
  2628. /**
  2629. * @brief Returns the parameter set of the distribution.
  2630. */
  2631. param_type
  2632. param() const
  2633. { return this->_M_param; }
  2634. /**
  2635. * @brief Sets the parameter set of the distribution.
  2636. * @param __param The new parameter set of the distribution.
  2637. */
  2638. void
  2639. param(const param_type& __param)
  2640. { this->_M_param = __param; }
  2641. /**
  2642. * @brief Returns the greatest lower bound value of the distribution.
  2643. */
  2644. result_type
  2645. min() const
  2646. {
  2647. using _IntType = typename std::make_signed<result_type>::type;
  2648. return static_cast<result_type>(std::max(static_cast<_IntType>(0),
  2649. static_cast<_IntType>(this->total_draws()
  2650. - this->unsuccessful_size())));
  2651. }
  2652. /**
  2653. * @brief Returns the least upper bound value of the distribution.
  2654. */
  2655. result_type
  2656. max() const
  2657. { return std::min(this->successful_size(), this->total_draws()); }
  2658. /**
  2659. * @brief Generating functions.
  2660. */
  2661. template<typename _UniformRandomNumberGenerator>
  2662. result_type
  2663. operator()(_UniformRandomNumberGenerator& __urng)
  2664. { return this->operator()(__urng, this->_M_param); }
  2665. template<typename _UniformRandomNumberGenerator>
  2666. result_type
  2667. operator()(_UniformRandomNumberGenerator& __urng,
  2668. const param_type& __p);
  2669. template<typename _ForwardIterator,
  2670. typename _UniformRandomNumberGenerator>
  2671. void
  2672. __generate(_ForwardIterator __f, _ForwardIterator __t,
  2673. _UniformRandomNumberGenerator& __urng)
  2674. { this->__generate(__f, __t, __urng, this->_M_param); }
  2675. template<typename _ForwardIterator,
  2676. typename _UniformRandomNumberGenerator>
  2677. void
  2678. __generate(_ForwardIterator __f, _ForwardIterator __t,
  2679. _UniformRandomNumberGenerator& __urng,
  2680. const param_type& __p)
  2681. { this->__generate_impl(__f, __t, __urng, __p); }
  2682. template<typename _UniformRandomNumberGenerator>
  2683. void
  2684. __generate(result_type* __f, result_type* __t,
  2685. _UniformRandomNumberGenerator& __urng,
  2686. const param_type& __p)
  2687. { this->__generate_impl(__f, __t, __urng, __p); }
  2688. /**
  2689. * @brief Return true if two hypergeometric distributions have the same
  2690. * parameters and the sequences that would be generated
  2691. * are equal.
  2692. */
  2693. friend bool
  2694. operator==(const hypergeometric_distribution& __d1,
  2695. const hypergeometric_distribution& __d2)
  2696. { return __d1._M_param == __d2._M_param; }
  2697. /**
  2698. * @brief Inserts a %hypergeometric_distribution random number
  2699. * distribution @p __x into the output stream @p __os.
  2700. *
  2701. * @param __os An output stream.
  2702. * @param __x A %hypergeometric_distribution random number
  2703. * distribution.
  2704. *
  2705. * @returns The output stream with the state of @p __x inserted or in
  2706. * an error state.
  2707. */
  2708. template<typename _UIntType1, typename _CharT, typename _Traits>
  2709. friend std::basic_ostream<_CharT, _Traits>&
  2710. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  2711. const __gnu_cxx::hypergeometric_distribution<_UIntType1>&
  2712. __x);
  2713. /**
  2714. * @brief Extracts a %hypergeometric_distribution random number
  2715. * distribution @p __x from the input stream @p __is.
  2716. *
  2717. * @param __is An input stream.
  2718. * @param __x A %hypergeometric_distribution random number generator
  2719. * distribution.
  2720. *
  2721. * @returns The input stream with @p __x extracted or in an error
  2722. * state.
  2723. */
  2724. template<typename _UIntType1, typename _CharT, typename _Traits>
  2725. friend std::basic_istream<_CharT, _Traits>&
  2726. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  2727. __gnu_cxx::hypergeometric_distribution<_UIntType1>& __x);
  2728. private:
  2729. template<typename _ForwardIterator,
  2730. typename _UniformRandomNumberGenerator>
  2731. void
  2732. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  2733. _UniformRandomNumberGenerator& __urng,
  2734. const param_type& __p);
  2735. param_type _M_param;
  2736. };
  2737. /**
  2738. * @brief Return true if two hypergeometric distributions are different.
  2739. */
  2740. template<typename _UIntType>
  2741. inline bool
  2742. operator!=(const __gnu_cxx::hypergeometric_distribution<_UIntType>& __d1,
  2743. const __gnu_cxx::hypergeometric_distribution<_UIntType>& __d2)
  2744. { return !(__d1 == __d2); }
  2745. /**
  2746. * @brief A logistic continuous distribution for random numbers.
  2747. *
  2748. * The formula for the logistic probability density function is
  2749. * @f[
  2750. * p(x|\a,\b) = \frac{e^{(x - a)/b}}{b[1 + e^{(x - a)/b}]^2}
  2751. * @f]
  2752. * where @f$b > 0@f$.
  2753. *
  2754. * The formula for the logistic probability function is
  2755. * @f[
  2756. * cdf(x|\a,\b) = \frac{e^{(x - a)/b}}{1 + e^{(x - a)/b}}
  2757. * @f]
  2758. * where @f$b > 0@f$.
  2759. *
  2760. * <table border=1 cellpadding=10 cellspacing=0>
  2761. * <caption align=top>Distribution Statistics</caption>
  2762. * <tr><td>Mean</td><td>@f$a@f$</td></tr>
  2763. * <tr><td>Variance</td><td>@f$b^2\pi^2/3@f$</td></tr>
  2764. * <tr><td>Range</td><td>@f$[0, \infty)@f$</td></tr>
  2765. * </table>
  2766. */
  2767. template<typename _RealType = double>
  2768. class
  2769. logistic_distribution
  2770. {
  2771. static_assert(std::is_floating_point<_RealType>::value,
  2772. "template argument not a floating point type");
  2773. public:
  2774. /** The type of the range of the distribution. */
  2775. typedef _RealType result_type;
  2776. /** Parameter type. */
  2777. struct param_type
  2778. {
  2779. typedef logistic_distribution<result_type> distribution_type;
  2780. param_type() : param_type(0) { }
  2781. explicit
  2782. param_type(result_type __a, result_type __b = result_type(1))
  2783. : _M_a(__a), _M_b(__b)
  2784. {
  2785. __glibcxx_assert(_M_b > result_type(0));
  2786. }
  2787. result_type
  2788. a() const
  2789. { return _M_a; }
  2790. result_type
  2791. b() const
  2792. { return _M_b; }
  2793. friend bool
  2794. operator==(const param_type& __p1, const param_type& __p2)
  2795. { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
  2796. friend bool
  2797. operator!=(const param_type& __p1, const param_type& __p2)
  2798. { return !(__p1 == __p2); }
  2799. private:
  2800. void _M_initialize();
  2801. result_type _M_a;
  2802. result_type _M_b;
  2803. };
  2804. /**
  2805. * @brief Constructors.
  2806. * @{
  2807. */
  2808. logistic_distribution() : logistic_distribution(0.0) { }
  2809. explicit
  2810. logistic_distribution(result_type __a, result_type __b = result_type(1))
  2811. : _M_param(__a, __b)
  2812. { }
  2813. explicit
  2814. logistic_distribution(const param_type& __p)
  2815. : _M_param(__p)
  2816. { }
  2817. // @}
  2818. /**
  2819. * @brief Resets the distribution state.
  2820. */
  2821. void
  2822. reset()
  2823. { }
  2824. /**
  2825. * @brief Return the parameters of the distribution.
  2826. */
  2827. result_type
  2828. a() const
  2829. { return _M_param.a(); }
  2830. result_type
  2831. b() const
  2832. { return _M_param.b(); }
  2833. /**
  2834. * @brief Returns the parameter set of the distribution.
  2835. */
  2836. param_type
  2837. param() const
  2838. { return _M_param; }
  2839. /**
  2840. * @brief Sets the parameter set of the distribution.
  2841. * @param __param The new parameter set of the distribution.
  2842. */
  2843. void
  2844. param(const param_type& __param)
  2845. { _M_param = __param; }
  2846. /**
  2847. * @brief Returns the greatest lower bound value of the distribution.
  2848. */
  2849. result_type
  2850. min() const
  2851. { return -std::numeric_limits<result_type>::max(); }
  2852. /**
  2853. * @brief Returns the least upper bound value of the distribution.
  2854. */
  2855. result_type
  2856. max() const
  2857. { return std::numeric_limits<result_type>::max(); }
  2858. /**
  2859. * @brief Generating functions.
  2860. */
  2861. template<typename _UniformRandomNumberGenerator>
  2862. result_type
  2863. operator()(_UniformRandomNumberGenerator& __urng)
  2864. { return this->operator()(__urng, this->_M_param); }
  2865. template<typename _UniformRandomNumberGenerator>
  2866. result_type
  2867. operator()(_UniformRandomNumberGenerator&,
  2868. const param_type&);
  2869. template<typename _ForwardIterator,
  2870. typename _UniformRandomNumberGenerator>
  2871. void
  2872. __generate(_ForwardIterator __f, _ForwardIterator __t,
  2873. _UniformRandomNumberGenerator& __urng)
  2874. { this->__generate(__f, __t, __urng, this->param()); }
  2875. template<typename _ForwardIterator,
  2876. typename _UniformRandomNumberGenerator>
  2877. void
  2878. __generate(_ForwardIterator __f, _ForwardIterator __t,
  2879. _UniformRandomNumberGenerator& __urng,
  2880. const param_type& __p)
  2881. { this->__generate_impl(__f, __t, __urng, __p); }
  2882. template<typename _UniformRandomNumberGenerator>
  2883. void
  2884. __generate(result_type* __f, result_type* __t,
  2885. _UniformRandomNumberGenerator& __urng,
  2886. const param_type& __p)
  2887. { this->__generate_impl(__f, __t, __urng, __p); }
  2888. /**
  2889. * @brief Return true if two logistic distributions have
  2890. * the same parameters and the sequences that would
  2891. * be generated are equal.
  2892. */
  2893. template<typename _RealType1>
  2894. friend bool
  2895. operator==(const logistic_distribution<_RealType1>& __d1,
  2896. const logistic_distribution<_RealType1>& __d2)
  2897. { return __d1.param() == __d2.param(); }
  2898. /**
  2899. * @brief Inserts a %logistic_distribution random number distribution
  2900. * @p __x into the output stream @p __os.
  2901. *
  2902. * @param __os An output stream.
  2903. * @param __x A %logistic_distribution random number distribution.
  2904. *
  2905. * @returns The output stream with the state of @p __x inserted or in
  2906. * an error state.
  2907. */
  2908. template<typename _RealType1, typename _CharT, typename _Traits>
  2909. friend std::basic_ostream<_CharT, _Traits>&
  2910. operator<<(std::basic_ostream<_CharT, _Traits>&,
  2911. const logistic_distribution<_RealType1>&);
  2912. /**
  2913. * @brief Extracts a %logistic_distribution random number distribution
  2914. * @p __x from the input stream @p __is.
  2915. *
  2916. * @param __is An input stream.
  2917. * @param __x A %logistic_distribution random number
  2918. * generator engine.
  2919. *
  2920. * @returns The input stream with @p __x extracted or in an error state.
  2921. */
  2922. template<typename _RealType1, typename _CharT, typename _Traits>
  2923. friend std::basic_istream<_CharT, _Traits>&
  2924. operator>>(std::basic_istream<_CharT, _Traits>&,
  2925. logistic_distribution<_RealType1>&);
  2926. private:
  2927. template<typename _ForwardIterator,
  2928. typename _UniformRandomNumberGenerator>
  2929. void
  2930. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  2931. _UniformRandomNumberGenerator& __urng,
  2932. const param_type& __p);
  2933. param_type _M_param;
  2934. };
  2935. /**
  2936. * @brief Return true if two logistic distributions are not equal.
  2937. */
  2938. template<typename _RealType1>
  2939. inline bool
  2940. operator!=(const logistic_distribution<_RealType1>& __d1,
  2941. const logistic_distribution<_RealType1>& __d2)
  2942. { return !(__d1 == __d2); }
  2943. /**
  2944. * @brief A distribution for random coordinates on a unit sphere.
  2945. *
  2946. * The method used in the generation function is attributed by Donald Knuth
  2947. * to G. W. Brown, Modern Mathematics for the Engineer (1956).
  2948. */
  2949. template<std::size_t _Dimen, typename _RealType = double>
  2950. class uniform_on_sphere_distribution
  2951. {
  2952. static_assert(std::is_floating_point<_RealType>::value,
  2953. "template argument not a floating point type");
  2954. static_assert(_Dimen != 0, "dimension is zero");
  2955. public:
  2956. /** The type of the range of the distribution. */
  2957. typedef std::array<_RealType, _Dimen> result_type;
  2958. /** Parameter type. */
  2959. struct param_type
  2960. {
  2961. param_type() { }
  2962. friend bool
  2963. operator==(const param_type&, const param_type&)
  2964. { return true; }
  2965. friend bool
  2966. operator!=(const param_type&, const param_type&)
  2967. { return false; }
  2968. };
  2969. /**
  2970. * @brief Constructs a uniform on sphere distribution.
  2971. */
  2972. uniform_on_sphere_distribution()
  2973. : _M_param(), _M_nd()
  2974. { }
  2975. explicit
  2976. uniform_on_sphere_distribution(const param_type& __p)
  2977. : _M_param(__p), _M_nd()
  2978. { }
  2979. /**
  2980. * @brief Resets the distribution state.
  2981. */
  2982. void
  2983. reset()
  2984. { _M_nd.reset(); }
  2985. /**
  2986. * @brief Returns the parameter set of the distribution.
  2987. */
  2988. param_type
  2989. param() const
  2990. { return _M_param; }
  2991. /**
  2992. * @brief Sets the parameter set of the distribution.
  2993. * @param __param The new parameter set of the distribution.
  2994. */
  2995. void
  2996. param(const param_type& __param)
  2997. { _M_param = __param; }
  2998. /**
  2999. * @brief Returns the greatest lower bound value of the distribution.
  3000. * This function makes no sense for this distribution.
  3001. */
  3002. result_type
  3003. min() const
  3004. {
  3005. result_type __res;
  3006. __res.fill(0);
  3007. return __res;
  3008. }
  3009. /**
  3010. * @brief Returns the least upper bound value of the distribution.
  3011. * This function makes no sense for this distribution.
  3012. */
  3013. result_type
  3014. max() const
  3015. {
  3016. result_type __res;
  3017. __res.fill(0);
  3018. return __res;
  3019. }
  3020. /**
  3021. * @brief Generating functions.
  3022. */
  3023. template<typename _UniformRandomNumberGenerator>
  3024. result_type
  3025. operator()(_UniformRandomNumberGenerator& __urng)
  3026. { return this->operator()(__urng, _M_param); }
  3027. template<typename _UniformRandomNumberGenerator>
  3028. result_type
  3029. operator()(_UniformRandomNumberGenerator& __urng,
  3030. const param_type& __p);
  3031. template<typename _ForwardIterator,
  3032. typename _UniformRandomNumberGenerator>
  3033. void
  3034. __generate(_ForwardIterator __f, _ForwardIterator __t,
  3035. _UniformRandomNumberGenerator& __urng)
  3036. { this->__generate(__f, __t, __urng, this->param()); }
  3037. template<typename _ForwardIterator,
  3038. typename _UniformRandomNumberGenerator>
  3039. void
  3040. __generate(_ForwardIterator __f, _ForwardIterator __t,
  3041. _UniformRandomNumberGenerator& __urng,
  3042. const param_type& __p)
  3043. { this->__generate_impl(__f, __t, __urng, __p); }
  3044. template<typename _UniformRandomNumberGenerator>
  3045. void
  3046. __generate(result_type* __f, result_type* __t,
  3047. _UniformRandomNumberGenerator& __urng,
  3048. const param_type& __p)
  3049. { this->__generate_impl(__f, __t, __urng, __p); }
  3050. /**
  3051. * @brief Return true if two uniform on sphere distributions have
  3052. * the same parameters and the sequences that would be
  3053. * generated are equal.
  3054. */
  3055. friend bool
  3056. operator==(const uniform_on_sphere_distribution& __d1,
  3057. const uniform_on_sphere_distribution& __d2)
  3058. { return __d1._M_nd == __d2._M_nd; }
  3059. /**
  3060. * @brief Inserts a %uniform_on_sphere_distribution random number
  3061. * distribution @p __x into the output stream @p __os.
  3062. *
  3063. * @param __os An output stream.
  3064. * @param __x A %uniform_on_sphere_distribution random number
  3065. * distribution.
  3066. *
  3067. * @returns The output stream with the state of @p __x inserted or in
  3068. * an error state.
  3069. */
  3070. template<size_t _Dimen1, typename _RealType1, typename _CharT,
  3071. typename _Traits>
  3072. friend std::basic_ostream<_CharT, _Traits>&
  3073. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  3074. const __gnu_cxx::uniform_on_sphere_distribution<_Dimen1,
  3075. _RealType1>&
  3076. __x);
  3077. /**
  3078. * @brief Extracts a %uniform_on_sphere_distribution random number
  3079. * distribution
  3080. * @p __x from the input stream @p __is.
  3081. *
  3082. * @param __is An input stream.
  3083. * @param __x A %uniform_on_sphere_distribution random number
  3084. * generator engine.
  3085. *
  3086. * @returns The input stream with @p __x extracted or in an error state.
  3087. */
  3088. template<std::size_t _Dimen1, typename _RealType1, typename _CharT,
  3089. typename _Traits>
  3090. friend std::basic_istream<_CharT, _Traits>&
  3091. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  3092. __gnu_cxx::uniform_on_sphere_distribution<_Dimen1,
  3093. _RealType1>& __x);
  3094. private:
  3095. template<typename _ForwardIterator,
  3096. typename _UniformRandomNumberGenerator>
  3097. void
  3098. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  3099. _UniformRandomNumberGenerator& __urng,
  3100. const param_type& __p);
  3101. param_type _M_param;
  3102. std::normal_distribution<_RealType> _M_nd;
  3103. };
  3104. /**
  3105. * @brief Return true if two uniform on sphere distributions are different.
  3106. */
  3107. template<std::size_t _Dimen, typename _RealType>
  3108. inline bool
  3109. operator!=(const __gnu_cxx::uniform_on_sphere_distribution<_Dimen,
  3110. _RealType>& __d1,
  3111. const __gnu_cxx::uniform_on_sphere_distribution<_Dimen,
  3112. _RealType>& __d2)
  3113. { return !(__d1 == __d2); }
  3114. /**
  3115. * @brief A distribution for random coordinates inside a unit sphere.
  3116. */
  3117. template<std::size_t _Dimen, typename _RealType = double>
  3118. class uniform_inside_sphere_distribution
  3119. {
  3120. static_assert(std::is_floating_point<_RealType>::value,
  3121. "template argument not a floating point type");
  3122. static_assert(_Dimen != 0, "dimension is zero");
  3123. public:
  3124. /** The type of the range of the distribution. */
  3125. using result_type = std::array<_RealType, _Dimen>;
  3126. /** Parameter type. */
  3127. struct param_type
  3128. {
  3129. using distribution_type
  3130. = uniform_inside_sphere_distribution<_Dimen, _RealType>;
  3131. friend class uniform_inside_sphere_distribution<_Dimen, _RealType>;
  3132. param_type() : param_type(1.0) { }
  3133. explicit
  3134. param_type(_RealType __radius)
  3135. : _M_radius(__radius)
  3136. {
  3137. __glibcxx_assert(_M_radius > _RealType(0));
  3138. }
  3139. _RealType
  3140. radius() const
  3141. { return _M_radius; }
  3142. friend bool
  3143. operator==(const param_type& __p1, const param_type& __p2)
  3144. { return __p1._M_radius == __p2._M_radius; }
  3145. friend bool
  3146. operator!=(const param_type& __p1, const param_type& __p2)
  3147. { return !(__p1 == __p2); }
  3148. private:
  3149. _RealType _M_radius;
  3150. };
  3151. /**
  3152. * @brief Constructors.
  3153. * @{
  3154. */
  3155. uniform_inside_sphere_distribution()
  3156. : uniform_inside_sphere_distribution(1.0)
  3157. { }
  3158. explicit
  3159. uniform_inside_sphere_distribution(_RealType __radius)
  3160. : _M_param(__radius), _M_uosd()
  3161. { }
  3162. explicit
  3163. uniform_inside_sphere_distribution(const param_type& __p)
  3164. : _M_param(__p), _M_uosd()
  3165. { }
  3166. // @}
  3167. /**
  3168. * @brief Resets the distribution state.
  3169. */
  3170. void
  3171. reset()
  3172. { _M_uosd.reset(); }
  3173. /**
  3174. * @brief Returns the @f$radius@f$ of the distribution.
  3175. */
  3176. _RealType
  3177. radius() const
  3178. { return _M_param.radius(); }
  3179. /**
  3180. * @brief Returns the parameter set of the distribution.
  3181. */
  3182. param_type
  3183. param() const
  3184. { return _M_param; }
  3185. /**
  3186. * @brief Sets the parameter set of the distribution.
  3187. * @param __param The new parameter set of the distribution.
  3188. */
  3189. void
  3190. param(const param_type& __param)
  3191. { _M_param = __param; }
  3192. /**
  3193. * @brief Returns the greatest lower bound value of the distribution.
  3194. * This function makes no sense for this distribution.
  3195. */
  3196. result_type
  3197. min() const
  3198. {
  3199. result_type __res;
  3200. __res.fill(0);
  3201. return __res;
  3202. }
  3203. /**
  3204. * @brief Returns the least upper bound value of the distribution.
  3205. * This function makes no sense for this distribution.
  3206. */
  3207. result_type
  3208. max() const
  3209. {
  3210. result_type __res;
  3211. __res.fill(0);
  3212. return __res;
  3213. }
  3214. /**
  3215. * @brief Generating functions.
  3216. */
  3217. template<typename _UniformRandomNumberGenerator>
  3218. result_type
  3219. operator()(_UniformRandomNumberGenerator& __urng)
  3220. { return this->operator()(__urng, _M_param); }
  3221. template<typename _UniformRandomNumberGenerator>
  3222. result_type
  3223. operator()(_UniformRandomNumberGenerator& __urng,
  3224. const param_type& __p);
  3225. template<typename _ForwardIterator,
  3226. typename _UniformRandomNumberGenerator>
  3227. void
  3228. __generate(_ForwardIterator __f, _ForwardIterator __t,
  3229. _UniformRandomNumberGenerator& __urng)
  3230. { this->__generate(__f, __t, __urng, this->param()); }
  3231. template<typename _ForwardIterator,
  3232. typename _UniformRandomNumberGenerator>
  3233. void
  3234. __generate(_ForwardIterator __f, _ForwardIterator __t,
  3235. _UniformRandomNumberGenerator& __urng,
  3236. const param_type& __p)
  3237. { this->__generate_impl(__f, __t, __urng, __p); }
  3238. template<typename _UniformRandomNumberGenerator>
  3239. void
  3240. __generate(result_type* __f, result_type* __t,
  3241. _UniformRandomNumberGenerator& __urng,
  3242. const param_type& __p)
  3243. { this->__generate_impl(__f, __t, __urng, __p); }
  3244. /**
  3245. * @brief Return true if two uniform on sphere distributions have
  3246. * the same parameters and the sequences that would be
  3247. * generated are equal.
  3248. */
  3249. friend bool
  3250. operator==(const uniform_inside_sphere_distribution& __d1,
  3251. const uniform_inside_sphere_distribution& __d2)
  3252. { return __d1._M_param == __d2._M_param && __d1._M_uosd == __d2._M_uosd; }
  3253. /**
  3254. * @brief Inserts a %uniform_inside_sphere_distribution random number
  3255. * distribution @p __x into the output stream @p __os.
  3256. *
  3257. * @param __os An output stream.
  3258. * @param __x A %uniform_inside_sphere_distribution random number
  3259. * distribution.
  3260. *
  3261. * @returns The output stream with the state of @p __x inserted or in
  3262. * an error state.
  3263. */
  3264. template<size_t _Dimen1, typename _RealType1, typename _CharT,
  3265. typename _Traits>
  3266. friend std::basic_ostream<_CharT, _Traits>&
  3267. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  3268. const __gnu_cxx::uniform_inside_sphere_distribution<_Dimen1,
  3269. _RealType1>&
  3270. );
  3271. /**
  3272. * @brief Extracts a %uniform_inside_sphere_distribution random number
  3273. * distribution
  3274. * @p __x from the input stream @p __is.
  3275. *
  3276. * @param __is An input stream.
  3277. * @param __x A %uniform_inside_sphere_distribution random number
  3278. * generator engine.
  3279. *
  3280. * @returns The input stream with @p __x extracted or in an error state.
  3281. */
  3282. template<std::size_t _Dimen1, typename _RealType1, typename _CharT,
  3283. typename _Traits>
  3284. friend std::basic_istream<_CharT, _Traits>&
  3285. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  3286. __gnu_cxx::uniform_inside_sphere_distribution<_Dimen1,
  3287. _RealType1>&);
  3288. private:
  3289. template<typename _ForwardIterator,
  3290. typename _UniformRandomNumberGenerator>
  3291. void
  3292. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  3293. _UniformRandomNumberGenerator& __urng,
  3294. const param_type& __p);
  3295. param_type _M_param;
  3296. uniform_on_sphere_distribution<_Dimen, _RealType> _M_uosd;
  3297. };
  3298. /**
  3299. * @brief Return true if two uniform on sphere distributions are different.
  3300. */
  3301. template<std::size_t _Dimen, typename _RealType>
  3302. inline bool
  3303. operator!=(const __gnu_cxx::uniform_inside_sphere_distribution<_Dimen,
  3304. _RealType>& __d1,
  3305. const __gnu_cxx::uniform_inside_sphere_distribution<_Dimen,
  3306. _RealType>& __d2)
  3307. { return !(__d1 == __d2); }
  3308. _GLIBCXX_END_NAMESPACE_VERSION
  3309. } // namespace __gnu_cxx
  3310. #include <ext/opt_random.h>
  3311. #include <ext/random.tcc>
  3312. #endif // _GLIBCXX_USE_C99_STDINT_TR1 && UINT32_C
  3313. #endif // C++11
  3314. #endif // _EXT_RANDOM