random 112 KB

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