random.h 173 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068
  1. // random number generation -*- C++ -*-
  2. // Copyright (C) 2009-2015 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. /**
  21. * @file bits/random.h
  22. * This is an internal header file, included by other library headers.
  23. * Do not attempt to use it directly. @headername{random}
  24. */
  25. #ifndef _RANDOM_H
  26. #define _RANDOM_H 1
  27. #include <vector>
  28. namespace std _GLIBCXX_VISIBILITY(default)
  29. {
  30. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  31. // [26.4] Random number generation
  32. /**
  33. * @defgroup random Random Number Generation
  34. * @ingroup numerics
  35. *
  36. * A facility for generating random numbers on selected distributions.
  37. * @{
  38. */
  39. /**
  40. * @brief A function template for converting the output of a (integral)
  41. * uniform random number generator to a floatng point result in the range
  42. * [0-1).
  43. */
  44. template<typename _RealType, size_t __bits,
  45. typename _UniformRandomNumberGenerator>
  46. _RealType
  47. generate_canonical(_UniformRandomNumberGenerator& __g);
  48. _GLIBCXX_END_NAMESPACE_VERSION
  49. /*
  50. * Implementation-space details.
  51. */
  52. namespace __detail
  53. {
  54. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  55. template<typename _UIntType, size_t __w,
  56. bool = __w < static_cast<size_t>
  57. (std::numeric_limits<_UIntType>::digits)>
  58. struct _Shift
  59. { static const _UIntType __value = 0; };
  60. template<typename _UIntType, size_t __w>
  61. struct _Shift<_UIntType, __w, true>
  62. { static const _UIntType __value = _UIntType(1) << __w; };
  63. template<int __s,
  64. int __which = ((__s <= __CHAR_BIT__ * sizeof (int))
  65. + (__s <= __CHAR_BIT__ * sizeof (long))
  66. + (__s <= __CHAR_BIT__ * sizeof (long long))
  67. /* assume long long no bigger than __int128 */
  68. + (__s <= 128))>
  69. struct _Select_uint_least_t
  70. {
  71. static_assert(__which < 0, /* needs to be dependent */
  72. "sorry, would be too much trouble for a slow result");
  73. };
  74. template<int __s>
  75. struct _Select_uint_least_t<__s, 4>
  76. { typedef unsigned int type; };
  77. template<int __s>
  78. struct _Select_uint_least_t<__s, 3>
  79. { typedef unsigned long type; };
  80. template<int __s>
  81. struct _Select_uint_least_t<__s, 2>
  82. { typedef unsigned long long type; };
  83. #ifdef _GLIBCXX_USE_INT128
  84. template<int __s>
  85. struct _Select_uint_least_t<__s, 1>
  86. { typedef unsigned __int128 type; };
  87. #endif
  88. // Assume a != 0, a < m, c < m, x < m.
  89. template<typename _Tp, _Tp __m, _Tp __a, _Tp __c,
  90. bool __big_enough = (!(__m & (__m - 1))
  91. || (_Tp(-1) - __c) / __a >= __m - 1),
  92. bool __schrage_ok = __m % __a < __m / __a>
  93. struct _Mod
  94. {
  95. typedef typename _Select_uint_least_t<std::__lg(__a)
  96. + std::__lg(__m) + 2>::type _Tp2;
  97. static _Tp
  98. __calc(_Tp __x)
  99. { return static_cast<_Tp>((_Tp2(__a) * __x + __c) % __m); }
  100. };
  101. // Schrage.
  102. template<typename _Tp, _Tp __m, _Tp __a, _Tp __c>
  103. struct _Mod<_Tp, __m, __a, __c, false, true>
  104. {
  105. static _Tp
  106. __calc(_Tp __x);
  107. };
  108. // Special cases:
  109. // - for m == 2^n or m == 0, unsigned integer overflow is safe.
  110. // - a * (m - 1) + c fits in _Tp, there is no overflow.
  111. template<typename _Tp, _Tp __m, _Tp __a, _Tp __c, bool __s>
  112. struct _Mod<_Tp, __m, __a, __c, true, __s>
  113. {
  114. static _Tp
  115. __calc(_Tp __x)
  116. {
  117. _Tp __res = __a * __x + __c;
  118. if (__m)
  119. __res %= __m;
  120. return __res;
  121. }
  122. };
  123. template<typename _Tp, _Tp __m, _Tp __a = 1, _Tp __c = 0>
  124. inline _Tp
  125. __mod(_Tp __x)
  126. { return _Mod<_Tp, __m, __a, __c>::__calc(__x); }
  127. /* Determine whether number is a power of 2. */
  128. template<typename _Tp>
  129. inline bool
  130. _Power_of_2(_Tp __x)
  131. {
  132. return ((__x - 1) & __x) == 0;
  133. };
  134. /*
  135. * An adaptor class for converting the output of any Generator into
  136. * the input for a specific Distribution.
  137. */
  138. template<typename _Engine, typename _DInputType>
  139. struct _Adaptor
  140. {
  141. static_assert(std::is_floating_point<_DInputType>::value,
  142. "template argument not a floating point type");
  143. public:
  144. _Adaptor(_Engine& __g)
  145. : _M_g(__g) { }
  146. _DInputType
  147. min() const
  148. { return _DInputType(0); }
  149. _DInputType
  150. max() const
  151. { return _DInputType(1); }
  152. /*
  153. * Converts a value generated by the adapted random number generator
  154. * into a value in the input domain for the dependent random number
  155. * distribution.
  156. */
  157. _DInputType
  158. operator()()
  159. {
  160. return std::generate_canonical<_DInputType,
  161. std::numeric_limits<_DInputType>::digits,
  162. _Engine>(_M_g);
  163. }
  164. private:
  165. _Engine& _M_g;
  166. };
  167. _GLIBCXX_END_NAMESPACE_VERSION
  168. } // namespace __detail
  169. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  170. /**
  171. * @addtogroup random_generators Random Number Generators
  172. * @ingroup random
  173. *
  174. * These classes define objects which provide random or pseudorandom
  175. * numbers, either from a discrete or a continuous interval. The
  176. * random number generator supplied as a part of this library are
  177. * all uniform random number generators which provide a sequence of
  178. * random number uniformly distributed over their range.
  179. *
  180. * A number generator is a function object with an operator() that
  181. * takes zero arguments and returns a number.
  182. *
  183. * A compliant random number generator must satisfy the following
  184. * requirements. <table border=1 cellpadding=10 cellspacing=0>
  185. * <caption align=top>Random Number Generator Requirements</caption>
  186. * <tr><td>To be documented.</td></tr> </table>
  187. *
  188. * @{
  189. */
  190. /**
  191. * @brief A model of a linear congruential random number generator.
  192. *
  193. * A random number generator that produces pseudorandom numbers via
  194. * linear function:
  195. * @f[
  196. * x_{i+1}\leftarrow(ax_{i} + c) \bmod m
  197. * @f]
  198. *
  199. * The template parameter @p _UIntType must be an unsigned integral type
  200. * large enough to store values up to (__m-1). If the template parameter
  201. * @p __m is 0, the modulus @p __m used is
  202. * std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template
  203. * parameters @p __a and @p __c must be less than @p __m.
  204. *
  205. * The size of the state is @f$1@f$.
  206. */
  207. template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
  208. class linear_congruential_engine
  209. {
  210. static_assert(std::is_unsigned<_UIntType>::value, "template argument "
  211. "substituting _UIntType not an unsigned integral type");
  212. static_assert(__m == 0u || (__a < __m && __c < __m),
  213. "template argument substituting __m out of bounds");
  214. public:
  215. /** The type of the generated random value. */
  216. typedef _UIntType result_type;
  217. /** The multiplier. */
  218. static constexpr result_type multiplier = __a;
  219. /** An increment. */
  220. static constexpr result_type increment = __c;
  221. /** The modulus. */
  222. static constexpr result_type modulus = __m;
  223. static constexpr result_type default_seed = 1u;
  224. /**
  225. * @brief Constructs a %linear_congruential_engine random number
  226. * generator engine with seed @p __s. The default seed value
  227. * is 1.
  228. *
  229. * @param __s The initial seed value.
  230. */
  231. explicit
  232. linear_congruential_engine(result_type __s = default_seed)
  233. { seed(__s); }
  234. /**
  235. * @brief Constructs a %linear_congruential_engine random number
  236. * generator engine seeded from the seed sequence @p __q.
  237. *
  238. * @param __q the seed sequence.
  239. */
  240. template<typename _Sseq, typename = typename
  241. std::enable_if<!std::is_same<_Sseq, linear_congruential_engine>::value>
  242. ::type>
  243. explicit
  244. linear_congruential_engine(_Sseq& __q)
  245. { seed(__q); }
  246. /**
  247. * @brief Reseeds the %linear_congruential_engine random number generator
  248. * engine sequence to the seed @p __s.
  249. *
  250. * @param __s The new seed.
  251. */
  252. void
  253. seed(result_type __s = default_seed);
  254. /**
  255. * @brief Reseeds the %linear_congruential_engine random number generator
  256. * engine
  257. * sequence using values from the seed sequence @p __q.
  258. *
  259. * @param __q the seed sequence.
  260. */
  261. template<typename _Sseq>
  262. typename std::enable_if<std::is_class<_Sseq>::value>::type
  263. seed(_Sseq& __q);
  264. /**
  265. * @brief Gets the smallest possible value in the output range.
  266. *
  267. * The minimum depends on the @p __c parameter: if it is zero, the
  268. * minimum generated must be > 0, otherwise 0 is allowed.
  269. */
  270. static constexpr result_type
  271. min()
  272. { return __c == 0u ? 1u : 0u; }
  273. /**
  274. * @brief Gets the largest possible value in the output range.
  275. */
  276. static constexpr result_type
  277. max()
  278. { return __m - 1u; }
  279. /**
  280. * @brief Discard a sequence of random numbers.
  281. */
  282. void
  283. discard(unsigned long long __z)
  284. {
  285. for (; __z != 0ULL; --__z)
  286. (*this)();
  287. }
  288. /**
  289. * @brief Gets the next random number in the sequence.
  290. */
  291. result_type
  292. operator()()
  293. {
  294. _M_x = __detail::__mod<_UIntType, __m, __a, __c>(_M_x);
  295. return _M_x;
  296. }
  297. /**
  298. * @brief Compares two linear congruential random number generator
  299. * objects of the same type for equality.
  300. *
  301. * @param __lhs A linear congruential random number generator object.
  302. * @param __rhs Another linear congruential random number generator
  303. * object.
  304. *
  305. * @returns true if the infinite sequences of generated values
  306. * would be equal, false otherwise.
  307. */
  308. friend bool
  309. operator==(const linear_congruential_engine& __lhs,
  310. const linear_congruential_engine& __rhs)
  311. { return __lhs._M_x == __rhs._M_x; }
  312. /**
  313. * @brief Writes the textual representation of the state x(i) of x to
  314. * @p __os.
  315. *
  316. * @param __os The output stream.
  317. * @param __lcr A % linear_congruential_engine random number generator.
  318. * @returns __os.
  319. */
  320. template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
  321. _UIntType1 __m1, typename _CharT, typename _Traits>
  322. friend std::basic_ostream<_CharT, _Traits>&
  323. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  324. const std::linear_congruential_engine<_UIntType1,
  325. __a1, __c1, __m1>& __lcr);
  326. /**
  327. * @brief Sets the state of the engine by reading its textual
  328. * representation from @p __is.
  329. *
  330. * The textual representation must have been previously written using
  331. * an output stream whose imbued locale and whose type's template
  332. * specialization arguments _CharT and _Traits were the same as those
  333. * of @p __is.
  334. *
  335. * @param __is The input stream.
  336. * @param __lcr A % linear_congruential_engine random number generator.
  337. * @returns __is.
  338. */
  339. template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
  340. _UIntType1 __m1, typename _CharT, typename _Traits>
  341. friend std::basic_istream<_CharT, _Traits>&
  342. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  343. std::linear_congruential_engine<_UIntType1, __a1,
  344. __c1, __m1>& __lcr);
  345. private:
  346. _UIntType _M_x;
  347. };
  348. /**
  349. * @brief Compares two linear congruential random number generator
  350. * objects of the same type for inequality.
  351. *
  352. * @param __lhs A linear congruential random number generator object.
  353. * @param __rhs Another linear congruential random number generator
  354. * object.
  355. *
  356. * @returns true if the infinite sequences of generated values
  357. * would be different, false otherwise.
  358. */
  359. template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
  360. inline bool
  361. operator!=(const std::linear_congruential_engine<_UIntType, __a,
  362. __c, __m>& __lhs,
  363. const std::linear_congruential_engine<_UIntType, __a,
  364. __c, __m>& __rhs)
  365. { return !(__lhs == __rhs); }
  366. /**
  367. * A generalized feedback shift register discrete random number generator.
  368. *
  369. * This algorithm avoids multiplication and division and is designed to be
  370. * friendly to a pipelined architecture. If the parameters are chosen
  371. * correctly, this generator will produce numbers with a very long period and
  372. * fairly good apparent entropy, although still not cryptographically strong.
  373. *
  374. * The best way to use this generator is with the predefined mt19937 class.
  375. *
  376. * This algorithm was originally invented by Makoto Matsumoto and
  377. * Takuji Nishimura.
  378. *
  379. * @tparam __w Word size, the number of bits in each element of
  380. * the state vector.
  381. * @tparam __n The degree of recursion.
  382. * @tparam __m The period parameter.
  383. * @tparam __r The separation point bit index.
  384. * @tparam __a The last row of the twist matrix.
  385. * @tparam __u The first right-shift tempering matrix parameter.
  386. * @tparam __d The first right-shift tempering matrix mask.
  387. * @tparam __s The first left-shift tempering matrix parameter.
  388. * @tparam __b The first left-shift tempering matrix mask.
  389. * @tparam __t The second left-shift tempering matrix parameter.
  390. * @tparam __c The second left-shift tempering matrix mask.
  391. * @tparam __l The second right-shift tempering matrix parameter.
  392. * @tparam __f Initialization multiplier.
  393. */
  394. template<typename _UIntType, size_t __w,
  395. size_t __n, size_t __m, size_t __r,
  396. _UIntType __a, size_t __u, _UIntType __d, size_t __s,
  397. _UIntType __b, size_t __t,
  398. _UIntType __c, size_t __l, _UIntType __f>
  399. class mersenne_twister_engine
  400. {
  401. static_assert(std::is_unsigned<_UIntType>::value, "template argument "
  402. "substituting _UIntType not an unsigned integral type");
  403. static_assert(1u <= __m && __m <= __n,
  404. "template argument substituting __m out of bounds");
  405. static_assert(__r <= __w, "template argument substituting "
  406. "__r out of bound");
  407. static_assert(__u <= __w, "template argument substituting "
  408. "__u out of bound");
  409. static_assert(__s <= __w, "template argument substituting "
  410. "__s out of bound");
  411. static_assert(__t <= __w, "template argument substituting "
  412. "__t out of bound");
  413. static_assert(__l <= __w, "template argument substituting "
  414. "__l out of bound");
  415. static_assert(__w <= std::numeric_limits<_UIntType>::digits,
  416. "template argument substituting __w out of bound");
  417. static_assert(__a <= (__detail::_Shift<_UIntType, __w>::__value - 1),
  418. "template argument substituting __a out of bound");
  419. static_assert(__b <= (__detail::_Shift<_UIntType, __w>::__value - 1),
  420. "template argument substituting __b out of bound");
  421. static_assert(__c <= (__detail::_Shift<_UIntType, __w>::__value - 1),
  422. "template argument substituting __c out of bound");
  423. static_assert(__d <= (__detail::_Shift<_UIntType, __w>::__value - 1),
  424. "template argument substituting __d out of bound");
  425. static_assert(__f <= (__detail::_Shift<_UIntType, __w>::__value - 1),
  426. "template argument substituting __f out of bound");
  427. public:
  428. /** The type of the generated random value. */
  429. typedef _UIntType result_type;
  430. // parameter values
  431. static constexpr size_t word_size = __w;
  432. static constexpr size_t state_size = __n;
  433. static constexpr size_t shift_size = __m;
  434. static constexpr size_t mask_bits = __r;
  435. static constexpr result_type xor_mask = __a;
  436. static constexpr size_t tempering_u = __u;
  437. static constexpr result_type tempering_d = __d;
  438. static constexpr size_t tempering_s = __s;
  439. static constexpr result_type tempering_b = __b;
  440. static constexpr size_t tempering_t = __t;
  441. static constexpr result_type tempering_c = __c;
  442. static constexpr size_t tempering_l = __l;
  443. static constexpr result_type initialization_multiplier = __f;
  444. static constexpr result_type default_seed = 5489u;
  445. // constructors and member function
  446. explicit
  447. mersenne_twister_engine(result_type __sd = default_seed)
  448. { seed(__sd); }
  449. /**
  450. * @brief Constructs a %mersenne_twister_engine random number generator
  451. * engine seeded from the seed sequence @p __q.
  452. *
  453. * @param __q the seed sequence.
  454. */
  455. template<typename _Sseq, typename = typename
  456. std::enable_if<!std::is_same<_Sseq, mersenne_twister_engine>::value>
  457. ::type>
  458. explicit
  459. mersenne_twister_engine(_Sseq& __q)
  460. { seed(__q); }
  461. void
  462. seed(result_type __sd = default_seed);
  463. template<typename _Sseq>
  464. typename std::enable_if<std::is_class<_Sseq>::value>::type
  465. seed(_Sseq& __q);
  466. /**
  467. * @brief Gets the smallest possible value in the output range.
  468. */
  469. static constexpr result_type
  470. min()
  471. { return 0; };
  472. /**
  473. * @brief Gets the largest possible value in the output range.
  474. */
  475. static constexpr result_type
  476. max()
  477. { return __detail::_Shift<_UIntType, __w>::__value - 1; }
  478. /**
  479. * @brief Discard a sequence of random numbers.
  480. */
  481. void
  482. discard(unsigned long long __z);
  483. result_type
  484. operator()();
  485. /**
  486. * @brief Compares two % mersenne_twister_engine random number generator
  487. * objects of the same type for equality.
  488. *
  489. * @param __lhs A % mersenne_twister_engine random number generator
  490. * object.
  491. * @param __rhs Another % mersenne_twister_engine random number
  492. * generator object.
  493. *
  494. * @returns true if the infinite sequences of generated values
  495. * would be equal, false otherwise.
  496. */
  497. friend bool
  498. operator==(const mersenne_twister_engine& __lhs,
  499. const mersenne_twister_engine& __rhs)
  500. { return (std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x)
  501. && __lhs._M_p == __rhs._M_p); }
  502. /**
  503. * @brief Inserts the current state of a % mersenne_twister_engine
  504. * random number generator engine @p __x into the output stream
  505. * @p __os.
  506. *
  507. * @param __os An output stream.
  508. * @param __x A % mersenne_twister_engine random number generator
  509. * engine.
  510. *
  511. * @returns The output stream with the state of @p __x inserted or in
  512. * an error state.
  513. */
  514. template<typename _UIntType1,
  515. size_t __w1, size_t __n1,
  516. size_t __m1, size_t __r1,
  517. _UIntType1 __a1, size_t __u1,
  518. _UIntType1 __d1, size_t __s1,
  519. _UIntType1 __b1, size_t __t1,
  520. _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
  521. typename _CharT, typename _Traits>
  522. friend std::basic_ostream<_CharT, _Traits>&
  523. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  524. const std::mersenne_twister_engine<_UIntType1, __w1, __n1,
  525. __m1, __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
  526. __l1, __f1>& __x);
  527. /**
  528. * @brief Extracts the current state of a % mersenne_twister_engine
  529. * random number generator engine @p __x from the input stream
  530. * @p __is.
  531. *
  532. * @param __is An input stream.
  533. * @param __x A % mersenne_twister_engine random number generator
  534. * engine.
  535. *
  536. * @returns The input stream with the state of @p __x extracted or in
  537. * an error state.
  538. */
  539. template<typename _UIntType1,
  540. size_t __w1, size_t __n1,
  541. size_t __m1, size_t __r1,
  542. _UIntType1 __a1, size_t __u1,
  543. _UIntType1 __d1, size_t __s1,
  544. _UIntType1 __b1, size_t __t1,
  545. _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
  546. typename _CharT, typename _Traits>
  547. friend std::basic_istream<_CharT, _Traits>&
  548. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  549. std::mersenne_twister_engine<_UIntType1, __w1, __n1, __m1,
  550. __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
  551. __l1, __f1>& __x);
  552. private:
  553. void _M_gen_rand();
  554. _UIntType _M_x[state_size];
  555. size_t _M_p;
  556. };
  557. /**
  558. * @brief Compares two % mersenne_twister_engine random number generator
  559. * objects of the same type for inequality.
  560. *
  561. * @param __lhs A % mersenne_twister_engine random number generator
  562. * object.
  563. * @param __rhs Another % mersenne_twister_engine random number
  564. * generator object.
  565. *
  566. * @returns true if the infinite sequences of generated values
  567. * would be different, false otherwise.
  568. */
  569. template<typename _UIntType, size_t __w,
  570. size_t __n, size_t __m, size_t __r,
  571. _UIntType __a, size_t __u, _UIntType __d, size_t __s,
  572. _UIntType __b, size_t __t,
  573. _UIntType __c, size_t __l, _UIntType __f>
  574. inline bool
  575. operator!=(const std::mersenne_twister_engine<_UIntType, __w, __n, __m,
  576. __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __lhs,
  577. const std::mersenne_twister_engine<_UIntType, __w, __n, __m,
  578. __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __rhs)
  579. { return !(__lhs == __rhs); }
  580. /**
  581. * @brief The Marsaglia-Zaman generator.
  582. *
  583. * This is a model of a Generalized Fibonacci discrete random number
  584. * generator, sometimes referred to as the SWC generator.
  585. *
  586. * A discrete random number generator that produces pseudorandom
  587. * numbers using:
  588. * @f[
  589. * x_{i}\leftarrow(x_{i - s} - x_{i - r} - carry_{i-1}) \bmod m
  590. * @f]
  591. *
  592. * The size of the state is @f$r@f$
  593. * and the maximum period of the generator is @f$(m^r - m^s - 1)@f$.
  594. */
  595. template<typename _UIntType, size_t __w, size_t __s, size_t __r>
  596. class subtract_with_carry_engine
  597. {
  598. static_assert(std::is_unsigned<_UIntType>::value, "template argument "
  599. "substituting _UIntType not an unsigned integral type");
  600. static_assert(0u < __s && __s < __r,
  601. "template argument substituting __s out of bounds");
  602. static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
  603. "template argument substituting __w out of bounds");
  604. public:
  605. /** The type of the generated random value. */
  606. typedef _UIntType result_type;
  607. // parameter values
  608. static constexpr size_t word_size = __w;
  609. static constexpr size_t short_lag = __s;
  610. static constexpr size_t long_lag = __r;
  611. static constexpr result_type default_seed = 19780503u;
  612. /**
  613. * @brief Constructs an explicitly seeded % subtract_with_carry_engine
  614. * random number generator.
  615. */
  616. explicit
  617. subtract_with_carry_engine(result_type __sd = default_seed)
  618. { seed(__sd); }
  619. /**
  620. * @brief Constructs a %subtract_with_carry_engine random number engine
  621. * seeded from the seed sequence @p __q.
  622. *
  623. * @param __q the seed sequence.
  624. */
  625. template<typename _Sseq, typename = typename
  626. std::enable_if<!std::is_same<_Sseq, subtract_with_carry_engine>::value>
  627. ::type>
  628. explicit
  629. subtract_with_carry_engine(_Sseq& __q)
  630. { seed(__q); }
  631. /**
  632. * @brief Seeds the initial state @f$x_0@f$ of the random number
  633. * generator.
  634. *
  635. * N1688[4.19] modifies this as follows. If @p __value == 0,
  636. * sets value to 19780503. In any case, with a linear
  637. * congruential generator lcg(i) having parameters @f$ m_{lcg} =
  638. * 2147483563, a_{lcg} = 40014, c_{lcg} = 0, and lcg(0) = value
  639. * @f$, sets @f$ x_{-r} \dots x_{-1} @f$ to @f$ lcg(1) \bmod m
  640. * \dots lcg(r) \bmod m @f$ respectively. If @f$ x_{-1} = 0 @f$
  641. * set carry to 1, otherwise sets carry to 0.
  642. */
  643. void
  644. seed(result_type __sd = default_seed);
  645. /**
  646. * @brief Seeds the initial state @f$x_0@f$ of the
  647. * % subtract_with_carry_engine random number generator.
  648. */
  649. template<typename _Sseq>
  650. typename std::enable_if<std::is_class<_Sseq>::value>::type
  651. seed(_Sseq& __q);
  652. /**
  653. * @brief Gets the inclusive minimum value of the range of random
  654. * integers returned by this generator.
  655. */
  656. static constexpr result_type
  657. min()
  658. { return 0; }
  659. /**
  660. * @brief Gets the inclusive maximum value of the range of random
  661. * integers returned by this generator.
  662. */
  663. static constexpr result_type
  664. max()
  665. { return __detail::_Shift<_UIntType, __w>::__value - 1; }
  666. /**
  667. * @brief Discard a sequence of random numbers.
  668. */
  669. void
  670. discard(unsigned long long __z)
  671. {
  672. for (; __z != 0ULL; --__z)
  673. (*this)();
  674. }
  675. /**
  676. * @brief Gets the next random number in the sequence.
  677. */
  678. result_type
  679. operator()();
  680. /**
  681. * @brief Compares two % subtract_with_carry_engine random number
  682. * generator objects of the same type for equality.
  683. *
  684. * @param __lhs A % subtract_with_carry_engine random number generator
  685. * object.
  686. * @param __rhs Another % subtract_with_carry_engine random number
  687. * generator object.
  688. *
  689. * @returns true if the infinite sequences of generated values
  690. * would be equal, false otherwise.
  691. */
  692. friend bool
  693. operator==(const subtract_with_carry_engine& __lhs,
  694. const subtract_with_carry_engine& __rhs)
  695. { return (std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x)
  696. && __lhs._M_carry == __rhs._M_carry
  697. && __lhs._M_p == __rhs._M_p); }
  698. /**
  699. * @brief Inserts the current state of a % subtract_with_carry_engine
  700. * random number generator engine @p __x into the output stream
  701. * @p __os.
  702. *
  703. * @param __os An output stream.
  704. * @param __x A % subtract_with_carry_engine random number generator
  705. * engine.
  706. *
  707. * @returns The output stream with the state of @p __x inserted or in
  708. * an error state.
  709. */
  710. template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
  711. typename _CharT, typename _Traits>
  712. friend std::basic_ostream<_CharT, _Traits>&
  713. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  714. const std::subtract_with_carry_engine<_UIntType1, __w1,
  715. __s1, __r1>& __x);
  716. /**
  717. * @brief Extracts the current state of a % subtract_with_carry_engine
  718. * random number generator engine @p __x from the input stream
  719. * @p __is.
  720. *
  721. * @param __is An input stream.
  722. * @param __x A % subtract_with_carry_engine random number generator
  723. * engine.
  724. *
  725. * @returns The input stream with the state of @p __x extracted or in
  726. * an error state.
  727. */
  728. template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
  729. typename _CharT, typename _Traits>
  730. friend std::basic_istream<_CharT, _Traits>&
  731. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  732. std::subtract_with_carry_engine<_UIntType1, __w1,
  733. __s1, __r1>& __x);
  734. private:
  735. /// The state of the generator. This is a ring buffer.
  736. _UIntType _M_x[long_lag];
  737. _UIntType _M_carry; ///< The carry
  738. size_t _M_p; ///< Current index of x(i - r).
  739. };
  740. /**
  741. * @brief Compares two % subtract_with_carry_engine random number
  742. * generator objects of the same type for inequality.
  743. *
  744. * @param __lhs A % subtract_with_carry_engine random number generator
  745. * object.
  746. * @param __rhs Another % subtract_with_carry_engine random number
  747. * generator object.
  748. *
  749. * @returns true if the infinite sequences of generated values
  750. * would be different, false otherwise.
  751. */
  752. template<typename _UIntType, size_t __w, size_t __s, size_t __r>
  753. inline bool
  754. operator!=(const std::subtract_with_carry_engine<_UIntType, __w,
  755. __s, __r>& __lhs,
  756. const std::subtract_with_carry_engine<_UIntType, __w,
  757. __s, __r>& __rhs)
  758. { return !(__lhs == __rhs); }
  759. /**
  760. * Produces random numbers from some base engine by discarding blocks of
  761. * data.
  762. *
  763. * 0 <= @p __r <= @p __p
  764. */
  765. template<typename _RandomNumberEngine, size_t __p, size_t __r>
  766. class discard_block_engine
  767. {
  768. static_assert(1 <= __r && __r <= __p,
  769. "template argument substituting __r out of bounds");
  770. public:
  771. /** The type of the generated random value. */
  772. typedef typename _RandomNumberEngine::result_type result_type;
  773. // parameter values
  774. static constexpr size_t block_size = __p;
  775. static constexpr size_t used_block = __r;
  776. /**
  777. * @brief Constructs a default %discard_block_engine engine.
  778. *
  779. * The underlying engine is default constructed as well.
  780. */
  781. discard_block_engine()
  782. : _M_b(), _M_n(0) { }
  783. /**
  784. * @brief Copy constructs a %discard_block_engine engine.
  785. *
  786. * Copies an existing base class random number generator.
  787. * @param __rng An existing (base class) engine object.
  788. */
  789. explicit
  790. discard_block_engine(const _RandomNumberEngine& __rng)
  791. : _M_b(__rng), _M_n(0) { }
  792. /**
  793. * @brief Move constructs a %discard_block_engine engine.
  794. *
  795. * Copies an existing base class random number generator.
  796. * @param __rng An existing (base class) engine object.
  797. */
  798. explicit
  799. discard_block_engine(_RandomNumberEngine&& __rng)
  800. : _M_b(std::move(__rng)), _M_n(0) { }
  801. /**
  802. * @brief Seed constructs a %discard_block_engine engine.
  803. *
  804. * Constructs the underlying generator engine seeded with @p __s.
  805. * @param __s A seed value for the base class engine.
  806. */
  807. explicit
  808. discard_block_engine(result_type __s)
  809. : _M_b(__s), _M_n(0) { }
  810. /**
  811. * @brief Generator construct a %discard_block_engine engine.
  812. *
  813. * @param __q A seed sequence.
  814. */
  815. template<typename _Sseq, typename = typename
  816. std::enable_if<!std::is_same<_Sseq, discard_block_engine>::value
  817. && !std::is_same<_Sseq, _RandomNumberEngine>::value>
  818. ::type>
  819. explicit
  820. discard_block_engine(_Sseq& __q)
  821. : _M_b(__q), _M_n(0)
  822. { }
  823. /**
  824. * @brief Reseeds the %discard_block_engine object with the default
  825. * seed for the underlying base class generator engine.
  826. */
  827. void
  828. seed()
  829. {
  830. _M_b.seed();
  831. _M_n = 0;
  832. }
  833. /**
  834. * @brief Reseeds the %discard_block_engine object with the default
  835. * seed for the underlying base class generator engine.
  836. */
  837. void
  838. seed(result_type __s)
  839. {
  840. _M_b.seed(__s);
  841. _M_n = 0;
  842. }
  843. /**
  844. * @brief Reseeds the %discard_block_engine object with the given seed
  845. * sequence.
  846. * @param __q A seed generator function.
  847. */
  848. template<typename _Sseq>
  849. void
  850. seed(_Sseq& __q)
  851. {
  852. _M_b.seed(__q);
  853. _M_n = 0;
  854. }
  855. /**
  856. * @brief Gets a const reference to the underlying generator engine
  857. * object.
  858. */
  859. const _RandomNumberEngine&
  860. base() const noexcept
  861. { return _M_b; }
  862. /**
  863. * @brief Gets the minimum value in the generated random number range.
  864. */
  865. static constexpr result_type
  866. min()
  867. { return _RandomNumberEngine::min(); }
  868. /**
  869. * @brief Gets the maximum value in the generated random number range.
  870. */
  871. static constexpr result_type
  872. max()
  873. { return _RandomNumberEngine::max(); }
  874. /**
  875. * @brief Discard a sequence of random numbers.
  876. */
  877. void
  878. discard(unsigned long long __z)
  879. {
  880. for (; __z != 0ULL; --__z)
  881. (*this)();
  882. }
  883. /**
  884. * @brief Gets the next value in the generated random number sequence.
  885. */
  886. result_type
  887. operator()();
  888. /**
  889. * @brief Compares two %discard_block_engine random number generator
  890. * objects of the same type for equality.
  891. *
  892. * @param __lhs A %discard_block_engine random number generator object.
  893. * @param __rhs Another %discard_block_engine random number generator
  894. * object.
  895. *
  896. * @returns true if the infinite sequences of generated values
  897. * would be equal, false otherwise.
  898. */
  899. friend bool
  900. operator==(const discard_block_engine& __lhs,
  901. const discard_block_engine& __rhs)
  902. { return __lhs._M_b == __rhs._M_b && __lhs._M_n == __rhs._M_n; }
  903. /**
  904. * @brief Inserts the current state of a %discard_block_engine random
  905. * number generator engine @p __x into the output stream
  906. * @p __os.
  907. *
  908. * @param __os An output stream.
  909. * @param __x A %discard_block_engine random number generator engine.
  910. *
  911. * @returns The output stream with the state of @p __x inserted or in
  912. * an error state.
  913. */
  914. template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
  915. typename _CharT, typename _Traits>
  916. friend std::basic_ostream<_CharT, _Traits>&
  917. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  918. const std::discard_block_engine<_RandomNumberEngine1,
  919. __p1, __r1>& __x);
  920. /**
  921. * @brief Extracts the current state of a % subtract_with_carry_engine
  922. * random number generator engine @p __x from the input stream
  923. * @p __is.
  924. *
  925. * @param __is An input stream.
  926. * @param __x A %discard_block_engine random number generator engine.
  927. *
  928. * @returns The input stream with the state of @p __x extracted or in
  929. * an error state.
  930. */
  931. template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
  932. typename _CharT, typename _Traits>
  933. friend std::basic_istream<_CharT, _Traits>&
  934. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  935. std::discard_block_engine<_RandomNumberEngine1,
  936. __p1, __r1>& __x);
  937. private:
  938. _RandomNumberEngine _M_b;
  939. size_t _M_n;
  940. };
  941. /**
  942. * @brief Compares two %discard_block_engine random number generator
  943. * objects of the same type for inequality.
  944. *
  945. * @param __lhs A %discard_block_engine random number generator object.
  946. * @param __rhs Another %discard_block_engine random number generator
  947. * object.
  948. *
  949. * @returns true if the infinite sequences of generated values
  950. * would be different, false otherwise.
  951. */
  952. template<typename _RandomNumberEngine, size_t __p, size_t __r>
  953. inline bool
  954. operator!=(const std::discard_block_engine<_RandomNumberEngine, __p,
  955. __r>& __lhs,
  956. const std::discard_block_engine<_RandomNumberEngine, __p,
  957. __r>& __rhs)
  958. { return !(__lhs == __rhs); }
  959. /**
  960. * Produces random numbers by combining random numbers from some base
  961. * engine to produce random numbers with a specifies number of bits @p __w.
  962. */
  963. template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
  964. class independent_bits_engine
  965. {
  966. static_assert(std::is_unsigned<_UIntType>::value, "template argument "
  967. "substituting _UIntType not an unsigned integral type");
  968. static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
  969. "template argument substituting __w out of bounds");
  970. public:
  971. /** The type of the generated random value. */
  972. typedef _UIntType result_type;
  973. /**
  974. * @brief Constructs a default %independent_bits_engine engine.
  975. *
  976. * The underlying engine is default constructed as well.
  977. */
  978. independent_bits_engine()
  979. : _M_b() { }
  980. /**
  981. * @brief Copy constructs a %independent_bits_engine engine.
  982. *
  983. * Copies an existing base class random number generator.
  984. * @param __rng An existing (base class) engine object.
  985. */
  986. explicit
  987. independent_bits_engine(const _RandomNumberEngine& __rng)
  988. : _M_b(__rng) { }
  989. /**
  990. * @brief Move constructs a %independent_bits_engine engine.
  991. *
  992. * Copies an existing base class random number generator.
  993. * @param __rng An existing (base class) engine object.
  994. */
  995. explicit
  996. independent_bits_engine(_RandomNumberEngine&& __rng)
  997. : _M_b(std::move(__rng)) { }
  998. /**
  999. * @brief Seed constructs a %independent_bits_engine engine.
  1000. *
  1001. * Constructs the underlying generator engine seeded with @p __s.
  1002. * @param __s A seed value for the base class engine.
  1003. */
  1004. explicit
  1005. independent_bits_engine(result_type __s)
  1006. : _M_b(__s) { }
  1007. /**
  1008. * @brief Generator construct a %independent_bits_engine engine.
  1009. *
  1010. * @param __q A seed sequence.
  1011. */
  1012. template<typename _Sseq, typename = typename
  1013. std::enable_if<!std::is_same<_Sseq, independent_bits_engine>::value
  1014. && !std::is_same<_Sseq, _RandomNumberEngine>::value>
  1015. ::type>
  1016. explicit
  1017. independent_bits_engine(_Sseq& __q)
  1018. : _M_b(__q)
  1019. { }
  1020. /**
  1021. * @brief Reseeds the %independent_bits_engine object with the default
  1022. * seed for the underlying base class generator engine.
  1023. */
  1024. void
  1025. seed()
  1026. { _M_b.seed(); }
  1027. /**
  1028. * @brief Reseeds the %independent_bits_engine object with the default
  1029. * seed for the underlying base class generator engine.
  1030. */
  1031. void
  1032. seed(result_type __s)
  1033. { _M_b.seed(__s); }
  1034. /**
  1035. * @brief Reseeds the %independent_bits_engine object with the given
  1036. * seed sequence.
  1037. * @param __q A seed generator function.
  1038. */
  1039. template<typename _Sseq>
  1040. void
  1041. seed(_Sseq& __q)
  1042. { _M_b.seed(__q); }
  1043. /**
  1044. * @brief Gets a const reference to the underlying generator engine
  1045. * object.
  1046. */
  1047. const _RandomNumberEngine&
  1048. base() const noexcept
  1049. { return _M_b; }
  1050. /**
  1051. * @brief Gets the minimum value in the generated random number range.
  1052. */
  1053. static constexpr result_type
  1054. min()
  1055. { return 0U; }
  1056. /**
  1057. * @brief Gets the maximum value in the generated random number range.
  1058. */
  1059. static constexpr result_type
  1060. max()
  1061. { return __detail::_Shift<_UIntType, __w>::__value - 1; }
  1062. /**
  1063. * @brief Discard a sequence of random numbers.
  1064. */
  1065. void
  1066. discard(unsigned long long __z)
  1067. {
  1068. for (; __z != 0ULL; --__z)
  1069. (*this)();
  1070. }
  1071. /**
  1072. * @brief Gets the next value in the generated random number sequence.
  1073. */
  1074. result_type
  1075. operator()();
  1076. /**
  1077. * @brief Compares two %independent_bits_engine random number generator
  1078. * objects of the same type for equality.
  1079. *
  1080. * @param __lhs A %independent_bits_engine random number generator
  1081. * object.
  1082. * @param __rhs Another %independent_bits_engine random number generator
  1083. * object.
  1084. *
  1085. * @returns true if the infinite sequences of generated values
  1086. * would be equal, false otherwise.
  1087. */
  1088. friend bool
  1089. operator==(const independent_bits_engine& __lhs,
  1090. const independent_bits_engine& __rhs)
  1091. { return __lhs._M_b == __rhs._M_b; }
  1092. /**
  1093. * @brief Extracts the current state of a % subtract_with_carry_engine
  1094. * random number generator engine @p __x from the input stream
  1095. * @p __is.
  1096. *
  1097. * @param __is An input stream.
  1098. * @param __x A %independent_bits_engine random number generator
  1099. * engine.
  1100. *
  1101. * @returns The input stream with the state of @p __x extracted or in
  1102. * an error state.
  1103. */
  1104. template<typename _CharT, typename _Traits>
  1105. friend std::basic_istream<_CharT, _Traits>&
  1106. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  1107. std::independent_bits_engine<_RandomNumberEngine,
  1108. __w, _UIntType>& __x)
  1109. {
  1110. __is >> __x._M_b;
  1111. return __is;
  1112. }
  1113. private:
  1114. _RandomNumberEngine _M_b;
  1115. };
  1116. /**
  1117. * @brief Compares two %independent_bits_engine random number generator
  1118. * objects of the same type for inequality.
  1119. *
  1120. * @param __lhs A %independent_bits_engine random number generator
  1121. * object.
  1122. * @param __rhs Another %independent_bits_engine random number generator
  1123. * object.
  1124. *
  1125. * @returns true if the infinite sequences of generated values
  1126. * would be different, false otherwise.
  1127. */
  1128. template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
  1129. inline bool
  1130. operator!=(const std::independent_bits_engine<_RandomNumberEngine, __w,
  1131. _UIntType>& __lhs,
  1132. const std::independent_bits_engine<_RandomNumberEngine, __w,
  1133. _UIntType>& __rhs)
  1134. { return !(__lhs == __rhs); }
  1135. /**
  1136. * @brief Inserts the current state of a %independent_bits_engine random
  1137. * number generator engine @p __x into the output stream @p __os.
  1138. *
  1139. * @param __os An output stream.
  1140. * @param __x A %independent_bits_engine random number generator engine.
  1141. *
  1142. * @returns The output stream with the state of @p __x inserted or in
  1143. * an error state.
  1144. */
  1145. template<typename _RandomNumberEngine, size_t __w, typename _UIntType,
  1146. typename _CharT, typename _Traits>
  1147. std::basic_ostream<_CharT, _Traits>&
  1148. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  1149. const std::independent_bits_engine<_RandomNumberEngine,
  1150. __w, _UIntType>& __x)
  1151. {
  1152. __os << __x.base();
  1153. return __os;
  1154. }
  1155. /**
  1156. * @brief Produces random numbers by combining random numbers from some
  1157. * base engine to produce random numbers with a specifies number of bits
  1158. * @p __w.
  1159. */
  1160. template<typename _RandomNumberEngine, size_t __k>
  1161. class shuffle_order_engine
  1162. {
  1163. static_assert(1u <= __k, "template argument substituting "
  1164. "__k out of bound");
  1165. public:
  1166. /** The type of the generated random value. */
  1167. typedef typename _RandomNumberEngine::result_type result_type;
  1168. static constexpr size_t table_size = __k;
  1169. /**
  1170. * @brief Constructs a default %shuffle_order_engine engine.
  1171. *
  1172. * The underlying engine is default constructed as well.
  1173. */
  1174. shuffle_order_engine()
  1175. : _M_b()
  1176. { _M_initialize(); }
  1177. /**
  1178. * @brief Copy constructs a %shuffle_order_engine engine.
  1179. *
  1180. * Copies an existing base class random number generator.
  1181. * @param __rng An existing (base class) engine object.
  1182. */
  1183. explicit
  1184. shuffle_order_engine(const _RandomNumberEngine& __rng)
  1185. : _M_b(__rng)
  1186. { _M_initialize(); }
  1187. /**
  1188. * @brief Move constructs a %shuffle_order_engine engine.
  1189. *
  1190. * Copies an existing base class random number generator.
  1191. * @param __rng An existing (base class) engine object.
  1192. */
  1193. explicit
  1194. shuffle_order_engine(_RandomNumberEngine&& __rng)
  1195. : _M_b(std::move(__rng))
  1196. { _M_initialize(); }
  1197. /**
  1198. * @brief Seed constructs a %shuffle_order_engine engine.
  1199. *
  1200. * Constructs the underlying generator engine seeded with @p __s.
  1201. * @param __s A seed value for the base class engine.
  1202. */
  1203. explicit
  1204. shuffle_order_engine(result_type __s)
  1205. : _M_b(__s)
  1206. { _M_initialize(); }
  1207. /**
  1208. * @brief Generator construct a %shuffle_order_engine engine.
  1209. *
  1210. * @param __q A seed sequence.
  1211. */
  1212. template<typename _Sseq, typename = typename
  1213. std::enable_if<!std::is_same<_Sseq, shuffle_order_engine>::value
  1214. && !std::is_same<_Sseq, _RandomNumberEngine>::value>
  1215. ::type>
  1216. explicit
  1217. shuffle_order_engine(_Sseq& __q)
  1218. : _M_b(__q)
  1219. { _M_initialize(); }
  1220. /**
  1221. * @brief Reseeds the %shuffle_order_engine object with the default seed
  1222. for the underlying base class generator engine.
  1223. */
  1224. void
  1225. seed()
  1226. {
  1227. _M_b.seed();
  1228. _M_initialize();
  1229. }
  1230. /**
  1231. * @brief Reseeds the %shuffle_order_engine object with the default seed
  1232. * for the underlying base class generator engine.
  1233. */
  1234. void
  1235. seed(result_type __s)
  1236. {
  1237. _M_b.seed(__s);
  1238. _M_initialize();
  1239. }
  1240. /**
  1241. * @brief Reseeds the %shuffle_order_engine object with the given seed
  1242. * sequence.
  1243. * @param __q A seed generator function.
  1244. */
  1245. template<typename _Sseq>
  1246. void
  1247. seed(_Sseq& __q)
  1248. {
  1249. _M_b.seed(__q);
  1250. _M_initialize();
  1251. }
  1252. /**
  1253. * Gets a const reference to the underlying generator engine object.
  1254. */
  1255. const _RandomNumberEngine&
  1256. base() const noexcept
  1257. { return _M_b; }
  1258. /**
  1259. * Gets the minimum value in the generated random number range.
  1260. */
  1261. static constexpr result_type
  1262. min()
  1263. { return _RandomNumberEngine::min(); }
  1264. /**
  1265. * Gets the maximum value in the generated random number range.
  1266. */
  1267. static constexpr result_type
  1268. max()
  1269. { return _RandomNumberEngine::max(); }
  1270. /**
  1271. * Discard a sequence of random numbers.
  1272. */
  1273. void
  1274. discard(unsigned long long __z)
  1275. {
  1276. for (; __z != 0ULL; --__z)
  1277. (*this)();
  1278. }
  1279. /**
  1280. * Gets the next value in the generated random number sequence.
  1281. */
  1282. result_type
  1283. operator()();
  1284. /**
  1285. * Compares two %shuffle_order_engine random number generator objects
  1286. * of the same type for equality.
  1287. *
  1288. * @param __lhs A %shuffle_order_engine random number generator object.
  1289. * @param __rhs Another %shuffle_order_engine random number generator
  1290. * object.
  1291. *
  1292. * @returns true if the infinite sequences of generated values
  1293. * would be equal, false otherwise.
  1294. */
  1295. friend bool
  1296. operator==(const shuffle_order_engine& __lhs,
  1297. const shuffle_order_engine& __rhs)
  1298. { return (__lhs._M_b == __rhs._M_b
  1299. && std::equal(__lhs._M_v, __lhs._M_v + __k, __rhs._M_v)
  1300. && __lhs._M_y == __rhs._M_y); }
  1301. /**
  1302. * @brief Inserts the current state of a %shuffle_order_engine random
  1303. * number generator engine @p __x into the output stream
  1304. @p __os.
  1305. *
  1306. * @param __os An output stream.
  1307. * @param __x A %shuffle_order_engine random number generator engine.
  1308. *
  1309. * @returns The output stream with the state of @p __x inserted or in
  1310. * an error state.
  1311. */
  1312. template<typename _RandomNumberEngine1, size_t __k1,
  1313. typename _CharT, typename _Traits>
  1314. friend std::basic_ostream<_CharT, _Traits>&
  1315. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  1316. const std::shuffle_order_engine<_RandomNumberEngine1,
  1317. __k1>& __x);
  1318. /**
  1319. * @brief Extracts the current state of a % subtract_with_carry_engine
  1320. * random number generator engine @p __x from the input stream
  1321. * @p __is.
  1322. *
  1323. * @param __is An input stream.
  1324. * @param __x A %shuffle_order_engine random number generator engine.
  1325. *
  1326. * @returns The input stream with the state of @p __x extracted or in
  1327. * an error state.
  1328. */
  1329. template<typename _RandomNumberEngine1, size_t __k1,
  1330. typename _CharT, typename _Traits>
  1331. friend std::basic_istream<_CharT, _Traits>&
  1332. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  1333. std::shuffle_order_engine<_RandomNumberEngine1, __k1>& __x);
  1334. private:
  1335. void _M_initialize()
  1336. {
  1337. for (size_t __i = 0; __i < __k; ++__i)
  1338. _M_v[__i] = _M_b();
  1339. _M_y = _M_b();
  1340. }
  1341. _RandomNumberEngine _M_b;
  1342. result_type _M_v[__k];
  1343. result_type _M_y;
  1344. };
  1345. /**
  1346. * Compares two %shuffle_order_engine random number generator objects
  1347. * of the same type for inequality.
  1348. *
  1349. * @param __lhs A %shuffle_order_engine random number generator object.
  1350. * @param __rhs Another %shuffle_order_engine random number generator
  1351. * object.
  1352. *
  1353. * @returns true if the infinite sequences of generated values
  1354. * would be different, false otherwise.
  1355. */
  1356. template<typename _RandomNumberEngine, size_t __k>
  1357. inline bool
  1358. operator!=(const std::shuffle_order_engine<_RandomNumberEngine,
  1359. __k>& __lhs,
  1360. const std::shuffle_order_engine<_RandomNumberEngine,
  1361. __k>& __rhs)
  1362. { return !(__lhs == __rhs); }
  1363. /**
  1364. * The classic Minimum Standard rand0 of Lewis, Goodman, and Miller.
  1365. */
  1366. typedef linear_congruential_engine<uint_fast32_t, 16807UL, 0UL, 2147483647UL>
  1367. minstd_rand0;
  1368. /**
  1369. * An alternative LCR (Lehmer Generator function).
  1370. */
  1371. typedef linear_congruential_engine<uint_fast32_t, 48271UL, 0UL, 2147483647UL>
  1372. minstd_rand;
  1373. /**
  1374. * The classic Mersenne Twister.
  1375. *
  1376. * Reference:
  1377. * M. Matsumoto and T. Nishimura, Mersenne Twister: A 623-Dimensionally
  1378. * Equidistributed Uniform Pseudo-Random Number Generator, ACM Transactions
  1379. * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.
  1380. */
  1381. typedef mersenne_twister_engine<
  1382. uint_fast32_t,
  1383. 32, 624, 397, 31,
  1384. 0x9908b0dfUL, 11,
  1385. 0xffffffffUL, 7,
  1386. 0x9d2c5680UL, 15,
  1387. 0xefc60000UL, 18, 1812433253UL> mt19937;
  1388. /**
  1389. * An alternative Mersenne Twister.
  1390. */
  1391. typedef mersenne_twister_engine<
  1392. uint_fast64_t,
  1393. 64, 312, 156, 31,
  1394. 0xb5026f5aa96619e9ULL, 29,
  1395. 0x5555555555555555ULL, 17,
  1396. 0x71d67fffeda60000ULL, 37,
  1397. 0xfff7eee000000000ULL, 43,
  1398. 6364136223846793005ULL> mt19937_64;
  1399. typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>
  1400. ranlux24_base;
  1401. typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>
  1402. ranlux48_base;
  1403. typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24;
  1404. typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48;
  1405. typedef shuffle_order_engine<minstd_rand0, 256> knuth_b;
  1406. typedef minstd_rand0 default_random_engine;
  1407. /**
  1408. * A standard interface to a platform-specific non-deterministic
  1409. * random number generator (if any are available).
  1410. */
  1411. class random_device
  1412. {
  1413. public:
  1414. /** The type of the generated random value. */
  1415. typedef unsigned int result_type;
  1416. // constructors, destructors and member functions
  1417. #ifdef _GLIBCXX_USE_RANDOM_TR1
  1418. explicit
  1419. random_device(const std::string& __token = "default")
  1420. {
  1421. _M_init(__token);
  1422. }
  1423. ~random_device()
  1424. { _M_fini(); }
  1425. #else
  1426. explicit
  1427. random_device(const std::string& __token = "mt19937")
  1428. { _M_init_pretr1(__token); }
  1429. public:
  1430. #endif
  1431. static constexpr result_type
  1432. min()
  1433. { return std::numeric_limits<result_type>::min(); }
  1434. static constexpr result_type
  1435. max()
  1436. { return std::numeric_limits<result_type>::max(); }
  1437. double
  1438. entropy() const noexcept
  1439. { return 0.0; }
  1440. result_type
  1441. operator()()
  1442. {
  1443. #ifdef _GLIBCXX_USE_RANDOM_TR1
  1444. return this->_M_getval();
  1445. #else
  1446. return this->_M_getval_pretr1();
  1447. #endif
  1448. }
  1449. // No copy functions.
  1450. random_device(const random_device&) = delete;
  1451. void operator=(const random_device&) = delete;
  1452. private:
  1453. void _M_init(const std::string& __token);
  1454. void _M_init_pretr1(const std::string& __token);
  1455. void _M_fini();
  1456. result_type _M_getval();
  1457. result_type _M_getval_pretr1();
  1458. union
  1459. {
  1460. void* _M_file;
  1461. mt19937 _M_mt;
  1462. };
  1463. };
  1464. /* @} */ // group random_generators
  1465. /**
  1466. * @addtogroup random_distributions Random Number Distributions
  1467. * @ingroup random
  1468. * @{
  1469. */
  1470. /**
  1471. * @addtogroup random_distributions_uniform Uniform Distributions
  1472. * @ingroup random_distributions
  1473. * @{
  1474. */
  1475. /**
  1476. * @brief Uniform discrete distribution for random numbers.
  1477. * A discrete random distribution on the range @f$[min, max]@f$ with equal
  1478. * probability throughout the range.
  1479. */
  1480. template<typename _IntType = int>
  1481. class uniform_int_distribution
  1482. {
  1483. static_assert(std::is_integral<_IntType>::value,
  1484. "template argument not an integral type");
  1485. public:
  1486. /** The type of the range of the distribution. */
  1487. typedef _IntType result_type;
  1488. /** Parameter type. */
  1489. struct param_type
  1490. {
  1491. typedef uniform_int_distribution<_IntType> distribution_type;
  1492. explicit
  1493. param_type(_IntType __a = 0,
  1494. _IntType __b = std::numeric_limits<_IntType>::max())
  1495. : _M_a(__a), _M_b(__b)
  1496. {
  1497. _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b);
  1498. }
  1499. result_type
  1500. a() const
  1501. { return _M_a; }
  1502. result_type
  1503. b() const
  1504. { return _M_b; }
  1505. friend bool
  1506. operator==(const param_type& __p1, const param_type& __p2)
  1507. { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
  1508. private:
  1509. _IntType _M_a;
  1510. _IntType _M_b;
  1511. };
  1512. public:
  1513. /**
  1514. * @brief Constructs a uniform distribution object.
  1515. */
  1516. explicit
  1517. uniform_int_distribution(_IntType __a = 0,
  1518. _IntType __b = std::numeric_limits<_IntType>::max())
  1519. : _M_param(__a, __b)
  1520. { }
  1521. explicit
  1522. uniform_int_distribution(const param_type& __p)
  1523. : _M_param(__p)
  1524. { }
  1525. /**
  1526. * @brief Resets the distribution state.
  1527. *
  1528. * Does nothing for the uniform integer distribution.
  1529. */
  1530. void
  1531. reset() { }
  1532. result_type
  1533. a() const
  1534. { return _M_param.a(); }
  1535. result_type
  1536. b() const
  1537. { return _M_param.b(); }
  1538. /**
  1539. * @brief Returns the parameter set of the distribution.
  1540. */
  1541. param_type
  1542. param() const
  1543. { return _M_param; }
  1544. /**
  1545. * @brief Sets the parameter set of the distribution.
  1546. * @param __param The new parameter set of the distribution.
  1547. */
  1548. void
  1549. param(const param_type& __param)
  1550. { _M_param = __param; }
  1551. /**
  1552. * @brief Returns the inclusive lower bound of the distribution range.
  1553. */
  1554. result_type
  1555. min() const
  1556. { return this->a(); }
  1557. /**
  1558. * @brief Returns the inclusive upper bound of the distribution range.
  1559. */
  1560. result_type
  1561. max() const
  1562. { return this->b(); }
  1563. /**
  1564. * @brief Generating functions.
  1565. */
  1566. template<typename _UniformRandomNumberGenerator>
  1567. result_type
  1568. operator()(_UniformRandomNumberGenerator& __urng)
  1569. { return this->operator()(__urng, _M_param); }
  1570. template<typename _UniformRandomNumberGenerator>
  1571. result_type
  1572. operator()(_UniformRandomNumberGenerator& __urng,
  1573. const param_type& __p);
  1574. template<typename _ForwardIterator,
  1575. typename _UniformRandomNumberGenerator>
  1576. void
  1577. __generate(_ForwardIterator __f, _ForwardIterator __t,
  1578. _UniformRandomNumberGenerator& __urng)
  1579. { this->__generate(__f, __t, __urng, _M_param); }
  1580. template<typename _ForwardIterator,
  1581. typename _UniformRandomNumberGenerator>
  1582. void
  1583. __generate(_ForwardIterator __f, _ForwardIterator __t,
  1584. _UniformRandomNumberGenerator& __urng,
  1585. const param_type& __p)
  1586. { this->__generate_impl(__f, __t, __urng, __p); }
  1587. template<typename _UniformRandomNumberGenerator>
  1588. void
  1589. __generate(result_type* __f, result_type* __t,
  1590. _UniformRandomNumberGenerator& __urng,
  1591. const param_type& __p)
  1592. { this->__generate_impl(__f, __t, __urng, __p); }
  1593. /**
  1594. * @brief Return true if two uniform integer distributions have
  1595. * the same parameters.
  1596. */
  1597. friend bool
  1598. operator==(const uniform_int_distribution& __d1,
  1599. const uniform_int_distribution& __d2)
  1600. { return __d1._M_param == __d2._M_param; }
  1601. private:
  1602. template<typename _ForwardIterator,
  1603. typename _UniformRandomNumberGenerator>
  1604. void
  1605. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  1606. _UniformRandomNumberGenerator& __urng,
  1607. const param_type& __p);
  1608. param_type _M_param;
  1609. };
  1610. /**
  1611. * @brief Return true if two uniform integer distributions have
  1612. * different parameters.
  1613. */
  1614. template<typename _IntType>
  1615. inline bool
  1616. operator!=(const std::uniform_int_distribution<_IntType>& __d1,
  1617. const std::uniform_int_distribution<_IntType>& __d2)
  1618. { return !(__d1 == __d2); }
  1619. /**
  1620. * @brief Inserts a %uniform_int_distribution random number
  1621. * distribution @p __x into the output stream @p os.
  1622. *
  1623. * @param __os An output stream.
  1624. * @param __x A %uniform_int_distribution random number distribution.
  1625. *
  1626. * @returns The output stream with the state of @p __x inserted or in
  1627. * an error state.
  1628. */
  1629. template<typename _IntType, typename _CharT, typename _Traits>
  1630. std::basic_ostream<_CharT, _Traits>&
  1631. operator<<(std::basic_ostream<_CharT, _Traits>&,
  1632. const std::uniform_int_distribution<_IntType>&);
  1633. /**
  1634. * @brief Extracts a %uniform_int_distribution random number distribution
  1635. * @p __x from the input stream @p __is.
  1636. *
  1637. * @param __is An input stream.
  1638. * @param __x A %uniform_int_distribution random number generator engine.
  1639. *
  1640. * @returns The input stream with @p __x extracted or in an error state.
  1641. */
  1642. template<typename _IntType, typename _CharT, typename _Traits>
  1643. std::basic_istream<_CharT, _Traits>&
  1644. operator>>(std::basic_istream<_CharT, _Traits>&,
  1645. std::uniform_int_distribution<_IntType>&);
  1646. /**
  1647. * @brief Uniform continuous distribution for random numbers.
  1648. *
  1649. * A continuous random distribution on the range [min, max) with equal
  1650. * probability throughout the range. The URNG should be real-valued and
  1651. * deliver number in the range [0, 1).
  1652. */
  1653. template<typename _RealType = double>
  1654. class uniform_real_distribution
  1655. {
  1656. static_assert(std::is_floating_point<_RealType>::value,
  1657. "template argument not a floating point type");
  1658. public:
  1659. /** The type of the range of the distribution. */
  1660. typedef _RealType result_type;
  1661. /** Parameter type. */
  1662. struct param_type
  1663. {
  1664. typedef uniform_real_distribution<_RealType> distribution_type;
  1665. explicit
  1666. param_type(_RealType __a = _RealType(0),
  1667. _RealType __b = _RealType(1))
  1668. : _M_a(__a), _M_b(__b)
  1669. {
  1670. _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b);
  1671. }
  1672. result_type
  1673. a() const
  1674. { return _M_a; }
  1675. result_type
  1676. b() const
  1677. { return _M_b; }
  1678. friend bool
  1679. operator==(const param_type& __p1, const param_type& __p2)
  1680. { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
  1681. private:
  1682. _RealType _M_a;
  1683. _RealType _M_b;
  1684. };
  1685. public:
  1686. /**
  1687. * @brief Constructs a uniform_real_distribution object.
  1688. *
  1689. * @param __a [IN] The lower bound of the distribution.
  1690. * @param __b [IN] The upper bound of the distribution.
  1691. */
  1692. explicit
  1693. uniform_real_distribution(_RealType __a = _RealType(0),
  1694. _RealType __b = _RealType(1))
  1695. : _M_param(__a, __b)
  1696. { }
  1697. explicit
  1698. uniform_real_distribution(const param_type& __p)
  1699. : _M_param(__p)
  1700. { }
  1701. /**
  1702. * @brief Resets the distribution state.
  1703. *
  1704. * Does nothing for the uniform real distribution.
  1705. */
  1706. void
  1707. reset() { }
  1708. result_type
  1709. a() const
  1710. { return _M_param.a(); }
  1711. result_type
  1712. b() const
  1713. { return _M_param.b(); }
  1714. /**
  1715. * @brief Returns the parameter set of the distribution.
  1716. */
  1717. param_type
  1718. param() const
  1719. { return _M_param; }
  1720. /**
  1721. * @brief Sets the parameter set of the distribution.
  1722. * @param __param The new parameter set of the distribution.
  1723. */
  1724. void
  1725. param(const param_type& __param)
  1726. { _M_param = __param; }
  1727. /**
  1728. * @brief Returns the inclusive lower bound of the distribution range.
  1729. */
  1730. result_type
  1731. min() const
  1732. { return this->a(); }
  1733. /**
  1734. * @brief Returns the inclusive upper bound of the distribution range.
  1735. */
  1736. result_type
  1737. max() const
  1738. { return this->b(); }
  1739. /**
  1740. * @brief Generating functions.
  1741. */
  1742. template<typename _UniformRandomNumberGenerator>
  1743. result_type
  1744. operator()(_UniformRandomNumberGenerator& __urng)
  1745. { return this->operator()(__urng, _M_param); }
  1746. template<typename _UniformRandomNumberGenerator>
  1747. result_type
  1748. operator()(_UniformRandomNumberGenerator& __urng,
  1749. const param_type& __p)
  1750. {
  1751. __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
  1752. __aurng(__urng);
  1753. return (__aurng() * (__p.b() - __p.a())) + __p.a();
  1754. }
  1755. template<typename _ForwardIterator,
  1756. typename _UniformRandomNumberGenerator>
  1757. void
  1758. __generate(_ForwardIterator __f, _ForwardIterator __t,
  1759. _UniformRandomNumberGenerator& __urng)
  1760. { this->__generate(__f, __t, __urng, _M_param); }
  1761. template<typename _ForwardIterator,
  1762. typename _UniformRandomNumberGenerator>
  1763. void
  1764. __generate(_ForwardIterator __f, _ForwardIterator __t,
  1765. _UniformRandomNumberGenerator& __urng,
  1766. const param_type& __p)
  1767. { this->__generate_impl(__f, __t, __urng, __p); }
  1768. template<typename _UniformRandomNumberGenerator>
  1769. void
  1770. __generate(result_type* __f, result_type* __t,
  1771. _UniformRandomNumberGenerator& __urng,
  1772. const param_type& __p)
  1773. { this->__generate_impl(__f, __t, __urng, __p); }
  1774. /**
  1775. * @brief Return true if two uniform real distributions have
  1776. * the same parameters.
  1777. */
  1778. friend bool
  1779. operator==(const uniform_real_distribution& __d1,
  1780. const uniform_real_distribution& __d2)
  1781. { return __d1._M_param == __d2._M_param; }
  1782. private:
  1783. template<typename _ForwardIterator,
  1784. typename _UniformRandomNumberGenerator>
  1785. void
  1786. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  1787. _UniformRandomNumberGenerator& __urng,
  1788. const param_type& __p);
  1789. param_type _M_param;
  1790. };
  1791. /**
  1792. * @brief Return true if two uniform real distributions have
  1793. * different parameters.
  1794. */
  1795. template<typename _IntType>
  1796. inline bool
  1797. operator!=(const std::uniform_real_distribution<_IntType>& __d1,
  1798. const std::uniform_real_distribution<_IntType>& __d2)
  1799. { return !(__d1 == __d2); }
  1800. /**
  1801. * @brief Inserts a %uniform_real_distribution random number
  1802. * distribution @p __x into the output stream @p __os.
  1803. *
  1804. * @param __os An output stream.
  1805. * @param __x A %uniform_real_distribution random number distribution.
  1806. *
  1807. * @returns The output stream with the state of @p __x inserted or in
  1808. * an error state.
  1809. */
  1810. template<typename _RealType, typename _CharT, typename _Traits>
  1811. std::basic_ostream<_CharT, _Traits>&
  1812. operator<<(std::basic_ostream<_CharT, _Traits>&,
  1813. const std::uniform_real_distribution<_RealType>&);
  1814. /**
  1815. * @brief Extracts a %uniform_real_distribution random number distribution
  1816. * @p __x from the input stream @p __is.
  1817. *
  1818. * @param __is An input stream.
  1819. * @param __x A %uniform_real_distribution random number generator engine.
  1820. *
  1821. * @returns The input stream with @p __x extracted or in an error state.
  1822. */
  1823. template<typename _RealType, typename _CharT, typename _Traits>
  1824. std::basic_istream<_CharT, _Traits>&
  1825. operator>>(std::basic_istream<_CharT, _Traits>&,
  1826. std::uniform_real_distribution<_RealType>&);
  1827. /* @} */ // group random_distributions_uniform
  1828. /**
  1829. * @addtogroup random_distributions_normal Normal Distributions
  1830. * @ingroup random_distributions
  1831. * @{
  1832. */
  1833. /**
  1834. * @brief A normal continuous distribution for random numbers.
  1835. *
  1836. * The formula for the normal probability density function is
  1837. * @f[
  1838. * p(x|\mu,\sigma) = \frac{1}{\sigma \sqrt{2 \pi}}
  1839. * e^{- \frac{{x - \mu}^ {2}}{2 \sigma ^ {2}} }
  1840. * @f]
  1841. */
  1842. template<typename _RealType = double>
  1843. class normal_distribution
  1844. {
  1845. static_assert(std::is_floating_point<_RealType>::value,
  1846. "template argument not a floating point type");
  1847. public:
  1848. /** The type of the range of the distribution. */
  1849. typedef _RealType result_type;
  1850. /** Parameter type. */
  1851. struct param_type
  1852. {
  1853. typedef normal_distribution<_RealType> distribution_type;
  1854. explicit
  1855. param_type(_RealType __mean = _RealType(0),
  1856. _RealType __stddev = _RealType(1))
  1857. : _M_mean(__mean), _M_stddev(__stddev)
  1858. {
  1859. _GLIBCXX_DEBUG_ASSERT(_M_stddev > _RealType(0));
  1860. }
  1861. _RealType
  1862. mean() const
  1863. { return _M_mean; }
  1864. _RealType
  1865. stddev() const
  1866. { return _M_stddev; }
  1867. friend bool
  1868. operator==(const param_type& __p1, const param_type& __p2)
  1869. { return (__p1._M_mean == __p2._M_mean
  1870. && __p1._M_stddev == __p2._M_stddev); }
  1871. private:
  1872. _RealType _M_mean;
  1873. _RealType _M_stddev;
  1874. };
  1875. public:
  1876. /**
  1877. * Constructs a normal distribution with parameters @f$mean@f$ and
  1878. * standard deviation.
  1879. */
  1880. explicit
  1881. normal_distribution(result_type __mean = result_type(0),
  1882. result_type __stddev = result_type(1))
  1883. : _M_param(__mean, __stddev), _M_saved_available(false)
  1884. { }
  1885. explicit
  1886. normal_distribution(const param_type& __p)
  1887. : _M_param(__p), _M_saved_available(false)
  1888. { }
  1889. /**
  1890. * @brief Resets the distribution state.
  1891. */
  1892. void
  1893. reset()
  1894. { _M_saved_available = false; }
  1895. /**
  1896. * @brief Returns the mean of the distribution.
  1897. */
  1898. _RealType
  1899. mean() const
  1900. { return _M_param.mean(); }
  1901. /**
  1902. * @brief Returns the standard deviation of the distribution.
  1903. */
  1904. _RealType
  1905. stddev() const
  1906. { return _M_param.stddev(); }
  1907. /**
  1908. * @brief Returns the parameter set of the distribution.
  1909. */
  1910. param_type
  1911. param() const
  1912. { return _M_param; }
  1913. /**
  1914. * @brief Sets the parameter set of the distribution.
  1915. * @param __param The new parameter set of the distribution.
  1916. */
  1917. void
  1918. param(const param_type& __param)
  1919. { _M_param = __param; }
  1920. /**
  1921. * @brief Returns the greatest lower bound value of the distribution.
  1922. */
  1923. result_type
  1924. min() const
  1925. { return std::numeric_limits<result_type>::lowest(); }
  1926. /**
  1927. * @brief Returns the least upper bound value of the distribution.
  1928. */
  1929. result_type
  1930. max() const
  1931. { return std::numeric_limits<result_type>::max(); }
  1932. /**
  1933. * @brief Generating functions.
  1934. */
  1935. template<typename _UniformRandomNumberGenerator>
  1936. result_type
  1937. operator()(_UniformRandomNumberGenerator& __urng)
  1938. { return this->operator()(__urng, _M_param); }
  1939. template<typename _UniformRandomNumberGenerator>
  1940. result_type
  1941. operator()(_UniformRandomNumberGenerator& __urng,
  1942. const param_type& __p);
  1943. template<typename _ForwardIterator,
  1944. typename _UniformRandomNumberGenerator>
  1945. void
  1946. __generate(_ForwardIterator __f, _ForwardIterator __t,
  1947. _UniformRandomNumberGenerator& __urng)
  1948. { this->__generate(__f, __t, __urng, _M_param); }
  1949. template<typename _ForwardIterator,
  1950. typename _UniformRandomNumberGenerator>
  1951. void
  1952. __generate(_ForwardIterator __f, _ForwardIterator __t,
  1953. _UniformRandomNumberGenerator& __urng,
  1954. const param_type& __p)
  1955. { this->__generate_impl(__f, __t, __urng, __p); }
  1956. template<typename _UniformRandomNumberGenerator>
  1957. void
  1958. __generate(result_type* __f, result_type* __t,
  1959. _UniformRandomNumberGenerator& __urng,
  1960. const param_type& __p)
  1961. { this->__generate_impl(__f, __t, __urng, __p); }
  1962. /**
  1963. * @brief Return true if two normal distributions have
  1964. * the same parameters and the sequences that would
  1965. * be generated are equal.
  1966. */
  1967. template<typename _RealType1>
  1968. friend bool
  1969. operator==(const std::normal_distribution<_RealType1>& __d1,
  1970. const std::normal_distribution<_RealType1>& __d2);
  1971. /**
  1972. * @brief Inserts a %normal_distribution random number distribution
  1973. * @p __x into the output stream @p __os.
  1974. *
  1975. * @param __os An output stream.
  1976. * @param __x A %normal_distribution random number distribution.
  1977. *
  1978. * @returns The output stream with the state of @p __x inserted or in
  1979. * an error state.
  1980. */
  1981. template<typename _RealType1, typename _CharT, typename _Traits>
  1982. friend std::basic_ostream<_CharT, _Traits>&
  1983. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  1984. const std::normal_distribution<_RealType1>& __x);
  1985. /**
  1986. * @brief Extracts a %normal_distribution random number distribution
  1987. * @p __x from the input stream @p __is.
  1988. *
  1989. * @param __is An input stream.
  1990. * @param __x A %normal_distribution random number generator engine.
  1991. *
  1992. * @returns The input stream with @p __x extracted or in an error
  1993. * state.
  1994. */
  1995. template<typename _RealType1, typename _CharT, typename _Traits>
  1996. friend std::basic_istream<_CharT, _Traits>&
  1997. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  1998. std::normal_distribution<_RealType1>& __x);
  1999. private:
  2000. template<typename _ForwardIterator,
  2001. typename _UniformRandomNumberGenerator>
  2002. void
  2003. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  2004. _UniformRandomNumberGenerator& __urng,
  2005. const param_type& __p);
  2006. param_type _M_param;
  2007. result_type _M_saved;
  2008. bool _M_saved_available;
  2009. };
  2010. /**
  2011. * @brief Return true if two normal distributions are different.
  2012. */
  2013. template<typename _RealType>
  2014. inline bool
  2015. operator!=(const std::normal_distribution<_RealType>& __d1,
  2016. const std::normal_distribution<_RealType>& __d2)
  2017. { return !(__d1 == __d2); }
  2018. /**
  2019. * @brief A lognormal_distribution random number distribution.
  2020. *
  2021. * The formula for the normal probability mass function is
  2022. * @f[
  2023. * p(x|m,s) = \frac{1}{sx\sqrt{2\pi}}
  2024. * \exp{-\frac{(\ln{x} - m)^2}{2s^2}}
  2025. * @f]
  2026. */
  2027. template<typename _RealType = double>
  2028. class lognormal_distribution
  2029. {
  2030. static_assert(std::is_floating_point<_RealType>::value,
  2031. "template argument not a floating point type");
  2032. public:
  2033. /** The type of the range of the distribution. */
  2034. typedef _RealType result_type;
  2035. /** Parameter type. */
  2036. struct param_type
  2037. {
  2038. typedef lognormal_distribution<_RealType> distribution_type;
  2039. explicit
  2040. param_type(_RealType __m = _RealType(0),
  2041. _RealType __s = _RealType(1))
  2042. : _M_m(__m), _M_s(__s)
  2043. { }
  2044. _RealType
  2045. m() const
  2046. { return _M_m; }
  2047. _RealType
  2048. s() const
  2049. { return _M_s; }
  2050. friend bool
  2051. operator==(const param_type& __p1, const param_type& __p2)
  2052. { return __p1._M_m == __p2._M_m && __p1._M_s == __p2._M_s; }
  2053. private:
  2054. _RealType _M_m;
  2055. _RealType _M_s;
  2056. };
  2057. explicit
  2058. lognormal_distribution(_RealType __m = _RealType(0),
  2059. _RealType __s = _RealType(1))
  2060. : _M_param(__m, __s), _M_nd()
  2061. { }
  2062. explicit
  2063. lognormal_distribution(const param_type& __p)
  2064. : _M_param(__p), _M_nd()
  2065. { }
  2066. /**
  2067. * Resets the distribution state.
  2068. */
  2069. void
  2070. reset()
  2071. { _M_nd.reset(); }
  2072. /**
  2073. *
  2074. */
  2075. _RealType
  2076. m() const
  2077. { return _M_param.m(); }
  2078. _RealType
  2079. s() const
  2080. { return _M_param.s(); }
  2081. /**
  2082. * @brief Returns the parameter set of the distribution.
  2083. */
  2084. param_type
  2085. param() const
  2086. { return _M_param; }
  2087. /**
  2088. * @brief Sets the parameter set of the distribution.
  2089. * @param __param The new parameter set of the distribution.
  2090. */
  2091. void
  2092. param(const param_type& __param)
  2093. { _M_param = __param; }
  2094. /**
  2095. * @brief Returns the greatest lower bound value of the distribution.
  2096. */
  2097. result_type
  2098. min() const
  2099. { return result_type(0); }
  2100. /**
  2101. * @brief Returns the least upper bound value of the distribution.
  2102. */
  2103. result_type
  2104. max() const
  2105. { return std::numeric_limits<result_type>::max(); }
  2106. /**
  2107. * @brief Generating functions.
  2108. */
  2109. template<typename _UniformRandomNumberGenerator>
  2110. result_type
  2111. operator()(_UniformRandomNumberGenerator& __urng)
  2112. { return this->operator()(__urng, _M_param); }
  2113. template<typename _UniformRandomNumberGenerator>
  2114. result_type
  2115. operator()(_UniformRandomNumberGenerator& __urng,
  2116. const param_type& __p)
  2117. { return std::exp(__p.s() * _M_nd(__urng) + __p.m()); }
  2118. template<typename _ForwardIterator,
  2119. typename _UniformRandomNumberGenerator>
  2120. void
  2121. __generate(_ForwardIterator __f, _ForwardIterator __t,
  2122. _UniformRandomNumberGenerator& __urng)
  2123. { this->__generate(__f, __t, __urng, _M_param); }
  2124. template<typename _ForwardIterator,
  2125. typename _UniformRandomNumberGenerator>
  2126. void
  2127. __generate(_ForwardIterator __f, _ForwardIterator __t,
  2128. _UniformRandomNumberGenerator& __urng,
  2129. const param_type& __p)
  2130. { this->__generate_impl(__f, __t, __urng, __p); }
  2131. template<typename _UniformRandomNumberGenerator>
  2132. void
  2133. __generate(result_type* __f, result_type* __t,
  2134. _UniformRandomNumberGenerator& __urng,
  2135. const param_type& __p)
  2136. { this->__generate_impl(__f, __t, __urng, __p); }
  2137. /**
  2138. * @brief Return true if two lognormal distributions have
  2139. * the same parameters and the sequences that would
  2140. * be generated are equal.
  2141. */
  2142. friend bool
  2143. operator==(const lognormal_distribution& __d1,
  2144. const lognormal_distribution& __d2)
  2145. { return (__d1._M_param == __d2._M_param
  2146. && __d1._M_nd == __d2._M_nd); }
  2147. /**
  2148. * @brief Inserts a %lognormal_distribution random number distribution
  2149. * @p __x into the output stream @p __os.
  2150. *
  2151. * @param __os An output stream.
  2152. * @param __x A %lognormal_distribution random number distribution.
  2153. *
  2154. * @returns The output stream with the state of @p __x inserted or in
  2155. * an error state.
  2156. */
  2157. template<typename _RealType1, typename _CharT, typename _Traits>
  2158. friend std::basic_ostream<_CharT, _Traits>&
  2159. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  2160. const std::lognormal_distribution<_RealType1>& __x);
  2161. /**
  2162. * @brief Extracts a %lognormal_distribution random number distribution
  2163. * @p __x from the input stream @p __is.
  2164. *
  2165. * @param __is An input stream.
  2166. * @param __x A %lognormal_distribution random number
  2167. * generator engine.
  2168. *
  2169. * @returns The input stream with @p __x extracted or in an error state.
  2170. */
  2171. template<typename _RealType1, typename _CharT, typename _Traits>
  2172. friend std::basic_istream<_CharT, _Traits>&
  2173. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  2174. std::lognormal_distribution<_RealType1>& __x);
  2175. private:
  2176. template<typename _ForwardIterator,
  2177. typename _UniformRandomNumberGenerator>
  2178. void
  2179. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  2180. _UniformRandomNumberGenerator& __urng,
  2181. const param_type& __p);
  2182. param_type _M_param;
  2183. std::normal_distribution<result_type> _M_nd;
  2184. };
  2185. /**
  2186. * @brief Return true if two lognormal distributions are different.
  2187. */
  2188. template<typename _RealType>
  2189. inline bool
  2190. operator!=(const std::lognormal_distribution<_RealType>& __d1,
  2191. const std::lognormal_distribution<_RealType>& __d2)
  2192. { return !(__d1 == __d2); }
  2193. /**
  2194. * @brief A gamma continuous distribution for random numbers.
  2195. *
  2196. * The formula for the gamma probability density function is:
  2197. * @f[
  2198. * p(x|\alpha,\beta) = \frac{1}{\beta\Gamma(\alpha)}
  2199. * (x/\beta)^{\alpha - 1} e^{-x/\beta}
  2200. * @f]
  2201. */
  2202. template<typename _RealType = double>
  2203. class gamma_distribution
  2204. {
  2205. static_assert(std::is_floating_point<_RealType>::value,
  2206. "template argument not a floating point type");
  2207. public:
  2208. /** The type of the range of the distribution. */
  2209. typedef _RealType result_type;
  2210. /** Parameter type. */
  2211. struct param_type
  2212. {
  2213. typedef gamma_distribution<_RealType> distribution_type;
  2214. friend class gamma_distribution<_RealType>;
  2215. explicit
  2216. param_type(_RealType __alpha_val = _RealType(1),
  2217. _RealType __beta_val = _RealType(1))
  2218. : _M_alpha(__alpha_val), _M_beta(__beta_val)
  2219. {
  2220. _GLIBCXX_DEBUG_ASSERT(_M_alpha > _RealType(0));
  2221. _M_initialize();
  2222. }
  2223. _RealType
  2224. alpha() const
  2225. { return _M_alpha; }
  2226. _RealType
  2227. beta() const
  2228. { return _M_beta; }
  2229. friend bool
  2230. operator==(const param_type& __p1, const param_type& __p2)
  2231. { return (__p1._M_alpha == __p2._M_alpha
  2232. && __p1._M_beta == __p2._M_beta); }
  2233. private:
  2234. void
  2235. _M_initialize();
  2236. _RealType _M_alpha;
  2237. _RealType _M_beta;
  2238. _RealType _M_malpha, _M_a2;
  2239. };
  2240. public:
  2241. /**
  2242. * @brief Constructs a gamma distribution with parameters
  2243. * @f$\alpha@f$ and @f$\beta@f$.
  2244. */
  2245. explicit
  2246. gamma_distribution(_RealType __alpha_val = _RealType(1),
  2247. _RealType __beta_val = _RealType(1))
  2248. : _M_param(__alpha_val, __beta_val), _M_nd()
  2249. { }
  2250. explicit
  2251. gamma_distribution(const param_type& __p)
  2252. : _M_param(__p), _M_nd()
  2253. { }
  2254. /**
  2255. * @brief Resets the distribution state.
  2256. */
  2257. void
  2258. reset()
  2259. { _M_nd.reset(); }
  2260. /**
  2261. * @brief Returns the @f$\alpha@f$ of the distribution.
  2262. */
  2263. _RealType
  2264. alpha() const
  2265. { return _M_param.alpha(); }
  2266. /**
  2267. * @brief Returns the @f$\beta@f$ of the distribution.
  2268. */
  2269. _RealType
  2270. beta() const
  2271. { return _M_param.beta(); }
  2272. /**
  2273. * @brief Returns the parameter set of the distribution.
  2274. */
  2275. param_type
  2276. param() const
  2277. { return _M_param; }
  2278. /**
  2279. * @brief Sets the parameter set of the distribution.
  2280. * @param __param The new parameter set of the distribution.
  2281. */
  2282. void
  2283. param(const param_type& __param)
  2284. { _M_param = __param; }
  2285. /**
  2286. * @brief Returns the greatest lower bound value of the distribution.
  2287. */
  2288. result_type
  2289. min() const
  2290. { return result_type(0); }
  2291. /**
  2292. * @brief Returns the least upper bound value of the distribution.
  2293. */
  2294. result_type
  2295. max() const
  2296. { return std::numeric_limits<result_type>::max(); }
  2297. /**
  2298. * @brief Generating functions.
  2299. */
  2300. template<typename _UniformRandomNumberGenerator>
  2301. result_type
  2302. operator()(_UniformRandomNumberGenerator& __urng)
  2303. { return this->operator()(__urng, _M_param); }
  2304. template<typename _UniformRandomNumberGenerator>
  2305. result_type
  2306. operator()(_UniformRandomNumberGenerator& __urng,
  2307. const param_type& __p);
  2308. template<typename _ForwardIterator,
  2309. typename _UniformRandomNumberGenerator>
  2310. void
  2311. __generate(_ForwardIterator __f, _ForwardIterator __t,
  2312. _UniformRandomNumberGenerator& __urng)
  2313. { this->__generate(__f, __t, __urng, _M_param); }
  2314. template<typename _ForwardIterator,
  2315. typename _UniformRandomNumberGenerator>
  2316. void
  2317. __generate(_ForwardIterator __f, _ForwardIterator __t,
  2318. _UniformRandomNumberGenerator& __urng,
  2319. const param_type& __p)
  2320. { this->__generate_impl(__f, __t, __urng, __p); }
  2321. template<typename _UniformRandomNumberGenerator>
  2322. void
  2323. __generate(result_type* __f, result_type* __t,
  2324. _UniformRandomNumberGenerator& __urng,
  2325. const param_type& __p)
  2326. { this->__generate_impl(__f, __t, __urng, __p); }
  2327. /**
  2328. * @brief Return true if two gamma distributions have the same
  2329. * parameters and the sequences that would be generated
  2330. * are equal.
  2331. */
  2332. friend bool
  2333. operator==(const gamma_distribution& __d1,
  2334. const gamma_distribution& __d2)
  2335. { return (__d1._M_param == __d2._M_param
  2336. && __d1._M_nd == __d2._M_nd); }
  2337. /**
  2338. * @brief Inserts a %gamma_distribution random number distribution
  2339. * @p __x into the output stream @p __os.
  2340. *
  2341. * @param __os An output stream.
  2342. * @param __x A %gamma_distribution random number distribution.
  2343. *
  2344. * @returns The output stream with the state of @p __x inserted or in
  2345. * an error state.
  2346. */
  2347. template<typename _RealType1, typename _CharT, typename _Traits>
  2348. friend std::basic_ostream<_CharT, _Traits>&
  2349. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  2350. const std::gamma_distribution<_RealType1>& __x);
  2351. /**
  2352. * @brief Extracts a %gamma_distribution random number distribution
  2353. * @p __x from the input stream @p __is.
  2354. *
  2355. * @param __is An input stream.
  2356. * @param __x A %gamma_distribution random number generator engine.
  2357. *
  2358. * @returns The input stream with @p __x extracted or in an error state.
  2359. */
  2360. template<typename _RealType1, typename _CharT, typename _Traits>
  2361. friend std::basic_istream<_CharT, _Traits>&
  2362. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  2363. std::gamma_distribution<_RealType1>& __x);
  2364. private:
  2365. template<typename _ForwardIterator,
  2366. typename _UniformRandomNumberGenerator>
  2367. void
  2368. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  2369. _UniformRandomNumberGenerator& __urng,
  2370. const param_type& __p);
  2371. param_type _M_param;
  2372. std::normal_distribution<result_type> _M_nd;
  2373. };
  2374. /**
  2375. * @brief Return true if two gamma distributions are different.
  2376. */
  2377. template<typename _RealType>
  2378. inline bool
  2379. operator!=(const std::gamma_distribution<_RealType>& __d1,
  2380. const std::gamma_distribution<_RealType>& __d2)
  2381. { return !(__d1 == __d2); }
  2382. /**
  2383. * @brief A chi_squared_distribution random number distribution.
  2384. *
  2385. * The formula for the normal probability mass function is
  2386. * @f$p(x|n) = \frac{x^{(n/2) - 1}e^{-x/2}}{\Gamma(n/2) 2^{n/2}}@f$
  2387. */
  2388. template<typename _RealType = double>
  2389. class chi_squared_distribution
  2390. {
  2391. static_assert(std::is_floating_point<_RealType>::value,
  2392. "template argument not a floating point type");
  2393. public:
  2394. /** The type of the range of the distribution. */
  2395. typedef _RealType result_type;
  2396. /** Parameter type. */
  2397. struct param_type
  2398. {
  2399. typedef chi_squared_distribution<_RealType> distribution_type;
  2400. explicit
  2401. param_type(_RealType __n = _RealType(1))
  2402. : _M_n(__n)
  2403. { }
  2404. _RealType
  2405. n() const
  2406. { return _M_n; }
  2407. friend bool
  2408. operator==(const param_type& __p1, const param_type& __p2)
  2409. { return __p1._M_n == __p2._M_n; }
  2410. private:
  2411. _RealType _M_n;
  2412. };
  2413. explicit
  2414. chi_squared_distribution(_RealType __n = _RealType(1))
  2415. : _M_param(__n), _M_gd(__n / 2)
  2416. { }
  2417. explicit
  2418. chi_squared_distribution(const param_type& __p)
  2419. : _M_param(__p), _M_gd(__p.n() / 2)
  2420. { }
  2421. /**
  2422. * @brief Resets the distribution state.
  2423. */
  2424. void
  2425. reset()
  2426. { _M_gd.reset(); }
  2427. /**
  2428. *
  2429. */
  2430. _RealType
  2431. n() const
  2432. { return _M_param.n(); }
  2433. /**
  2434. * @brief Returns the parameter set of the distribution.
  2435. */
  2436. param_type
  2437. param() const
  2438. { return _M_param; }
  2439. /**
  2440. * @brief Sets the parameter set of the distribution.
  2441. * @param __param The new parameter set of the distribution.
  2442. */
  2443. void
  2444. param(const param_type& __param)
  2445. { _M_param = __param; }
  2446. /**
  2447. * @brief Returns the greatest lower bound value of the distribution.
  2448. */
  2449. result_type
  2450. min() const
  2451. { return result_type(0); }
  2452. /**
  2453. * @brief Returns the least upper bound value of the distribution.
  2454. */
  2455. result_type
  2456. max() const
  2457. { return std::numeric_limits<result_type>::max(); }
  2458. /**
  2459. * @brief Generating functions.
  2460. */
  2461. template<typename _UniformRandomNumberGenerator>
  2462. result_type
  2463. operator()(_UniformRandomNumberGenerator& __urng)
  2464. { return 2 * _M_gd(__urng); }
  2465. template<typename _UniformRandomNumberGenerator>
  2466. result_type
  2467. operator()(_UniformRandomNumberGenerator& __urng,
  2468. const param_type& __p)
  2469. {
  2470. typedef typename std::gamma_distribution<result_type>::param_type
  2471. param_type;
  2472. return 2 * _M_gd(__urng, param_type(__p.n() / 2));
  2473. }
  2474. template<typename _ForwardIterator,
  2475. typename _UniformRandomNumberGenerator>
  2476. void
  2477. __generate(_ForwardIterator __f, _ForwardIterator __t,
  2478. _UniformRandomNumberGenerator& __urng)
  2479. { this->__generate_impl(__f, __t, __urng); }
  2480. template<typename _ForwardIterator,
  2481. typename _UniformRandomNumberGenerator>
  2482. void
  2483. __generate(_ForwardIterator __f, _ForwardIterator __t,
  2484. _UniformRandomNumberGenerator& __urng,
  2485. const param_type& __p)
  2486. { typename std::gamma_distribution<result_type>::param_type
  2487. __p2(__p.n() / 2);
  2488. this->__generate_impl(__f, __t, __urng, __p2); }
  2489. template<typename _UniformRandomNumberGenerator>
  2490. void
  2491. __generate(result_type* __f, result_type* __t,
  2492. _UniformRandomNumberGenerator& __urng)
  2493. { this->__generate_impl(__f, __t, __urng); }
  2494. template<typename _UniformRandomNumberGenerator>
  2495. void
  2496. __generate(result_type* __f, result_type* __t,
  2497. _UniformRandomNumberGenerator& __urng,
  2498. const param_type& __p)
  2499. { typename std::gamma_distribution<result_type>::param_type
  2500. __p2(__p.n() / 2);
  2501. this->__generate_impl(__f, __t, __urng, __p2); }
  2502. /**
  2503. * @brief Return true if two Chi-squared distributions have
  2504. * the same parameters and the sequences that would be
  2505. * generated are equal.
  2506. */
  2507. friend bool
  2508. operator==(const chi_squared_distribution& __d1,
  2509. const chi_squared_distribution& __d2)
  2510. { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; }
  2511. /**
  2512. * @brief Inserts a %chi_squared_distribution random number distribution
  2513. * @p __x into the output stream @p __os.
  2514. *
  2515. * @param __os An output stream.
  2516. * @param __x A %chi_squared_distribution random number distribution.
  2517. *
  2518. * @returns The output stream with the state of @p __x inserted or in
  2519. * an error state.
  2520. */
  2521. template<typename _RealType1, typename _CharT, typename _Traits>
  2522. friend std::basic_ostream<_CharT, _Traits>&
  2523. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  2524. const std::chi_squared_distribution<_RealType1>& __x);
  2525. /**
  2526. * @brief Extracts a %chi_squared_distribution random number distribution
  2527. * @p __x from the input stream @p __is.
  2528. *
  2529. * @param __is An input stream.
  2530. * @param __x A %chi_squared_distribution random number
  2531. * generator engine.
  2532. *
  2533. * @returns The input stream with @p __x extracted or in an error state.
  2534. */
  2535. template<typename _RealType1, typename _CharT, typename _Traits>
  2536. friend std::basic_istream<_CharT, _Traits>&
  2537. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  2538. std::chi_squared_distribution<_RealType1>& __x);
  2539. private:
  2540. template<typename _ForwardIterator,
  2541. typename _UniformRandomNumberGenerator>
  2542. void
  2543. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  2544. _UniformRandomNumberGenerator& __urng);
  2545. template<typename _ForwardIterator,
  2546. typename _UniformRandomNumberGenerator>
  2547. void
  2548. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  2549. _UniformRandomNumberGenerator& __urng,
  2550. const typename
  2551. std::gamma_distribution<result_type>::param_type& __p);
  2552. param_type _M_param;
  2553. std::gamma_distribution<result_type> _M_gd;
  2554. };
  2555. /**
  2556. * @brief Return true if two Chi-squared distributions are different.
  2557. */
  2558. template<typename _RealType>
  2559. inline bool
  2560. operator!=(const std::chi_squared_distribution<_RealType>& __d1,
  2561. const std::chi_squared_distribution<_RealType>& __d2)
  2562. { return !(__d1 == __d2); }
  2563. /**
  2564. * @brief A cauchy_distribution random number distribution.
  2565. *
  2566. * The formula for the normal probability mass function is
  2567. * @f$p(x|a,b) = (\pi b (1 + (\frac{x-a}{b})^2))^{-1}@f$
  2568. */
  2569. template<typename _RealType = double>
  2570. class cauchy_distribution
  2571. {
  2572. static_assert(std::is_floating_point<_RealType>::value,
  2573. "template argument not a floating point type");
  2574. public:
  2575. /** The type of the range of the distribution. */
  2576. typedef _RealType result_type;
  2577. /** Parameter type. */
  2578. struct param_type
  2579. {
  2580. typedef cauchy_distribution<_RealType> distribution_type;
  2581. explicit
  2582. param_type(_RealType __a = _RealType(0),
  2583. _RealType __b = _RealType(1))
  2584. : _M_a(__a), _M_b(__b)
  2585. { }
  2586. _RealType
  2587. a() const
  2588. { return _M_a; }
  2589. _RealType
  2590. b() const
  2591. { return _M_b; }
  2592. friend bool
  2593. operator==(const param_type& __p1, const param_type& __p2)
  2594. { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
  2595. private:
  2596. _RealType _M_a;
  2597. _RealType _M_b;
  2598. };
  2599. explicit
  2600. cauchy_distribution(_RealType __a = _RealType(0),
  2601. _RealType __b = _RealType(1))
  2602. : _M_param(__a, __b)
  2603. { }
  2604. explicit
  2605. cauchy_distribution(const param_type& __p)
  2606. : _M_param(__p)
  2607. { }
  2608. /**
  2609. * @brief Resets the distribution state.
  2610. */
  2611. void
  2612. reset()
  2613. { }
  2614. /**
  2615. *
  2616. */
  2617. _RealType
  2618. a() const
  2619. { return _M_param.a(); }
  2620. _RealType
  2621. b() const
  2622. { return _M_param.b(); }
  2623. /**
  2624. * @brief Returns the parameter set of the distribution.
  2625. */
  2626. param_type
  2627. param() const
  2628. { return _M_param; }
  2629. /**
  2630. * @brief Sets the parameter set of the distribution.
  2631. * @param __param The new parameter set of the distribution.
  2632. */
  2633. void
  2634. param(const param_type& __param)
  2635. { _M_param = __param; }
  2636. /**
  2637. * @brief Returns the greatest lower bound value of the distribution.
  2638. */
  2639. result_type
  2640. min() const
  2641. { return std::numeric_limits<result_type>::lowest(); }
  2642. /**
  2643. * @brief Returns the least upper bound value of the distribution.
  2644. */
  2645. result_type
  2646. max() const
  2647. { return std::numeric_limits<result_type>::max(); }
  2648. /**
  2649. * @brief Generating functions.
  2650. */
  2651. template<typename _UniformRandomNumberGenerator>
  2652. result_type
  2653. operator()(_UniformRandomNumberGenerator& __urng)
  2654. { return this->operator()(__urng, _M_param); }
  2655. template<typename _UniformRandomNumberGenerator>
  2656. result_type
  2657. operator()(_UniformRandomNumberGenerator& __urng,
  2658. const param_type& __p);
  2659. template<typename _ForwardIterator,
  2660. typename _UniformRandomNumberGenerator>
  2661. void
  2662. __generate(_ForwardIterator __f, _ForwardIterator __t,
  2663. _UniformRandomNumberGenerator& __urng)
  2664. { this->__generate(__f, __t, __urng, _M_param); }
  2665. template<typename _ForwardIterator,
  2666. typename _UniformRandomNumberGenerator>
  2667. void
  2668. __generate(_ForwardIterator __f, _ForwardIterator __t,
  2669. _UniformRandomNumberGenerator& __urng,
  2670. const param_type& __p)
  2671. { this->__generate_impl(__f, __t, __urng, __p); }
  2672. template<typename _UniformRandomNumberGenerator>
  2673. void
  2674. __generate(result_type* __f, result_type* __t,
  2675. _UniformRandomNumberGenerator& __urng,
  2676. const param_type& __p)
  2677. { this->__generate_impl(__f, __t, __urng, __p); }
  2678. /**
  2679. * @brief Return true if two Cauchy distributions have
  2680. * the same parameters.
  2681. */
  2682. friend bool
  2683. operator==(const cauchy_distribution& __d1,
  2684. const cauchy_distribution& __d2)
  2685. { return __d1._M_param == __d2._M_param; }
  2686. private:
  2687. template<typename _ForwardIterator,
  2688. typename _UniformRandomNumberGenerator>
  2689. void
  2690. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  2691. _UniformRandomNumberGenerator& __urng,
  2692. const param_type& __p);
  2693. param_type _M_param;
  2694. };
  2695. /**
  2696. * @brief Return true if two Cauchy distributions have
  2697. * different parameters.
  2698. */
  2699. template<typename _RealType>
  2700. inline bool
  2701. operator!=(const std::cauchy_distribution<_RealType>& __d1,
  2702. const std::cauchy_distribution<_RealType>& __d2)
  2703. { return !(__d1 == __d2); }
  2704. /**
  2705. * @brief Inserts a %cauchy_distribution random number distribution
  2706. * @p __x into the output stream @p __os.
  2707. *
  2708. * @param __os An output stream.
  2709. * @param __x A %cauchy_distribution random number distribution.
  2710. *
  2711. * @returns The output stream with the state of @p __x inserted or in
  2712. * an error state.
  2713. */
  2714. template<typename _RealType, typename _CharT, typename _Traits>
  2715. std::basic_ostream<_CharT, _Traits>&
  2716. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  2717. const std::cauchy_distribution<_RealType>& __x);
  2718. /**
  2719. * @brief Extracts a %cauchy_distribution random number distribution
  2720. * @p __x from the input stream @p __is.
  2721. *
  2722. * @param __is An input stream.
  2723. * @param __x A %cauchy_distribution random number
  2724. * generator engine.
  2725. *
  2726. * @returns The input stream with @p __x extracted or in an error state.
  2727. */
  2728. template<typename _RealType, typename _CharT, typename _Traits>
  2729. std::basic_istream<_CharT, _Traits>&
  2730. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  2731. std::cauchy_distribution<_RealType>& __x);
  2732. /**
  2733. * @brief A fisher_f_distribution random number distribution.
  2734. *
  2735. * The formula for the normal probability mass function is
  2736. * @f[
  2737. * p(x|m,n) = \frac{\Gamma((m+n)/2)}{\Gamma(m/2)\Gamma(n/2)}
  2738. * (\frac{m}{n})^{m/2} x^{(m/2)-1}
  2739. * (1 + \frac{mx}{n})^{-(m+n)/2}
  2740. * @f]
  2741. */
  2742. template<typename _RealType = double>
  2743. class fisher_f_distribution
  2744. {
  2745. static_assert(std::is_floating_point<_RealType>::value,
  2746. "template argument not a floating point type");
  2747. public:
  2748. /** The type of the range of the distribution. */
  2749. typedef _RealType result_type;
  2750. /** Parameter type. */
  2751. struct param_type
  2752. {
  2753. typedef fisher_f_distribution<_RealType> distribution_type;
  2754. explicit
  2755. param_type(_RealType __m = _RealType(1),
  2756. _RealType __n = _RealType(1))
  2757. : _M_m(__m), _M_n(__n)
  2758. { }
  2759. _RealType
  2760. m() const
  2761. { return _M_m; }
  2762. _RealType
  2763. n() const
  2764. { return _M_n; }
  2765. friend bool
  2766. operator==(const param_type& __p1, const param_type& __p2)
  2767. { return __p1._M_m == __p2._M_m && __p1._M_n == __p2._M_n; }
  2768. private:
  2769. _RealType _M_m;
  2770. _RealType _M_n;
  2771. };
  2772. explicit
  2773. fisher_f_distribution(_RealType __m = _RealType(1),
  2774. _RealType __n = _RealType(1))
  2775. : _M_param(__m, __n), _M_gd_x(__m / 2), _M_gd_y(__n / 2)
  2776. { }
  2777. explicit
  2778. fisher_f_distribution(const param_type& __p)
  2779. : _M_param(__p), _M_gd_x(__p.m() / 2), _M_gd_y(__p.n() / 2)
  2780. { }
  2781. /**
  2782. * @brief Resets the distribution state.
  2783. */
  2784. void
  2785. reset()
  2786. {
  2787. _M_gd_x.reset();
  2788. _M_gd_y.reset();
  2789. }
  2790. /**
  2791. *
  2792. */
  2793. _RealType
  2794. m() const
  2795. { return _M_param.m(); }
  2796. _RealType
  2797. n() const
  2798. { return _M_param.n(); }
  2799. /**
  2800. * @brief Returns the parameter set of the distribution.
  2801. */
  2802. param_type
  2803. param() const
  2804. { return _M_param; }
  2805. /**
  2806. * @brief Sets the parameter set of the distribution.
  2807. * @param __param The new parameter set of the distribution.
  2808. */
  2809. void
  2810. param(const param_type& __param)
  2811. { _M_param = __param; }
  2812. /**
  2813. * @brief Returns the greatest lower bound value of the distribution.
  2814. */
  2815. result_type
  2816. min() const
  2817. { return result_type(0); }
  2818. /**
  2819. * @brief Returns the least upper bound value of the distribution.
  2820. */
  2821. result_type
  2822. max() const
  2823. { return std::numeric_limits<result_type>::max(); }
  2824. /**
  2825. * @brief Generating functions.
  2826. */
  2827. template<typename _UniformRandomNumberGenerator>
  2828. result_type
  2829. operator()(_UniformRandomNumberGenerator& __urng)
  2830. { return (_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()); }
  2831. template<typename _UniformRandomNumberGenerator>
  2832. result_type
  2833. operator()(_UniformRandomNumberGenerator& __urng,
  2834. const param_type& __p)
  2835. {
  2836. typedef typename std::gamma_distribution<result_type>::param_type
  2837. param_type;
  2838. return ((_M_gd_x(__urng, param_type(__p.m() / 2)) * n())
  2839. / (_M_gd_y(__urng, param_type(__p.n() / 2)) * m()));
  2840. }
  2841. template<typename _ForwardIterator,
  2842. typename _UniformRandomNumberGenerator>
  2843. void
  2844. __generate(_ForwardIterator __f, _ForwardIterator __t,
  2845. _UniformRandomNumberGenerator& __urng)
  2846. { this->__generate_impl(__f, __t, __urng); }
  2847. template<typename _ForwardIterator,
  2848. typename _UniformRandomNumberGenerator>
  2849. void
  2850. __generate(_ForwardIterator __f, _ForwardIterator __t,
  2851. _UniformRandomNumberGenerator& __urng,
  2852. const param_type& __p)
  2853. { this->__generate_impl(__f, __t, __urng, __p); }
  2854. template<typename _UniformRandomNumberGenerator>
  2855. void
  2856. __generate(result_type* __f, result_type* __t,
  2857. _UniformRandomNumberGenerator& __urng)
  2858. { this->__generate_impl(__f, __t, __urng); }
  2859. template<typename _UniformRandomNumberGenerator>
  2860. void
  2861. __generate(result_type* __f, result_type* __t,
  2862. _UniformRandomNumberGenerator& __urng,
  2863. const param_type& __p)
  2864. { this->__generate_impl(__f, __t, __urng, __p); }
  2865. /**
  2866. * @brief Return true if two Fisher f distributions have
  2867. * the same parameters and the sequences that would
  2868. * be generated are equal.
  2869. */
  2870. friend bool
  2871. operator==(const fisher_f_distribution& __d1,
  2872. const fisher_f_distribution& __d2)
  2873. { return (__d1._M_param == __d2._M_param
  2874. && __d1._M_gd_x == __d2._M_gd_x
  2875. && __d1._M_gd_y == __d2._M_gd_y); }
  2876. /**
  2877. * @brief Inserts a %fisher_f_distribution random number distribution
  2878. * @p __x into the output stream @p __os.
  2879. *
  2880. * @param __os An output stream.
  2881. * @param __x A %fisher_f_distribution random number distribution.
  2882. *
  2883. * @returns The output stream with the state of @p __x inserted or in
  2884. * an error state.
  2885. */
  2886. template<typename _RealType1, typename _CharT, typename _Traits>
  2887. friend std::basic_ostream<_CharT, _Traits>&
  2888. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  2889. const std::fisher_f_distribution<_RealType1>& __x);
  2890. /**
  2891. * @brief Extracts a %fisher_f_distribution random number distribution
  2892. * @p __x from the input stream @p __is.
  2893. *
  2894. * @param __is An input stream.
  2895. * @param __x A %fisher_f_distribution random number
  2896. * generator engine.
  2897. *
  2898. * @returns The input stream with @p __x extracted or in an error state.
  2899. */
  2900. template<typename _RealType1, typename _CharT, typename _Traits>
  2901. friend std::basic_istream<_CharT, _Traits>&
  2902. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  2903. std::fisher_f_distribution<_RealType1>& __x);
  2904. private:
  2905. template<typename _ForwardIterator,
  2906. typename _UniformRandomNumberGenerator>
  2907. void
  2908. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  2909. _UniformRandomNumberGenerator& __urng);
  2910. template<typename _ForwardIterator,
  2911. typename _UniformRandomNumberGenerator>
  2912. void
  2913. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  2914. _UniformRandomNumberGenerator& __urng,
  2915. const param_type& __p);
  2916. param_type _M_param;
  2917. std::gamma_distribution<result_type> _M_gd_x, _M_gd_y;
  2918. };
  2919. /**
  2920. * @brief Return true if two Fisher f distributions are different.
  2921. */
  2922. template<typename _RealType>
  2923. inline bool
  2924. operator!=(const std::fisher_f_distribution<_RealType>& __d1,
  2925. const std::fisher_f_distribution<_RealType>& __d2)
  2926. { return !(__d1 == __d2); }
  2927. /**
  2928. * @brief A student_t_distribution random number distribution.
  2929. *
  2930. * The formula for the normal probability mass function is:
  2931. * @f[
  2932. * p(x|n) = \frac{1}{\sqrt(n\pi)} \frac{\Gamma((n+1)/2)}{\Gamma(n/2)}
  2933. * (1 + \frac{x^2}{n}) ^{-(n+1)/2}
  2934. * @f]
  2935. */
  2936. template<typename _RealType = double>
  2937. class student_t_distribution
  2938. {
  2939. static_assert(std::is_floating_point<_RealType>::value,
  2940. "template argument not a floating point type");
  2941. public:
  2942. /** The type of the range of the distribution. */
  2943. typedef _RealType result_type;
  2944. /** Parameter type. */
  2945. struct param_type
  2946. {
  2947. typedef student_t_distribution<_RealType> distribution_type;
  2948. explicit
  2949. param_type(_RealType __n = _RealType(1))
  2950. : _M_n(__n)
  2951. { }
  2952. _RealType
  2953. n() const
  2954. { return _M_n; }
  2955. friend bool
  2956. operator==(const param_type& __p1, const param_type& __p2)
  2957. { return __p1._M_n == __p2._M_n; }
  2958. private:
  2959. _RealType _M_n;
  2960. };
  2961. explicit
  2962. student_t_distribution(_RealType __n = _RealType(1))
  2963. : _M_param(__n), _M_nd(), _M_gd(__n / 2, 2)
  2964. { }
  2965. explicit
  2966. student_t_distribution(const param_type& __p)
  2967. : _M_param(__p), _M_nd(), _M_gd(__p.n() / 2, 2)
  2968. { }
  2969. /**
  2970. * @brief Resets the distribution state.
  2971. */
  2972. void
  2973. reset()
  2974. {
  2975. _M_nd.reset();
  2976. _M_gd.reset();
  2977. }
  2978. /**
  2979. *
  2980. */
  2981. _RealType
  2982. n() const
  2983. { return _M_param.n(); }
  2984. /**
  2985. * @brief Returns the parameter set of the distribution.
  2986. */
  2987. param_type
  2988. param() const
  2989. { return _M_param; }
  2990. /**
  2991. * @brief Sets the parameter set of the distribution.
  2992. * @param __param The new parameter set of the distribution.
  2993. */
  2994. void
  2995. param(const param_type& __param)
  2996. { _M_param = __param; }
  2997. /**
  2998. * @brief Returns the greatest lower bound value of the distribution.
  2999. */
  3000. result_type
  3001. min() const
  3002. { return std::numeric_limits<result_type>::lowest(); }
  3003. /**
  3004. * @brief Returns the least upper bound value of the distribution.
  3005. */
  3006. result_type
  3007. max() const
  3008. { return std::numeric_limits<result_type>::max(); }
  3009. /**
  3010. * @brief Generating functions.
  3011. */
  3012. template<typename _UniformRandomNumberGenerator>
  3013. result_type
  3014. operator()(_UniformRandomNumberGenerator& __urng)
  3015. { return _M_nd(__urng) * std::sqrt(n() / _M_gd(__urng)); }
  3016. template<typename _UniformRandomNumberGenerator>
  3017. result_type
  3018. operator()(_UniformRandomNumberGenerator& __urng,
  3019. const param_type& __p)
  3020. {
  3021. typedef typename std::gamma_distribution<result_type>::param_type
  3022. param_type;
  3023. const result_type __g = _M_gd(__urng, param_type(__p.n() / 2, 2));
  3024. return _M_nd(__urng) * std::sqrt(__p.n() / __g);
  3025. }
  3026. template<typename _ForwardIterator,
  3027. typename _UniformRandomNumberGenerator>
  3028. void
  3029. __generate(_ForwardIterator __f, _ForwardIterator __t,
  3030. _UniformRandomNumberGenerator& __urng)
  3031. { this->__generate_impl(__f, __t, __urng); }
  3032. template<typename _ForwardIterator,
  3033. typename _UniformRandomNumberGenerator>
  3034. void
  3035. __generate(_ForwardIterator __f, _ForwardIterator __t,
  3036. _UniformRandomNumberGenerator& __urng,
  3037. const param_type& __p)
  3038. { this->__generate_impl(__f, __t, __urng, __p); }
  3039. template<typename _UniformRandomNumberGenerator>
  3040. void
  3041. __generate(result_type* __f, result_type* __t,
  3042. _UniformRandomNumberGenerator& __urng)
  3043. { this->__generate_impl(__f, __t, __urng); }
  3044. template<typename _UniformRandomNumberGenerator>
  3045. void
  3046. __generate(result_type* __f, result_type* __t,
  3047. _UniformRandomNumberGenerator& __urng,
  3048. const param_type& __p)
  3049. { this->__generate_impl(__f, __t, __urng, __p); }
  3050. /**
  3051. * @brief Return true if two Student t distributions have
  3052. * the same parameters and the sequences that would
  3053. * be generated are equal.
  3054. */
  3055. friend bool
  3056. operator==(const student_t_distribution& __d1,
  3057. const student_t_distribution& __d2)
  3058. { return (__d1._M_param == __d2._M_param
  3059. && __d1._M_nd == __d2._M_nd && __d1._M_gd == __d2._M_gd); }
  3060. /**
  3061. * @brief Inserts a %student_t_distribution random number distribution
  3062. * @p __x into the output stream @p __os.
  3063. *
  3064. * @param __os An output stream.
  3065. * @param __x A %student_t_distribution random number distribution.
  3066. *
  3067. * @returns The output stream with the state of @p __x inserted or in
  3068. * an error state.
  3069. */
  3070. template<typename _RealType1, typename _CharT, typename _Traits>
  3071. friend std::basic_ostream<_CharT, _Traits>&
  3072. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  3073. const std::student_t_distribution<_RealType1>& __x);
  3074. /**
  3075. * @brief Extracts a %student_t_distribution random number distribution
  3076. * @p __x from the input stream @p __is.
  3077. *
  3078. * @param __is An input stream.
  3079. * @param __x A %student_t_distribution random number
  3080. * generator engine.
  3081. *
  3082. * @returns The input stream with @p __x extracted or in an error state.
  3083. */
  3084. template<typename _RealType1, typename _CharT, typename _Traits>
  3085. friend std::basic_istream<_CharT, _Traits>&
  3086. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  3087. std::student_t_distribution<_RealType1>& __x);
  3088. private:
  3089. template<typename _ForwardIterator,
  3090. typename _UniformRandomNumberGenerator>
  3091. void
  3092. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  3093. _UniformRandomNumberGenerator& __urng);
  3094. template<typename _ForwardIterator,
  3095. typename _UniformRandomNumberGenerator>
  3096. void
  3097. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  3098. _UniformRandomNumberGenerator& __urng,
  3099. const param_type& __p);
  3100. param_type _M_param;
  3101. std::normal_distribution<result_type> _M_nd;
  3102. std::gamma_distribution<result_type> _M_gd;
  3103. };
  3104. /**
  3105. * @brief Return true if two Student t distributions are different.
  3106. */
  3107. template<typename _RealType>
  3108. inline bool
  3109. operator!=(const std::student_t_distribution<_RealType>& __d1,
  3110. const std::student_t_distribution<_RealType>& __d2)
  3111. { return !(__d1 == __d2); }
  3112. /* @} */ // group random_distributions_normal
  3113. /**
  3114. * @addtogroup random_distributions_bernoulli Bernoulli Distributions
  3115. * @ingroup random_distributions
  3116. * @{
  3117. */
  3118. /**
  3119. * @brief A Bernoulli random number distribution.
  3120. *
  3121. * Generates a sequence of true and false values with likelihood @f$p@f$
  3122. * that true will come up and @f$(1 - p)@f$ that false will appear.
  3123. */
  3124. class bernoulli_distribution
  3125. {
  3126. public:
  3127. /** The type of the range of the distribution. */
  3128. typedef bool result_type;
  3129. /** Parameter type. */
  3130. struct param_type
  3131. {
  3132. typedef bernoulli_distribution distribution_type;
  3133. explicit
  3134. param_type(double __p = 0.5)
  3135. : _M_p(__p)
  3136. {
  3137. _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0) && (_M_p <= 1.0));
  3138. }
  3139. double
  3140. p() const
  3141. { return _M_p; }
  3142. friend bool
  3143. operator==(const param_type& __p1, const param_type& __p2)
  3144. { return __p1._M_p == __p2._M_p; }
  3145. private:
  3146. double _M_p;
  3147. };
  3148. public:
  3149. /**
  3150. * @brief Constructs a Bernoulli distribution with likelihood @p p.
  3151. *
  3152. * @param __p [IN] The likelihood of a true result being returned.
  3153. * Must be in the interval @f$[0, 1]@f$.
  3154. */
  3155. explicit
  3156. bernoulli_distribution(double __p = 0.5)
  3157. : _M_param(__p)
  3158. { }
  3159. explicit
  3160. bernoulli_distribution(const param_type& __p)
  3161. : _M_param(__p)
  3162. { }
  3163. /**
  3164. * @brief Resets the distribution state.
  3165. *
  3166. * Does nothing for a Bernoulli distribution.
  3167. */
  3168. void
  3169. reset() { }
  3170. /**
  3171. * @brief Returns the @p p parameter of the distribution.
  3172. */
  3173. double
  3174. p() const
  3175. { return _M_param.p(); }
  3176. /**
  3177. * @brief Returns the parameter set of the distribution.
  3178. */
  3179. param_type
  3180. param() const
  3181. { return _M_param; }
  3182. /**
  3183. * @brief Sets the parameter set of the distribution.
  3184. * @param __param The new parameter set of the distribution.
  3185. */
  3186. void
  3187. param(const param_type& __param)
  3188. { _M_param = __param; }
  3189. /**
  3190. * @brief Returns the greatest lower bound value of the distribution.
  3191. */
  3192. result_type
  3193. min() const
  3194. { return std::numeric_limits<result_type>::min(); }
  3195. /**
  3196. * @brief Returns the least upper bound value of the distribution.
  3197. */
  3198. result_type
  3199. max() const
  3200. { return std::numeric_limits<result_type>::max(); }
  3201. /**
  3202. * @brief Generating functions.
  3203. */
  3204. template<typename _UniformRandomNumberGenerator>
  3205. result_type
  3206. operator()(_UniformRandomNumberGenerator& __urng)
  3207. { return this->operator()(__urng, _M_param); }
  3208. template<typename _UniformRandomNumberGenerator>
  3209. result_type
  3210. operator()(_UniformRandomNumberGenerator& __urng,
  3211. const param_type& __p)
  3212. {
  3213. __detail::_Adaptor<_UniformRandomNumberGenerator, double>
  3214. __aurng(__urng);
  3215. if ((__aurng() - __aurng.min())
  3216. < __p.p() * (__aurng.max() - __aurng.min()))
  3217. return true;
  3218. return false;
  3219. }
  3220. template<typename _ForwardIterator,
  3221. typename _UniformRandomNumberGenerator>
  3222. void
  3223. __generate(_ForwardIterator __f, _ForwardIterator __t,
  3224. _UniformRandomNumberGenerator& __urng)
  3225. { this->__generate(__f, __t, __urng, _M_param); }
  3226. template<typename _ForwardIterator,
  3227. typename _UniformRandomNumberGenerator>
  3228. void
  3229. __generate(_ForwardIterator __f, _ForwardIterator __t,
  3230. _UniformRandomNumberGenerator& __urng, const param_type& __p)
  3231. { this->__generate_impl(__f, __t, __urng, __p); }
  3232. template<typename _UniformRandomNumberGenerator>
  3233. void
  3234. __generate(result_type* __f, result_type* __t,
  3235. _UniformRandomNumberGenerator& __urng,
  3236. const param_type& __p)
  3237. { this->__generate_impl(__f, __t, __urng, __p); }
  3238. /**
  3239. * @brief Return true if two Bernoulli distributions have
  3240. * the same parameters.
  3241. */
  3242. friend bool
  3243. operator==(const bernoulli_distribution& __d1,
  3244. const bernoulli_distribution& __d2)
  3245. { return __d1._M_param == __d2._M_param; }
  3246. private:
  3247. template<typename _ForwardIterator,
  3248. typename _UniformRandomNumberGenerator>
  3249. void
  3250. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  3251. _UniformRandomNumberGenerator& __urng,
  3252. const param_type& __p);
  3253. param_type _M_param;
  3254. };
  3255. /**
  3256. * @brief Return true if two Bernoulli distributions have
  3257. * different parameters.
  3258. */
  3259. inline bool
  3260. operator!=(const std::bernoulli_distribution& __d1,
  3261. const std::bernoulli_distribution& __d2)
  3262. { return !(__d1 == __d2); }
  3263. /**
  3264. * @brief Inserts a %bernoulli_distribution random number distribution
  3265. * @p __x into the output stream @p __os.
  3266. *
  3267. * @param __os An output stream.
  3268. * @param __x A %bernoulli_distribution random number distribution.
  3269. *
  3270. * @returns The output stream with the state of @p __x inserted or in
  3271. * an error state.
  3272. */
  3273. template<typename _CharT, typename _Traits>
  3274. std::basic_ostream<_CharT, _Traits>&
  3275. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  3276. const std::bernoulli_distribution& __x);
  3277. /**
  3278. * @brief Extracts a %bernoulli_distribution random number distribution
  3279. * @p __x from the input stream @p __is.
  3280. *
  3281. * @param __is An input stream.
  3282. * @param __x A %bernoulli_distribution random number generator engine.
  3283. *
  3284. * @returns The input stream with @p __x extracted or in an error state.
  3285. */
  3286. template<typename _CharT, typename _Traits>
  3287. std::basic_istream<_CharT, _Traits>&
  3288. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  3289. std::bernoulli_distribution& __x)
  3290. {
  3291. double __p;
  3292. __is >> __p;
  3293. __x.param(bernoulli_distribution::param_type(__p));
  3294. return __is;
  3295. }
  3296. /**
  3297. * @brief A discrete binomial random number distribution.
  3298. *
  3299. * The formula for the binomial probability density function is
  3300. * @f$p(i|t,p) = \binom{t}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
  3301. * and @f$p@f$ are the parameters of the distribution.
  3302. */
  3303. template<typename _IntType = int>
  3304. class binomial_distribution
  3305. {
  3306. static_assert(std::is_integral<_IntType>::value,
  3307. "template argument not an integral type");
  3308. public:
  3309. /** The type of the range of the distribution. */
  3310. typedef _IntType result_type;
  3311. /** Parameter type. */
  3312. struct param_type
  3313. {
  3314. typedef binomial_distribution<_IntType> distribution_type;
  3315. friend class binomial_distribution<_IntType>;
  3316. explicit
  3317. param_type(_IntType __t = _IntType(1), double __p = 0.5)
  3318. : _M_t(__t), _M_p(__p)
  3319. {
  3320. _GLIBCXX_DEBUG_ASSERT((_M_t >= _IntType(0))
  3321. && (_M_p >= 0.0)
  3322. && (_M_p <= 1.0));
  3323. _M_initialize();
  3324. }
  3325. _IntType
  3326. t() const
  3327. { return _M_t; }
  3328. double
  3329. p() const
  3330. { return _M_p; }
  3331. friend bool
  3332. operator==(const param_type& __p1, const param_type& __p2)
  3333. { return __p1._M_t == __p2._M_t && __p1._M_p == __p2._M_p; }
  3334. private:
  3335. void
  3336. _M_initialize();
  3337. _IntType _M_t;
  3338. double _M_p;
  3339. double _M_q;
  3340. #if _GLIBCXX_USE_C99_MATH_TR1
  3341. double _M_d1, _M_d2, _M_s1, _M_s2, _M_c,
  3342. _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p;
  3343. #endif
  3344. bool _M_easy;
  3345. };
  3346. // constructors and member function
  3347. explicit
  3348. binomial_distribution(_IntType __t = _IntType(1),
  3349. double __p = 0.5)
  3350. : _M_param(__t, __p), _M_nd()
  3351. { }
  3352. explicit
  3353. binomial_distribution(const param_type& __p)
  3354. : _M_param(__p), _M_nd()
  3355. { }
  3356. /**
  3357. * @brief Resets the distribution state.
  3358. */
  3359. void
  3360. reset()
  3361. { _M_nd.reset(); }
  3362. /**
  3363. * @brief Returns the distribution @p t parameter.
  3364. */
  3365. _IntType
  3366. t() const
  3367. { return _M_param.t(); }
  3368. /**
  3369. * @brief Returns the distribution @p p parameter.
  3370. */
  3371. double
  3372. p() const
  3373. { return _M_param.p(); }
  3374. /**
  3375. * @brief Returns the parameter set of the distribution.
  3376. */
  3377. param_type
  3378. param() const
  3379. { return _M_param; }
  3380. /**
  3381. * @brief Sets the parameter set of the distribution.
  3382. * @param __param The new parameter set of the distribution.
  3383. */
  3384. void
  3385. param(const param_type& __param)
  3386. { _M_param = __param; }
  3387. /**
  3388. * @brief Returns the greatest lower bound value of the distribution.
  3389. */
  3390. result_type
  3391. min() const
  3392. { return 0; }
  3393. /**
  3394. * @brief Returns the least upper bound value of the distribution.
  3395. */
  3396. result_type
  3397. max() const
  3398. { return _M_param.t(); }
  3399. /**
  3400. * @brief Generating functions.
  3401. */
  3402. template<typename _UniformRandomNumberGenerator>
  3403. result_type
  3404. operator()(_UniformRandomNumberGenerator& __urng)
  3405. { return this->operator()(__urng, _M_param); }
  3406. template<typename _UniformRandomNumberGenerator>
  3407. result_type
  3408. operator()(_UniformRandomNumberGenerator& __urng,
  3409. const param_type& __p);
  3410. template<typename _ForwardIterator,
  3411. typename _UniformRandomNumberGenerator>
  3412. void
  3413. __generate(_ForwardIterator __f, _ForwardIterator __t,
  3414. _UniformRandomNumberGenerator& __urng)
  3415. { this->__generate(__f, __t, __urng, _M_param); }
  3416. template<typename _ForwardIterator,
  3417. typename _UniformRandomNumberGenerator>
  3418. void
  3419. __generate(_ForwardIterator __f, _ForwardIterator __t,
  3420. _UniformRandomNumberGenerator& __urng,
  3421. const param_type& __p)
  3422. { this->__generate_impl(__f, __t, __urng, __p); }
  3423. template<typename _UniformRandomNumberGenerator>
  3424. void
  3425. __generate(result_type* __f, result_type* __t,
  3426. _UniformRandomNumberGenerator& __urng,
  3427. const param_type& __p)
  3428. { this->__generate_impl(__f, __t, __urng, __p); }
  3429. /**
  3430. * @brief Return true if two binomial distributions have
  3431. * the same parameters and the sequences that would
  3432. * be generated are equal.
  3433. */
  3434. friend bool
  3435. operator==(const binomial_distribution& __d1,
  3436. const binomial_distribution& __d2)
  3437. #ifdef _GLIBCXX_USE_C99_MATH_TR1
  3438. { return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; }
  3439. #else
  3440. { return __d1._M_param == __d2._M_param; }
  3441. #endif
  3442. /**
  3443. * @brief Inserts a %binomial_distribution random number distribution
  3444. * @p __x into the output stream @p __os.
  3445. *
  3446. * @param __os An output stream.
  3447. * @param __x A %binomial_distribution random number distribution.
  3448. *
  3449. * @returns The output stream with the state of @p __x inserted or in
  3450. * an error state.
  3451. */
  3452. template<typename _IntType1,
  3453. typename _CharT, typename _Traits>
  3454. friend std::basic_ostream<_CharT, _Traits>&
  3455. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  3456. const std::binomial_distribution<_IntType1>& __x);
  3457. /**
  3458. * @brief Extracts a %binomial_distribution random number distribution
  3459. * @p __x from the input stream @p __is.
  3460. *
  3461. * @param __is An input stream.
  3462. * @param __x A %binomial_distribution random number generator engine.
  3463. *
  3464. * @returns The input stream with @p __x extracted or in an error
  3465. * state.
  3466. */
  3467. template<typename _IntType1,
  3468. typename _CharT, typename _Traits>
  3469. friend std::basic_istream<_CharT, _Traits>&
  3470. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  3471. std::binomial_distribution<_IntType1>& __x);
  3472. private:
  3473. template<typename _ForwardIterator,
  3474. typename _UniformRandomNumberGenerator>
  3475. void
  3476. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  3477. _UniformRandomNumberGenerator& __urng,
  3478. const param_type& __p);
  3479. template<typename _UniformRandomNumberGenerator>
  3480. result_type
  3481. _M_waiting(_UniformRandomNumberGenerator& __urng,
  3482. _IntType __t, double __q);
  3483. param_type _M_param;
  3484. // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
  3485. std::normal_distribution<double> _M_nd;
  3486. };
  3487. /**
  3488. * @brief Return true if two binomial distributions are different.
  3489. */
  3490. template<typename _IntType>
  3491. inline bool
  3492. operator!=(const std::binomial_distribution<_IntType>& __d1,
  3493. const std::binomial_distribution<_IntType>& __d2)
  3494. { return !(__d1 == __d2); }
  3495. /**
  3496. * @brief A discrete geometric random number distribution.
  3497. *
  3498. * The formula for the geometric probability density function is
  3499. * @f$p(i|p) = p(1 - p)^{i}@f$ where @f$p@f$ is the parameter of the
  3500. * distribution.
  3501. */
  3502. template<typename _IntType = int>
  3503. class geometric_distribution
  3504. {
  3505. static_assert(std::is_integral<_IntType>::value,
  3506. "template argument not an integral type");
  3507. public:
  3508. /** The type of the range of the distribution. */
  3509. typedef _IntType result_type;
  3510. /** Parameter type. */
  3511. struct param_type
  3512. {
  3513. typedef geometric_distribution<_IntType> distribution_type;
  3514. friend class geometric_distribution<_IntType>;
  3515. explicit
  3516. param_type(double __p = 0.5)
  3517. : _M_p(__p)
  3518. {
  3519. _GLIBCXX_DEBUG_ASSERT((_M_p > 0.0) && (_M_p < 1.0));
  3520. _M_initialize();
  3521. }
  3522. double
  3523. p() const
  3524. { return _M_p; }
  3525. friend bool
  3526. operator==(const param_type& __p1, const param_type& __p2)
  3527. { return __p1._M_p == __p2._M_p; }
  3528. private:
  3529. void
  3530. _M_initialize()
  3531. { _M_log_1_p = std::log(1.0 - _M_p); }
  3532. double _M_p;
  3533. double _M_log_1_p;
  3534. };
  3535. // constructors and member function
  3536. explicit
  3537. geometric_distribution(double __p = 0.5)
  3538. : _M_param(__p)
  3539. { }
  3540. explicit
  3541. geometric_distribution(const param_type& __p)
  3542. : _M_param(__p)
  3543. { }
  3544. /**
  3545. * @brief Resets the distribution state.
  3546. *
  3547. * Does nothing for the geometric distribution.
  3548. */
  3549. void
  3550. reset() { }
  3551. /**
  3552. * @brief Returns the distribution parameter @p p.
  3553. */
  3554. double
  3555. p() const
  3556. { return _M_param.p(); }
  3557. /**
  3558. * @brief Returns the parameter set of the distribution.
  3559. */
  3560. param_type
  3561. param() const
  3562. { return _M_param; }
  3563. /**
  3564. * @brief Sets the parameter set of the distribution.
  3565. * @param __param The new parameter set of the distribution.
  3566. */
  3567. void
  3568. param(const param_type& __param)
  3569. { _M_param = __param; }
  3570. /**
  3571. * @brief Returns the greatest lower bound value of the distribution.
  3572. */
  3573. result_type
  3574. min() const
  3575. { return 0; }
  3576. /**
  3577. * @brief Returns the least upper bound value of the distribution.
  3578. */
  3579. result_type
  3580. max() const
  3581. { return std::numeric_limits<result_type>::max(); }
  3582. /**
  3583. * @brief Generating functions.
  3584. */
  3585. template<typename _UniformRandomNumberGenerator>
  3586. result_type
  3587. operator()(_UniformRandomNumberGenerator& __urng)
  3588. { return this->operator()(__urng, _M_param); }
  3589. template<typename _UniformRandomNumberGenerator>
  3590. result_type
  3591. operator()(_UniformRandomNumberGenerator& __urng,
  3592. const param_type& __p);
  3593. template<typename _ForwardIterator,
  3594. typename _UniformRandomNumberGenerator>
  3595. void
  3596. __generate(_ForwardIterator __f, _ForwardIterator __t,
  3597. _UniformRandomNumberGenerator& __urng)
  3598. { this->__generate(__f, __t, __urng, _M_param); }
  3599. template<typename _ForwardIterator,
  3600. typename _UniformRandomNumberGenerator>
  3601. void
  3602. __generate(_ForwardIterator __f, _ForwardIterator __t,
  3603. _UniformRandomNumberGenerator& __urng,
  3604. const param_type& __p)
  3605. { this->__generate_impl(__f, __t, __urng, __p); }
  3606. template<typename _UniformRandomNumberGenerator>
  3607. void
  3608. __generate(result_type* __f, result_type* __t,
  3609. _UniformRandomNumberGenerator& __urng,
  3610. const param_type& __p)
  3611. { this->__generate_impl(__f, __t, __urng, __p); }
  3612. /**
  3613. * @brief Return true if two geometric distributions have
  3614. * the same parameters.
  3615. */
  3616. friend bool
  3617. operator==(const geometric_distribution& __d1,
  3618. const geometric_distribution& __d2)
  3619. { return __d1._M_param == __d2._M_param; }
  3620. private:
  3621. template<typename _ForwardIterator,
  3622. typename _UniformRandomNumberGenerator>
  3623. void
  3624. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  3625. _UniformRandomNumberGenerator& __urng,
  3626. const param_type& __p);
  3627. param_type _M_param;
  3628. };
  3629. /**
  3630. * @brief Return true if two geometric distributions have
  3631. * different parameters.
  3632. */
  3633. template<typename _IntType>
  3634. inline bool
  3635. operator!=(const std::geometric_distribution<_IntType>& __d1,
  3636. const std::geometric_distribution<_IntType>& __d2)
  3637. { return !(__d1 == __d2); }
  3638. /**
  3639. * @brief Inserts a %geometric_distribution random number distribution
  3640. * @p __x into the output stream @p __os.
  3641. *
  3642. * @param __os An output stream.
  3643. * @param __x A %geometric_distribution random number distribution.
  3644. *
  3645. * @returns The output stream with the state of @p __x inserted or in
  3646. * an error state.
  3647. */
  3648. template<typename _IntType,
  3649. typename _CharT, typename _Traits>
  3650. std::basic_ostream<_CharT, _Traits>&
  3651. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  3652. const std::geometric_distribution<_IntType>& __x);
  3653. /**
  3654. * @brief Extracts a %geometric_distribution random number distribution
  3655. * @p __x from the input stream @p __is.
  3656. *
  3657. * @param __is An input stream.
  3658. * @param __x A %geometric_distribution random number generator engine.
  3659. *
  3660. * @returns The input stream with @p __x extracted or in an error state.
  3661. */
  3662. template<typename _IntType,
  3663. typename _CharT, typename _Traits>
  3664. std::basic_istream<_CharT, _Traits>&
  3665. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  3666. std::geometric_distribution<_IntType>& __x);
  3667. /**
  3668. * @brief A negative_binomial_distribution random number distribution.
  3669. *
  3670. * The formula for the negative binomial probability mass function is
  3671. * @f$p(i) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
  3672. * and @f$p@f$ are the parameters of the distribution.
  3673. */
  3674. template<typename _IntType = int>
  3675. class negative_binomial_distribution
  3676. {
  3677. static_assert(std::is_integral<_IntType>::value,
  3678. "template argument not an integral type");
  3679. public:
  3680. /** The type of the range of the distribution. */
  3681. typedef _IntType result_type;
  3682. /** Parameter type. */
  3683. struct param_type
  3684. {
  3685. typedef negative_binomial_distribution<_IntType> distribution_type;
  3686. explicit
  3687. param_type(_IntType __k = 1, double __p = 0.5)
  3688. : _M_k(__k), _M_p(__p)
  3689. {
  3690. _GLIBCXX_DEBUG_ASSERT((_M_k > 0) && (_M_p > 0.0) && (_M_p <= 1.0));
  3691. }
  3692. _IntType
  3693. k() const
  3694. { return _M_k; }
  3695. double
  3696. p() const
  3697. { return _M_p; }
  3698. friend bool
  3699. operator==(const param_type& __p1, const param_type& __p2)
  3700. { return __p1._M_k == __p2._M_k && __p1._M_p == __p2._M_p; }
  3701. private:
  3702. _IntType _M_k;
  3703. double _M_p;
  3704. };
  3705. explicit
  3706. negative_binomial_distribution(_IntType __k = 1, double __p = 0.5)
  3707. : _M_param(__k, __p), _M_gd(__k, (1.0 - __p) / __p)
  3708. { }
  3709. explicit
  3710. negative_binomial_distribution(const param_type& __p)
  3711. : _M_param(__p), _M_gd(__p.k(), (1.0 - __p.p()) / __p.p())
  3712. { }
  3713. /**
  3714. * @brief Resets the distribution state.
  3715. */
  3716. void
  3717. reset()
  3718. { _M_gd.reset(); }
  3719. /**
  3720. * @brief Return the @f$k@f$ parameter of the distribution.
  3721. */
  3722. _IntType
  3723. k() const
  3724. { return _M_param.k(); }
  3725. /**
  3726. * @brief Return the @f$p@f$ parameter of the distribution.
  3727. */
  3728. double
  3729. p() const
  3730. { return _M_param.p(); }
  3731. /**
  3732. * @brief Returns the parameter set of the distribution.
  3733. */
  3734. param_type
  3735. param() const
  3736. { return _M_param; }
  3737. /**
  3738. * @brief Sets the parameter set of the distribution.
  3739. * @param __param The new parameter set of the distribution.
  3740. */
  3741. void
  3742. param(const param_type& __param)
  3743. { _M_param = __param; }
  3744. /**
  3745. * @brief Returns the greatest lower bound value of the distribution.
  3746. */
  3747. result_type
  3748. min() const
  3749. { return result_type(0); }
  3750. /**
  3751. * @brief Returns the least upper bound value of the distribution.
  3752. */
  3753. result_type
  3754. max() const
  3755. { return std::numeric_limits<result_type>::max(); }
  3756. /**
  3757. * @brief Generating functions.
  3758. */
  3759. template<typename _UniformRandomNumberGenerator>
  3760. result_type
  3761. operator()(_UniformRandomNumberGenerator& __urng);
  3762. template<typename _UniformRandomNumberGenerator>
  3763. result_type
  3764. operator()(_UniformRandomNumberGenerator& __urng,
  3765. const param_type& __p);
  3766. template<typename _ForwardIterator,
  3767. typename _UniformRandomNumberGenerator>
  3768. void
  3769. __generate(_ForwardIterator __f, _ForwardIterator __t,
  3770. _UniformRandomNumberGenerator& __urng)
  3771. { this->__generate_impl(__f, __t, __urng); }
  3772. template<typename _ForwardIterator,
  3773. typename _UniformRandomNumberGenerator>
  3774. void
  3775. __generate(_ForwardIterator __f, _ForwardIterator __t,
  3776. _UniformRandomNumberGenerator& __urng,
  3777. const param_type& __p)
  3778. { this->__generate_impl(__f, __t, __urng, __p); }
  3779. template<typename _UniformRandomNumberGenerator>
  3780. void
  3781. __generate(result_type* __f, result_type* __t,
  3782. _UniformRandomNumberGenerator& __urng)
  3783. { this->__generate_impl(__f, __t, __urng); }
  3784. template<typename _UniformRandomNumberGenerator>
  3785. void
  3786. __generate(result_type* __f, result_type* __t,
  3787. _UniformRandomNumberGenerator& __urng,
  3788. const param_type& __p)
  3789. { this->__generate_impl(__f, __t, __urng, __p); }
  3790. /**
  3791. * @brief Return true if two negative binomial distributions have
  3792. * the same parameters and the sequences that would be
  3793. * generated are equal.
  3794. */
  3795. friend bool
  3796. operator==(const negative_binomial_distribution& __d1,
  3797. const negative_binomial_distribution& __d2)
  3798. { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; }
  3799. /**
  3800. * @brief Inserts a %negative_binomial_distribution random
  3801. * number distribution @p __x into the output stream @p __os.
  3802. *
  3803. * @param __os An output stream.
  3804. * @param __x A %negative_binomial_distribution random number
  3805. * distribution.
  3806. *
  3807. * @returns The output stream with the state of @p __x inserted or in
  3808. * an error state.
  3809. */
  3810. template<typename _IntType1, typename _CharT, typename _Traits>
  3811. friend std::basic_ostream<_CharT, _Traits>&
  3812. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  3813. const std::negative_binomial_distribution<_IntType1>& __x);
  3814. /**
  3815. * @brief Extracts a %negative_binomial_distribution random number
  3816. * distribution @p __x from the input stream @p __is.
  3817. *
  3818. * @param __is An input stream.
  3819. * @param __x A %negative_binomial_distribution random number
  3820. * generator engine.
  3821. *
  3822. * @returns The input stream with @p __x extracted or in an error state.
  3823. */
  3824. template<typename _IntType1, typename _CharT, typename _Traits>
  3825. friend std::basic_istream<_CharT, _Traits>&
  3826. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  3827. std::negative_binomial_distribution<_IntType1>& __x);
  3828. private:
  3829. template<typename _ForwardIterator,
  3830. typename _UniformRandomNumberGenerator>
  3831. void
  3832. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  3833. _UniformRandomNumberGenerator& __urng);
  3834. template<typename _ForwardIterator,
  3835. typename _UniformRandomNumberGenerator>
  3836. void
  3837. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  3838. _UniformRandomNumberGenerator& __urng,
  3839. const param_type& __p);
  3840. param_type _M_param;
  3841. std::gamma_distribution<double> _M_gd;
  3842. };
  3843. /**
  3844. * @brief Return true if two negative binomial distributions are different.
  3845. */
  3846. template<typename _IntType>
  3847. inline bool
  3848. operator!=(const std::negative_binomial_distribution<_IntType>& __d1,
  3849. const std::negative_binomial_distribution<_IntType>& __d2)
  3850. { return !(__d1 == __d2); }
  3851. /* @} */ // group random_distributions_bernoulli
  3852. /**
  3853. * @addtogroup random_distributions_poisson Poisson Distributions
  3854. * @ingroup random_distributions
  3855. * @{
  3856. */
  3857. /**
  3858. * @brief A discrete Poisson random number distribution.
  3859. *
  3860. * The formula for the Poisson probability density function is
  3861. * @f$p(i|\mu) = \frac{\mu^i}{i!} e^{-\mu}@f$ where @f$\mu@f$ is the
  3862. * parameter of the distribution.
  3863. */
  3864. template<typename _IntType = int>
  3865. class poisson_distribution
  3866. {
  3867. static_assert(std::is_integral<_IntType>::value,
  3868. "template argument not an integral type");
  3869. public:
  3870. /** The type of the range of the distribution. */
  3871. typedef _IntType result_type;
  3872. /** Parameter type. */
  3873. struct param_type
  3874. {
  3875. typedef poisson_distribution<_IntType> distribution_type;
  3876. friend class poisson_distribution<_IntType>;
  3877. explicit
  3878. param_type(double __mean = 1.0)
  3879. : _M_mean(__mean)
  3880. {
  3881. _GLIBCXX_DEBUG_ASSERT(_M_mean > 0.0);
  3882. _M_initialize();
  3883. }
  3884. double
  3885. mean() const
  3886. { return _M_mean; }
  3887. friend bool
  3888. operator==(const param_type& __p1, const param_type& __p2)
  3889. { return __p1._M_mean == __p2._M_mean; }
  3890. private:
  3891. // Hosts either log(mean) or the threshold of the simple method.
  3892. void
  3893. _M_initialize();
  3894. double _M_mean;
  3895. double _M_lm_thr;
  3896. #if _GLIBCXX_USE_C99_MATH_TR1
  3897. double _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb;
  3898. #endif
  3899. };
  3900. // constructors and member function
  3901. explicit
  3902. poisson_distribution(double __mean = 1.0)
  3903. : _M_param(__mean), _M_nd()
  3904. { }
  3905. explicit
  3906. poisson_distribution(const param_type& __p)
  3907. : _M_param(__p), _M_nd()
  3908. { }
  3909. /**
  3910. * @brief Resets the distribution state.
  3911. */
  3912. void
  3913. reset()
  3914. { _M_nd.reset(); }
  3915. /**
  3916. * @brief Returns the distribution parameter @p mean.
  3917. */
  3918. double
  3919. mean() const
  3920. { return _M_param.mean(); }
  3921. /**
  3922. * @brief Returns the parameter set of the distribution.
  3923. */
  3924. param_type
  3925. param() const
  3926. { return _M_param; }
  3927. /**
  3928. * @brief Sets the parameter set of the distribution.
  3929. * @param __param The new parameter set of the distribution.
  3930. */
  3931. void
  3932. param(const param_type& __param)
  3933. { _M_param = __param; }
  3934. /**
  3935. * @brief Returns the greatest lower bound value of the distribution.
  3936. */
  3937. result_type
  3938. min() const
  3939. { return 0; }
  3940. /**
  3941. * @brief Returns the least upper bound value of the distribution.
  3942. */
  3943. result_type
  3944. max() const
  3945. { return std::numeric_limits<result_type>::max(); }
  3946. /**
  3947. * @brief Generating functions.
  3948. */
  3949. template<typename _UniformRandomNumberGenerator>
  3950. result_type
  3951. operator()(_UniformRandomNumberGenerator& __urng)
  3952. { return this->operator()(__urng, _M_param); }
  3953. template<typename _UniformRandomNumberGenerator>
  3954. result_type
  3955. operator()(_UniformRandomNumberGenerator& __urng,
  3956. const param_type& __p);
  3957. template<typename _ForwardIterator,
  3958. typename _UniformRandomNumberGenerator>
  3959. void
  3960. __generate(_ForwardIterator __f, _ForwardIterator __t,
  3961. _UniformRandomNumberGenerator& __urng)
  3962. { this->__generate(__f, __t, __urng, _M_param); }
  3963. template<typename _ForwardIterator,
  3964. typename _UniformRandomNumberGenerator>
  3965. void
  3966. __generate(_ForwardIterator __f, _ForwardIterator __t,
  3967. _UniformRandomNumberGenerator& __urng,
  3968. const param_type& __p)
  3969. { this->__generate_impl(__f, __t, __urng, __p); }
  3970. template<typename _UniformRandomNumberGenerator>
  3971. void
  3972. __generate(result_type* __f, result_type* __t,
  3973. _UniformRandomNumberGenerator& __urng,
  3974. const param_type& __p)
  3975. { this->__generate_impl(__f, __t, __urng, __p); }
  3976. /**
  3977. * @brief Return true if two Poisson distributions have the same
  3978. * parameters and the sequences that would be generated
  3979. * are equal.
  3980. */
  3981. friend bool
  3982. operator==(const poisson_distribution& __d1,
  3983. const poisson_distribution& __d2)
  3984. #ifdef _GLIBCXX_USE_C99_MATH_TR1
  3985. { return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; }
  3986. #else
  3987. { return __d1._M_param == __d2._M_param; }
  3988. #endif
  3989. /**
  3990. * @brief Inserts a %poisson_distribution random number distribution
  3991. * @p __x into the output stream @p __os.
  3992. *
  3993. * @param __os An output stream.
  3994. * @param __x A %poisson_distribution random number distribution.
  3995. *
  3996. * @returns The output stream with the state of @p __x inserted or in
  3997. * an error state.
  3998. */
  3999. template<typename _IntType1, typename _CharT, typename _Traits>
  4000. friend std::basic_ostream<_CharT, _Traits>&
  4001. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  4002. const std::poisson_distribution<_IntType1>& __x);
  4003. /**
  4004. * @brief Extracts a %poisson_distribution random number distribution
  4005. * @p __x from the input stream @p __is.
  4006. *
  4007. * @param __is An input stream.
  4008. * @param __x A %poisson_distribution random number generator engine.
  4009. *
  4010. * @returns The input stream with @p __x extracted or in an error
  4011. * state.
  4012. */
  4013. template<typename _IntType1, typename _CharT, typename _Traits>
  4014. friend std::basic_istream<_CharT, _Traits>&
  4015. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  4016. std::poisson_distribution<_IntType1>& __x);
  4017. private:
  4018. template<typename _ForwardIterator,
  4019. typename _UniformRandomNumberGenerator>
  4020. void
  4021. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  4022. _UniformRandomNumberGenerator& __urng,
  4023. const param_type& __p);
  4024. param_type _M_param;
  4025. // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
  4026. std::normal_distribution<double> _M_nd;
  4027. };
  4028. /**
  4029. * @brief Return true if two Poisson distributions are different.
  4030. */
  4031. template<typename _IntType>
  4032. inline bool
  4033. operator!=(const std::poisson_distribution<_IntType>& __d1,
  4034. const std::poisson_distribution<_IntType>& __d2)
  4035. { return !(__d1 == __d2); }
  4036. /**
  4037. * @brief An exponential continuous distribution for random numbers.
  4038. *
  4039. * The formula for the exponential probability density function is
  4040. * @f$p(x|\lambda) = \lambda e^{-\lambda x}@f$.
  4041. *
  4042. * <table border=1 cellpadding=10 cellspacing=0>
  4043. * <caption align=top>Distribution Statistics</caption>
  4044. * <tr><td>Mean</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
  4045. * <tr><td>Median</td><td>@f$\frac{\ln 2}{\lambda}@f$</td></tr>
  4046. * <tr><td>Mode</td><td>@f$zero@f$</td></tr>
  4047. * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr>
  4048. * <tr><td>Standard Deviation</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
  4049. * </table>
  4050. */
  4051. template<typename _RealType = double>
  4052. class exponential_distribution
  4053. {
  4054. static_assert(std::is_floating_point<_RealType>::value,
  4055. "template argument not a floating point type");
  4056. public:
  4057. /** The type of the range of the distribution. */
  4058. typedef _RealType result_type;
  4059. /** Parameter type. */
  4060. struct param_type
  4061. {
  4062. typedef exponential_distribution<_RealType> distribution_type;
  4063. explicit
  4064. param_type(_RealType __lambda = _RealType(1))
  4065. : _M_lambda(__lambda)
  4066. {
  4067. _GLIBCXX_DEBUG_ASSERT(_M_lambda > _RealType(0));
  4068. }
  4069. _RealType
  4070. lambda() const
  4071. { return _M_lambda; }
  4072. friend bool
  4073. operator==(const param_type& __p1, const param_type& __p2)
  4074. { return __p1._M_lambda == __p2._M_lambda; }
  4075. private:
  4076. _RealType _M_lambda;
  4077. };
  4078. public:
  4079. /**
  4080. * @brief Constructs an exponential distribution with inverse scale
  4081. * parameter @f$\lambda@f$.
  4082. */
  4083. explicit
  4084. exponential_distribution(const result_type& __lambda = result_type(1))
  4085. : _M_param(__lambda)
  4086. { }
  4087. explicit
  4088. exponential_distribution(const param_type& __p)
  4089. : _M_param(__p)
  4090. { }
  4091. /**
  4092. * @brief Resets the distribution state.
  4093. *
  4094. * Has no effect on exponential distributions.
  4095. */
  4096. void
  4097. reset() { }
  4098. /**
  4099. * @brief Returns the inverse scale parameter of the distribution.
  4100. */
  4101. _RealType
  4102. lambda() const
  4103. { return _M_param.lambda(); }
  4104. /**
  4105. * @brief Returns the parameter set of the distribution.
  4106. */
  4107. param_type
  4108. param() const
  4109. { return _M_param; }
  4110. /**
  4111. * @brief Sets the parameter set of the distribution.
  4112. * @param __param The new parameter set of the distribution.
  4113. */
  4114. void
  4115. param(const param_type& __param)
  4116. { _M_param = __param; }
  4117. /**
  4118. * @brief Returns the greatest lower bound value of the distribution.
  4119. */
  4120. result_type
  4121. min() const
  4122. { return result_type(0); }
  4123. /**
  4124. * @brief Returns the least upper bound value of the distribution.
  4125. */
  4126. result_type
  4127. max() const
  4128. { return std::numeric_limits<result_type>::max(); }
  4129. /**
  4130. * @brief Generating functions.
  4131. */
  4132. template<typename _UniformRandomNumberGenerator>
  4133. result_type
  4134. operator()(_UniformRandomNumberGenerator& __urng)
  4135. { return this->operator()(__urng, _M_param); }
  4136. template<typename _UniformRandomNumberGenerator>
  4137. result_type
  4138. operator()(_UniformRandomNumberGenerator& __urng,
  4139. const param_type& __p)
  4140. {
  4141. __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
  4142. __aurng(__urng);
  4143. return -std::log(result_type(1) - __aurng()) / __p.lambda();
  4144. }
  4145. template<typename _ForwardIterator,
  4146. typename _UniformRandomNumberGenerator>
  4147. void
  4148. __generate(_ForwardIterator __f, _ForwardIterator __t,
  4149. _UniformRandomNumberGenerator& __urng)
  4150. { this->__generate(__f, __t, __urng, _M_param); }
  4151. template<typename _ForwardIterator,
  4152. typename _UniformRandomNumberGenerator>
  4153. void
  4154. __generate(_ForwardIterator __f, _ForwardIterator __t,
  4155. _UniformRandomNumberGenerator& __urng,
  4156. const param_type& __p)
  4157. { this->__generate_impl(__f, __t, __urng, __p); }
  4158. template<typename _UniformRandomNumberGenerator>
  4159. void
  4160. __generate(result_type* __f, result_type* __t,
  4161. _UniformRandomNumberGenerator& __urng,
  4162. const param_type& __p)
  4163. { this->__generate_impl(__f, __t, __urng, __p); }
  4164. /**
  4165. * @brief Return true if two exponential distributions have the same
  4166. * parameters.
  4167. */
  4168. friend bool
  4169. operator==(const exponential_distribution& __d1,
  4170. const exponential_distribution& __d2)
  4171. { return __d1._M_param == __d2._M_param; }
  4172. private:
  4173. template<typename _ForwardIterator,
  4174. typename _UniformRandomNumberGenerator>
  4175. void
  4176. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  4177. _UniformRandomNumberGenerator& __urng,
  4178. const param_type& __p);
  4179. param_type _M_param;
  4180. };
  4181. /**
  4182. * @brief Return true if two exponential distributions have different
  4183. * parameters.
  4184. */
  4185. template<typename _RealType>
  4186. inline bool
  4187. operator!=(const std::exponential_distribution<_RealType>& __d1,
  4188. const std::exponential_distribution<_RealType>& __d2)
  4189. { return !(__d1 == __d2); }
  4190. /**
  4191. * @brief Inserts a %exponential_distribution random number distribution
  4192. * @p __x into the output stream @p __os.
  4193. *
  4194. * @param __os An output stream.
  4195. * @param __x A %exponential_distribution random number distribution.
  4196. *
  4197. * @returns The output stream with the state of @p __x inserted or in
  4198. * an error state.
  4199. */
  4200. template<typename _RealType, typename _CharT, typename _Traits>
  4201. std::basic_ostream<_CharT, _Traits>&
  4202. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  4203. const std::exponential_distribution<_RealType>& __x);
  4204. /**
  4205. * @brief Extracts a %exponential_distribution random number distribution
  4206. * @p __x from the input stream @p __is.
  4207. *
  4208. * @param __is An input stream.
  4209. * @param __x A %exponential_distribution random number
  4210. * generator engine.
  4211. *
  4212. * @returns The input stream with @p __x extracted or in an error state.
  4213. */
  4214. template<typename _RealType, typename _CharT, typename _Traits>
  4215. std::basic_istream<_CharT, _Traits>&
  4216. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  4217. std::exponential_distribution<_RealType>& __x);
  4218. /**
  4219. * @brief A weibull_distribution random number distribution.
  4220. *
  4221. * The formula for the normal probability density function is:
  4222. * @f[
  4223. * p(x|\alpha,\beta) = \frac{\alpha}{\beta} (\frac{x}{\beta})^{\alpha-1}
  4224. * \exp{(-(\frac{x}{\beta})^\alpha)}
  4225. * @f]
  4226. */
  4227. template<typename _RealType = double>
  4228. class weibull_distribution
  4229. {
  4230. static_assert(std::is_floating_point<_RealType>::value,
  4231. "template argument not a floating point type");
  4232. public:
  4233. /** The type of the range of the distribution. */
  4234. typedef _RealType result_type;
  4235. /** Parameter type. */
  4236. struct param_type
  4237. {
  4238. typedef weibull_distribution<_RealType> distribution_type;
  4239. explicit
  4240. param_type(_RealType __a = _RealType(1),
  4241. _RealType __b = _RealType(1))
  4242. : _M_a(__a), _M_b(__b)
  4243. { }
  4244. _RealType
  4245. a() const
  4246. { return _M_a; }
  4247. _RealType
  4248. b() const
  4249. { return _M_b; }
  4250. friend bool
  4251. operator==(const param_type& __p1, const param_type& __p2)
  4252. { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
  4253. private:
  4254. _RealType _M_a;
  4255. _RealType _M_b;
  4256. };
  4257. explicit
  4258. weibull_distribution(_RealType __a = _RealType(1),
  4259. _RealType __b = _RealType(1))
  4260. : _M_param(__a, __b)
  4261. { }
  4262. explicit
  4263. weibull_distribution(const param_type& __p)
  4264. : _M_param(__p)
  4265. { }
  4266. /**
  4267. * @brief Resets the distribution state.
  4268. */
  4269. void
  4270. reset()
  4271. { }
  4272. /**
  4273. * @brief Return the @f$a@f$ parameter of the distribution.
  4274. */
  4275. _RealType
  4276. a() const
  4277. { return _M_param.a(); }
  4278. /**
  4279. * @brief Return the @f$b@f$ parameter of the distribution.
  4280. */
  4281. _RealType
  4282. b() const
  4283. { return _M_param.b(); }
  4284. /**
  4285. * @brief Returns the parameter set of the distribution.
  4286. */
  4287. param_type
  4288. param() const
  4289. { return _M_param; }
  4290. /**
  4291. * @brief Sets the parameter set of the distribution.
  4292. * @param __param The new parameter set of the distribution.
  4293. */
  4294. void
  4295. param(const param_type& __param)
  4296. { _M_param = __param; }
  4297. /**
  4298. * @brief Returns the greatest lower bound value of the distribution.
  4299. */
  4300. result_type
  4301. min() const
  4302. { return result_type(0); }
  4303. /**
  4304. * @brief Returns the least upper bound value of the distribution.
  4305. */
  4306. result_type
  4307. max() const
  4308. { return std::numeric_limits<result_type>::max(); }
  4309. /**
  4310. * @brief Generating functions.
  4311. */
  4312. template<typename _UniformRandomNumberGenerator>
  4313. result_type
  4314. operator()(_UniformRandomNumberGenerator& __urng)
  4315. { return this->operator()(__urng, _M_param); }
  4316. template<typename _UniformRandomNumberGenerator>
  4317. result_type
  4318. operator()(_UniformRandomNumberGenerator& __urng,
  4319. const param_type& __p);
  4320. template<typename _ForwardIterator,
  4321. typename _UniformRandomNumberGenerator>
  4322. void
  4323. __generate(_ForwardIterator __f, _ForwardIterator __t,
  4324. _UniformRandomNumberGenerator& __urng)
  4325. { this->__generate(__f, __t, __urng, _M_param); }
  4326. template<typename _ForwardIterator,
  4327. typename _UniformRandomNumberGenerator>
  4328. void
  4329. __generate(_ForwardIterator __f, _ForwardIterator __t,
  4330. _UniformRandomNumberGenerator& __urng,
  4331. const param_type& __p)
  4332. { this->__generate_impl(__f, __t, __urng, __p); }
  4333. template<typename _UniformRandomNumberGenerator>
  4334. void
  4335. __generate(result_type* __f, result_type* __t,
  4336. _UniformRandomNumberGenerator& __urng,
  4337. const param_type& __p)
  4338. { this->__generate_impl(__f, __t, __urng, __p); }
  4339. /**
  4340. * @brief Return true if two Weibull distributions have the same
  4341. * parameters.
  4342. */
  4343. friend bool
  4344. operator==(const weibull_distribution& __d1,
  4345. const weibull_distribution& __d2)
  4346. { return __d1._M_param == __d2._M_param; }
  4347. private:
  4348. template<typename _ForwardIterator,
  4349. typename _UniformRandomNumberGenerator>
  4350. void
  4351. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  4352. _UniformRandomNumberGenerator& __urng,
  4353. const param_type& __p);
  4354. param_type _M_param;
  4355. };
  4356. /**
  4357. * @brief Return true if two Weibull distributions have different
  4358. * parameters.
  4359. */
  4360. template<typename _RealType>
  4361. inline bool
  4362. operator!=(const std::weibull_distribution<_RealType>& __d1,
  4363. const std::weibull_distribution<_RealType>& __d2)
  4364. { return !(__d1 == __d2); }
  4365. /**
  4366. * @brief Inserts a %weibull_distribution random number distribution
  4367. * @p __x into the output stream @p __os.
  4368. *
  4369. * @param __os An output stream.
  4370. * @param __x A %weibull_distribution random number distribution.
  4371. *
  4372. * @returns The output stream with the state of @p __x inserted or in
  4373. * an error state.
  4374. */
  4375. template<typename _RealType, typename _CharT, typename _Traits>
  4376. std::basic_ostream<_CharT, _Traits>&
  4377. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  4378. const std::weibull_distribution<_RealType>& __x);
  4379. /**
  4380. * @brief Extracts a %weibull_distribution random number distribution
  4381. * @p __x from the input stream @p __is.
  4382. *
  4383. * @param __is An input stream.
  4384. * @param __x A %weibull_distribution random number
  4385. * generator engine.
  4386. *
  4387. * @returns The input stream with @p __x extracted or in an error state.
  4388. */
  4389. template<typename _RealType, typename _CharT, typename _Traits>
  4390. std::basic_istream<_CharT, _Traits>&
  4391. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  4392. std::weibull_distribution<_RealType>& __x);
  4393. /**
  4394. * @brief A extreme_value_distribution random number distribution.
  4395. *
  4396. * The formula for the normal probability mass function is
  4397. * @f[
  4398. * p(x|a,b) = \frac{1}{b}
  4399. * \exp( \frac{a-x}{b} - \exp(\frac{a-x}{b}))
  4400. * @f]
  4401. */
  4402. template<typename _RealType = double>
  4403. class extreme_value_distribution
  4404. {
  4405. static_assert(std::is_floating_point<_RealType>::value,
  4406. "template argument not a floating point type");
  4407. public:
  4408. /** The type of the range of the distribution. */
  4409. typedef _RealType result_type;
  4410. /** Parameter type. */
  4411. struct param_type
  4412. {
  4413. typedef extreme_value_distribution<_RealType> distribution_type;
  4414. explicit
  4415. param_type(_RealType __a = _RealType(0),
  4416. _RealType __b = _RealType(1))
  4417. : _M_a(__a), _M_b(__b)
  4418. { }
  4419. _RealType
  4420. a() const
  4421. { return _M_a; }
  4422. _RealType
  4423. b() const
  4424. { return _M_b; }
  4425. friend bool
  4426. operator==(const param_type& __p1, const param_type& __p2)
  4427. { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
  4428. private:
  4429. _RealType _M_a;
  4430. _RealType _M_b;
  4431. };
  4432. explicit
  4433. extreme_value_distribution(_RealType __a = _RealType(0),
  4434. _RealType __b = _RealType(1))
  4435. : _M_param(__a, __b)
  4436. { }
  4437. explicit
  4438. extreme_value_distribution(const param_type& __p)
  4439. : _M_param(__p)
  4440. { }
  4441. /**
  4442. * @brief Resets the distribution state.
  4443. */
  4444. void
  4445. reset()
  4446. { }
  4447. /**
  4448. * @brief Return the @f$a@f$ parameter of the distribution.
  4449. */
  4450. _RealType
  4451. a() const
  4452. { return _M_param.a(); }
  4453. /**
  4454. * @brief Return the @f$b@f$ parameter of the distribution.
  4455. */
  4456. _RealType
  4457. b() const
  4458. { return _M_param.b(); }
  4459. /**
  4460. * @brief Returns the parameter set of the distribution.
  4461. */
  4462. param_type
  4463. param() const
  4464. { return _M_param; }
  4465. /**
  4466. * @brief Sets the parameter set of the distribution.
  4467. * @param __param The new parameter set of the distribution.
  4468. */
  4469. void
  4470. param(const param_type& __param)
  4471. { _M_param = __param; }
  4472. /**
  4473. * @brief Returns the greatest lower bound value of the distribution.
  4474. */
  4475. result_type
  4476. min() const
  4477. { return std::numeric_limits<result_type>::lowest(); }
  4478. /**
  4479. * @brief Returns the least upper bound value of the distribution.
  4480. */
  4481. result_type
  4482. max() const
  4483. { return std::numeric_limits<result_type>::max(); }
  4484. /**
  4485. * @brief Generating functions.
  4486. */
  4487. template<typename _UniformRandomNumberGenerator>
  4488. result_type
  4489. operator()(_UniformRandomNumberGenerator& __urng)
  4490. { return this->operator()(__urng, _M_param); }
  4491. template<typename _UniformRandomNumberGenerator>
  4492. result_type
  4493. operator()(_UniformRandomNumberGenerator& __urng,
  4494. const param_type& __p);
  4495. template<typename _ForwardIterator,
  4496. typename _UniformRandomNumberGenerator>
  4497. void
  4498. __generate(_ForwardIterator __f, _ForwardIterator __t,
  4499. _UniformRandomNumberGenerator& __urng)
  4500. { this->__generate(__f, __t, __urng, _M_param); }
  4501. template<typename _ForwardIterator,
  4502. typename _UniformRandomNumberGenerator>
  4503. void
  4504. __generate(_ForwardIterator __f, _ForwardIterator __t,
  4505. _UniformRandomNumberGenerator& __urng,
  4506. const param_type& __p)
  4507. { this->__generate_impl(__f, __t, __urng, __p); }
  4508. template<typename _UniformRandomNumberGenerator>
  4509. void
  4510. __generate(result_type* __f, result_type* __t,
  4511. _UniformRandomNumberGenerator& __urng,
  4512. const param_type& __p)
  4513. { this->__generate_impl(__f, __t, __urng, __p); }
  4514. /**
  4515. * @brief Return true if two extreme value distributions have the same
  4516. * parameters.
  4517. */
  4518. friend bool
  4519. operator==(const extreme_value_distribution& __d1,
  4520. const extreme_value_distribution& __d2)
  4521. { return __d1._M_param == __d2._M_param; }
  4522. private:
  4523. template<typename _ForwardIterator,
  4524. typename _UniformRandomNumberGenerator>
  4525. void
  4526. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  4527. _UniformRandomNumberGenerator& __urng,
  4528. const param_type& __p);
  4529. param_type _M_param;
  4530. };
  4531. /**
  4532. * @brief Return true if two extreme value distributions have different
  4533. * parameters.
  4534. */
  4535. template<typename _RealType>
  4536. inline bool
  4537. operator!=(const std::extreme_value_distribution<_RealType>& __d1,
  4538. const std::extreme_value_distribution<_RealType>& __d2)
  4539. { return !(__d1 == __d2); }
  4540. /**
  4541. * @brief Inserts a %extreme_value_distribution random number distribution
  4542. * @p __x into the output stream @p __os.
  4543. *
  4544. * @param __os An output stream.
  4545. * @param __x A %extreme_value_distribution random number distribution.
  4546. *
  4547. * @returns The output stream with the state of @p __x inserted or in
  4548. * an error state.
  4549. */
  4550. template<typename _RealType, typename _CharT, typename _Traits>
  4551. std::basic_ostream<_CharT, _Traits>&
  4552. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  4553. const std::extreme_value_distribution<_RealType>& __x);
  4554. /**
  4555. * @brief Extracts a %extreme_value_distribution random number
  4556. * distribution @p __x from the input stream @p __is.
  4557. *
  4558. * @param __is An input stream.
  4559. * @param __x A %extreme_value_distribution random number
  4560. * generator engine.
  4561. *
  4562. * @returns The input stream with @p __x extracted or in an error state.
  4563. */
  4564. template<typename _RealType, typename _CharT, typename _Traits>
  4565. std::basic_istream<_CharT, _Traits>&
  4566. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  4567. std::extreme_value_distribution<_RealType>& __x);
  4568. /**
  4569. * @brief A discrete_distribution random number distribution.
  4570. *
  4571. * The formula for the discrete probability mass function is
  4572. *
  4573. */
  4574. template<typename _IntType = int>
  4575. class discrete_distribution
  4576. {
  4577. static_assert(std::is_integral<_IntType>::value,
  4578. "template argument not an integral type");
  4579. public:
  4580. /** The type of the range of the distribution. */
  4581. typedef _IntType result_type;
  4582. /** Parameter type. */
  4583. struct param_type
  4584. {
  4585. typedef discrete_distribution<_IntType> distribution_type;
  4586. friend class discrete_distribution<_IntType>;
  4587. param_type()
  4588. : _M_prob(), _M_cp()
  4589. { }
  4590. template<typename _InputIterator>
  4591. param_type(_InputIterator __wbegin,
  4592. _InputIterator __wend)
  4593. : _M_prob(__wbegin, __wend), _M_cp()
  4594. { _M_initialize(); }
  4595. param_type(initializer_list<double> __wil)
  4596. : _M_prob(__wil.begin(), __wil.end()), _M_cp()
  4597. { _M_initialize(); }
  4598. template<typename _Func>
  4599. param_type(size_t __nw, double __xmin, double __xmax,
  4600. _Func __fw);
  4601. // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
  4602. param_type(const param_type&) = default;
  4603. param_type& operator=(const param_type&) = default;
  4604. std::vector<double>
  4605. probabilities() const
  4606. { return _M_prob.empty() ? std::vector<double>(1, 1.0) : _M_prob; }
  4607. friend bool
  4608. operator==(const param_type& __p1, const param_type& __p2)
  4609. { return __p1._M_prob == __p2._M_prob; }
  4610. private:
  4611. void
  4612. _M_initialize();
  4613. std::vector<double> _M_prob;
  4614. std::vector<double> _M_cp;
  4615. };
  4616. discrete_distribution()
  4617. : _M_param()
  4618. { }
  4619. template<typename _InputIterator>
  4620. discrete_distribution(_InputIterator __wbegin,
  4621. _InputIterator __wend)
  4622. : _M_param(__wbegin, __wend)
  4623. { }
  4624. discrete_distribution(initializer_list<double> __wl)
  4625. : _M_param(__wl)
  4626. { }
  4627. template<typename _Func>
  4628. discrete_distribution(size_t __nw, double __xmin, double __xmax,
  4629. _Func __fw)
  4630. : _M_param(__nw, __xmin, __xmax, __fw)
  4631. { }
  4632. explicit
  4633. discrete_distribution(const param_type& __p)
  4634. : _M_param(__p)
  4635. { }
  4636. /**
  4637. * @brief Resets the distribution state.
  4638. */
  4639. void
  4640. reset()
  4641. { }
  4642. /**
  4643. * @brief Returns the probabilities of the distribution.
  4644. */
  4645. std::vector<double>
  4646. probabilities() const
  4647. {
  4648. return _M_param._M_prob.empty()
  4649. ? std::vector<double>(1, 1.0) : _M_param._M_prob;
  4650. }
  4651. /**
  4652. * @brief Returns the parameter set of the distribution.
  4653. */
  4654. param_type
  4655. param() const
  4656. { return _M_param; }
  4657. /**
  4658. * @brief Sets the parameter set of the distribution.
  4659. * @param __param The new parameter set of the distribution.
  4660. */
  4661. void
  4662. param(const param_type& __param)
  4663. { _M_param = __param; }
  4664. /**
  4665. * @brief Returns the greatest lower bound value of the distribution.
  4666. */
  4667. result_type
  4668. min() const
  4669. { return result_type(0); }
  4670. /**
  4671. * @brief Returns the least upper bound value of the distribution.
  4672. */
  4673. result_type
  4674. max() const
  4675. {
  4676. return _M_param._M_prob.empty()
  4677. ? result_type(0) : result_type(_M_param._M_prob.size() - 1);
  4678. }
  4679. /**
  4680. * @brief Generating functions.
  4681. */
  4682. template<typename _UniformRandomNumberGenerator>
  4683. result_type
  4684. operator()(_UniformRandomNumberGenerator& __urng)
  4685. { return this->operator()(__urng, _M_param); }
  4686. template<typename _UniformRandomNumberGenerator>
  4687. result_type
  4688. operator()(_UniformRandomNumberGenerator& __urng,
  4689. const param_type& __p);
  4690. template<typename _ForwardIterator,
  4691. typename _UniformRandomNumberGenerator>
  4692. void
  4693. __generate(_ForwardIterator __f, _ForwardIterator __t,
  4694. _UniformRandomNumberGenerator& __urng)
  4695. { this->__generate(__f, __t, __urng, _M_param); }
  4696. template<typename _ForwardIterator,
  4697. typename _UniformRandomNumberGenerator>
  4698. void
  4699. __generate(_ForwardIterator __f, _ForwardIterator __t,
  4700. _UniformRandomNumberGenerator& __urng,
  4701. const param_type& __p)
  4702. { this->__generate_impl(__f, __t, __urng, __p); }
  4703. template<typename _UniformRandomNumberGenerator>
  4704. void
  4705. __generate(result_type* __f, result_type* __t,
  4706. _UniformRandomNumberGenerator& __urng,
  4707. const param_type& __p)
  4708. { this->__generate_impl(__f, __t, __urng, __p); }
  4709. /**
  4710. * @brief Return true if two discrete distributions have the same
  4711. * parameters.
  4712. */
  4713. friend bool
  4714. operator==(const discrete_distribution& __d1,
  4715. const discrete_distribution& __d2)
  4716. { return __d1._M_param == __d2._M_param; }
  4717. /**
  4718. * @brief Inserts a %discrete_distribution random number distribution
  4719. * @p __x into the output stream @p __os.
  4720. *
  4721. * @param __os An output stream.
  4722. * @param __x A %discrete_distribution random number distribution.
  4723. *
  4724. * @returns The output stream with the state of @p __x inserted or in
  4725. * an error state.
  4726. */
  4727. template<typename _IntType1, typename _CharT, typename _Traits>
  4728. friend std::basic_ostream<_CharT, _Traits>&
  4729. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  4730. const std::discrete_distribution<_IntType1>& __x);
  4731. /**
  4732. * @brief Extracts a %discrete_distribution random number distribution
  4733. * @p __x from the input stream @p __is.
  4734. *
  4735. * @param __is An input stream.
  4736. * @param __x A %discrete_distribution random number
  4737. * generator engine.
  4738. *
  4739. * @returns The input stream with @p __x extracted or in an error
  4740. * state.
  4741. */
  4742. template<typename _IntType1, typename _CharT, typename _Traits>
  4743. friend std::basic_istream<_CharT, _Traits>&
  4744. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  4745. std::discrete_distribution<_IntType1>& __x);
  4746. private:
  4747. template<typename _ForwardIterator,
  4748. typename _UniformRandomNumberGenerator>
  4749. void
  4750. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  4751. _UniformRandomNumberGenerator& __urng,
  4752. const param_type& __p);
  4753. param_type _M_param;
  4754. };
  4755. /**
  4756. * @brief Return true if two discrete distributions have different
  4757. * parameters.
  4758. */
  4759. template<typename _IntType>
  4760. inline bool
  4761. operator!=(const std::discrete_distribution<_IntType>& __d1,
  4762. const std::discrete_distribution<_IntType>& __d2)
  4763. { return !(__d1 == __d2); }
  4764. /**
  4765. * @brief A piecewise_constant_distribution random number distribution.
  4766. *
  4767. * The formula for the piecewise constant probability mass function is
  4768. *
  4769. */
  4770. template<typename _RealType = double>
  4771. class piecewise_constant_distribution
  4772. {
  4773. static_assert(std::is_floating_point<_RealType>::value,
  4774. "template argument not a floating point type");
  4775. public:
  4776. /** The type of the range of the distribution. */
  4777. typedef _RealType result_type;
  4778. /** Parameter type. */
  4779. struct param_type
  4780. {
  4781. typedef piecewise_constant_distribution<_RealType> distribution_type;
  4782. friend class piecewise_constant_distribution<_RealType>;
  4783. param_type()
  4784. : _M_int(), _M_den(), _M_cp()
  4785. { }
  4786. template<typename _InputIteratorB, typename _InputIteratorW>
  4787. param_type(_InputIteratorB __bfirst,
  4788. _InputIteratorB __bend,
  4789. _InputIteratorW __wbegin);
  4790. template<typename _Func>
  4791. param_type(initializer_list<_RealType> __bi, _Func __fw);
  4792. template<typename _Func>
  4793. param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
  4794. _Func __fw);
  4795. // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
  4796. param_type(const param_type&) = default;
  4797. param_type& operator=(const param_type&) = default;
  4798. std::vector<_RealType>
  4799. intervals() const
  4800. {
  4801. if (_M_int.empty())
  4802. {
  4803. std::vector<_RealType> __tmp(2);
  4804. __tmp[1] = _RealType(1);
  4805. return __tmp;
  4806. }
  4807. else
  4808. return _M_int;
  4809. }
  4810. std::vector<double>
  4811. densities() const
  4812. { return _M_den.empty() ? std::vector<double>(1, 1.0) : _M_den; }
  4813. friend bool
  4814. operator==(const param_type& __p1, const param_type& __p2)
  4815. { return __p1._M_int == __p2._M_int && __p1._M_den == __p2._M_den; }
  4816. private:
  4817. void
  4818. _M_initialize();
  4819. std::vector<_RealType> _M_int;
  4820. std::vector<double> _M_den;
  4821. std::vector<double> _M_cp;
  4822. };
  4823. explicit
  4824. piecewise_constant_distribution()
  4825. : _M_param()
  4826. { }
  4827. template<typename _InputIteratorB, typename _InputIteratorW>
  4828. piecewise_constant_distribution(_InputIteratorB __bfirst,
  4829. _InputIteratorB __bend,
  4830. _InputIteratorW __wbegin)
  4831. : _M_param(__bfirst, __bend, __wbegin)
  4832. { }
  4833. template<typename _Func>
  4834. piecewise_constant_distribution(initializer_list<_RealType> __bl,
  4835. _Func __fw)
  4836. : _M_param(__bl, __fw)
  4837. { }
  4838. template<typename _Func>
  4839. piecewise_constant_distribution(size_t __nw,
  4840. _RealType __xmin, _RealType __xmax,
  4841. _Func __fw)
  4842. : _M_param(__nw, __xmin, __xmax, __fw)
  4843. { }
  4844. explicit
  4845. piecewise_constant_distribution(const param_type& __p)
  4846. : _M_param(__p)
  4847. { }
  4848. /**
  4849. * @brief Resets the distribution state.
  4850. */
  4851. void
  4852. reset()
  4853. { }
  4854. /**
  4855. * @brief Returns a vector of the intervals.
  4856. */
  4857. std::vector<_RealType>
  4858. intervals() const
  4859. {
  4860. if (_M_param._M_int.empty())
  4861. {
  4862. std::vector<_RealType> __tmp(2);
  4863. __tmp[1] = _RealType(1);
  4864. return __tmp;
  4865. }
  4866. else
  4867. return _M_param._M_int;
  4868. }
  4869. /**
  4870. * @brief Returns a vector of the probability densities.
  4871. */
  4872. std::vector<double>
  4873. densities() const
  4874. {
  4875. return _M_param._M_den.empty()
  4876. ? std::vector<double>(1, 1.0) : _M_param._M_den;
  4877. }
  4878. /**
  4879. * @brief Returns the parameter set of the distribution.
  4880. */
  4881. param_type
  4882. param() const
  4883. { return _M_param; }
  4884. /**
  4885. * @brief Sets the parameter set of the distribution.
  4886. * @param __param The new parameter set of the distribution.
  4887. */
  4888. void
  4889. param(const param_type& __param)
  4890. { _M_param = __param; }
  4891. /**
  4892. * @brief Returns the greatest lower bound value of the distribution.
  4893. */
  4894. result_type
  4895. min() const
  4896. {
  4897. return _M_param._M_int.empty()
  4898. ? result_type(0) : _M_param._M_int.front();
  4899. }
  4900. /**
  4901. * @brief Returns the least upper bound value of the distribution.
  4902. */
  4903. result_type
  4904. max() const
  4905. {
  4906. return _M_param._M_int.empty()
  4907. ? result_type(1) : _M_param._M_int.back();
  4908. }
  4909. /**
  4910. * @brief Generating functions.
  4911. */
  4912. template<typename _UniformRandomNumberGenerator>
  4913. result_type
  4914. operator()(_UniformRandomNumberGenerator& __urng)
  4915. { return this->operator()(__urng, _M_param); }
  4916. template<typename _UniformRandomNumberGenerator>
  4917. result_type
  4918. operator()(_UniformRandomNumberGenerator& __urng,
  4919. const param_type& __p);
  4920. template<typename _ForwardIterator,
  4921. typename _UniformRandomNumberGenerator>
  4922. void
  4923. __generate(_ForwardIterator __f, _ForwardIterator __t,
  4924. _UniformRandomNumberGenerator& __urng)
  4925. { this->__generate(__f, __t, __urng, _M_param); }
  4926. template<typename _ForwardIterator,
  4927. typename _UniformRandomNumberGenerator>
  4928. void
  4929. __generate(_ForwardIterator __f, _ForwardIterator __t,
  4930. _UniformRandomNumberGenerator& __urng,
  4931. const param_type& __p)
  4932. { this->__generate_impl(__f, __t, __urng, __p); }
  4933. template<typename _UniformRandomNumberGenerator>
  4934. void
  4935. __generate(result_type* __f, result_type* __t,
  4936. _UniformRandomNumberGenerator& __urng,
  4937. const param_type& __p)
  4938. { this->__generate_impl(__f, __t, __urng, __p); }
  4939. /**
  4940. * @brief Return true if two piecewise constant distributions have the
  4941. * same parameters.
  4942. */
  4943. friend bool
  4944. operator==(const piecewise_constant_distribution& __d1,
  4945. const piecewise_constant_distribution& __d2)
  4946. { return __d1._M_param == __d2._M_param; }
  4947. /**
  4948. * @brief Inserts a %piecewise_constant_distribution random
  4949. * number distribution @p __x into the output stream @p __os.
  4950. *
  4951. * @param __os An output stream.
  4952. * @param __x A %piecewise_constant_distribution random number
  4953. * distribution.
  4954. *
  4955. * @returns The output stream with the state of @p __x inserted or in
  4956. * an error state.
  4957. */
  4958. template<typename _RealType1, typename _CharT, typename _Traits>
  4959. friend std::basic_ostream<_CharT, _Traits>&
  4960. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  4961. const std::piecewise_constant_distribution<_RealType1>& __x);
  4962. /**
  4963. * @brief Extracts a %piecewise_constant_distribution random
  4964. * number distribution @p __x from the input stream @p __is.
  4965. *
  4966. * @param __is An input stream.
  4967. * @param __x A %piecewise_constant_distribution random number
  4968. * generator engine.
  4969. *
  4970. * @returns The input stream with @p __x extracted or in an error
  4971. * state.
  4972. */
  4973. template<typename _RealType1, typename _CharT, typename _Traits>
  4974. friend std::basic_istream<_CharT, _Traits>&
  4975. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  4976. std::piecewise_constant_distribution<_RealType1>& __x);
  4977. private:
  4978. template<typename _ForwardIterator,
  4979. typename _UniformRandomNumberGenerator>
  4980. void
  4981. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  4982. _UniformRandomNumberGenerator& __urng,
  4983. const param_type& __p);
  4984. param_type _M_param;
  4985. };
  4986. /**
  4987. * @brief Return true if two piecewise constant distributions have
  4988. * different parameters.
  4989. */
  4990. template<typename _RealType>
  4991. inline bool
  4992. operator!=(const std::piecewise_constant_distribution<_RealType>& __d1,
  4993. const std::piecewise_constant_distribution<_RealType>& __d2)
  4994. { return !(__d1 == __d2); }
  4995. /**
  4996. * @brief A piecewise_linear_distribution random number distribution.
  4997. *
  4998. * The formula for the piecewise linear probability mass function is
  4999. *
  5000. */
  5001. template<typename _RealType = double>
  5002. class piecewise_linear_distribution
  5003. {
  5004. static_assert(std::is_floating_point<_RealType>::value,
  5005. "template argument not a floating point type");
  5006. public:
  5007. /** The type of the range of the distribution. */
  5008. typedef _RealType result_type;
  5009. /** Parameter type. */
  5010. struct param_type
  5011. {
  5012. typedef piecewise_linear_distribution<_RealType> distribution_type;
  5013. friend class piecewise_linear_distribution<_RealType>;
  5014. param_type()
  5015. : _M_int(), _M_den(), _M_cp(), _M_m()
  5016. { }
  5017. template<typename _InputIteratorB, typename _InputIteratorW>
  5018. param_type(_InputIteratorB __bfirst,
  5019. _InputIteratorB __bend,
  5020. _InputIteratorW __wbegin);
  5021. template<typename _Func>
  5022. param_type(initializer_list<_RealType> __bl, _Func __fw);
  5023. template<typename _Func>
  5024. param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
  5025. _Func __fw);
  5026. // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
  5027. param_type(const param_type&) = default;
  5028. param_type& operator=(const param_type&) = default;
  5029. std::vector<_RealType>
  5030. intervals() const
  5031. {
  5032. if (_M_int.empty())
  5033. {
  5034. std::vector<_RealType> __tmp(2);
  5035. __tmp[1] = _RealType(1);
  5036. return __tmp;
  5037. }
  5038. else
  5039. return _M_int;
  5040. }
  5041. std::vector<double>
  5042. densities() const
  5043. { return _M_den.empty() ? std::vector<double>(2, 1.0) : _M_den; }
  5044. friend bool
  5045. operator==(const param_type& __p1, const param_type& __p2)
  5046. { return (__p1._M_int == __p2._M_int
  5047. && __p1._M_den == __p2._M_den); }
  5048. private:
  5049. void
  5050. _M_initialize();
  5051. std::vector<_RealType> _M_int;
  5052. std::vector<double> _M_den;
  5053. std::vector<double> _M_cp;
  5054. std::vector<double> _M_m;
  5055. };
  5056. explicit
  5057. piecewise_linear_distribution()
  5058. : _M_param()
  5059. { }
  5060. template<typename _InputIteratorB, typename _InputIteratorW>
  5061. piecewise_linear_distribution(_InputIteratorB __bfirst,
  5062. _InputIteratorB __bend,
  5063. _InputIteratorW __wbegin)
  5064. : _M_param(__bfirst, __bend, __wbegin)
  5065. { }
  5066. template<typename _Func>
  5067. piecewise_linear_distribution(initializer_list<_RealType> __bl,
  5068. _Func __fw)
  5069. : _M_param(__bl, __fw)
  5070. { }
  5071. template<typename _Func>
  5072. piecewise_linear_distribution(size_t __nw,
  5073. _RealType __xmin, _RealType __xmax,
  5074. _Func __fw)
  5075. : _M_param(__nw, __xmin, __xmax, __fw)
  5076. { }
  5077. explicit
  5078. piecewise_linear_distribution(const param_type& __p)
  5079. : _M_param(__p)
  5080. { }
  5081. /**
  5082. * Resets the distribution state.
  5083. */
  5084. void
  5085. reset()
  5086. { }
  5087. /**
  5088. * @brief Return the intervals of the distribution.
  5089. */
  5090. std::vector<_RealType>
  5091. intervals() const
  5092. {
  5093. if (_M_param._M_int.empty())
  5094. {
  5095. std::vector<_RealType> __tmp(2);
  5096. __tmp[1] = _RealType(1);
  5097. return __tmp;
  5098. }
  5099. else
  5100. return _M_param._M_int;
  5101. }
  5102. /**
  5103. * @brief Return a vector of the probability densities of the
  5104. * distribution.
  5105. */
  5106. std::vector<double>
  5107. densities() const
  5108. {
  5109. return _M_param._M_den.empty()
  5110. ? std::vector<double>(2, 1.0) : _M_param._M_den;
  5111. }
  5112. /**
  5113. * @brief Returns the parameter set of the distribution.
  5114. */
  5115. param_type
  5116. param() const
  5117. { return _M_param; }
  5118. /**
  5119. * @brief Sets the parameter set of the distribution.
  5120. * @param __param The new parameter set of the distribution.
  5121. */
  5122. void
  5123. param(const param_type& __param)
  5124. { _M_param = __param; }
  5125. /**
  5126. * @brief Returns the greatest lower bound value of the distribution.
  5127. */
  5128. result_type
  5129. min() const
  5130. {
  5131. return _M_param._M_int.empty()
  5132. ? result_type(0) : _M_param._M_int.front();
  5133. }
  5134. /**
  5135. * @brief Returns the least upper bound value of the distribution.
  5136. */
  5137. result_type
  5138. max() const
  5139. {
  5140. return _M_param._M_int.empty()
  5141. ? result_type(1) : _M_param._M_int.back();
  5142. }
  5143. /**
  5144. * @brief Generating functions.
  5145. */
  5146. template<typename _UniformRandomNumberGenerator>
  5147. result_type
  5148. operator()(_UniformRandomNumberGenerator& __urng)
  5149. { return this->operator()(__urng, _M_param); }
  5150. template<typename _UniformRandomNumberGenerator>
  5151. result_type
  5152. operator()(_UniformRandomNumberGenerator& __urng,
  5153. const param_type& __p);
  5154. template<typename _ForwardIterator,
  5155. typename _UniformRandomNumberGenerator>
  5156. void
  5157. __generate(_ForwardIterator __f, _ForwardIterator __t,
  5158. _UniformRandomNumberGenerator& __urng)
  5159. { this->__generate(__f, __t, __urng, _M_param); }
  5160. template<typename _ForwardIterator,
  5161. typename _UniformRandomNumberGenerator>
  5162. void
  5163. __generate(_ForwardIterator __f, _ForwardIterator __t,
  5164. _UniformRandomNumberGenerator& __urng,
  5165. const param_type& __p)
  5166. { this->__generate_impl(__f, __t, __urng, __p); }
  5167. template<typename _UniformRandomNumberGenerator>
  5168. void
  5169. __generate(result_type* __f, result_type* __t,
  5170. _UniformRandomNumberGenerator& __urng,
  5171. const param_type& __p)
  5172. { this->__generate_impl(__f, __t, __urng, __p); }
  5173. /**
  5174. * @brief Return true if two piecewise linear distributions have the
  5175. * same parameters.
  5176. */
  5177. friend bool
  5178. operator==(const piecewise_linear_distribution& __d1,
  5179. const piecewise_linear_distribution& __d2)
  5180. { return __d1._M_param == __d2._M_param; }
  5181. /**
  5182. * @brief Inserts a %piecewise_linear_distribution random number
  5183. * distribution @p __x into the output stream @p __os.
  5184. *
  5185. * @param __os An output stream.
  5186. * @param __x A %piecewise_linear_distribution random number
  5187. * distribution.
  5188. *
  5189. * @returns The output stream with the state of @p __x inserted or in
  5190. * an error state.
  5191. */
  5192. template<typename _RealType1, typename _CharT, typename _Traits>
  5193. friend std::basic_ostream<_CharT, _Traits>&
  5194. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  5195. const std::piecewise_linear_distribution<_RealType1>& __x);
  5196. /**
  5197. * @brief Extracts a %piecewise_linear_distribution random number
  5198. * distribution @p __x from the input stream @p __is.
  5199. *
  5200. * @param __is An input stream.
  5201. * @param __x A %piecewise_linear_distribution random number
  5202. * generator engine.
  5203. *
  5204. * @returns The input stream with @p __x extracted or in an error
  5205. * state.
  5206. */
  5207. template<typename _RealType1, typename _CharT, typename _Traits>
  5208. friend std::basic_istream<_CharT, _Traits>&
  5209. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  5210. std::piecewise_linear_distribution<_RealType1>& __x);
  5211. private:
  5212. template<typename _ForwardIterator,
  5213. typename _UniformRandomNumberGenerator>
  5214. void
  5215. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  5216. _UniformRandomNumberGenerator& __urng,
  5217. const param_type& __p);
  5218. param_type _M_param;
  5219. };
  5220. /**
  5221. * @brief Return true if two piecewise linear distributions have
  5222. * different parameters.
  5223. */
  5224. template<typename _RealType>
  5225. inline bool
  5226. operator!=(const std::piecewise_linear_distribution<_RealType>& __d1,
  5227. const std::piecewise_linear_distribution<_RealType>& __d2)
  5228. { return !(__d1 == __d2); }
  5229. /* @} */ // group random_distributions_poisson
  5230. /* @} */ // group random_distributions
  5231. /**
  5232. * @addtogroup random_utilities Random Number Utilities
  5233. * @ingroup random
  5234. * @{
  5235. */
  5236. /**
  5237. * @brief The seed_seq class generates sequences of seeds for random
  5238. * number generators.
  5239. */
  5240. class seed_seq
  5241. {
  5242. public:
  5243. /** The type of the seed vales. */
  5244. typedef uint_least32_t result_type;
  5245. /** Default constructor. */
  5246. seed_seq()
  5247. : _M_v()
  5248. { }
  5249. template<typename _IntType>
  5250. seed_seq(std::initializer_list<_IntType> il);
  5251. template<typename _InputIterator>
  5252. seed_seq(_InputIterator __begin, _InputIterator __end);
  5253. // generating functions
  5254. template<typename _RandomAccessIterator>
  5255. void
  5256. generate(_RandomAccessIterator __begin, _RandomAccessIterator __end);
  5257. // property functions
  5258. size_t size() const
  5259. { return _M_v.size(); }
  5260. template<typename OutputIterator>
  5261. void
  5262. param(OutputIterator __dest) const
  5263. { std::copy(_M_v.begin(), _M_v.end(), __dest); }
  5264. private:
  5265. ///
  5266. std::vector<result_type> _M_v;
  5267. };
  5268. /* @} */ // group random_utilities
  5269. /* @} */ // group random
  5270. _GLIBCXX_END_NAMESPACE_VERSION
  5271. } // namespace std
  5272. #endif