random 111 KB

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