| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100 |
- // random number generation -*- C++ -*-
- // Copyright (C) 2009-2020 Free Software Foundation, Inc.
- //
- // This file is part of the GNU ISO C++ Library. This library is free
- // software; you can redistribute it and/or modify it under the
- // terms of the GNU General Public License as published by the
- // Free Software Foundation; either version 3, or (at your option)
- // any later version.
- // This library is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- // Under Section 7 of GPL version 3, you are granted additional
- // permissions described in the GCC Runtime Library Exception, version
- // 3.1, as published by the Free Software Foundation.
- // You should have received a copy of the GNU General Public License and
- // a copy of the GCC Runtime Library Exception along with this program;
- // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
- // <http://www.gnu.org/licenses/>.
- /**
- * @file bits/random.h
- * This is an internal header file, included by other library headers.
- * Do not attempt to use it directly. @headername{random}
- */
- #ifndef _RANDOM_H
- #define _RANDOM_H 1
- #include <vector>
- #include <bits/uniform_int_dist.h>
- namespace std _GLIBCXX_VISIBILITY(default)
- {
- _GLIBCXX_BEGIN_NAMESPACE_VERSION
- // [26.4] Random number generation
- /**
- * @defgroup random Random Number Generation
- * @ingroup numerics
- *
- * A facility for generating random numbers on selected distributions.
- * @{
- */
- // std::uniform_random_bit_generator is defined in <bits/uniform_int_dist.h>
- /**
- * @brief A function template for converting the output of a (integral)
- * uniform random number generator to a floatng point result in the range
- * [0-1).
- */
- template<typename _RealType, size_t __bits,
- typename _UniformRandomNumberGenerator>
- _RealType
- generate_canonical(_UniformRandomNumberGenerator& __g);
- /*
- * Implementation-space details.
- */
- namespace __detail
- {
- template<typename _UIntType, size_t __w,
- bool = __w < static_cast<size_t>
- (std::numeric_limits<_UIntType>::digits)>
- struct _Shift
- { static const _UIntType __value = 0; };
- template<typename _UIntType, size_t __w>
- struct _Shift<_UIntType, __w, true>
- { static const _UIntType __value = _UIntType(1) << __w; };
- template<int __s,
- int __which = ((__s <= __CHAR_BIT__ * sizeof (int))
- + (__s <= __CHAR_BIT__ * sizeof (long))
- + (__s <= __CHAR_BIT__ * sizeof (long long))
- /* assume long long no bigger than __int128 */
- + (__s <= 128))>
- struct _Select_uint_least_t
- {
- static_assert(__which < 0, /* needs to be dependent */
- "sorry, would be too much trouble for a slow result");
- };
- template<int __s>
- struct _Select_uint_least_t<__s, 4>
- { typedef unsigned int type; };
- template<int __s>
- struct _Select_uint_least_t<__s, 3>
- { typedef unsigned long type; };
- template<int __s>
- struct _Select_uint_least_t<__s, 2>
- { typedef unsigned long long type; };
- #ifdef _GLIBCXX_USE_INT128
- template<int __s>
- struct _Select_uint_least_t<__s, 1>
- { typedef unsigned __int128 type; };
- #endif
- // Assume a != 0, a < m, c < m, x < m.
- template<typename _Tp, _Tp __m, _Tp __a, _Tp __c,
- bool __big_enough = (!(__m & (__m - 1))
- || (_Tp(-1) - __c) / __a >= __m - 1),
- bool __schrage_ok = __m % __a < __m / __a>
- struct _Mod
- {
- typedef typename _Select_uint_least_t<std::__lg(__a)
- + std::__lg(__m) + 2>::type _Tp2;
- static _Tp
- __calc(_Tp __x)
- { return static_cast<_Tp>((_Tp2(__a) * __x + __c) % __m); }
- };
- // Schrage.
- template<typename _Tp, _Tp __m, _Tp __a, _Tp __c>
- struct _Mod<_Tp, __m, __a, __c, false, true>
- {
- static _Tp
- __calc(_Tp __x);
- };
- // Special cases:
- // - for m == 2^n or m == 0, unsigned integer overflow is safe.
- // - a * (m - 1) + c fits in _Tp, there is no overflow.
- template<typename _Tp, _Tp __m, _Tp __a, _Tp __c, bool __s>
- struct _Mod<_Tp, __m, __a, __c, true, __s>
- {
- static _Tp
- __calc(_Tp __x)
- {
- _Tp __res = __a * __x + __c;
- if (__m)
- __res %= __m;
- return __res;
- }
- };
- template<typename _Tp, _Tp __m, _Tp __a = 1, _Tp __c = 0>
- inline _Tp
- __mod(_Tp __x)
- { return _Mod<_Tp, __m, __a, __c>::__calc(__x); }
- /*
- * An adaptor class for converting the output of any Generator into
- * the input for a specific Distribution.
- */
- template<typename _Engine, typename _DInputType>
- struct _Adaptor
- {
- static_assert(std::is_floating_point<_DInputType>::value,
- "template argument must be a floating point type");
- public:
- _Adaptor(_Engine& __g)
- : _M_g(__g) { }
- _DInputType
- min() const
- { return _DInputType(0); }
- _DInputType
- max() const
- { return _DInputType(1); }
- /*
- * Converts a value generated by the adapted random number generator
- * into a value in the input domain for the dependent random number
- * distribution.
- */
- _DInputType
- operator()()
- {
- return std::generate_canonical<_DInputType,
- std::numeric_limits<_DInputType>::digits,
- _Engine>(_M_g);
- }
- private:
- _Engine& _M_g;
- };
- template<typename _Sseq>
- using __seed_seq_generate_t = decltype(
- std::declval<_Sseq&>().generate(std::declval<uint_least32_t*>(),
- std::declval<uint_least32_t*>()));
- // Detect whether _Sseq is a valid seed sequence for
- // a random number engine _Engine with result type _Res.
- template<typename _Sseq, typename _Engine, typename _Res,
- typename _GenerateCheck = __seed_seq_generate_t<_Sseq>>
- using __is_seed_seq = __and_<
- __not_<is_same<__remove_cvref_t<_Sseq>, _Engine>>,
- is_unsigned<typename _Sseq::result_type>,
- __not_<is_convertible<_Sseq, _Res>>
- >;
- } // namespace __detail
- /**
- * @addtogroup random_generators Random Number Generators
- * @ingroup random
- *
- * These classes define objects which provide random or pseudorandom
- * numbers, either from a discrete or a continuous interval. The
- * random number generator supplied as a part of this library are
- * all uniform random number generators which provide a sequence of
- * random number uniformly distributed over their range.
- *
- * A number generator is a function object with an operator() that
- * takes zero arguments and returns a number.
- *
- * A compliant random number generator must satisfy the following
- * requirements. <table border=1 cellpadding=10 cellspacing=0>
- * <caption align=top>Random Number Generator Requirements</caption>
- * <tr><td>To be documented.</td></tr> </table>
- *
- * @{
- */
- /**
- * @brief A model of a linear congruential random number generator.
- *
- * A random number generator that produces pseudorandom numbers via
- * linear function:
- * @f[
- * x_{i+1}\leftarrow(ax_{i} + c) \bmod m
- * @f]
- *
- * The template parameter @p _UIntType must be an unsigned integral type
- * large enough to store values up to (__m-1). If the template parameter
- * @p __m is 0, the modulus @p __m used is
- * std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template
- * parameters @p __a and @p __c must be less than @p __m.
- *
- * The size of the state is @f$1@f$.
- */
- template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
- class linear_congruential_engine
- {
- static_assert(std::is_unsigned<_UIntType>::value,
- "result_type must be an unsigned integral type");
- static_assert(__m == 0u || (__a < __m && __c < __m),
- "template argument substituting __m out of bounds");
- template<typename _Sseq>
- using _If_seed_seq = typename enable_if<__detail::__is_seed_seq<
- _Sseq, linear_congruential_engine, _UIntType>::value>::type;
- public:
- /** The type of the generated random value. */
- typedef _UIntType result_type;
- /** The multiplier. */
- static constexpr result_type multiplier = __a;
- /** An increment. */
- static constexpr result_type increment = __c;
- /** The modulus. */
- static constexpr result_type modulus = __m;
- static constexpr result_type default_seed = 1u;
- /**
- * @brief Constructs a %linear_congruential_engine random number
- * generator engine with seed 1.
- */
- linear_congruential_engine() : linear_congruential_engine(default_seed)
- { }
- /**
- * @brief Constructs a %linear_congruential_engine random number
- * generator engine with seed @p __s. The default seed value
- * is 1.
- *
- * @param __s The initial seed value.
- */
- explicit
- linear_congruential_engine(result_type __s)
- { seed(__s); }
- /**
- * @brief Constructs a %linear_congruential_engine random number
- * generator engine seeded from the seed sequence @p __q.
- *
- * @param __q the seed sequence.
- */
- template<typename _Sseq, typename = _If_seed_seq<_Sseq>>
- explicit
- linear_congruential_engine(_Sseq& __q)
- { seed(__q); }
- /**
- * @brief Reseeds the %linear_congruential_engine random number generator
- * engine sequence to the seed @p __s.
- *
- * @param __s The new seed.
- */
- void
- seed(result_type __s = default_seed);
- /**
- * @brief Reseeds the %linear_congruential_engine random number generator
- * engine
- * sequence using values from the seed sequence @p __q.
- *
- * @param __q the seed sequence.
- */
- template<typename _Sseq>
- _If_seed_seq<_Sseq>
- seed(_Sseq& __q);
- /**
- * @brief Gets the smallest possible value in the output range.
- *
- * The minimum depends on the @p __c parameter: if it is zero, the
- * minimum generated must be > 0, otherwise 0 is allowed.
- */
- static constexpr result_type
- min()
- { return __c == 0u ? 1u : 0u; }
- /**
- * @brief Gets the largest possible value in the output range.
- */
- static constexpr result_type
- max()
- { return __m - 1u; }
- /**
- * @brief Discard a sequence of random numbers.
- */
- void
- discard(unsigned long long __z)
- {
- for (; __z != 0ULL; --__z)
- (*this)();
- }
- /**
- * @brief Gets the next random number in the sequence.
- */
- result_type
- operator()()
- {
- _M_x = __detail::__mod<_UIntType, __m, __a, __c>(_M_x);
- return _M_x;
- }
- /**
- * @brief Compares two linear congruential random number generator
- * objects of the same type for equality.
- *
- * @param __lhs A linear congruential random number generator object.
- * @param __rhs Another linear congruential random number generator
- * object.
- *
- * @returns true if the infinite sequences of generated values
- * would be equal, false otherwise.
- */
- friend bool
- operator==(const linear_congruential_engine& __lhs,
- const linear_congruential_engine& __rhs)
- { return __lhs._M_x == __rhs._M_x; }
- /**
- * @brief Writes the textual representation of the state x(i) of x to
- * @p __os.
- *
- * @param __os The output stream.
- * @param __lcr A % linear_congruential_engine random number generator.
- * @returns __os.
- */
- template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
- _UIntType1 __m1, typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const std::linear_congruential_engine<_UIntType1,
- __a1, __c1, __m1>& __lcr);
- /**
- * @brief Sets the state of the engine by reading its textual
- * representation from @p __is.
- *
- * The textual representation must have been previously written using
- * an output stream whose imbued locale and whose type's template
- * specialization arguments _CharT and _Traits were the same as those
- * of @p __is.
- *
- * @param __is The input stream.
- * @param __lcr A % linear_congruential_engine random number generator.
- * @returns __is.
- */
- template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1,
- _UIntType1 __m1, typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- std::linear_congruential_engine<_UIntType1, __a1,
- __c1, __m1>& __lcr);
- private:
- _UIntType _M_x;
- };
- /**
- * @brief Compares two linear congruential random number generator
- * objects of the same type for inequality.
- *
- * @param __lhs A linear congruential random number generator object.
- * @param __rhs Another linear congruential random number generator
- * object.
- *
- * @returns true if the infinite sequences of generated values
- * would be different, false otherwise.
- */
- template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
- inline bool
- operator!=(const std::linear_congruential_engine<_UIntType, __a,
- __c, __m>& __lhs,
- const std::linear_congruential_engine<_UIntType, __a,
- __c, __m>& __rhs)
- { return !(__lhs == __rhs); }
- /**
- * A generalized feedback shift register discrete random number generator.
- *
- * This algorithm avoids multiplication and division and is designed to be
- * friendly to a pipelined architecture. If the parameters are chosen
- * correctly, this generator will produce numbers with a very long period and
- * fairly good apparent entropy, although still not cryptographically strong.
- *
- * The best way to use this generator is with the predefined mt19937 class.
- *
- * This algorithm was originally invented by Makoto Matsumoto and
- * Takuji Nishimura.
- *
- * @tparam __w Word size, the number of bits in each element of
- * the state vector.
- * @tparam __n The degree of recursion.
- * @tparam __m The period parameter.
- * @tparam __r The separation point bit index.
- * @tparam __a The last row of the twist matrix.
- * @tparam __u The first right-shift tempering matrix parameter.
- * @tparam __d The first right-shift tempering matrix mask.
- * @tparam __s The first left-shift tempering matrix parameter.
- * @tparam __b The first left-shift tempering matrix mask.
- * @tparam __t The second left-shift tempering matrix parameter.
- * @tparam __c The second left-shift tempering matrix mask.
- * @tparam __l The second right-shift tempering matrix parameter.
- * @tparam __f Initialization multiplier.
- */
- template<typename _UIntType, size_t __w,
- size_t __n, size_t __m, size_t __r,
- _UIntType __a, size_t __u, _UIntType __d, size_t __s,
- _UIntType __b, size_t __t,
- _UIntType __c, size_t __l, _UIntType __f>
- class mersenne_twister_engine
- {
- static_assert(std::is_unsigned<_UIntType>::value,
- "result_type must be an unsigned integral type");
- static_assert(1u <= __m && __m <= __n,
- "template argument substituting __m out of bounds");
- static_assert(__r <= __w, "template argument substituting "
- "__r out of bound");
- static_assert(__u <= __w, "template argument substituting "
- "__u out of bound");
- static_assert(__s <= __w, "template argument substituting "
- "__s out of bound");
- static_assert(__t <= __w, "template argument substituting "
- "__t out of bound");
- static_assert(__l <= __w, "template argument substituting "
- "__l out of bound");
- static_assert(__w <= std::numeric_limits<_UIntType>::digits,
- "template argument substituting __w out of bound");
- static_assert(__a <= (__detail::_Shift<_UIntType, __w>::__value - 1),
- "template argument substituting __a out of bound");
- static_assert(__b <= (__detail::_Shift<_UIntType, __w>::__value - 1),
- "template argument substituting __b out of bound");
- static_assert(__c <= (__detail::_Shift<_UIntType, __w>::__value - 1),
- "template argument substituting __c out of bound");
- static_assert(__d <= (__detail::_Shift<_UIntType, __w>::__value - 1),
- "template argument substituting __d out of bound");
- static_assert(__f <= (__detail::_Shift<_UIntType, __w>::__value - 1),
- "template argument substituting __f out of bound");
- template<typename _Sseq>
- using _If_seed_seq = typename enable_if<__detail::__is_seed_seq<
- _Sseq, mersenne_twister_engine, _UIntType>::value>::type;
- public:
- /** The type of the generated random value. */
- typedef _UIntType result_type;
- // parameter values
- static constexpr size_t word_size = __w;
- static constexpr size_t state_size = __n;
- static constexpr size_t shift_size = __m;
- static constexpr size_t mask_bits = __r;
- static constexpr result_type xor_mask = __a;
- static constexpr size_t tempering_u = __u;
- static constexpr result_type tempering_d = __d;
- static constexpr size_t tempering_s = __s;
- static constexpr result_type tempering_b = __b;
- static constexpr size_t tempering_t = __t;
- static constexpr result_type tempering_c = __c;
- static constexpr size_t tempering_l = __l;
- static constexpr result_type initialization_multiplier = __f;
- static constexpr result_type default_seed = 5489u;
- // constructors and member functions
- mersenne_twister_engine() : mersenne_twister_engine(default_seed) { }
- explicit
- mersenne_twister_engine(result_type __sd)
- { seed(__sd); }
- /**
- * @brief Constructs a %mersenne_twister_engine random number generator
- * engine seeded from the seed sequence @p __q.
- *
- * @param __q the seed sequence.
- */
- template<typename _Sseq, typename = _If_seed_seq<_Sseq>>
- explicit
- mersenne_twister_engine(_Sseq& __q)
- { seed(__q); }
- void
- seed(result_type __sd = default_seed);
- template<typename _Sseq>
- _If_seed_seq<_Sseq>
- seed(_Sseq& __q);
- /**
- * @brief Gets the smallest possible value in the output range.
- */
- static constexpr result_type
- min()
- { return 0; }
- /**
- * @brief Gets the largest possible value in the output range.
- */
- static constexpr result_type
- max()
- { return __detail::_Shift<_UIntType, __w>::__value - 1; }
- /**
- * @brief Discard a sequence of random numbers.
- */
- void
- discard(unsigned long long __z);
- result_type
- operator()();
- /**
- * @brief Compares two % mersenne_twister_engine random number generator
- * objects of the same type for equality.
- *
- * @param __lhs A % mersenne_twister_engine random number generator
- * object.
- * @param __rhs Another % mersenne_twister_engine random number
- * generator object.
- *
- * @returns true if the infinite sequences of generated values
- * would be equal, false otherwise.
- */
- friend bool
- operator==(const mersenne_twister_engine& __lhs,
- const mersenne_twister_engine& __rhs)
- { return (std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x)
- && __lhs._M_p == __rhs._M_p); }
- /**
- * @brief Inserts the current state of a % mersenne_twister_engine
- * random number generator engine @p __x into the output stream
- * @p __os.
- *
- * @param __os An output stream.
- * @param __x A % mersenne_twister_engine random number generator
- * engine.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _UIntType1,
- size_t __w1, size_t __n1,
- size_t __m1, size_t __r1,
- _UIntType1 __a1, size_t __u1,
- _UIntType1 __d1, size_t __s1,
- _UIntType1 __b1, size_t __t1,
- _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
- typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const std::mersenne_twister_engine<_UIntType1, __w1, __n1,
- __m1, __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
- __l1, __f1>& __x);
- /**
- * @brief Extracts the current state of a % mersenne_twister_engine
- * random number generator engine @p __x from the input stream
- * @p __is.
- *
- * @param __is An input stream.
- * @param __x A % mersenne_twister_engine random number generator
- * engine.
- *
- * @returns The input stream with the state of @p __x extracted or in
- * an error state.
- */
- template<typename _UIntType1,
- size_t __w1, size_t __n1,
- size_t __m1, size_t __r1,
- _UIntType1 __a1, size_t __u1,
- _UIntType1 __d1, size_t __s1,
- _UIntType1 __b1, size_t __t1,
- _UIntType1 __c1, size_t __l1, _UIntType1 __f1,
- typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- std::mersenne_twister_engine<_UIntType1, __w1, __n1, __m1,
- __r1, __a1, __u1, __d1, __s1, __b1, __t1, __c1,
- __l1, __f1>& __x);
- private:
- void _M_gen_rand();
- _UIntType _M_x[state_size];
- size_t _M_p;
- };
- /**
- * @brief Compares two % mersenne_twister_engine random number generator
- * objects of the same type for inequality.
- *
- * @param __lhs A % mersenne_twister_engine random number generator
- * object.
- * @param __rhs Another % mersenne_twister_engine random number
- * generator object.
- *
- * @returns true if the infinite sequences of generated values
- * would be different, false otherwise.
- */
- template<typename _UIntType, size_t __w,
- size_t __n, size_t __m, size_t __r,
- _UIntType __a, size_t __u, _UIntType __d, size_t __s,
- _UIntType __b, size_t __t,
- _UIntType __c, size_t __l, _UIntType __f>
- inline bool
- operator!=(const std::mersenne_twister_engine<_UIntType, __w, __n, __m,
- __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __lhs,
- const std::mersenne_twister_engine<_UIntType, __w, __n, __m,
- __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __rhs)
- { return !(__lhs == __rhs); }
- /**
- * @brief The Marsaglia-Zaman generator.
- *
- * This is a model of a Generalized Fibonacci discrete random number
- * generator, sometimes referred to as the SWC generator.
- *
- * A discrete random number generator that produces pseudorandom
- * numbers using:
- * @f[
- * x_{i}\leftarrow(x_{i - s} - x_{i - r} - carry_{i-1}) \bmod m
- * @f]
- *
- * The size of the state is @f$r@f$
- * and the maximum period of the generator is @f$(m^r - m^s - 1)@f$.
- */
- template<typename _UIntType, size_t __w, size_t __s, size_t __r>
- class subtract_with_carry_engine
- {
- static_assert(std::is_unsigned<_UIntType>::value,
- "result_type must be an unsigned integral type");
- static_assert(0u < __s && __s < __r,
- "0 < s < r");
- static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
- "template argument substituting __w out of bounds");
- template<typename _Sseq>
- using _If_seed_seq = typename enable_if<__detail::__is_seed_seq<
- _Sseq, subtract_with_carry_engine, _UIntType>::value>::type;
- public:
- /** The type of the generated random value. */
- typedef _UIntType result_type;
- // parameter values
- static constexpr size_t word_size = __w;
- static constexpr size_t short_lag = __s;
- static constexpr size_t long_lag = __r;
- static constexpr result_type default_seed = 19780503u;
- subtract_with_carry_engine() : subtract_with_carry_engine(default_seed)
- { }
- /**
- * @brief Constructs an explicitly seeded %subtract_with_carry_engine
- * random number generator.
- */
- explicit
- subtract_with_carry_engine(result_type __sd)
- { seed(__sd); }
- /**
- * @brief Constructs a %subtract_with_carry_engine random number engine
- * seeded from the seed sequence @p __q.
- *
- * @param __q the seed sequence.
- */
- template<typename _Sseq, typename = _If_seed_seq<_Sseq>>
- explicit
- subtract_with_carry_engine(_Sseq& __q)
- { seed(__q); }
- /**
- * @brief Seeds the initial state @f$x_0@f$ of the random number
- * generator.
- *
- * N1688[4.19] modifies this as follows. If @p __value == 0,
- * sets value to 19780503. In any case, with a linear
- * congruential generator lcg(i) having parameters @f$ m_{lcg} =
- * 2147483563, a_{lcg} = 40014, c_{lcg} = 0, and lcg(0) = value
- * @f$, sets @f$ x_{-r} \dots x_{-1} @f$ to @f$ lcg(1) \bmod m
- * \dots lcg(r) \bmod m @f$ respectively. If @f$ x_{-1} = 0 @f$
- * set carry to 1, otherwise sets carry to 0.
- */
- void
- seed(result_type __sd = default_seed);
- /**
- * @brief Seeds the initial state @f$x_0@f$ of the
- * % subtract_with_carry_engine random number generator.
- */
- template<typename _Sseq>
- _If_seed_seq<_Sseq>
- seed(_Sseq& __q);
- /**
- * @brief Gets the inclusive minimum value of the range of random
- * integers returned by this generator.
- */
- static constexpr result_type
- min()
- { return 0; }
- /**
- * @brief Gets the inclusive maximum value of the range of random
- * integers returned by this generator.
- */
- static constexpr result_type
- max()
- { return __detail::_Shift<_UIntType, __w>::__value - 1; }
- /**
- * @brief Discard a sequence of random numbers.
- */
- void
- discard(unsigned long long __z)
- {
- for (; __z != 0ULL; --__z)
- (*this)();
- }
- /**
- * @brief Gets the next random number in the sequence.
- */
- result_type
- operator()();
- /**
- * @brief Compares two % subtract_with_carry_engine random number
- * generator objects of the same type for equality.
- *
- * @param __lhs A % subtract_with_carry_engine random number generator
- * object.
- * @param __rhs Another % subtract_with_carry_engine random number
- * generator object.
- *
- * @returns true if the infinite sequences of generated values
- * would be equal, false otherwise.
- */
- friend bool
- operator==(const subtract_with_carry_engine& __lhs,
- const subtract_with_carry_engine& __rhs)
- { return (std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x)
- && __lhs._M_carry == __rhs._M_carry
- && __lhs._M_p == __rhs._M_p); }
- /**
- * @brief Inserts the current state of a % subtract_with_carry_engine
- * random number generator engine @p __x into the output stream
- * @p __os.
- *
- * @param __os An output stream.
- * @param __x A % subtract_with_carry_engine random number generator
- * engine.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
- typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const std::subtract_with_carry_engine<_UIntType1, __w1,
- __s1, __r1>& __x);
- /**
- * @brief Extracts the current state of a % subtract_with_carry_engine
- * random number generator engine @p __x from the input stream
- * @p __is.
- *
- * @param __is An input stream.
- * @param __x A % subtract_with_carry_engine random number generator
- * engine.
- *
- * @returns The input stream with the state of @p __x extracted or in
- * an error state.
- */
- template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1,
- typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- std::subtract_with_carry_engine<_UIntType1, __w1,
- __s1, __r1>& __x);
- private:
- /// The state of the generator. This is a ring buffer.
- _UIntType _M_x[long_lag];
- _UIntType _M_carry; ///< The carry
- size_t _M_p; ///< Current index of x(i - r).
- };
- /**
- * @brief Compares two % subtract_with_carry_engine random number
- * generator objects of the same type for inequality.
- *
- * @param __lhs A % subtract_with_carry_engine random number generator
- * object.
- * @param __rhs Another % subtract_with_carry_engine random number
- * generator object.
- *
- * @returns true if the infinite sequences of generated values
- * would be different, false otherwise.
- */
- template<typename _UIntType, size_t __w, size_t __s, size_t __r>
- inline bool
- operator!=(const std::subtract_with_carry_engine<_UIntType, __w,
- __s, __r>& __lhs,
- const std::subtract_with_carry_engine<_UIntType, __w,
- __s, __r>& __rhs)
- { return !(__lhs == __rhs); }
- /**
- * Produces random numbers from some base engine by discarding blocks of
- * data.
- *
- * 0 <= @p __r <= @p __p
- */
- template<typename _RandomNumberEngine, size_t __p, size_t __r>
- class discard_block_engine
- {
- static_assert(1 <= __r && __r <= __p,
- "template argument substituting __r out of bounds");
- public:
- /** The type of the generated random value. */
- typedef typename _RandomNumberEngine::result_type result_type;
- template<typename _Sseq>
- using _If_seed_seq = typename enable_if<__detail::__is_seed_seq<
- _Sseq, discard_block_engine, result_type>::value>::type;
- // parameter values
- static constexpr size_t block_size = __p;
- static constexpr size_t used_block = __r;
- /**
- * @brief Constructs a default %discard_block_engine engine.
- *
- * The underlying engine is default constructed as well.
- */
- discard_block_engine()
- : _M_b(), _M_n(0) { }
- /**
- * @brief Copy constructs a %discard_block_engine engine.
- *
- * Copies an existing base class random number generator.
- * @param __rng An existing (base class) engine object.
- */
- explicit
- discard_block_engine(const _RandomNumberEngine& __rng)
- : _M_b(__rng), _M_n(0) { }
- /**
- * @brief Move constructs a %discard_block_engine engine.
- *
- * Copies an existing base class random number generator.
- * @param __rng An existing (base class) engine object.
- */
- explicit
- discard_block_engine(_RandomNumberEngine&& __rng)
- : _M_b(std::move(__rng)), _M_n(0) { }
- /**
- * @brief Seed constructs a %discard_block_engine engine.
- *
- * Constructs the underlying generator engine seeded with @p __s.
- * @param __s A seed value for the base class engine.
- */
- explicit
- discard_block_engine(result_type __s)
- : _M_b(__s), _M_n(0) { }
- /**
- * @brief Generator construct a %discard_block_engine engine.
- *
- * @param __q A seed sequence.
- */
- template<typename _Sseq, typename = _If_seed_seq<_Sseq>>
- explicit
- discard_block_engine(_Sseq& __q)
- : _M_b(__q), _M_n(0)
- { }
- /**
- * @brief Reseeds the %discard_block_engine object with the default
- * seed for the underlying base class generator engine.
- */
- void
- seed()
- {
- _M_b.seed();
- _M_n = 0;
- }
- /**
- * @brief Reseeds the %discard_block_engine object with the default
- * seed for the underlying base class generator engine.
- */
- void
- seed(result_type __s)
- {
- _M_b.seed(__s);
- _M_n = 0;
- }
- /**
- * @brief Reseeds the %discard_block_engine object with the given seed
- * sequence.
- * @param __q A seed generator function.
- */
- template<typename _Sseq>
- _If_seed_seq<_Sseq>
- seed(_Sseq& __q)
- {
- _M_b.seed(__q);
- _M_n = 0;
- }
- /**
- * @brief Gets a const reference to the underlying generator engine
- * object.
- */
- const _RandomNumberEngine&
- base() const noexcept
- { return _M_b; }
- /**
- * @brief Gets the minimum value in the generated random number range.
- */
- static constexpr result_type
- min()
- { return _RandomNumberEngine::min(); }
- /**
- * @brief Gets the maximum value in the generated random number range.
- */
- static constexpr result_type
- max()
- { return _RandomNumberEngine::max(); }
- /**
- * @brief Discard a sequence of random numbers.
- */
- void
- discard(unsigned long long __z)
- {
- for (; __z != 0ULL; --__z)
- (*this)();
- }
- /**
- * @brief Gets the next value in the generated random number sequence.
- */
- result_type
- operator()();
- /**
- * @brief Compares two %discard_block_engine random number generator
- * objects of the same type for equality.
- *
- * @param __lhs A %discard_block_engine random number generator object.
- * @param __rhs Another %discard_block_engine random number generator
- * object.
- *
- * @returns true if the infinite sequences of generated values
- * would be equal, false otherwise.
- */
- friend bool
- operator==(const discard_block_engine& __lhs,
- const discard_block_engine& __rhs)
- { return __lhs._M_b == __rhs._M_b && __lhs._M_n == __rhs._M_n; }
- /**
- * @brief Inserts the current state of a %discard_block_engine random
- * number generator engine @p __x into the output stream
- * @p __os.
- *
- * @param __os An output stream.
- * @param __x A %discard_block_engine random number generator engine.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
- typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const std::discard_block_engine<_RandomNumberEngine1,
- __p1, __r1>& __x);
- /**
- * @brief Extracts the current state of a % subtract_with_carry_engine
- * random number generator engine @p __x from the input stream
- * @p __is.
- *
- * @param __is An input stream.
- * @param __x A %discard_block_engine random number generator engine.
- *
- * @returns The input stream with the state of @p __x extracted or in
- * an error state.
- */
- template<typename _RandomNumberEngine1, size_t __p1, size_t __r1,
- typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- std::discard_block_engine<_RandomNumberEngine1,
- __p1, __r1>& __x);
- private:
- _RandomNumberEngine _M_b;
- size_t _M_n;
- };
- /**
- * @brief Compares two %discard_block_engine random number generator
- * objects of the same type for inequality.
- *
- * @param __lhs A %discard_block_engine random number generator object.
- * @param __rhs Another %discard_block_engine random number generator
- * object.
- *
- * @returns true if the infinite sequences of generated values
- * would be different, false otherwise.
- */
- template<typename _RandomNumberEngine, size_t __p, size_t __r>
- inline bool
- operator!=(const std::discard_block_engine<_RandomNumberEngine, __p,
- __r>& __lhs,
- const std::discard_block_engine<_RandomNumberEngine, __p,
- __r>& __rhs)
- { return !(__lhs == __rhs); }
- /**
- * Produces random numbers by combining random numbers from some base
- * engine to produce random numbers with a specifies number of bits @p __w.
- */
- template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
- class independent_bits_engine
- {
- static_assert(std::is_unsigned<_UIntType>::value,
- "result_type must be an unsigned integral type");
- static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
- "template argument substituting __w out of bounds");
- template<typename _Sseq>
- using _If_seed_seq = typename enable_if<__detail::__is_seed_seq<
- _Sseq, independent_bits_engine, _UIntType>::value>::type;
- public:
- /** The type of the generated random value. */
- typedef _UIntType result_type;
- /**
- * @brief Constructs a default %independent_bits_engine engine.
- *
- * The underlying engine is default constructed as well.
- */
- independent_bits_engine()
- : _M_b() { }
- /**
- * @brief Copy constructs a %independent_bits_engine engine.
- *
- * Copies an existing base class random number generator.
- * @param __rng An existing (base class) engine object.
- */
- explicit
- independent_bits_engine(const _RandomNumberEngine& __rng)
- : _M_b(__rng) { }
- /**
- * @brief Move constructs a %independent_bits_engine engine.
- *
- * Copies an existing base class random number generator.
- * @param __rng An existing (base class) engine object.
- */
- explicit
- independent_bits_engine(_RandomNumberEngine&& __rng)
- : _M_b(std::move(__rng)) { }
- /**
- * @brief Seed constructs a %independent_bits_engine engine.
- *
- * Constructs the underlying generator engine seeded with @p __s.
- * @param __s A seed value for the base class engine.
- */
- explicit
- independent_bits_engine(result_type __s)
- : _M_b(__s) { }
- /**
- * @brief Generator construct a %independent_bits_engine engine.
- *
- * @param __q A seed sequence.
- */
- template<typename _Sseq, typename = _If_seed_seq<_Sseq>>
- explicit
- independent_bits_engine(_Sseq& __q)
- : _M_b(__q)
- { }
- /**
- * @brief Reseeds the %independent_bits_engine object with the default
- * seed for the underlying base class generator engine.
- */
- void
- seed()
- { _M_b.seed(); }
- /**
- * @brief Reseeds the %independent_bits_engine object with the default
- * seed for the underlying base class generator engine.
- */
- void
- seed(result_type __s)
- { _M_b.seed(__s); }
- /**
- * @brief Reseeds the %independent_bits_engine object with the given
- * seed sequence.
- * @param __q A seed generator function.
- */
- template<typename _Sseq>
- _If_seed_seq<_Sseq>
- seed(_Sseq& __q)
- { _M_b.seed(__q); }
- /**
- * @brief Gets a const reference to the underlying generator engine
- * object.
- */
- const _RandomNumberEngine&
- base() const noexcept
- { return _M_b; }
- /**
- * @brief Gets the minimum value in the generated random number range.
- */
- static constexpr result_type
- min()
- { return 0U; }
- /**
- * @brief Gets the maximum value in the generated random number range.
- */
- static constexpr result_type
- max()
- { return __detail::_Shift<_UIntType, __w>::__value - 1; }
- /**
- * @brief Discard a sequence of random numbers.
- */
- void
- discard(unsigned long long __z)
- {
- for (; __z != 0ULL; --__z)
- (*this)();
- }
- /**
- * @brief Gets the next value in the generated random number sequence.
- */
- result_type
- operator()();
- /**
- * @brief Compares two %independent_bits_engine random number generator
- * objects of the same type for equality.
- *
- * @param __lhs A %independent_bits_engine random number generator
- * object.
- * @param __rhs Another %independent_bits_engine random number generator
- * object.
- *
- * @returns true if the infinite sequences of generated values
- * would be equal, false otherwise.
- */
- friend bool
- operator==(const independent_bits_engine& __lhs,
- const independent_bits_engine& __rhs)
- { return __lhs._M_b == __rhs._M_b; }
- /**
- * @brief Extracts the current state of a % subtract_with_carry_engine
- * random number generator engine @p __x from the input stream
- * @p __is.
- *
- * @param __is An input stream.
- * @param __x A %independent_bits_engine random number generator
- * engine.
- *
- * @returns The input stream with the state of @p __x extracted or in
- * an error state.
- */
- template<typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- std::independent_bits_engine<_RandomNumberEngine,
- __w, _UIntType>& __x)
- {
- __is >> __x._M_b;
- return __is;
- }
- private:
- _RandomNumberEngine _M_b;
- };
- /**
- * @brief Compares two %independent_bits_engine random number generator
- * objects of the same type for inequality.
- *
- * @param __lhs A %independent_bits_engine random number generator
- * object.
- * @param __rhs Another %independent_bits_engine random number generator
- * object.
- *
- * @returns true if the infinite sequences of generated values
- * would be different, false otherwise.
- */
- template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
- inline bool
- operator!=(const std::independent_bits_engine<_RandomNumberEngine, __w,
- _UIntType>& __lhs,
- const std::independent_bits_engine<_RandomNumberEngine, __w,
- _UIntType>& __rhs)
- { return !(__lhs == __rhs); }
- /**
- * @brief Inserts the current state of a %independent_bits_engine random
- * number generator engine @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %independent_bits_engine random number generator engine.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _RandomNumberEngine, size_t __w, typename _UIntType,
- typename _CharT, typename _Traits>
- std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const std::independent_bits_engine<_RandomNumberEngine,
- __w, _UIntType>& __x)
- {
- __os << __x.base();
- return __os;
- }
- /**
- * @brief Produces random numbers by combining random numbers from some
- * base engine to produce random numbers with a specifies number of bits
- * @p __k.
- */
- template<typename _RandomNumberEngine, size_t __k>
- class shuffle_order_engine
- {
- static_assert(1u <= __k, "template argument substituting "
- "__k out of bound");
- public:
- /** The type of the generated random value. */
- typedef typename _RandomNumberEngine::result_type result_type;
- template<typename _Sseq>
- using _If_seed_seq = typename enable_if<__detail::__is_seed_seq<
- _Sseq, shuffle_order_engine, result_type>::value>::type;
- static constexpr size_t table_size = __k;
- /**
- * @brief Constructs a default %shuffle_order_engine engine.
- *
- * The underlying engine is default constructed as well.
- */
- shuffle_order_engine()
- : _M_b()
- { _M_initialize(); }
- /**
- * @brief Copy constructs a %shuffle_order_engine engine.
- *
- * Copies an existing base class random number generator.
- * @param __rng An existing (base class) engine object.
- */
- explicit
- shuffle_order_engine(const _RandomNumberEngine& __rng)
- : _M_b(__rng)
- { _M_initialize(); }
- /**
- * @brief Move constructs a %shuffle_order_engine engine.
- *
- * Copies an existing base class random number generator.
- * @param __rng An existing (base class) engine object.
- */
- explicit
- shuffle_order_engine(_RandomNumberEngine&& __rng)
- : _M_b(std::move(__rng))
- { _M_initialize(); }
- /**
- * @brief Seed constructs a %shuffle_order_engine engine.
- *
- * Constructs the underlying generator engine seeded with @p __s.
- * @param __s A seed value for the base class engine.
- */
- explicit
- shuffle_order_engine(result_type __s)
- : _M_b(__s)
- { _M_initialize(); }
- /**
- * @brief Generator construct a %shuffle_order_engine engine.
- *
- * @param __q A seed sequence.
- */
- template<typename _Sseq, typename = _If_seed_seq<_Sseq>>
- explicit
- shuffle_order_engine(_Sseq& __q)
- : _M_b(__q)
- { _M_initialize(); }
- /**
- * @brief Reseeds the %shuffle_order_engine object with the default seed
- for the underlying base class generator engine.
- */
- void
- seed()
- {
- _M_b.seed();
- _M_initialize();
- }
- /**
- * @brief Reseeds the %shuffle_order_engine object with the default seed
- * for the underlying base class generator engine.
- */
- void
- seed(result_type __s)
- {
- _M_b.seed(__s);
- _M_initialize();
- }
- /**
- * @brief Reseeds the %shuffle_order_engine object with the given seed
- * sequence.
- * @param __q A seed generator function.
- */
- template<typename _Sseq>
- _If_seed_seq<_Sseq>
- seed(_Sseq& __q)
- {
- _M_b.seed(__q);
- _M_initialize();
- }
- /**
- * Gets a const reference to the underlying generator engine object.
- */
- const _RandomNumberEngine&
- base() const noexcept
- { return _M_b; }
- /**
- * Gets the minimum value in the generated random number range.
- */
- static constexpr result_type
- min()
- { return _RandomNumberEngine::min(); }
- /**
- * Gets the maximum value in the generated random number range.
- */
- static constexpr result_type
- max()
- { return _RandomNumberEngine::max(); }
- /**
- * Discard a sequence of random numbers.
- */
- void
- discard(unsigned long long __z)
- {
- for (; __z != 0ULL; --__z)
- (*this)();
- }
- /**
- * Gets the next value in the generated random number sequence.
- */
- result_type
- operator()();
- /**
- * Compares two %shuffle_order_engine random number generator objects
- * of the same type for equality.
- *
- * @param __lhs A %shuffle_order_engine random number generator object.
- * @param __rhs Another %shuffle_order_engine random number generator
- * object.
- *
- * @returns true if the infinite sequences of generated values
- * would be equal, false otherwise.
- */
- friend bool
- operator==(const shuffle_order_engine& __lhs,
- const shuffle_order_engine& __rhs)
- { return (__lhs._M_b == __rhs._M_b
- && std::equal(__lhs._M_v, __lhs._M_v + __k, __rhs._M_v)
- && __lhs._M_y == __rhs._M_y); }
- /**
- * @brief Inserts the current state of a %shuffle_order_engine random
- * number generator engine @p __x into the output stream
- @p __os.
- *
- * @param __os An output stream.
- * @param __x A %shuffle_order_engine random number generator engine.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _RandomNumberEngine1, size_t __k1,
- typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const std::shuffle_order_engine<_RandomNumberEngine1,
- __k1>& __x);
- /**
- * @brief Extracts the current state of a % subtract_with_carry_engine
- * random number generator engine @p __x from the input stream
- * @p __is.
- *
- * @param __is An input stream.
- * @param __x A %shuffle_order_engine random number generator engine.
- *
- * @returns The input stream with the state of @p __x extracted or in
- * an error state.
- */
- template<typename _RandomNumberEngine1, size_t __k1,
- typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- std::shuffle_order_engine<_RandomNumberEngine1, __k1>& __x);
- private:
- void _M_initialize()
- {
- for (size_t __i = 0; __i < __k; ++__i)
- _M_v[__i] = _M_b();
- _M_y = _M_b();
- }
- _RandomNumberEngine _M_b;
- result_type _M_v[__k];
- result_type _M_y;
- };
- /**
- * Compares two %shuffle_order_engine random number generator objects
- * of the same type for inequality.
- *
- * @param __lhs A %shuffle_order_engine random number generator object.
- * @param __rhs Another %shuffle_order_engine random number generator
- * object.
- *
- * @returns true if the infinite sequences of generated values
- * would be different, false otherwise.
- */
- template<typename _RandomNumberEngine, size_t __k>
- inline bool
- operator!=(const std::shuffle_order_engine<_RandomNumberEngine,
- __k>& __lhs,
- const std::shuffle_order_engine<_RandomNumberEngine,
- __k>& __rhs)
- { return !(__lhs == __rhs); }
- /**
- * The classic Minimum Standard rand0 of Lewis, Goodman, and Miller.
- */
- typedef linear_congruential_engine<uint_fast32_t, 16807UL, 0UL, 2147483647UL>
- minstd_rand0;
- /**
- * An alternative LCR (Lehmer Generator function).
- */
- typedef linear_congruential_engine<uint_fast32_t, 48271UL, 0UL, 2147483647UL>
- minstd_rand;
- /**
- * The classic Mersenne Twister.
- *
- * Reference:
- * M. Matsumoto and T. Nishimura, Mersenne Twister: A 623-Dimensionally
- * Equidistributed Uniform Pseudo-Random Number Generator, ACM Transactions
- * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.
- */
- typedef mersenne_twister_engine<
- uint_fast32_t,
- 32, 624, 397, 31,
- 0x9908b0dfUL, 11,
- 0xffffffffUL, 7,
- 0x9d2c5680UL, 15,
- 0xefc60000UL, 18, 1812433253UL> mt19937;
- /**
- * An alternative Mersenne Twister.
- */
- typedef mersenne_twister_engine<
- uint_fast64_t,
- 64, 312, 156, 31,
- 0xb5026f5aa96619e9ULL, 29,
- 0x5555555555555555ULL, 17,
- 0x71d67fffeda60000ULL, 37,
- 0xfff7eee000000000ULL, 43,
- 6364136223846793005ULL> mt19937_64;
- typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>
- ranlux24_base;
- typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>
- ranlux48_base;
- typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24;
- typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48;
- typedef shuffle_order_engine<minstd_rand0, 256> knuth_b;
- typedef minstd_rand0 default_random_engine;
- /**
- * A standard interface to a platform-specific non-deterministic
- * random number generator (if any are available).
- */
- class random_device
- {
- public:
- /** The type of the generated random value. */
- typedef unsigned int result_type;
- // constructors, destructors and member functions
- random_device() { _M_init("default"); }
- explicit
- random_device(const std::string& __token) { _M_init(__token); }
- #if defined _GLIBCXX_USE_DEV_RANDOM
- ~random_device()
- { _M_fini(); }
- #endif
- static constexpr result_type
- min()
- { return std::numeric_limits<result_type>::min(); }
- static constexpr result_type
- max()
- { return std::numeric_limits<result_type>::max(); }
- double
- entropy() const noexcept
- {
- #ifdef _GLIBCXX_USE_DEV_RANDOM
- return this->_M_getentropy();
- #else
- return 0.0;
- #endif
- }
- result_type
- operator()()
- { return this->_M_getval(); }
- // No copy functions.
- random_device(const random_device&) = delete;
- void operator=(const random_device&) = delete;
- private:
- void _M_init(const std::string& __token);
- void _M_init_pretr1(const std::string& __token);
- void _M_fini();
- result_type _M_getval();
- result_type _M_getval_pretr1();
- double _M_getentropy() const noexcept;
- void _M_init(const char*, size_t); // not exported from the shared library
- union
- {
- struct
- {
- void* _M_file;
- result_type (*_M_func)(void*);
- int _M_fd;
- };
- mt19937 _M_mt;
- };
- };
- /* @} */ // group random_generators
- /**
- * @addtogroup random_distributions Random Number Distributions
- * @ingroup random
- * @{
- */
- /**
- * @addtogroup random_distributions_uniform Uniform Distributions
- * @ingroup random_distributions
- * @{
- */
- // std::uniform_int_distribution is defined in <bits/uniform_int_dist.h>
- /**
- * @brief Return true if two uniform integer distributions have
- * different parameters.
- */
- template<typename _IntType>
- inline bool
- operator!=(const std::uniform_int_distribution<_IntType>& __d1,
- const std::uniform_int_distribution<_IntType>& __d2)
- { return !(__d1 == __d2); }
- /**
- * @brief Inserts a %uniform_int_distribution random number
- * distribution @p __x into the output stream @p os.
- *
- * @param __os An output stream.
- * @param __x A %uniform_int_distribution random number distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _IntType, typename _CharT, typename _Traits>
- std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>&,
- const std::uniform_int_distribution<_IntType>&);
- /**
- * @brief Extracts a %uniform_int_distribution random number distribution
- * @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %uniform_int_distribution random number generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error state.
- */
- template<typename _IntType, typename _CharT, typename _Traits>
- std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>&,
- std::uniform_int_distribution<_IntType>&);
- /**
- * @brief Uniform continuous distribution for random numbers.
- *
- * A continuous random distribution on the range [min, max) with equal
- * probability throughout the range. The URNG should be real-valued and
- * deliver number in the range [0, 1).
- */
- template<typename _RealType = double>
- class uniform_real_distribution
- {
- static_assert(std::is_floating_point<_RealType>::value,
- "result_type must be a floating point type");
- public:
- /** The type of the range of the distribution. */
- typedef _RealType result_type;
- /** Parameter type. */
- struct param_type
- {
- typedef uniform_real_distribution<_RealType> distribution_type;
- param_type() : param_type(0) { }
- explicit
- param_type(_RealType __a, _RealType __b = _RealType(1))
- : _M_a(__a), _M_b(__b)
- {
- __glibcxx_assert(_M_a <= _M_b);
- }
- result_type
- a() const
- { return _M_a; }
- result_type
- b() const
- { return _M_b; }
- friend bool
- operator==(const param_type& __p1, const param_type& __p2)
- { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
- friend bool
- operator!=(const param_type& __p1, const param_type& __p2)
- { return !(__p1 == __p2); }
- private:
- _RealType _M_a;
- _RealType _M_b;
- };
- public:
- /**
- * @brief Constructs a uniform_real_distribution object.
- *
- * The lower bound is set to 0.0 and the upper bound to 1.0
- */
- uniform_real_distribution() : uniform_real_distribution(0.0) { }
- /**
- * @brief Constructs a uniform_real_distribution object.
- *
- * @param __a [IN] The lower bound of the distribution.
- * @param __b [IN] The upper bound of the distribution.
- */
- explicit
- uniform_real_distribution(_RealType __a, _RealType __b = _RealType(1))
- : _M_param(__a, __b)
- { }
- explicit
- uniform_real_distribution(const param_type& __p)
- : _M_param(__p)
- { }
- /**
- * @brief Resets the distribution state.
- *
- * Does nothing for the uniform real distribution.
- */
- void
- reset() { }
- result_type
- a() const
- { return _M_param.a(); }
- result_type
- b() const
- { return _M_param.b(); }
- /**
- * @brief Returns the parameter set of the distribution.
- */
- param_type
- param() const
- { return _M_param; }
- /**
- * @brief Sets the parameter set of the distribution.
- * @param __param The new parameter set of the distribution.
- */
- void
- param(const param_type& __param)
- { _M_param = __param; }
- /**
- * @brief Returns the inclusive lower bound of the distribution range.
- */
- result_type
- min() const
- { return this->a(); }
- /**
- * @brief Returns the inclusive upper bound of the distribution range.
- */
- result_type
- max() const
- { return this->b(); }
- /**
- * @brief Generating functions.
- */
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, _M_param); }
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- {
- __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
- __aurng(__urng);
- return (__aurng() * (__p.b() - __p.a())) + __p.a();
- }
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng)
- { this->__generate(__f, __t, __urng, _M_param); }
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- template<typename _UniformRandomNumberGenerator>
- void
- __generate(result_type* __f, result_type* __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- /**
- * @brief Return true if two uniform real distributions have
- * the same parameters.
- */
- friend bool
- operator==(const uniform_real_distribution& __d1,
- const uniform_real_distribution& __d2)
- { return __d1._M_param == __d2._M_param; }
- private:
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- param_type _M_param;
- };
- /**
- * @brief Return true if two uniform real distributions have
- * different parameters.
- */
- template<typename _IntType>
- inline bool
- operator!=(const std::uniform_real_distribution<_IntType>& __d1,
- const std::uniform_real_distribution<_IntType>& __d2)
- { return !(__d1 == __d2); }
- /**
- * @brief Inserts a %uniform_real_distribution random number
- * distribution @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %uniform_real_distribution random number distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _RealType, typename _CharT, typename _Traits>
- std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>&,
- const std::uniform_real_distribution<_RealType>&);
- /**
- * @brief Extracts a %uniform_real_distribution random number distribution
- * @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %uniform_real_distribution random number generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error state.
- */
- template<typename _RealType, typename _CharT, typename _Traits>
- std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>&,
- std::uniform_real_distribution<_RealType>&);
- /* @} */ // group random_distributions_uniform
- /**
- * @addtogroup random_distributions_normal Normal Distributions
- * @ingroup random_distributions
- * @{
- */
- /**
- * @brief A normal continuous distribution for random numbers.
- *
- * The formula for the normal probability density function is
- * @f[
- * p(x|\mu,\sigma) = \frac{1}{\sigma \sqrt{2 \pi}}
- * e^{- \frac{{x - \mu}^ {2}}{2 \sigma ^ {2}} }
- * @f]
- */
- template<typename _RealType = double>
- class normal_distribution
- {
- static_assert(std::is_floating_point<_RealType>::value,
- "result_type must be a floating point type");
- public:
- /** The type of the range of the distribution. */
- typedef _RealType result_type;
- /** Parameter type. */
- struct param_type
- {
- typedef normal_distribution<_RealType> distribution_type;
- param_type() : param_type(0.0) { }
- explicit
- param_type(_RealType __mean, _RealType __stddev = _RealType(1))
- : _M_mean(__mean), _M_stddev(__stddev)
- {
- __glibcxx_assert(_M_stddev > _RealType(0));
- }
- _RealType
- mean() const
- { return _M_mean; }
- _RealType
- stddev() const
- { return _M_stddev; }
- friend bool
- operator==(const param_type& __p1, const param_type& __p2)
- { return (__p1._M_mean == __p2._M_mean
- && __p1._M_stddev == __p2._M_stddev); }
- friend bool
- operator!=(const param_type& __p1, const param_type& __p2)
- { return !(__p1 == __p2); }
- private:
- _RealType _M_mean;
- _RealType _M_stddev;
- };
- public:
- normal_distribution() : normal_distribution(0.0) { }
- /**
- * Constructs a normal distribution with parameters @f$mean@f$ and
- * standard deviation.
- */
- explicit
- normal_distribution(result_type __mean,
- result_type __stddev = result_type(1))
- : _M_param(__mean, __stddev), _M_saved_available(false)
- { }
- explicit
- normal_distribution(const param_type& __p)
- : _M_param(__p), _M_saved_available(false)
- { }
- /**
- * @brief Resets the distribution state.
- */
- void
- reset()
- { _M_saved_available = false; }
- /**
- * @brief Returns the mean of the distribution.
- */
- _RealType
- mean() const
- { return _M_param.mean(); }
- /**
- * @brief Returns the standard deviation of the distribution.
- */
- _RealType
- stddev() const
- { return _M_param.stddev(); }
- /**
- * @brief Returns the parameter set of the distribution.
- */
- param_type
- param() const
- { return _M_param; }
- /**
- * @brief Sets the parameter set of the distribution.
- * @param __param The new parameter set of the distribution.
- */
- void
- param(const param_type& __param)
- { _M_param = __param; }
- /**
- * @brief Returns the greatest lower bound value of the distribution.
- */
- result_type
- min() const
- { return std::numeric_limits<result_type>::lowest(); }
- /**
- * @brief Returns the least upper bound value of the distribution.
- */
- result_type
- max() const
- { return std::numeric_limits<result_type>::max(); }
- /**
- * @brief Generating functions.
- */
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, _M_param); }
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng)
- { this->__generate(__f, __t, __urng, _M_param); }
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- template<typename _UniformRandomNumberGenerator>
- void
- __generate(result_type* __f, result_type* __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- /**
- * @brief Return true if two normal distributions have
- * the same parameters and the sequences that would
- * be generated are equal.
- */
- template<typename _RealType1>
- friend bool
- operator==(const std::normal_distribution<_RealType1>& __d1,
- const std::normal_distribution<_RealType1>& __d2);
- /**
- * @brief Inserts a %normal_distribution random number distribution
- * @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %normal_distribution random number distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _RealType1, typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const std::normal_distribution<_RealType1>& __x);
- /**
- * @brief Extracts a %normal_distribution random number distribution
- * @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %normal_distribution random number generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error
- * state.
- */
- template<typename _RealType1, typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- std::normal_distribution<_RealType1>& __x);
- private:
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- param_type _M_param;
- result_type _M_saved;
- bool _M_saved_available;
- };
- /**
- * @brief Return true if two normal distributions are different.
- */
- template<typename _RealType>
- inline bool
- operator!=(const std::normal_distribution<_RealType>& __d1,
- const std::normal_distribution<_RealType>& __d2)
- { return !(__d1 == __d2); }
- /**
- * @brief A lognormal_distribution random number distribution.
- *
- * The formula for the normal probability mass function is
- * @f[
- * p(x|m,s) = \frac{1}{sx\sqrt{2\pi}}
- * \exp{-\frac{(\ln{x} - m)^2}{2s^2}}
- * @f]
- */
- template<typename _RealType = double>
- class lognormal_distribution
- {
- static_assert(std::is_floating_point<_RealType>::value,
- "result_type must be a floating point type");
- public:
- /** The type of the range of the distribution. */
- typedef _RealType result_type;
- /** Parameter type. */
- struct param_type
- {
- typedef lognormal_distribution<_RealType> distribution_type;
- param_type() : param_type(0.0) { }
- explicit
- param_type(_RealType __m, _RealType __s = _RealType(1))
- : _M_m(__m), _M_s(__s)
- { }
- _RealType
- m() const
- { return _M_m; }
- _RealType
- s() const
- { return _M_s; }
- friend bool
- operator==(const param_type& __p1, const param_type& __p2)
- { return __p1._M_m == __p2._M_m && __p1._M_s == __p2._M_s; }
- friend bool
- operator!=(const param_type& __p1, const param_type& __p2)
- { return !(__p1 == __p2); }
- private:
- _RealType _M_m;
- _RealType _M_s;
- };
- lognormal_distribution() : lognormal_distribution(0.0) { }
- explicit
- lognormal_distribution(_RealType __m, _RealType __s = _RealType(1))
- : _M_param(__m, __s), _M_nd()
- { }
- explicit
- lognormal_distribution(const param_type& __p)
- : _M_param(__p), _M_nd()
- { }
- /**
- * Resets the distribution state.
- */
- void
- reset()
- { _M_nd.reset(); }
- /**
- *
- */
- _RealType
- m() const
- { return _M_param.m(); }
- _RealType
- s() const
- { return _M_param.s(); }
- /**
- * @brief Returns the parameter set of the distribution.
- */
- param_type
- param() const
- { return _M_param; }
- /**
- * @brief Sets the parameter set of the distribution.
- * @param __param The new parameter set of the distribution.
- */
- void
- param(const param_type& __param)
- { _M_param = __param; }
- /**
- * @brief Returns the greatest lower bound value of the distribution.
- */
- result_type
- min() const
- { return result_type(0); }
- /**
- * @brief Returns the least upper bound value of the distribution.
- */
- result_type
- max() const
- { return std::numeric_limits<result_type>::max(); }
- /**
- * @brief Generating functions.
- */
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, _M_param); }
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { return std::exp(__p.s() * _M_nd(__urng) + __p.m()); }
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng)
- { this->__generate(__f, __t, __urng, _M_param); }
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- template<typename _UniformRandomNumberGenerator>
- void
- __generate(result_type* __f, result_type* __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- /**
- * @brief Return true if two lognormal distributions have
- * the same parameters and the sequences that would
- * be generated are equal.
- */
- friend bool
- operator==(const lognormal_distribution& __d1,
- const lognormal_distribution& __d2)
- { return (__d1._M_param == __d2._M_param
- && __d1._M_nd == __d2._M_nd); }
- /**
- * @brief Inserts a %lognormal_distribution random number distribution
- * @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %lognormal_distribution random number distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _RealType1, typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const std::lognormal_distribution<_RealType1>& __x);
- /**
- * @brief Extracts a %lognormal_distribution random number distribution
- * @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %lognormal_distribution random number
- * generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error state.
- */
- template<typename _RealType1, typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- std::lognormal_distribution<_RealType1>& __x);
- private:
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- param_type _M_param;
- std::normal_distribution<result_type> _M_nd;
- };
- /**
- * @brief Return true if two lognormal distributions are different.
- */
- template<typename _RealType>
- inline bool
- operator!=(const std::lognormal_distribution<_RealType>& __d1,
- const std::lognormal_distribution<_RealType>& __d2)
- { return !(__d1 == __d2); }
- /**
- * @brief A gamma continuous distribution for random numbers.
- *
- * The formula for the gamma probability density function is:
- * @f[
- * p(x|\alpha,\beta) = \frac{1}{\beta\Gamma(\alpha)}
- * (x/\beta)^{\alpha - 1} e^{-x/\beta}
- * @f]
- */
- template<typename _RealType = double>
- class gamma_distribution
- {
- static_assert(std::is_floating_point<_RealType>::value,
- "result_type must be a floating point type");
- public:
- /** The type of the range of the distribution. */
- typedef _RealType result_type;
- /** Parameter type. */
- struct param_type
- {
- typedef gamma_distribution<_RealType> distribution_type;
- friend class gamma_distribution<_RealType>;
- param_type() : param_type(1.0) { }
- explicit
- param_type(_RealType __alpha_val, _RealType __beta_val = _RealType(1))
- : _M_alpha(__alpha_val), _M_beta(__beta_val)
- {
- __glibcxx_assert(_M_alpha > _RealType(0));
- _M_initialize();
- }
- _RealType
- alpha() const
- { return _M_alpha; }
- _RealType
- beta() const
- { return _M_beta; }
- friend bool
- operator==(const param_type& __p1, const param_type& __p2)
- { return (__p1._M_alpha == __p2._M_alpha
- && __p1._M_beta == __p2._M_beta); }
- friend bool
- operator!=(const param_type& __p1, const param_type& __p2)
- { return !(__p1 == __p2); }
- private:
- void
- _M_initialize();
- _RealType _M_alpha;
- _RealType _M_beta;
- _RealType _M_malpha, _M_a2;
- };
- public:
- /**
- * @brief Constructs a gamma distribution with parameters 1 and 1.
- */
- gamma_distribution() : gamma_distribution(1.0) { }
- /**
- * @brief Constructs a gamma distribution with parameters
- * @f$\alpha@f$ and @f$\beta@f$.
- */
- explicit
- gamma_distribution(_RealType __alpha_val,
- _RealType __beta_val = _RealType(1))
- : _M_param(__alpha_val, __beta_val), _M_nd()
- { }
- explicit
- gamma_distribution(const param_type& __p)
- : _M_param(__p), _M_nd()
- { }
- /**
- * @brief Resets the distribution state.
- */
- void
- reset()
- { _M_nd.reset(); }
- /**
- * @brief Returns the @f$\alpha@f$ of the distribution.
- */
- _RealType
- alpha() const
- { return _M_param.alpha(); }
- /**
- * @brief Returns the @f$\beta@f$ of the distribution.
- */
- _RealType
- beta() const
- { return _M_param.beta(); }
- /**
- * @brief Returns the parameter set of the distribution.
- */
- param_type
- param() const
- { return _M_param; }
- /**
- * @brief Sets the parameter set of the distribution.
- * @param __param The new parameter set of the distribution.
- */
- void
- param(const param_type& __param)
- { _M_param = __param; }
- /**
- * @brief Returns the greatest lower bound value of the distribution.
- */
- result_type
- min() const
- { return result_type(0); }
- /**
- * @brief Returns the least upper bound value of the distribution.
- */
- result_type
- max() const
- { return std::numeric_limits<result_type>::max(); }
- /**
- * @brief Generating functions.
- */
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, _M_param); }
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng)
- { this->__generate(__f, __t, __urng, _M_param); }
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- template<typename _UniformRandomNumberGenerator>
- void
- __generate(result_type* __f, result_type* __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- /**
- * @brief Return true if two gamma distributions have the same
- * parameters and the sequences that would be generated
- * are equal.
- */
- friend bool
- operator==(const gamma_distribution& __d1,
- const gamma_distribution& __d2)
- { return (__d1._M_param == __d2._M_param
- && __d1._M_nd == __d2._M_nd); }
- /**
- * @brief Inserts a %gamma_distribution random number distribution
- * @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %gamma_distribution random number distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _RealType1, typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const std::gamma_distribution<_RealType1>& __x);
- /**
- * @brief Extracts a %gamma_distribution random number distribution
- * @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %gamma_distribution random number generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error state.
- */
- template<typename _RealType1, typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- std::gamma_distribution<_RealType1>& __x);
- private:
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- param_type _M_param;
- std::normal_distribution<result_type> _M_nd;
- };
- /**
- * @brief Return true if two gamma distributions are different.
- */
- template<typename _RealType>
- inline bool
- operator!=(const std::gamma_distribution<_RealType>& __d1,
- const std::gamma_distribution<_RealType>& __d2)
- { return !(__d1 == __d2); }
- /**
- * @brief A chi_squared_distribution random number distribution.
- *
- * The formula for the normal probability mass function is
- * @f$p(x|n) = \frac{x^{(n/2) - 1}e^{-x/2}}{\Gamma(n/2) 2^{n/2}}@f$
- */
- template<typename _RealType = double>
- class chi_squared_distribution
- {
- static_assert(std::is_floating_point<_RealType>::value,
- "result_type must be a floating point type");
- public:
- /** The type of the range of the distribution. */
- typedef _RealType result_type;
- /** Parameter type. */
- struct param_type
- {
- typedef chi_squared_distribution<_RealType> distribution_type;
- param_type() : param_type(1) { }
- explicit
- param_type(_RealType __n)
- : _M_n(__n)
- { }
- _RealType
- n() const
- { return _M_n; }
- friend bool
- operator==(const param_type& __p1, const param_type& __p2)
- { return __p1._M_n == __p2._M_n; }
- friend bool
- operator!=(const param_type& __p1, const param_type& __p2)
- { return !(__p1 == __p2); }
- private:
- _RealType _M_n;
- };
- chi_squared_distribution() : chi_squared_distribution(1) { }
- explicit
- chi_squared_distribution(_RealType __n)
- : _M_param(__n), _M_gd(__n / 2)
- { }
- explicit
- chi_squared_distribution(const param_type& __p)
- : _M_param(__p), _M_gd(__p.n() / 2)
- { }
- /**
- * @brief Resets the distribution state.
- */
- void
- reset()
- { _M_gd.reset(); }
- /**
- *
- */
- _RealType
- n() const
- { return _M_param.n(); }
- /**
- * @brief Returns the parameter set of the distribution.
- */
- param_type
- param() const
- { return _M_param; }
- /**
- * @brief Sets the parameter set of the distribution.
- * @param __param The new parameter set of the distribution.
- */
- void
- param(const param_type& __param)
- {
- _M_param = __param;
- typedef typename std::gamma_distribution<result_type>::param_type
- param_type;
- _M_gd.param(param_type{__param.n() / 2});
- }
- /**
- * @brief Returns the greatest lower bound value of the distribution.
- */
- result_type
- min() const
- { return result_type(0); }
- /**
- * @brief Returns the least upper bound value of the distribution.
- */
- result_type
- max() const
- { return std::numeric_limits<result_type>::max(); }
- /**
- * @brief Generating functions.
- */
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng)
- { return 2 * _M_gd(__urng); }
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- {
- typedef typename std::gamma_distribution<result_type>::param_type
- param_type;
- return 2 * _M_gd(__urng, param_type(__p.n() / 2));
- }
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng)
- { this->__generate_impl(__f, __t, __urng); }
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { typename std::gamma_distribution<result_type>::param_type
- __p2(__p.n() / 2);
- this->__generate_impl(__f, __t, __urng, __p2); }
- template<typename _UniformRandomNumberGenerator>
- void
- __generate(result_type* __f, result_type* __t,
- _UniformRandomNumberGenerator& __urng)
- { this->__generate_impl(__f, __t, __urng); }
- template<typename _UniformRandomNumberGenerator>
- void
- __generate(result_type* __f, result_type* __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { typename std::gamma_distribution<result_type>::param_type
- __p2(__p.n() / 2);
- this->__generate_impl(__f, __t, __urng, __p2); }
- /**
- * @brief Return true if two Chi-squared distributions have
- * the same parameters and the sequences that would be
- * generated are equal.
- */
- friend bool
- operator==(const chi_squared_distribution& __d1,
- const chi_squared_distribution& __d2)
- { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; }
- /**
- * @brief Inserts a %chi_squared_distribution random number distribution
- * @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %chi_squared_distribution random number distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _RealType1, typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const std::chi_squared_distribution<_RealType1>& __x);
- /**
- * @brief Extracts a %chi_squared_distribution random number distribution
- * @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %chi_squared_distribution random number
- * generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error state.
- */
- template<typename _RealType1, typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- std::chi_squared_distribution<_RealType1>& __x);
- private:
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng);
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const typename
- std::gamma_distribution<result_type>::param_type& __p);
- param_type _M_param;
- std::gamma_distribution<result_type> _M_gd;
- };
- /**
- * @brief Return true if two Chi-squared distributions are different.
- */
- template<typename _RealType>
- inline bool
- operator!=(const std::chi_squared_distribution<_RealType>& __d1,
- const std::chi_squared_distribution<_RealType>& __d2)
- { return !(__d1 == __d2); }
- /**
- * @brief A cauchy_distribution random number distribution.
- *
- * The formula for the normal probability mass function is
- * @f$p(x|a,b) = (\pi b (1 + (\frac{x-a}{b})^2))^{-1}@f$
- */
- template<typename _RealType = double>
- class cauchy_distribution
- {
- static_assert(std::is_floating_point<_RealType>::value,
- "result_type must be a floating point type");
- public:
- /** The type of the range of the distribution. */
- typedef _RealType result_type;
- /** Parameter type. */
- struct param_type
- {
- typedef cauchy_distribution<_RealType> distribution_type;
- param_type() : param_type(0) { }
- explicit
- param_type(_RealType __a, _RealType __b = _RealType(1))
- : _M_a(__a), _M_b(__b)
- { }
- _RealType
- a() const
- { return _M_a; }
- _RealType
- b() const
- { return _M_b; }
- friend bool
- operator==(const param_type& __p1, const param_type& __p2)
- { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
- friend bool
- operator!=(const param_type& __p1, const param_type& __p2)
- { return !(__p1 == __p2); }
- private:
- _RealType _M_a;
- _RealType _M_b;
- };
- cauchy_distribution() : cauchy_distribution(0.0) { }
- explicit
- cauchy_distribution(_RealType __a, _RealType __b = 1.0)
- : _M_param(__a, __b)
- { }
- explicit
- cauchy_distribution(const param_type& __p)
- : _M_param(__p)
- { }
- /**
- * @brief Resets the distribution state.
- */
- void
- reset()
- { }
- /**
- *
- */
- _RealType
- a() const
- { return _M_param.a(); }
- _RealType
- b() const
- { return _M_param.b(); }
- /**
- * @brief Returns the parameter set of the distribution.
- */
- param_type
- param() const
- { return _M_param; }
- /**
- * @brief Sets the parameter set of the distribution.
- * @param __param The new parameter set of the distribution.
- */
- void
- param(const param_type& __param)
- { _M_param = __param; }
- /**
- * @brief Returns the greatest lower bound value of the distribution.
- */
- result_type
- min() const
- { return std::numeric_limits<result_type>::lowest(); }
- /**
- * @brief Returns the least upper bound value of the distribution.
- */
- result_type
- max() const
- { return std::numeric_limits<result_type>::max(); }
- /**
- * @brief Generating functions.
- */
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, _M_param); }
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng)
- { this->__generate(__f, __t, __urng, _M_param); }
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- template<typename _UniformRandomNumberGenerator>
- void
- __generate(result_type* __f, result_type* __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- /**
- * @brief Return true if two Cauchy distributions have
- * the same parameters.
- */
- friend bool
- operator==(const cauchy_distribution& __d1,
- const cauchy_distribution& __d2)
- { return __d1._M_param == __d2._M_param; }
- private:
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- param_type _M_param;
- };
- /**
- * @brief Return true if two Cauchy distributions have
- * different parameters.
- */
- template<typename _RealType>
- inline bool
- operator!=(const std::cauchy_distribution<_RealType>& __d1,
- const std::cauchy_distribution<_RealType>& __d2)
- { return !(__d1 == __d2); }
- /**
- * @brief Inserts a %cauchy_distribution random number distribution
- * @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %cauchy_distribution random number distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _RealType, typename _CharT, typename _Traits>
- std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const std::cauchy_distribution<_RealType>& __x);
- /**
- * @brief Extracts a %cauchy_distribution random number distribution
- * @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %cauchy_distribution random number
- * generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error state.
- */
- template<typename _RealType, typename _CharT, typename _Traits>
- std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- std::cauchy_distribution<_RealType>& __x);
- /**
- * @brief A fisher_f_distribution random number distribution.
- *
- * The formula for the normal probability mass function is
- * @f[
- * p(x|m,n) = \frac{\Gamma((m+n)/2)}{\Gamma(m/2)\Gamma(n/2)}
- * (\frac{m}{n})^{m/2} x^{(m/2)-1}
- * (1 + \frac{mx}{n})^{-(m+n)/2}
- * @f]
- */
- template<typename _RealType = double>
- class fisher_f_distribution
- {
- static_assert(std::is_floating_point<_RealType>::value,
- "result_type must be a floating point type");
- public:
- /** The type of the range of the distribution. */
- typedef _RealType result_type;
- /** Parameter type. */
- struct param_type
- {
- typedef fisher_f_distribution<_RealType> distribution_type;
- param_type() : param_type(1) { }
- explicit
- param_type(_RealType __m, _RealType __n = _RealType(1))
- : _M_m(__m), _M_n(__n)
- { }
- _RealType
- m() const
- { return _M_m; }
- _RealType
- n() const
- { return _M_n; }
- friend bool
- operator==(const param_type& __p1, const param_type& __p2)
- { return __p1._M_m == __p2._M_m && __p1._M_n == __p2._M_n; }
- friend bool
- operator!=(const param_type& __p1, const param_type& __p2)
- { return !(__p1 == __p2); }
- private:
- _RealType _M_m;
- _RealType _M_n;
- };
- fisher_f_distribution() : fisher_f_distribution(1.0) { }
- explicit
- fisher_f_distribution(_RealType __m,
- _RealType __n = _RealType(1))
- : _M_param(__m, __n), _M_gd_x(__m / 2), _M_gd_y(__n / 2)
- { }
- explicit
- fisher_f_distribution(const param_type& __p)
- : _M_param(__p), _M_gd_x(__p.m() / 2), _M_gd_y(__p.n() / 2)
- { }
- /**
- * @brief Resets the distribution state.
- */
- void
- reset()
- {
- _M_gd_x.reset();
- _M_gd_y.reset();
- }
- /**
- *
- */
- _RealType
- m() const
- { return _M_param.m(); }
- _RealType
- n() const
- { return _M_param.n(); }
- /**
- * @brief Returns the parameter set of the distribution.
- */
- param_type
- param() const
- { return _M_param; }
- /**
- * @brief Sets the parameter set of the distribution.
- * @param __param The new parameter set of the distribution.
- */
- void
- param(const param_type& __param)
- { _M_param = __param; }
- /**
- * @brief Returns the greatest lower bound value of the distribution.
- */
- result_type
- min() const
- { return result_type(0); }
- /**
- * @brief Returns the least upper bound value of the distribution.
- */
- result_type
- max() const
- { return std::numeric_limits<result_type>::max(); }
- /**
- * @brief Generating functions.
- */
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng)
- { return (_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()); }
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- {
- typedef typename std::gamma_distribution<result_type>::param_type
- param_type;
- return ((_M_gd_x(__urng, param_type(__p.m() / 2)) * n())
- / (_M_gd_y(__urng, param_type(__p.n() / 2)) * m()));
- }
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng)
- { this->__generate_impl(__f, __t, __urng); }
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- template<typename _UniformRandomNumberGenerator>
- void
- __generate(result_type* __f, result_type* __t,
- _UniformRandomNumberGenerator& __urng)
- { this->__generate_impl(__f, __t, __urng); }
- template<typename _UniformRandomNumberGenerator>
- void
- __generate(result_type* __f, result_type* __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- /**
- * @brief Return true if two Fisher f distributions have
- * the same parameters and the sequences that would
- * be generated are equal.
- */
- friend bool
- operator==(const fisher_f_distribution& __d1,
- const fisher_f_distribution& __d2)
- { return (__d1._M_param == __d2._M_param
- && __d1._M_gd_x == __d2._M_gd_x
- && __d1._M_gd_y == __d2._M_gd_y); }
- /**
- * @brief Inserts a %fisher_f_distribution random number distribution
- * @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %fisher_f_distribution random number distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _RealType1, typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const std::fisher_f_distribution<_RealType1>& __x);
- /**
- * @brief Extracts a %fisher_f_distribution random number distribution
- * @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %fisher_f_distribution random number
- * generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error state.
- */
- template<typename _RealType1, typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- std::fisher_f_distribution<_RealType1>& __x);
- private:
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng);
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- param_type _M_param;
- std::gamma_distribution<result_type> _M_gd_x, _M_gd_y;
- };
- /**
- * @brief Return true if two Fisher f distributions are different.
- */
- template<typename _RealType>
- inline bool
- operator!=(const std::fisher_f_distribution<_RealType>& __d1,
- const std::fisher_f_distribution<_RealType>& __d2)
- { return !(__d1 == __d2); }
- /**
- * @brief A student_t_distribution random number distribution.
- *
- * The formula for the normal probability mass function is:
- * @f[
- * p(x|n) = \frac{1}{\sqrt(n\pi)} \frac{\Gamma((n+1)/2)}{\Gamma(n/2)}
- * (1 + \frac{x^2}{n}) ^{-(n+1)/2}
- * @f]
- */
- template<typename _RealType = double>
- class student_t_distribution
- {
- static_assert(std::is_floating_point<_RealType>::value,
- "result_type must be a floating point type");
- public:
- /** The type of the range of the distribution. */
- typedef _RealType result_type;
- /** Parameter type. */
- struct param_type
- {
- typedef student_t_distribution<_RealType> distribution_type;
- param_type() : param_type(1) { }
- explicit
- param_type(_RealType __n)
- : _M_n(__n)
- { }
- _RealType
- n() const
- { return _M_n; }
- friend bool
- operator==(const param_type& __p1, const param_type& __p2)
- { return __p1._M_n == __p2._M_n; }
- friend bool
- operator!=(const param_type& __p1, const param_type& __p2)
- { return !(__p1 == __p2); }
- private:
- _RealType _M_n;
- };
- student_t_distribution() : student_t_distribution(1.0) { }
- explicit
- student_t_distribution(_RealType __n)
- : _M_param(__n), _M_nd(), _M_gd(__n / 2, 2)
- { }
- explicit
- student_t_distribution(const param_type& __p)
- : _M_param(__p), _M_nd(), _M_gd(__p.n() / 2, 2)
- { }
- /**
- * @brief Resets the distribution state.
- */
- void
- reset()
- {
- _M_nd.reset();
- _M_gd.reset();
- }
- /**
- *
- */
- _RealType
- n() const
- { return _M_param.n(); }
- /**
- * @brief Returns the parameter set of the distribution.
- */
- param_type
- param() const
- { return _M_param; }
- /**
- * @brief Sets the parameter set of the distribution.
- * @param __param The new parameter set of the distribution.
- */
- void
- param(const param_type& __param)
- { _M_param = __param; }
- /**
- * @brief Returns the greatest lower bound value of the distribution.
- */
- result_type
- min() const
- { return std::numeric_limits<result_type>::lowest(); }
- /**
- * @brief Returns the least upper bound value of the distribution.
- */
- result_type
- max() const
- { return std::numeric_limits<result_type>::max(); }
- /**
- * @brief Generating functions.
- */
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng)
- { return _M_nd(__urng) * std::sqrt(n() / _M_gd(__urng)); }
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- {
- typedef typename std::gamma_distribution<result_type>::param_type
- param_type;
-
- const result_type __g = _M_gd(__urng, param_type(__p.n() / 2, 2));
- return _M_nd(__urng) * std::sqrt(__p.n() / __g);
- }
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng)
- { this->__generate_impl(__f, __t, __urng); }
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- template<typename _UniformRandomNumberGenerator>
- void
- __generate(result_type* __f, result_type* __t,
- _UniformRandomNumberGenerator& __urng)
- { this->__generate_impl(__f, __t, __urng); }
- template<typename _UniformRandomNumberGenerator>
- void
- __generate(result_type* __f, result_type* __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- /**
- * @brief Return true if two Student t distributions have
- * the same parameters and the sequences that would
- * be generated are equal.
- */
- friend bool
- operator==(const student_t_distribution& __d1,
- const student_t_distribution& __d2)
- { return (__d1._M_param == __d2._M_param
- && __d1._M_nd == __d2._M_nd && __d1._M_gd == __d2._M_gd); }
- /**
- * @brief Inserts a %student_t_distribution random number distribution
- * @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %student_t_distribution random number distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _RealType1, typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const std::student_t_distribution<_RealType1>& __x);
- /**
- * @brief Extracts a %student_t_distribution random number distribution
- * @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %student_t_distribution random number
- * generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error state.
- */
- template<typename _RealType1, typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- std::student_t_distribution<_RealType1>& __x);
- private:
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng);
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- param_type _M_param;
- std::normal_distribution<result_type> _M_nd;
- std::gamma_distribution<result_type> _M_gd;
- };
- /**
- * @brief Return true if two Student t distributions are different.
- */
- template<typename _RealType>
- inline bool
- operator!=(const std::student_t_distribution<_RealType>& __d1,
- const std::student_t_distribution<_RealType>& __d2)
- { return !(__d1 == __d2); }
- /* @} */ // group random_distributions_normal
- /**
- * @addtogroup random_distributions_bernoulli Bernoulli Distributions
- * @ingroup random_distributions
- * @{
- */
- /**
- * @brief A Bernoulli random number distribution.
- *
- * Generates a sequence of true and false values with likelihood @f$p@f$
- * that true will come up and @f$(1 - p)@f$ that false will appear.
- */
- class bernoulli_distribution
- {
- public:
- /** The type of the range of the distribution. */
- typedef bool result_type;
- /** Parameter type. */
- struct param_type
- {
- typedef bernoulli_distribution distribution_type;
- param_type() : param_type(0.5) { }
- explicit
- param_type(double __p)
- : _M_p(__p)
- {
- __glibcxx_assert((_M_p >= 0.0) && (_M_p <= 1.0));
- }
- double
- p() const
- { return _M_p; }
- friend bool
- operator==(const param_type& __p1, const param_type& __p2)
- { return __p1._M_p == __p2._M_p; }
- friend bool
- operator!=(const param_type& __p1, const param_type& __p2)
- { return !(__p1 == __p2); }
- private:
- double _M_p;
- };
- public:
- /**
- * @brief Constructs a Bernoulli distribution with likelihood 0.5.
- */
- bernoulli_distribution() : bernoulli_distribution(0.5) { }
- /**
- * @brief Constructs a Bernoulli distribution with likelihood @p p.
- *
- * @param __p [IN] The likelihood of a true result being returned.
- * Must be in the interval @f$[0, 1]@f$.
- */
- explicit
- bernoulli_distribution(double __p)
- : _M_param(__p)
- { }
- explicit
- bernoulli_distribution(const param_type& __p)
- : _M_param(__p)
- { }
- /**
- * @brief Resets the distribution state.
- *
- * Does nothing for a Bernoulli distribution.
- */
- void
- reset() { }
- /**
- * @brief Returns the @p p parameter of the distribution.
- */
- double
- p() const
- { return _M_param.p(); }
- /**
- * @brief Returns the parameter set of the distribution.
- */
- param_type
- param() const
- { return _M_param; }
- /**
- * @brief Sets the parameter set of the distribution.
- * @param __param The new parameter set of the distribution.
- */
- void
- param(const param_type& __param)
- { _M_param = __param; }
- /**
- * @brief Returns the greatest lower bound value of the distribution.
- */
- result_type
- min() const
- { return std::numeric_limits<result_type>::min(); }
- /**
- * @brief Returns the least upper bound value of the distribution.
- */
- result_type
- max() const
- { return std::numeric_limits<result_type>::max(); }
- /**
- * @brief Generating functions.
- */
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, _M_param); }
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- {
- __detail::_Adaptor<_UniformRandomNumberGenerator, double>
- __aurng(__urng);
- if ((__aurng() - __aurng.min())
- < __p.p() * (__aurng.max() - __aurng.min()))
- return true;
- return false;
- }
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng)
- { this->__generate(__f, __t, __urng, _M_param); }
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng, const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- template<typename _UniformRandomNumberGenerator>
- void
- __generate(result_type* __f, result_type* __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- /**
- * @brief Return true if two Bernoulli distributions have
- * the same parameters.
- */
- friend bool
- operator==(const bernoulli_distribution& __d1,
- const bernoulli_distribution& __d2)
- { return __d1._M_param == __d2._M_param; }
- private:
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- param_type _M_param;
- };
- /**
- * @brief Return true if two Bernoulli distributions have
- * different parameters.
- */
- inline bool
- operator!=(const std::bernoulli_distribution& __d1,
- const std::bernoulli_distribution& __d2)
- { return !(__d1 == __d2); }
- /**
- * @brief Inserts a %bernoulli_distribution random number distribution
- * @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %bernoulli_distribution random number distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _CharT, typename _Traits>
- std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const std::bernoulli_distribution& __x);
- /**
- * @brief Extracts a %bernoulli_distribution random number distribution
- * @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %bernoulli_distribution random number generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error state.
- */
- template<typename _CharT, typename _Traits>
- inline std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- std::bernoulli_distribution& __x)
- {
- double __p;
- if (__is >> __p)
- __x.param(bernoulli_distribution::param_type(__p));
- return __is;
- }
- /**
- * @brief A discrete binomial random number distribution.
- *
- * The formula for the binomial probability density function is
- * @f$p(i|t,p) = \binom{t}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
- * and @f$p@f$ are the parameters of the distribution.
- */
- template<typename _IntType = int>
- class binomial_distribution
- {
- static_assert(std::is_integral<_IntType>::value,
- "result_type must be an integral type");
- public:
- /** The type of the range of the distribution. */
- typedef _IntType result_type;
- /** Parameter type. */
- struct param_type
- {
- typedef binomial_distribution<_IntType> distribution_type;
- friend class binomial_distribution<_IntType>;
- param_type() : param_type(1) { }
- explicit
- param_type(_IntType __t, double __p = 0.5)
- : _M_t(__t), _M_p(__p)
- {
- __glibcxx_assert((_M_t >= _IntType(0))
- && (_M_p >= 0.0)
- && (_M_p <= 1.0));
- _M_initialize();
- }
- _IntType
- t() const
- { return _M_t; }
- double
- p() const
- { return _M_p; }
- friend bool
- operator==(const param_type& __p1, const param_type& __p2)
- { return __p1._M_t == __p2._M_t && __p1._M_p == __p2._M_p; }
- friend bool
- operator!=(const param_type& __p1, const param_type& __p2)
- { return !(__p1 == __p2); }
- private:
- void
- _M_initialize();
- _IntType _M_t;
- double _M_p;
- double _M_q;
- #if _GLIBCXX_USE_C99_MATH_TR1
- double _M_d1, _M_d2, _M_s1, _M_s2, _M_c,
- _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p;
- #endif
- bool _M_easy;
- };
- // constructors and member functions
- binomial_distribution() : binomial_distribution(1) { }
- explicit
- binomial_distribution(_IntType __t, double __p = 0.5)
- : _M_param(__t, __p), _M_nd()
- { }
- explicit
- binomial_distribution(const param_type& __p)
- : _M_param(__p), _M_nd()
- { }
- /**
- * @brief Resets the distribution state.
- */
- void
- reset()
- { _M_nd.reset(); }
- /**
- * @brief Returns the distribution @p t parameter.
- */
- _IntType
- t() const
- { return _M_param.t(); }
- /**
- * @brief Returns the distribution @p p parameter.
- */
- double
- p() const
- { return _M_param.p(); }
- /**
- * @brief Returns the parameter set of the distribution.
- */
- param_type
- param() const
- { return _M_param; }
- /**
- * @brief Sets the parameter set of the distribution.
- * @param __param The new parameter set of the distribution.
- */
- void
- param(const param_type& __param)
- { _M_param = __param; }
- /**
- * @brief Returns the greatest lower bound value of the distribution.
- */
- result_type
- min() const
- { return 0; }
- /**
- * @brief Returns the least upper bound value of the distribution.
- */
- result_type
- max() const
- { return _M_param.t(); }
- /**
- * @brief Generating functions.
- */
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, _M_param); }
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng)
- { this->__generate(__f, __t, __urng, _M_param); }
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- template<typename _UniformRandomNumberGenerator>
- void
- __generate(result_type* __f, result_type* __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- /**
- * @brief Return true if two binomial distributions have
- * the same parameters and the sequences that would
- * be generated are equal.
- */
- friend bool
- operator==(const binomial_distribution& __d1,
- const binomial_distribution& __d2)
- #ifdef _GLIBCXX_USE_C99_MATH_TR1
- { return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; }
- #else
- { return __d1._M_param == __d2._M_param; }
- #endif
- /**
- * @brief Inserts a %binomial_distribution random number distribution
- * @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %binomial_distribution random number distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _IntType1,
- typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const std::binomial_distribution<_IntType1>& __x);
- /**
- * @brief Extracts a %binomial_distribution random number distribution
- * @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %binomial_distribution random number generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error
- * state.
- */
- template<typename _IntType1,
- typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- std::binomial_distribution<_IntType1>& __x);
- private:
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- template<typename _UniformRandomNumberGenerator>
- result_type
- _M_waiting(_UniformRandomNumberGenerator& __urng,
- _IntType __t, double __q);
- param_type _M_param;
- // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
- std::normal_distribution<double> _M_nd;
- };
- /**
- * @brief Return true if two binomial distributions are different.
- */
- template<typename _IntType>
- inline bool
- operator!=(const std::binomial_distribution<_IntType>& __d1,
- const std::binomial_distribution<_IntType>& __d2)
- { return !(__d1 == __d2); }
- /**
- * @brief A discrete geometric random number distribution.
- *
- * The formula for the geometric probability density function is
- * @f$p(i|p) = p(1 - p)^{i}@f$ where @f$p@f$ is the parameter of the
- * distribution.
- */
- template<typename _IntType = int>
- class geometric_distribution
- {
- static_assert(std::is_integral<_IntType>::value,
- "result_type must be an integral type");
- public:
- /** The type of the range of the distribution. */
- typedef _IntType result_type;
- /** Parameter type. */
- struct param_type
- {
- typedef geometric_distribution<_IntType> distribution_type;
- friend class geometric_distribution<_IntType>;
- param_type() : param_type(0.5) { }
- explicit
- param_type(double __p)
- : _M_p(__p)
- {
- __glibcxx_assert((_M_p > 0.0) && (_M_p < 1.0));
- _M_initialize();
- }
- double
- p() const
- { return _M_p; }
- friend bool
- operator==(const param_type& __p1, const param_type& __p2)
- { return __p1._M_p == __p2._M_p; }
- friend bool
- operator!=(const param_type& __p1, const param_type& __p2)
- { return !(__p1 == __p2); }
- private:
- void
- _M_initialize()
- { _M_log_1_p = std::log(1.0 - _M_p); }
- double _M_p;
- double _M_log_1_p;
- };
- // constructors and member functions
- geometric_distribution() : geometric_distribution(0.5) { }
- explicit
- geometric_distribution(double __p)
- : _M_param(__p)
- { }
- explicit
- geometric_distribution(const param_type& __p)
- : _M_param(__p)
- { }
- /**
- * @brief Resets the distribution state.
- *
- * Does nothing for the geometric distribution.
- */
- void
- reset() { }
- /**
- * @brief Returns the distribution parameter @p p.
- */
- double
- p() const
- { return _M_param.p(); }
- /**
- * @brief Returns the parameter set of the distribution.
- */
- param_type
- param() const
- { return _M_param; }
- /**
- * @brief Sets the parameter set of the distribution.
- * @param __param The new parameter set of the distribution.
- */
- void
- param(const param_type& __param)
- { _M_param = __param; }
- /**
- * @brief Returns the greatest lower bound value of the distribution.
- */
- result_type
- min() const
- { return 0; }
- /**
- * @brief Returns the least upper bound value of the distribution.
- */
- result_type
- max() const
- { return std::numeric_limits<result_type>::max(); }
- /**
- * @brief Generating functions.
- */
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, _M_param); }
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng)
- { this->__generate(__f, __t, __urng, _M_param); }
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- template<typename _UniformRandomNumberGenerator>
- void
- __generate(result_type* __f, result_type* __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- /**
- * @brief Return true if two geometric distributions have
- * the same parameters.
- */
- friend bool
- operator==(const geometric_distribution& __d1,
- const geometric_distribution& __d2)
- { return __d1._M_param == __d2._M_param; }
- private:
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- param_type _M_param;
- };
- /**
- * @brief Return true if two geometric distributions have
- * different parameters.
- */
- template<typename _IntType>
- inline bool
- operator!=(const std::geometric_distribution<_IntType>& __d1,
- const std::geometric_distribution<_IntType>& __d2)
- { return !(__d1 == __d2); }
- /**
- * @brief Inserts a %geometric_distribution random number distribution
- * @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %geometric_distribution random number distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _IntType,
- typename _CharT, typename _Traits>
- std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const std::geometric_distribution<_IntType>& __x);
- /**
- * @brief Extracts a %geometric_distribution random number distribution
- * @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %geometric_distribution random number generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error state.
- */
- template<typename _IntType,
- typename _CharT, typename _Traits>
- std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- std::geometric_distribution<_IntType>& __x);
- /**
- * @brief A negative_binomial_distribution random number distribution.
- *
- * The formula for the negative binomial probability mass function is
- * @f$p(i) = \binom{n}{i} p^i (1 - p)^{t - i}@f$ where @f$t@f$
- * and @f$p@f$ are the parameters of the distribution.
- */
- template<typename _IntType = int>
- class negative_binomial_distribution
- {
- static_assert(std::is_integral<_IntType>::value,
- "result_type must be an integral type");
- public:
- /** The type of the range of the distribution. */
- typedef _IntType result_type;
- /** Parameter type. */
- struct param_type
- {
- typedef negative_binomial_distribution<_IntType> distribution_type;
- param_type() : param_type(1) { }
- explicit
- param_type(_IntType __k, double __p = 0.5)
- : _M_k(__k), _M_p(__p)
- {
- __glibcxx_assert((_M_k > 0) && (_M_p > 0.0) && (_M_p <= 1.0));
- }
- _IntType
- k() const
- { return _M_k; }
- double
- p() const
- { return _M_p; }
- friend bool
- operator==(const param_type& __p1, const param_type& __p2)
- { return __p1._M_k == __p2._M_k && __p1._M_p == __p2._M_p; }
- friend bool
- operator!=(const param_type& __p1, const param_type& __p2)
- { return !(__p1 == __p2); }
- private:
- _IntType _M_k;
- double _M_p;
- };
- negative_binomial_distribution() : negative_binomial_distribution(1) { }
- explicit
- negative_binomial_distribution(_IntType __k, double __p = 0.5)
- : _M_param(__k, __p), _M_gd(__k, (1.0 - __p) / __p)
- { }
- explicit
- negative_binomial_distribution(const param_type& __p)
- : _M_param(__p), _M_gd(__p.k(), (1.0 - __p.p()) / __p.p())
- { }
- /**
- * @brief Resets the distribution state.
- */
- void
- reset()
- { _M_gd.reset(); }
- /**
- * @brief Return the @f$k@f$ parameter of the distribution.
- */
- _IntType
- k() const
- { return _M_param.k(); }
- /**
- * @brief Return the @f$p@f$ parameter of the distribution.
- */
- double
- p() const
- { return _M_param.p(); }
- /**
- * @brief Returns the parameter set of the distribution.
- */
- param_type
- param() const
- { return _M_param; }
- /**
- * @brief Sets the parameter set of the distribution.
- * @param __param The new parameter set of the distribution.
- */
- void
- param(const param_type& __param)
- { _M_param = __param; }
- /**
- * @brief Returns the greatest lower bound value of the distribution.
- */
- result_type
- min() const
- { return result_type(0); }
- /**
- * @brief Returns the least upper bound value of the distribution.
- */
- result_type
- max() const
- { return std::numeric_limits<result_type>::max(); }
- /**
- * @brief Generating functions.
- */
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng);
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng)
- { this->__generate_impl(__f, __t, __urng); }
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- template<typename _UniformRandomNumberGenerator>
- void
- __generate(result_type* __f, result_type* __t,
- _UniformRandomNumberGenerator& __urng)
- { this->__generate_impl(__f, __t, __urng); }
- template<typename _UniformRandomNumberGenerator>
- void
- __generate(result_type* __f, result_type* __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- /**
- * @brief Return true if two negative binomial distributions have
- * the same parameters and the sequences that would be
- * generated are equal.
- */
- friend bool
- operator==(const negative_binomial_distribution& __d1,
- const negative_binomial_distribution& __d2)
- { return __d1._M_param == __d2._M_param && __d1._M_gd == __d2._M_gd; }
- /**
- * @brief Inserts a %negative_binomial_distribution random
- * number distribution @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %negative_binomial_distribution random number
- * distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _IntType1, typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const std::negative_binomial_distribution<_IntType1>& __x);
- /**
- * @brief Extracts a %negative_binomial_distribution random number
- * distribution @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %negative_binomial_distribution random number
- * generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error state.
- */
- template<typename _IntType1, typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- std::negative_binomial_distribution<_IntType1>& __x);
- private:
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng);
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- param_type _M_param;
- std::gamma_distribution<double> _M_gd;
- };
- /**
- * @brief Return true if two negative binomial distributions are different.
- */
- template<typename _IntType>
- inline bool
- operator!=(const std::negative_binomial_distribution<_IntType>& __d1,
- const std::negative_binomial_distribution<_IntType>& __d2)
- { return !(__d1 == __d2); }
- /* @} */ // group random_distributions_bernoulli
- /**
- * @addtogroup random_distributions_poisson Poisson Distributions
- * @ingroup random_distributions
- * @{
- */
- /**
- * @brief A discrete Poisson random number distribution.
- *
- * The formula for the Poisson probability density function is
- * @f$p(i|\mu) = \frac{\mu^i}{i!} e^{-\mu}@f$ where @f$\mu@f$ is the
- * parameter of the distribution.
- */
- template<typename _IntType = int>
- class poisson_distribution
- {
- static_assert(std::is_integral<_IntType>::value,
- "result_type must be an integral type");
- public:
- /** The type of the range of the distribution. */
- typedef _IntType result_type;
- /** Parameter type. */
- struct param_type
- {
- typedef poisson_distribution<_IntType> distribution_type;
- friend class poisson_distribution<_IntType>;
- param_type() : param_type(1.0) { }
- explicit
- param_type(double __mean)
- : _M_mean(__mean)
- {
- __glibcxx_assert(_M_mean > 0.0);
- _M_initialize();
- }
- double
- mean() const
- { return _M_mean; }
- friend bool
- operator==(const param_type& __p1, const param_type& __p2)
- { return __p1._M_mean == __p2._M_mean; }
- friend bool
- operator!=(const param_type& __p1, const param_type& __p2)
- { return !(__p1 == __p2); }
- private:
- // Hosts either log(mean) or the threshold of the simple method.
- void
- _M_initialize();
- double _M_mean;
- double _M_lm_thr;
- #if _GLIBCXX_USE_C99_MATH_TR1
- double _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb;
- #endif
- };
- // constructors and member functions
- poisson_distribution() : poisson_distribution(1.0) { }
- explicit
- poisson_distribution(double __mean)
- : _M_param(__mean), _M_nd()
- { }
- explicit
- poisson_distribution(const param_type& __p)
- : _M_param(__p), _M_nd()
- { }
- /**
- * @brief Resets the distribution state.
- */
- void
- reset()
- { _M_nd.reset(); }
- /**
- * @brief Returns the distribution parameter @p mean.
- */
- double
- mean() const
- { return _M_param.mean(); }
- /**
- * @brief Returns the parameter set of the distribution.
- */
- param_type
- param() const
- { return _M_param; }
- /**
- * @brief Sets the parameter set of the distribution.
- * @param __param The new parameter set of the distribution.
- */
- void
- param(const param_type& __param)
- { _M_param = __param; }
- /**
- * @brief Returns the greatest lower bound value of the distribution.
- */
- result_type
- min() const
- { return 0; }
- /**
- * @brief Returns the least upper bound value of the distribution.
- */
- result_type
- max() const
- { return std::numeric_limits<result_type>::max(); }
- /**
- * @brief Generating functions.
- */
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, _M_param); }
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng)
- { this->__generate(__f, __t, __urng, _M_param); }
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- template<typename _UniformRandomNumberGenerator>
- void
- __generate(result_type* __f, result_type* __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- /**
- * @brief Return true if two Poisson distributions have the same
- * parameters and the sequences that would be generated
- * are equal.
- */
- friend bool
- operator==(const poisson_distribution& __d1,
- const poisson_distribution& __d2)
- #ifdef _GLIBCXX_USE_C99_MATH_TR1
- { return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; }
- #else
- { return __d1._M_param == __d2._M_param; }
- #endif
- /**
- * @brief Inserts a %poisson_distribution random number distribution
- * @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %poisson_distribution random number distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _IntType1, typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const std::poisson_distribution<_IntType1>& __x);
- /**
- * @brief Extracts a %poisson_distribution random number distribution
- * @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %poisson_distribution random number generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error
- * state.
- */
- template<typename _IntType1, typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- std::poisson_distribution<_IntType1>& __x);
- private:
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- param_type _M_param;
- // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
- std::normal_distribution<double> _M_nd;
- };
- /**
- * @brief Return true if two Poisson distributions are different.
- */
- template<typename _IntType>
- inline bool
- operator!=(const std::poisson_distribution<_IntType>& __d1,
- const std::poisson_distribution<_IntType>& __d2)
- { return !(__d1 == __d2); }
- /**
- * @brief An exponential continuous distribution for random numbers.
- *
- * The formula for the exponential probability density function is
- * @f$p(x|\lambda) = \lambda e^{-\lambda x}@f$.
- *
- * <table border=1 cellpadding=10 cellspacing=0>
- * <caption align=top>Distribution Statistics</caption>
- * <tr><td>Mean</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
- * <tr><td>Median</td><td>@f$\frac{\ln 2}{\lambda}@f$</td></tr>
- * <tr><td>Mode</td><td>@f$zero@f$</td></tr>
- * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr>
- * <tr><td>Standard Deviation</td><td>@f$\frac{1}{\lambda}@f$</td></tr>
- * </table>
- */
- template<typename _RealType = double>
- class exponential_distribution
- {
- static_assert(std::is_floating_point<_RealType>::value,
- "result_type must be a floating point type");
- public:
- /** The type of the range of the distribution. */
- typedef _RealType result_type;
- /** Parameter type. */
- struct param_type
- {
- typedef exponential_distribution<_RealType> distribution_type;
- param_type() : param_type(1.0) { }
- explicit
- param_type(_RealType __lambda)
- : _M_lambda(__lambda)
- {
- __glibcxx_assert(_M_lambda > _RealType(0));
- }
- _RealType
- lambda() const
- { return _M_lambda; }
- friend bool
- operator==(const param_type& __p1, const param_type& __p2)
- { return __p1._M_lambda == __p2._M_lambda; }
- friend bool
- operator!=(const param_type& __p1, const param_type& __p2)
- { return !(__p1 == __p2); }
- private:
- _RealType _M_lambda;
- };
- public:
- /**
- * @brief Constructs an exponential distribution with inverse scale
- * parameter 1.0
- */
- exponential_distribution() : exponential_distribution(1.0) { }
- /**
- * @brief Constructs an exponential distribution with inverse scale
- * parameter @f$\lambda@f$.
- */
- explicit
- exponential_distribution(_RealType __lambda)
- : _M_param(__lambda)
- { }
- explicit
- exponential_distribution(const param_type& __p)
- : _M_param(__p)
- { }
- /**
- * @brief Resets the distribution state.
- *
- * Has no effect on exponential distributions.
- */
- void
- reset() { }
- /**
- * @brief Returns the inverse scale parameter of the distribution.
- */
- _RealType
- lambda() const
- { return _M_param.lambda(); }
- /**
- * @brief Returns the parameter set of the distribution.
- */
- param_type
- param() const
- { return _M_param; }
- /**
- * @brief Sets the parameter set of the distribution.
- * @param __param The new parameter set of the distribution.
- */
- void
- param(const param_type& __param)
- { _M_param = __param; }
- /**
- * @brief Returns the greatest lower bound value of the distribution.
- */
- result_type
- min() const
- { return result_type(0); }
- /**
- * @brief Returns the least upper bound value of the distribution.
- */
- result_type
- max() const
- { return std::numeric_limits<result_type>::max(); }
- /**
- * @brief Generating functions.
- */
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, _M_param); }
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- {
- __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
- __aurng(__urng);
- return -std::log(result_type(1) - __aurng()) / __p.lambda();
- }
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng)
- { this->__generate(__f, __t, __urng, _M_param); }
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- template<typename _UniformRandomNumberGenerator>
- void
- __generate(result_type* __f, result_type* __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- /**
- * @brief Return true if two exponential distributions have the same
- * parameters.
- */
- friend bool
- operator==(const exponential_distribution& __d1,
- const exponential_distribution& __d2)
- { return __d1._M_param == __d2._M_param; }
- private:
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- param_type _M_param;
- };
- /**
- * @brief Return true if two exponential distributions have different
- * parameters.
- */
- template<typename _RealType>
- inline bool
- operator!=(const std::exponential_distribution<_RealType>& __d1,
- const std::exponential_distribution<_RealType>& __d2)
- { return !(__d1 == __d2); }
- /**
- * @brief Inserts a %exponential_distribution random number distribution
- * @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %exponential_distribution random number distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _RealType, typename _CharT, typename _Traits>
- std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const std::exponential_distribution<_RealType>& __x);
- /**
- * @brief Extracts a %exponential_distribution random number distribution
- * @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %exponential_distribution random number
- * generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error state.
- */
- template<typename _RealType, typename _CharT, typename _Traits>
- std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- std::exponential_distribution<_RealType>& __x);
- /**
- * @brief A weibull_distribution random number distribution.
- *
- * The formula for the normal probability density function is:
- * @f[
- * p(x|\alpha,\beta) = \frac{\alpha}{\beta} (\frac{x}{\beta})^{\alpha-1}
- * \exp{(-(\frac{x}{\beta})^\alpha)}
- * @f]
- */
- template<typename _RealType = double>
- class weibull_distribution
- {
- static_assert(std::is_floating_point<_RealType>::value,
- "result_type must be a floating point type");
- public:
- /** The type of the range of the distribution. */
- typedef _RealType result_type;
- /** Parameter type. */
- struct param_type
- {
- typedef weibull_distribution<_RealType> distribution_type;
- param_type() : param_type(1.0) { }
- explicit
- param_type(_RealType __a, _RealType __b = _RealType(1.0))
- : _M_a(__a), _M_b(__b)
- { }
- _RealType
- a() const
- { return _M_a; }
- _RealType
- b() const
- { return _M_b; }
- friend bool
- operator==(const param_type& __p1, const param_type& __p2)
- { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
- friend bool
- operator!=(const param_type& __p1, const param_type& __p2)
- { return !(__p1 == __p2); }
- private:
- _RealType _M_a;
- _RealType _M_b;
- };
- weibull_distribution() : weibull_distribution(1.0) { }
- explicit
- weibull_distribution(_RealType __a, _RealType __b = _RealType(1))
- : _M_param(__a, __b)
- { }
- explicit
- weibull_distribution(const param_type& __p)
- : _M_param(__p)
- { }
- /**
- * @brief Resets the distribution state.
- */
- void
- reset()
- { }
- /**
- * @brief Return the @f$a@f$ parameter of the distribution.
- */
- _RealType
- a() const
- { return _M_param.a(); }
- /**
- * @brief Return the @f$b@f$ parameter of the distribution.
- */
- _RealType
- b() const
- { return _M_param.b(); }
- /**
- * @brief Returns the parameter set of the distribution.
- */
- param_type
- param() const
- { return _M_param; }
- /**
- * @brief Sets the parameter set of the distribution.
- * @param __param The new parameter set of the distribution.
- */
- void
- param(const param_type& __param)
- { _M_param = __param; }
- /**
- * @brief Returns the greatest lower bound value of the distribution.
- */
- result_type
- min() const
- { return result_type(0); }
- /**
- * @brief Returns the least upper bound value of the distribution.
- */
- result_type
- max() const
- { return std::numeric_limits<result_type>::max(); }
- /**
- * @brief Generating functions.
- */
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, _M_param); }
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng)
- { this->__generate(__f, __t, __urng, _M_param); }
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- template<typename _UniformRandomNumberGenerator>
- void
- __generate(result_type* __f, result_type* __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- /**
- * @brief Return true if two Weibull distributions have the same
- * parameters.
- */
- friend bool
- operator==(const weibull_distribution& __d1,
- const weibull_distribution& __d2)
- { return __d1._M_param == __d2._M_param; }
- private:
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- param_type _M_param;
- };
- /**
- * @brief Return true if two Weibull distributions have different
- * parameters.
- */
- template<typename _RealType>
- inline bool
- operator!=(const std::weibull_distribution<_RealType>& __d1,
- const std::weibull_distribution<_RealType>& __d2)
- { return !(__d1 == __d2); }
- /**
- * @brief Inserts a %weibull_distribution random number distribution
- * @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %weibull_distribution random number distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _RealType, typename _CharT, typename _Traits>
- std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const std::weibull_distribution<_RealType>& __x);
- /**
- * @brief Extracts a %weibull_distribution random number distribution
- * @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %weibull_distribution random number
- * generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error state.
- */
- template<typename _RealType, typename _CharT, typename _Traits>
- std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- std::weibull_distribution<_RealType>& __x);
- /**
- * @brief A extreme_value_distribution random number distribution.
- *
- * The formula for the normal probability mass function is
- * @f[
- * p(x|a,b) = \frac{1}{b}
- * \exp( \frac{a-x}{b} - \exp(\frac{a-x}{b}))
- * @f]
- */
- template<typename _RealType = double>
- class extreme_value_distribution
- {
- static_assert(std::is_floating_point<_RealType>::value,
- "result_type must be a floating point type");
- public:
- /** The type of the range of the distribution. */
- typedef _RealType result_type;
- /** Parameter type. */
- struct param_type
- {
- typedef extreme_value_distribution<_RealType> distribution_type;
- param_type() : param_type(0.0) { }
- explicit
- param_type(_RealType __a, _RealType __b = _RealType(1.0))
- : _M_a(__a), _M_b(__b)
- { }
- _RealType
- a() const
- { return _M_a; }
- _RealType
- b() const
- { return _M_b; }
- friend bool
- operator==(const param_type& __p1, const param_type& __p2)
- { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
- friend bool
- operator!=(const param_type& __p1, const param_type& __p2)
- { return !(__p1 == __p2); }
- private:
- _RealType _M_a;
- _RealType _M_b;
- };
- extreme_value_distribution() : extreme_value_distribution(0.0) { }
- explicit
- extreme_value_distribution(_RealType __a, _RealType __b = _RealType(1))
- : _M_param(__a, __b)
- { }
- explicit
- extreme_value_distribution(const param_type& __p)
- : _M_param(__p)
- { }
- /**
- * @brief Resets the distribution state.
- */
- void
- reset()
- { }
- /**
- * @brief Return the @f$a@f$ parameter of the distribution.
- */
- _RealType
- a() const
- { return _M_param.a(); }
- /**
- * @brief Return the @f$b@f$ parameter of the distribution.
- */
- _RealType
- b() const
- { return _M_param.b(); }
- /**
- * @brief Returns the parameter set of the distribution.
- */
- param_type
- param() const
- { return _M_param; }
- /**
- * @brief Sets the parameter set of the distribution.
- * @param __param The new parameter set of the distribution.
- */
- void
- param(const param_type& __param)
- { _M_param = __param; }
- /**
- * @brief Returns the greatest lower bound value of the distribution.
- */
- result_type
- min() const
- { return std::numeric_limits<result_type>::lowest(); }
- /**
- * @brief Returns the least upper bound value of the distribution.
- */
- result_type
- max() const
- { return std::numeric_limits<result_type>::max(); }
- /**
- * @brief Generating functions.
- */
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, _M_param); }
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng)
- { this->__generate(__f, __t, __urng, _M_param); }
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- template<typename _UniformRandomNumberGenerator>
- void
- __generate(result_type* __f, result_type* __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- /**
- * @brief Return true if two extreme value distributions have the same
- * parameters.
- */
- friend bool
- operator==(const extreme_value_distribution& __d1,
- const extreme_value_distribution& __d2)
- { return __d1._M_param == __d2._M_param; }
- private:
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- param_type _M_param;
- };
- /**
- * @brief Return true if two extreme value distributions have different
- * parameters.
- */
- template<typename _RealType>
- inline bool
- operator!=(const std::extreme_value_distribution<_RealType>& __d1,
- const std::extreme_value_distribution<_RealType>& __d2)
- { return !(__d1 == __d2); }
- /**
- * @brief Inserts a %extreme_value_distribution random number distribution
- * @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %extreme_value_distribution random number distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _RealType, typename _CharT, typename _Traits>
- std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const std::extreme_value_distribution<_RealType>& __x);
- /**
- * @brief Extracts a %extreme_value_distribution random number
- * distribution @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %extreme_value_distribution random number
- * generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error state.
- */
- template<typename _RealType, typename _CharT, typename _Traits>
- std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- std::extreme_value_distribution<_RealType>& __x);
- /**
- * @brief A discrete_distribution random number distribution.
- *
- * The formula for the discrete probability mass function is
- *
- */
- template<typename _IntType = int>
- class discrete_distribution
- {
- static_assert(std::is_integral<_IntType>::value,
- "result_type must be an integral type");
- public:
- /** The type of the range of the distribution. */
- typedef _IntType result_type;
- /** Parameter type. */
- struct param_type
- {
- typedef discrete_distribution<_IntType> distribution_type;
- friend class discrete_distribution<_IntType>;
- param_type()
- : _M_prob(), _M_cp()
- { }
- template<typename _InputIterator>
- param_type(_InputIterator __wbegin,
- _InputIterator __wend)
- : _M_prob(__wbegin, __wend), _M_cp()
- { _M_initialize(); }
- param_type(initializer_list<double> __wil)
- : _M_prob(__wil.begin(), __wil.end()), _M_cp()
- { _M_initialize(); }
- template<typename _Func>
- param_type(size_t __nw, double __xmin, double __xmax,
- _Func __fw);
- // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
- param_type(const param_type&) = default;
- param_type& operator=(const param_type&) = default;
- std::vector<double>
- probabilities() const
- { return _M_prob.empty() ? std::vector<double>(1, 1.0) : _M_prob; }
- friend bool
- operator==(const param_type& __p1, const param_type& __p2)
- { return __p1._M_prob == __p2._M_prob; }
- friend bool
- operator!=(const param_type& __p1, const param_type& __p2)
- { return !(__p1 == __p2); }
- private:
- void
- _M_initialize();
- std::vector<double> _M_prob;
- std::vector<double> _M_cp;
- };
- discrete_distribution()
- : _M_param()
- { }
- template<typename _InputIterator>
- discrete_distribution(_InputIterator __wbegin,
- _InputIterator __wend)
- : _M_param(__wbegin, __wend)
- { }
- discrete_distribution(initializer_list<double> __wl)
- : _M_param(__wl)
- { }
- template<typename _Func>
- discrete_distribution(size_t __nw, double __xmin, double __xmax,
- _Func __fw)
- : _M_param(__nw, __xmin, __xmax, __fw)
- { }
- explicit
- discrete_distribution(const param_type& __p)
- : _M_param(__p)
- { }
- /**
- * @brief Resets the distribution state.
- */
- void
- reset()
- { }
- /**
- * @brief Returns the probabilities of the distribution.
- */
- std::vector<double>
- probabilities() const
- {
- return _M_param._M_prob.empty()
- ? std::vector<double>(1, 1.0) : _M_param._M_prob;
- }
- /**
- * @brief Returns the parameter set of the distribution.
- */
- param_type
- param() const
- { return _M_param; }
- /**
- * @brief Sets the parameter set of the distribution.
- * @param __param The new parameter set of the distribution.
- */
- void
- param(const param_type& __param)
- { _M_param = __param; }
- /**
- * @brief Returns the greatest lower bound value of the distribution.
- */
- result_type
- min() const
- { return result_type(0); }
- /**
- * @brief Returns the least upper bound value of the distribution.
- */
- result_type
- max() const
- {
- return _M_param._M_prob.empty()
- ? result_type(0) : result_type(_M_param._M_prob.size() - 1);
- }
- /**
- * @brief Generating functions.
- */
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, _M_param); }
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng)
- { this->__generate(__f, __t, __urng, _M_param); }
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- template<typename _UniformRandomNumberGenerator>
- void
- __generate(result_type* __f, result_type* __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- /**
- * @brief Return true if two discrete distributions have the same
- * parameters.
- */
- friend bool
- operator==(const discrete_distribution& __d1,
- const discrete_distribution& __d2)
- { return __d1._M_param == __d2._M_param; }
- /**
- * @brief Inserts a %discrete_distribution random number distribution
- * @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %discrete_distribution random number distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _IntType1, typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const std::discrete_distribution<_IntType1>& __x);
- /**
- * @brief Extracts a %discrete_distribution random number distribution
- * @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %discrete_distribution random number
- * generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error
- * state.
- */
- template<typename _IntType1, typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- std::discrete_distribution<_IntType1>& __x);
- private:
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- param_type _M_param;
- };
- /**
- * @brief Return true if two discrete distributions have different
- * parameters.
- */
- template<typename _IntType>
- inline bool
- operator!=(const std::discrete_distribution<_IntType>& __d1,
- const std::discrete_distribution<_IntType>& __d2)
- { return !(__d1 == __d2); }
- /**
- * @brief A piecewise_constant_distribution random number distribution.
- *
- * The formula for the piecewise constant probability mass function is
- *
- */
- template<typename _RealType = double>
- class piecewise_constant_distribution
- {
- static_assert(std::is_floating_point<_RealType>::value,
- "result_type must be a floating point type");
- public:
- /** The type of the range of the distribution. */
- typedef _RealType result_type;
- /** Parameter type. */
- struct param_type
- {
- typedef piecewise_constant_distribution<_RealType> distribution_type;
- friend class piecewise_constant_distribution<_RealType>;
- param_type()
- : _M_int(), _M_den(), _M_cp()
- { }
- template<typename _InputIteratorB, typename _InputIteratorW>
- param_type(_InputIteratorB __bfirst,
- _InputIteratorB __bend,
- _InputIteratorW __wbegin);
- template<typename _Func>
- param_type(initializer_list<_RealType> __bi, _Func __fw);
- template<typename _Func>
- param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
- _Func __fw);
- // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
- param_type(const param_type&) = default;
- param_type& operator=(const param_type&) = default;
- std::vector<_RealType>
- intervals() const
- {
- if (_M_int.empty())
- {
- std::vector<_RealType> __tmp(2);
- __tmp[1] = _RealType(1);
- return __tmp;
- }
- else
- return _M_int;
- }
- std::vector<double>
- densities() const
- { return _M_den.empty() ? std::vector<double>(1, 1.0) : _M_den; }
- friend bool
- operator==(const param_type& __p1, const param_type& __p2)
- { return __p1._M_int == __p2._M_int && __p1._M_den == __p2._M_den; }
- friend bool
- operator!=(const param_type& __p1, const param_type& __p2)
- { return !(__p1 == __p2); }
- private:
- void
- _M_initialize();
- std::vector<_RealType> _M_int;
- std::vector<double> _M_den;
- std::vector<double> _M_cp;
- };
- piecewise_constant_distribution()
- : _M_param()
- { }
- template<typename _InputIteratorB, typename _InputIteratorW>
- piecewise_constant_distribution(_InputIteratorB __bfirst,
- _InputIteratorB __bend,
- _InputIteratorW __wbegin)
- : _M_param(__bfirst, __bend, __wbegin)
- { }
- template<typename _Func>
- piecewise_constant_distribution(initializer_list<_RealType> __bl,
- _Func __fw)
- : _M_param(__bl, __fw)
- { }
- template<typename _Func>
- piecewise_constant_distribution(size_t __nw,
- _RealType __xmin, _RealType __xmax,
- _Func __fw)
- : _M_param(__nw, __xmin, __xmax, __fw)
- { }
- explicit
- piecewise_constant_distribution(const param_type& __p)
- : _M_param(__p)
- { }
- /**
- * @brief Resets the distribution state.
- */
- void
- reset()
- { }
- /**
- * @brief Returns a vector of the intervals.
- */
- std::vector<_RealType>
- intervals() const
- {
- if (_M_param._M_int.empty())
- {
- std::vector<_RealType> __tmp(2);
- __tmp[1] = _RealType(1);
- return __tmp;
- }
- else
- return _M_param._M_int;
- }
- /**
- * @brief Returns a vector of the probability densities.
- */
- std::vector<double>
- densities() const
- {
- return _M_param._M_den.empty()
- ? std::vector<double>(1, 1.0) : _M_param._M_den;
- }
- /**
- * @brief Returns the parameter set of the distribution.
- */
- param_type
- param() const
- { return _M_param; }
- /**
- * @brief Sets the parameter set of the distribution.
- * @param __param The new parameter set of the distribution.
- */
- void
- param(const param_type& __param)
- { _M_param = __param; }
- /**
- * @brief Returns the greatest lower bound value of the distribution.
- */
- result_type
- min() const
- {
- return _M_param._M_int.empty()
- ? result_type(0) : _M_param._M_int.front();
- }
- /**
- * @brief Returns the least upper bound value of the distribution.
- */
- result_type
- max() const
- {
- return _M_param._M_int.empty()
- ? result_type(1) : _M_param._M_int.back();
- }
- /**
- * @brief Generating functions.
- */
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, _M_param); }
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng)
- { this->__generate(__f, __t, __urng, _M_param); }
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- template<typename _UniformRandomNumberGenerator>
- void
- __generate(result_type* __f, result_type* __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- /**
- * @brief Return true if two piecewise constant distributions have the
- * same parameters.
- */
- friend bool
- operator==(const piecewise_constant_distribution& __d1,
- const piecewise_constant_distribution& __d2)
- { return __d1._M_param == __d2._M_param; }
- /**
- * @brief Inserts a %piecewise_constant_distribution random
- * number distribution @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %piecewise_constant_distribution random number
- * distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _RealType1, typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const std::piecewise_constant_distribution<_RealType1>& __x);
- /**
- * @brief Extracts a %piecewise_constant_distribution random
- * number distribution @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %piecewise_constant_distribution random number
- * generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error
- * state.
- */
- template<typename _RealType1, typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- std::piecewise_constant_distribution<_RealType1>& __x);
- private:
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- param_type _M_param;
- };
- /**
- * @brief Return true if two piecewise constant distributions have
- * different parameters.
- */
- template<typename _RealType>
- inline bool
- operator!=(const std::piecewise_constant_distribution<_RealType>& __d1,
- const std::piecewise_constant_distribution<_RealType>& __d2)
- { return !(__d1 == __d2); }
- /**
- * @brief A piecewise_linear_distribution random number distribution.
- *
- * The formula for the piecewise linear probability mass function is
- *
- */
- template<typename _RealType = double>
- class piecewise_linear_distribution
- {
- static_assert(std::is_floating_point<_RealType>::value,
- "result_type must be a floating point type");
- public:
- /** The type of the range of the distribution. */
- typedef _RealType result_type;
- /** Parameter type. */
- struct param_type
- {
- typedef piecewise_linear_distribution<_RealType> distribution_type;
- friend class piecewise_linear_distribution<_RealType>;
- param_type()
- : _M_int(), _M_den(), _M_cp(), _M_m()
- { }
- template<typename _InputIteratorB, typename _InputIteratorW>
- param_type(_InputIteratorB __bfirst,
- _InputIteratorB __bend,
- _InputIteratorW __wbegin);
- template<typename _Func>
- param_type(initializer_list<_RealType> __bl, _Func __fw);
- template<typename _Func>
- param_type(size_t __nw, _RealType __xmin, _RealType __xmax,
- _Func __fw);
- // See: http://cpp-next.com/archive/2010/10/implicit-move-must-go/
- param_type(const param_type&) = default;
- param_type& operator=(const param_type&) = default;
- std::vector<_RealType>
- intervals() const
- {
- if (_M_int.empty())
- {
- std::vector<_RealType> __tmp(2);
- __tmp[1] = _RealType(1);
- return __tmp;
- }
- else
- return _M_int;
- }
- std::vector<double>
- densities() const
- { return _M_den.empty() ? std::vector<double>(2, 1.0) : _M_den; }
- friend bool
- operator==(const param_type& __p1, const param_type& __p2)
- { return __p1._M_int == __p2._M_int && __p1._M_den == __p2._M_den; }
- friend bool
- operator!=(const param_type& __p1, const param_type& __p2)
- { return !(__p1 == __p2); }
- private:
- void
- _M_initialize();
- std::vector<_RealType> _M_int;
- std::vector<double> _M_den;
- std::vector<double> _M_cp;
- std::vector<double> _M_m;
- };
- piecewise_linear_distribution()
- : _M_param()
- { }
- template<typename _InputIteratorB, typename _InputIteratorW>
- piecewise_linear_distribution(_InputIteratorB __bfirst,
- _InputIteratorB __bend,
- _InputIteratorW __wbegin)
- : _M_param(__bfirst, __bend, __wbegin)
- { }
- template<typename _Func>
- piecewise_linear_distribution(initializer_list<_RealType> __bl,
- _Func __fw)
- : _M_param(__bl, __fw)
- { }
- template<typename _Func>
- piecewise_linear_distribution(size_t __nw,
- _RealType __xmin, _RealType __xmax,
- _Func __fw)
- : _M_param(__nw, __xmin, __xmax, __fw)
- { }
- explicit
- piecewise_linear_distribution(const param_type& __p)
- : _M_param(__p)
- { }
- /**
- * Resets the distribution state.
- */
- void
- reset()
- { }
- /**
- * @brief Return the intervals of the distribution.
- */
- std::vector<_RealType>
- intervals() const
- {
- if (_M_param._M_int.empty())
- {
- std::vector<_RealType> __tmp(2);
- __tmp[1] = _RealType(1);
- return __tmp;
- }
- else
- return _M_param._M_int;
- }
- /**
- * @brief Return a vector of the probability densities of the
- * distribution.
- */
- std::vector<double>
- densities() const
- {
- return _M_param._M_den.empty()
- ? std::vector<double>(2, 1.0) : _M_param._M_den;
- }
- /**
- * @brief Returns the parameter set of the distribution.
- */
- param_type
- param() const
- { return _M_param; }
- /**
- * @brief Sets the parameter set of the distribution.
- * @param __param The new parameter set of the distribution.
- */
- void
- param(const param_type& __param)
- { _M_param = __param; }
- /**
- * @brief Returns the greatest lower bound value of the distribution.
- */
- result_type
- min() const
- {
- return _M_param._M_int.empty()
- ? result_type(0) : _M_param._M_int.front();
- }
- /**
- * @brief Returns the least upper bound value of the distribution.
- */
- result_type
- max() const
- {
- return _M_param._M_int.empty()
- ? result_type(1) : _M_param._M_int.back();
- }
- /**
- * @brief Generating functions.
- */
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng)
- { return this->operator()(__urng, _M_param); }
- template<typename _UniformRandomNumberGenerator>
- result_type
- operator()(_UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng)
- { this->__generate(__f, __t, __urng, _M_param); }
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- template<typename _UniformRandomNumberGenerator>
- void
- __generate(result_type* __f, result_type* __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p)
- { this->__generate_impl(__f, __t, __urng, __p); }
- /**
- * @brief Return true if two piecewise linear distributions have the
- * same parameters.
- */
- friend bool
- operator==(const piecewise_linear_distribution& __d1,
- const piecewise_linear_distribution& __d2)
- { return __d1._M_param == __d2._M_param; }
- /**
- * @brief Inserts a %piecewise_linear_distribution random number
- * distribution @p __x into the output stream @p __os.
- *
- * @param __os An output stream.
- * @param __x A %piecewise_linear_distribution random number
- * distribution.
- *
- * @returns The output stream with the state of @p __x inserted or in
- * an error state.
- */
- template<typename _RealType1, typename _CharT, typename _Traits>
- friend std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& __os,
- const std::piecewise_linear_distribution<_RealType1>& __x);
- /**
- * @brief Extracts a %piecewise_linear_distribution random number
- * distribution @p __x from the input stream @p __is.
- *
- * @param __is An input stream.
- * @param __x A %piecewise_linear_distribution random number
- * generator engine.
- *
- * @returns The input stream with @p __x extracted or in an error
- * state.
- */
- template<typename _RealType1, typename _CharT, typename _Traits>
- friend std::basic_istream<_CharT, _Traits>&
- operator>>(std::basic_istream<_CharT, _Traits>& __is,
- std::piecewise_linear_distribution<_RealType1>& __x);
- private:
- template<typename _ForwardIterator,
- typename _UniformRandomNumberGenerator>
- void
- __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
- _UniformRandomNumberGenerator& __urng,
- const param_type& __p);
- param_type _M_param;
- };
- /**
- * @brief Return true if two piecewise linear distributions have
- * different parameters.
- */
- template<typename _RealType>
- inline bool
- operator!=(const std::piecewise_linear_distribution<_RealType>& __d1,
- const std::piecewise_linear_distribution<_RealType>& __d2)
- { return !(__d1 == __d2); }
- /* @} */ // group random_distributions_poisson
- /* @} */ // group random_distributions
- /**
- * @addtogroup random_utilities Random Number Utilities
- * @ingroup random
- * @{
- */
- /**
- * @brief The seed_seq class generates sequences of seeds for random
- * number generators.
- */
- class seed_seq
- {
- public:
- /** The type of the seed vales. */
- typedef uint_least32_t result_type;
- /** Default constructor. */
- seed_seq() noexcept
- : _M_v()
- { }
- template<typename _IntType>
- seed_seq(std::initializer_list<_IntType> il);
- template<typename _InputIterator>
- seed_seq(_InputIterator __begin, _InputIterator __end);
- // generating functions
- template<typename _RandomAccessIterator>
- void
- generate(_RandomAccessIterator __begin, _RandomAccessIterator __end);
- // property functions
- size_t size() const noexcept
- { return _M_v.size(); }
- template<typename _OutputIterator>
- void
- param(_OutputIterator __dest) const
- { std::copy(_M_v.begin(), _M_v.end(), __dest); }
- // no copy functions
- seed_seq(const seed_seq&) = delete;
- seed_seq& operator=(const seed_seq&) = delete;
- private:
- std::vector<result_type> _M_v;
- };
- /* @} */ // group random_utilities
- /* @} */ // group random
- _GLIBCXX_END_NAMESPACE_VERSION
- } // namespace std
- #endif
|