random 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP_RANDOM
  10. #define _LIBCPP_RANDOM
  11. /*
  12. random synopsis
  13. #include <initializer_list>
  14. namespace std
  15. {
  16. // [rand.req.urng], uniform random bit generator requirements
  17. template<class G>
  18. concept uniform_random_bit_generator = see below; // C++20
  19. // Engines
  20. template <class UIntType, UIntType a, UIntType c, UIntType m>
  21. class linear_congruential_engine
  22. {
  23. public:
  24. // types
  25. typedef UIntType result_type;
  26. // engine characteristics
  27. static constexpr result_type multiplier = a;
  28. static constexpr result_type increment = c;
  29. static constexpr result_type modulus = m;
  30. static constexpr result_type min() { return c == 0u ? 1u: 0u;}
  31. static constexpr result_type max() { return m - 1u;}
  32. static constexpr result_type default_seed = 1u;
  33. // constructors and seeding functions
  34. explicit linear_congruential_engine(result_type s = default_seed); // before C++20
  35. linear_congruential_engine() : linear_congruential_engine(default_seed) {} // C++20
  36. explicit linear_congruential_engine(result_type s); // C++20
  37. template<class Sseq> explicit linear_congruential_engine(Sseq& q);
  38. void seed(result_type s = default_seed);
  39. template<class Sseq> void seed(Sseq& q);
  40. // generating functions
  41. result_type operator()();
  42. void discard(unsigned long long z);
  43. };
  44. template <class UIntType, UIntType a, UIntType c, UIntType m>
  45. bool
  46. operator==(const linear_congruential_engine<UIntType, a, c, m>& x,
  47. const linear_congruential_engine<UIntType, a, c, m>& y);
  48. template <class UIntType, UIntType a, UIntType c, UIntType m>
  49. bool
  50. operator!=(const linear_congruential_engine<UIntType, a, c, m>& x,
  51. const linear_congruential_engine<UIntType, a, c, m>& y);
  52. template <class charT, class traits,
  53. class UIntType, UIntType a, UIntType c, UIntType m>
  54. basic_ostream<charT, traits>&
  55. operator<<(basic_ostream<charT, traits>& os,
  56. const linear_congruential_engine<UIntType, a, c, m>& x);
  57. template <class charT, class traits,
  58. class UIntType, UIntType a, UIntType c, UIntType m>
  59. basic_istream<charT, traits>&
  60. operator>>(basic_istream<charT, traits>& is,
  61. linear_congruential_engine<UIntType, a, c, m>& x);
  62. template <class UIntType, size_t w, size_t n, size_t m, size_t r,
  63. UIntType a, size_t u, UIntType d, size_t s,
  64. UIntType b, size_t t, UIntType c, size_t l, UIntType f>
  65. class mersenne_twister_engine
  66. {
  67. public:
  68. // types
  69. typedef UIntType result_type;
  70. // engine characteristics
  71. static constexpr size_t word_size = w;
  72. static constexpr size_t state_size = n;
  73. static constexpr size_t shift_size = m;
  74. static constexpr size_t mask_bits = r;
  75. static constexpr result_type xor_mask = a;
  76. static constexpr size_t tempering_u = u;
  77. static constexpr result_type tempering_d = d;
  78. static constexpr size_t tempering_s = s;
  79. static constexpr result_type tempering_b = b;
  80. static constexpr size_t tempering_t = t;
  81. static constexpr result_type tempering_c = c;
  82. static constexpr size_t tempering_l = l;
  83. static constexpr result_type initialization_multiplier = f;
  84. static constexpr result_type min () { return 0; }
  85. static constexpr result_type max() { return 2^w - 1; }
  86. static constexpr result_type default_seed = 5489u;
  87. // constructors and seeding functions
  88. explicit mersenne_twister_engine(result_type s = default_seed); // before C++20
  89. mersenne_twister_engine() : mersenne_twister_engine(default_seed) {} // C++20
  90. explicit mersenne_twister_engine(result_type s); // C++20
  91. template<class Sseq> explicit mersenne_twister_engine(Sseq& q);
  92. void seed(result_type value = default_seed);
  93. template<class Sseq> void seed(Sseq& q);
  94. // generating functions
  95. result_type operator()();
  96. void discard(unsigned long long z);
  97. };
  98. template <class UIntType, size_t w, size_t n, size_t m, size_t r,
  99. UIntType a, size_t u, UIntType d, size_t s,
  100. UIntType b, size_t t, UIntType c, size_t l, UIntType f>
  101. bool
  102. operator==(
  103. const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x,
  104. const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& y);
  105. template <class UIntType, size_t w, size_t n, size_t m, size_t r,
  106. UIntType a, size_t u, UIntType d, size_t s,
  107. UIntType b, size_t t, UIntType c, size_t l, UIntType f>
  108. bool
  109. operator!=(
  110. const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x,
  111. const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& y);
  112. template <class charT, class traits,
  113. class UIntType, size_t w, size_t n, size_t m, size_t r,
  114. UIntType a, size_t u, UIntType d, size_t s,
  115. UIntType b, size_t t, UIntType c, size_t l, UIntType f>
  116. basic_ostream<charT, traits>&
  117. operator<<(basic_ostream<charT, traits>& os,
  118. const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x);
  119. template <class charT, class traits,
  120. class UIntType, size_t w, size_t n, size_t m, size_t r,
  121. UIntType a, size_t u, UIntType d, size_t s,
  122. UIntType b, size_t t, UIntType c, size_t l, UIntType f>
  123. basic_istream<charT, traits>&
  124. operator>>(basic_istream<charT, traits>& is,
  125. mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x);
  126. template<class UIntType, size_t w, size_t s, size_t r>
  127. class subtract_with_carry_engine
  128. {
  129. public:
  130. // types
  131. typedef UIntType result_type;
  132. // engine characteristics
  133. static constexpr size_t word_size = w;
  134. static constexpr size_t short_lag = s;
  135. static constexpr size_t long_lag = r;
  136. static constexpr result_type min() { return 0; }
  137. static constexpr result_type max() { return m-1; }
  138. static constexpr result_type default_seed = 19780503u;
  139. // constructors and seeding functions
  140. explicit subtract_with_carry_engine(result_type value = default_seed); // before C++20
  141. subtract_with_carry_engine() : subtract_with_carry_engine(default_seed) {} // C++20
  142. explicit subtract_with_carry_engine(result_type value); // C++20
  143. template<class Sseq> explicit subtract_with_carry_engine(Sseq& q);
  144. void seed(result_type value = default_seed);
  145. template<class Sseq> void seed(Sseq& q);
  146. // generating functions
  147. result_type operator()();
  148. void discard(unsigned long long z);
  149. };
  150. template<class UIntType, size_t w, size_t s, size_t r>
  151. bool
  152. operator==(
  153. const subtract_with_carry_engine<UIntType, w, s, r>& x,
  154. const subtract_with_carry_engine<UIntType, w, s, r>& y);
  155. template<class UIntType, size_t w, size_t s, size_t r>
  156. bool
  157. operator!=(
  158. const subtract_with_carry_engine<UIntType, w, s, r>& x,
  159. const subtract_with_carry_engine<UIntType, w, s, r>& y);
  160. template <class charT, class traits,
  161. class UIntType, size_t w, size_t s, size_t r>
  162. basic_ostream<charT, traits>&
  163. operator<<(basic_ostream<charT, traits>& os,
  164. const subtract_with_carry_engine<UIntType, w, s, r>& x);
  165. template <class charT, class traits,
  166. class UIntType, size_t w, size_t s, size_t r>
  167. basic_istream<charT, traits>&
  168. operator>>(basic_istream<charT, traits>& is,
  169. subtract_with_carry_engine<UIntType, w, s, r>& x);
  170. template<class Engine, size_t p, size_t r>
  171. class discard_block_engine
  172. {
  173. public:
  174. // types
  175. typedef typename Engine::result_type result_type;
  176. // engine characteristics
  177. static constexpr size_t block_size = p;
  178. static constexpr size_t used_block = r;
  179. static constexpr result_type min() { return Engine::min(); }
  180. static constexpr result_type max() { return Engine::max(); }
  181. // constructors and seeding functions
  182. discard_block_engine();
  183. explicit discard_block_engine(const Engine& e);
  184. explicit discard_block_engine(Engine&& e);
  185. explicit discard_block_engine(result_type s);
  186. template<class Sseq> explicit discard_block_engine(Sseq& q);
  187. void seed();
  188. void seed(result_type s);
  189. template<class Sseq> void seed(Sseq& q);
  190. // generating functions
  191. result_type operator()();
  192. void discard(unsigned long long z);
  193. // property functions
  194. const Engine& base() const noexcept;
  195. };
  196. template<class Engine, size_t p, size_t r>
  197. bool
  198. operator==(
  199. const discard_block_engine<Engine, p, r>& x,
  200. const discard_block_engine<Engine, p, r>& y);
  201. template<class Engine, size_t p, size_t r>
  202. bool
  203. operator!=(
  204. const discard_block_engine<Engine, p, r>& x,
  205. const discard_block_engine<Engine, p, r>& y);
  206. template <class charT, class traits,
  207. class Engine, size_t p, size_t r>
  208. basic_ostream<charT, traits>&
  209. operator<<(basic_ostream<charT, traits>& os,
  210. const discard_block_engine<Engine, p, r>& x);
  211. template <class charT, class traits,
  212. class Engine, size_t p, size_t r>
  213. basic_istream<charT, traits>&
  214. operator>>(basic_istream<charT, traits>& is,
  215. discard_block_engine<Engine, p, r>& x);
  216. template<class Engine, size_t w, class UIntType>
  217. class independent_bits_engine
  218. {
  219. public:
  220. // types
  221. typedef UIntType result_type;
  222. // engine characteristics
  223. static constexpr result_type min() { return 0; }
  224. static constexpr result_type max() { return 2^w - 1; }
  225. // constructors and seeding functions
  226. independent_bits_engine();
  227. explicit independent_bits_engine(const Engine& e);
  228. explicit independent_bits_engine(Engine&& e);
  229. explicit independent_bits_engine(result_type s);
  230. template<class Sseq> explicit independent_bits_engine(Sseq& q);
  231. void seed();
  232. void seed(result_type s);
  233. template<class Sseq> void seed(Sseq& q);
  234. // generating functions
  235. result_type operator()(); void discard(unsigned long long z);
  236. // property functions
  237. const Engine& base() const noexcept;
  238. };
  239. template<class Engine, size_t w, class UIntType>
  240. bool
  241. operator==(
  242. const independent_bits_engine<Engine, w, UIntType>& x,
  243. const independent_bits_engine<Engine, w, UIntType>& y);
  244. template<class Engine, size_t w, class UIntType>
  245. bool
  246. operator!=(
  247. const independent_bits_engine<Engine, w, UIntType>& x,
  248. const independent_bits_engine<Engine, w, UIntType>& y);
  249. template <class charT, class traits,
  250. class Engine, size_t w, class UIntType>
  251. basic_ostream<charT, traits>&
  252. operator<<(basic_ostream<charT, traits>& os,
  253. const independent_bits_engine<Engine, w, UIntType>& x);
  254. template <class charT, class traits,
  255. class Engine, size_t w, class UIntType>
  256. basic_istream<charT, traits>&
  257. operator>>(basic_istream<charT, traits>& is,
  258. independent_bits_engine<Engine, w, UIntType>& x);
  259. template<class Engine, size_t k>
  260. class shuffle_order_engine
  261. {
  262. public:
  263. // types
  264. typedef typename Engine::result_type result_type;
  265. // engine characteristics
  266. static constexpr size_t table_size = k;
  267. static constexpr result_type min() { return Engine::min; }
  268. static constexpr result_type max() { return Engine::max; }
  269. // constructors and seeding functions
  270. shuffle_order_engine();
  271. explicit shuffle_order_engine(const Engine& e);
  272. explicit shuffle_order_engine(Engine&& e);
  273. explicit shuffle_order_engine(result_type s);
  274. template<class Sseq> explicit shuffle_order_engine(Sseq& q);
  275. void seed();
  276. void seed(result_type s);
  277. template<class Sseq> void seed(Sseq& q);
  278. // generating functions
  279. result_type operator()();
  280. void discard(unsigned long long z);
  281. // property functions
  282. const Engine& base() const noexcept;
  283. };
  284. template<class Engine, size_t k>
  285. bool
  286. operator==(
  287. const shuffle_order_engine<Engine, k>& x,
  288. const shuffle_order_engine<Engine, k>& y);
  289. template<class Engine, size_t k>
  290. bool
  291. operator!=(
  292. const shuffle_order_engine<Engine, k>& x,
  293. const shuffle_order_engine<Engine, k>& y);
  294. template <class charT, class traits,
  295. class Engine, size_t k>
  296. basic_ostream<charT, traits>&
  297. operator<<(basic_ostream<charT, traits>& os,
  298. const shuffle_order_engine<Engine, k>& x);
  299. template <class charT, class traits,
  300. class Engine, size_t k>
  301. basic_istream<charT, traits>&
  302. operator>>(basic_istream<charT, traits>& is,
  303. shuffle_order_engine<Engine, k>& x);
  304. typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647>
  305. minstd_rand0;
  306. typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647>
  307. minstd_rand;
  308. typedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31,
  309. 0x9908b0df,
  310. 11, 0xffffffff,
  311. 7, 0x9d2c5680,
  312. 15, 0xefc60000,
  313. 18, 1812433253> mt19937;
  314. typedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31,
  315. 0xb5026f5aa96619e9,
  316. 29, 0x5555555555555555,
  317. 17, 0x71d67fffeda60000,
  318. 37, 0xfff7eee000000000,
  319. 43, 6364136223846793005> mt19937_64;
  320. typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> ranlux24_base;
  321. typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> ranlux48_base;
  322. typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24;
  323. typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48;
  324. typedef shuffle_order_engine<minstd_rand0, 256> knuth_b;
  325. typedef minstd_rand default_random_engine;
  326. // Generators
  327. class random_device
  328. {
  329. public:
  330. // types
  331. typedef unsigned int result_type;
  332. // generator characteristics
  333. static constexpr result_type min() { return numeric_limits<result_type>::min(); }
  334. static constexpr result_type max() { return numeric_limits<result_type>::max(); }
  335. // constructors
  336. explicit random_device(const string& token = implementation-defined); // before C++20
  337. random_device() : random_device(implementation-defined) {} // C++20
  338. explicit random_device(const string& token); // C++20
  339. // generating functions
  340. result_type operator()();
  341. // property functions
  342. double entropy() const noexcept;
  343. // no copy functions
  344. random_device(const random_device& ) = delete;
  345. void operator=(const random_device& ) = delete;
  346. };
  347. // Utilities
  348. class seed_seq
  349. {
  350. public:
  351. // types
  352. typedef uint_least32_t result_type;
  353. // constructors
  354. seed_seq();
  355. template<class T>
  356. seed_seq(initializer_list<T> il);
  357. template<class InputIterator>
  358. seed_seq(InputIterator begin, InputIterator end);
  359. // generating functions
  360. template<class RandomAccessIterator>
  361. void generate(RandomAccessIterator begin, RandomAccessIterator end);
  362. // property functions
  363. size_t size() const;
  364. template<class OutputIterator>
  365. void param(OutputIterator dest) const;
  366. // no copy functions
  367. seed_seq(const seed_seq&) = delete;
  368. void operator=(const seed_seq& ) = delete;
  369. };
  370. template<class RealType, size_t bits, class URNG>
  371. RealType generate_canonical(URNG& g);
  372. // Distributions
  373. template<class IntType = int>
  374. class uniform_int_distribution
  375. {
  376. public:
  377. // types
  378. typedef IntType result_type;
  379. class param_type
  380. {
  381. public:
  382. typedef uniform_int_distribution distribution_type;
  383. explicit param_type(IntType a = 0,
  384. IntType b = numeric_limits<IntType>::max());
  385. result_type a() const;
  386. result_type b() const;
  387. friend bool operator==(const param_type& x, const param_type& y);
  388. friend bool operator!=(const param_type& x, const param_type& y);
  389. };
  390. // constructors and reset functions
  391. explicit uniform_int_distribution(IntType a = 0,
  392. IntType b = numeric_limits<IntType>::max()); // before C++20
  393. uniform_int_distribution() : uniform_int_distribution(0) {} // C++20
  394. explicit uniform_int_distribution(IntType a,
  395. IntType b = numeric_limits<IntType>::max()); // C++20
  396. explicit uniform_int_distribution(const param_type& parm);
  397. void reset();
  398. // generating functions
  399. template<class URNG> result_type operator()(URNG& g);
  400. template<class URNG> result_type operator()(URNG& g, const param_type& parm);
  401. // property functions
  402. result_type a() const;
  403. result_type b() const;
  404. param_type param() const;
  405. void param(const param_type& parm);
  406. result_type min() const;
  407. result_type max() const;
  408. friend bool operator==(const uniform_int_distribution& x,
  409. const uniform_int_distribution& y);
  410. friend bool operator!=(const uniform_int_distribution& x,
  411. const uniform_int_distribution& y);
  412. template <class charT, class traits>
  413. friend
  414. basic_ostream<charT, traits>&
  415. operator<<(basic_ostream<charT, traits>& os,
  416. const uniform_int_distribution& x);
  417. template <class charT, class traits>
  418. friend
  419. basic_istream<charT, traits>&
  420. operator>>(basic_istream<charT, traits>& is,
  421. uniform_int_distribution& x);
  422. };
  423. template<class RealType = double>
  424. class uniform_real_distribution
  425. {
  426. public:
  427. // types
  428. typedef RealType result_type;
  429. class param_type
  430. {
  431. public:
  432. typedef uniform_real_distribution distribution_type;
  433. explicit param_type(RealType a = 0,
  434. RealType b = 1);
  435. result_type a() const;
  436. result_type b() const;
  437. friend bool operator==(const param_type& x, const param_type& y);
  438. friend bool operator!=(const param_type& x, const param_type& y);
  439. };
  440. // constructors and reset functions
  441. explicit uniform_real_distribution(RealType a = 0.0, RealType b = 1.0); // before C++20
  442. uniform_real_distribution() : uniform_real_distribution(0.0) {} // C++20
  443. explicit uniform_real_distribution(RealType a, RealType b = 1.0); // C++20
  444. explicit uniform_real_distribution(const param_type& parm);
  445. void reset();
  446. // generating functions
  447. template<class URNG> result_type operator()(URNG& g);
  448. template<class URNG> result_type operator()(URNG& g, const param_type& parm);
  449. // property functions
  450. result_type a() const;
  451. result_type b() const;
  452. param_type param() const;
  453. void param(const param_type& parm);
  454. result_type min() const;
  455. result_type max() const;
  456. friend bool operator==(const uniform_real_distribution& x,
  457. const uniform_real_distribution& y);
  458. friend bool operator!=(const uniform_real_distribution& x,
  459. const uniform_real_distribution& y);
  460. template <class charT, class traits>
  461. friend
  462. basic_ostream<charT, traits>&
  463. operator<<(basic_ostream<charT, traits>& os,
  464. const uniform_real_distribution& x);
  465. template <class charT, class traits>
  466. friend
  467. basic_istream<charT, traits>&
  468. operator>>(basic_istream<charT, traits>& is,
  469. uniform_real_distribution& x);
  470. };
  471. class bernoulli_distribution
  472. {
  473. public:
  474. // types
  475. typedef bool result_type;
  476. class param_type
  477. {
  478. public:
  479. typedef bernoulli_distribution distribution_type;
  480. explicit param_type(double p = 0.5);
  481. double p() const;
  482. friend bool operator==(const param_type& x, const param_type& y);
  483. friend bool operator!=(const param_type& x, const param_type& y);
  484. };
  485. // constructors and reset functions
  486. explicit bernoulli_distribution(double p = 0.5); // before C++20
  487. bernoulli_distribution() : bernoulli_distribution(0.5) {} // C++20
  488. explicit bernoulli_distribution(double p); // C++20
  489. explicit bernoulli_distribution(const param_type& parm);
  490. void reset();
  491. // generating functions
  492. template<class URNG> result_type operator()(URNG& g);
  493. template<class URNG> result_type operator()(URNG& g, const param_type& parm);
  494. // property functions
  495. double p() const;
  496. param_type param() const;
  497. void param(const param_type& parm);
  498. result_type min() const;
  499. result_type max() const;
  500. friend bool operator==(const bernoulli_distribution& x,
  501. const bernoulli_distribution& y);
  502. friend bool operator!=(const bernoulli_distribution& x,
  503. const bernoulli_distribution& y);
  504. template <class charT, class traits>
  505. friend
  506. basic_ostream<charT, traits>&
  507. operator<<(basic_ostream<charT, traits>& os,
  508. const bernoulli_distribution& x);
  509. template <class charT, class traits>
  510. friend
  511. basic_istream<charT, traits>&
  512. operator>>(basic_istream<charT, traits>& is,
  513. bernoulli_distribution& x);
  514. };
  515. template<class IntType = int>
  516. class binomial_distribution
  517. {
  518. public:
  519. // types
  520. typedef IntType result_type;
  521. class param_type
  522. {
  523. public:
  524. typedef binomial_distribution distribution_type;
  525. explicit param_type(IntType t = 1, double p = 0.5);
  526. IntType t() const;
  527. double p() const;
  528. friend bool operator==(const param_type& x, const param_type& y);
  529. friend bool operator!=(const param_type& x, const param_type& y);
  530. };
  531. // constructors and reset functions
  532. explicit binomial_distribution(IntType t = 1, double p = 0.5); // before C++20
  533. binomial_distribution() : binomial_distribution(1) {} // C++20
  534. explicit binomial_distribution(IntType t, double p = 0.5); // C++20
  535. explicit binomial_distribution(const param_type& parm);
  536. void reset();
  537. // generating functions
  538. template<class URNG> result_type operator()(URNG& g);
  539. template<class URNG> result_type operator()(URNG& g, const param_type& parm);
  540. // property functions
  541. IntType t() const;
  542. double p() const;
  543. param_type param() const;
  544. void param(const param_type& parm);
  545. result_type min() const;
  546. result_type max() const;
  547. friend bool operator==(const binomial_distribution& x,
  548. const binomial_distribution& y);
  549. friend bool operator!=(const binomial_distribution& x,
  550. const binomial_distribution& y);
  551. template <class charT, class traits>
  552. friend
  553. basic_ostream<charT, traits>&
  554. operator<<(basic_ostream<charT, traits>& os,
  555. const binomial_distribution& x);
  556. template <class charT, class traits>
  557. friend
  558. basic_istream<charT, traits>&
  559. operator>>(basic_istream<charT, traits>& is,
  560. binomial_distribution& x);
  561. };
  562. template<class IntType = int>
  563. class geometric_distribution
  564. {
  565. public:
  566. // types
  567. typedef IntType result_type;
  568. class param_type
  569. {
  570. public:
  571. typedef geometric_distribution distribution_type;
  572. explicit param_type(double p = 0.5);
  573. double p() const;
  574. friend bool operator==(const param_type& x, const param_type& y);
  575. friend bool operator!=(const param_type& x, const param_type& y);
  576. };
  577. // constructors and reset functions
  578. explicit geometric_distribution(double p = 0.5); // before C++20
  579. geometric_distribution() : geometric_distribution(0.5) {} // C++20
  580. explicit geometric_distribution(double p); // C++20
  581. explicit geometric_distribution(const param_type& parm);
  582. void reset();
  583. // generating functions
  584. template<class URNG> result_type operator()(URNG& g);
  585. template<class URNG> result_type operator()(URNG& g, const param_type& parm);
  586. // property functions
  587. double p() const;
  588. param_type param() const;
  589. void param(const param_type& parm);
  590. result_type min() const;
  591. result_type max() const;
  592. friend bool operator==(const geometric_distribution& x,
  593. const geometric_distribution& y);
  594. friend bool operator!=(const geometric_distribution& x,
  595. const geometric_distribution& y);
  596. template <class charT, class traits>
  597. friend
  598. basic_ostream<charT, traits>&
  599. operator<<(basic_ostream<charT, traits>& os,
  600. const geometric_distribution& x);
  601. template <class charT, class traits>
  602. friend
  603. basic_istream<charT, traits>&
  604. operator>>(basic_istream<charT, traits>& is,
  605. geometric_distribution& x);
  606. };
  607. template<class IntType = int>
  608. class negative_binomial_distribution
  609. {
  610. public:
  611. // types
  612. typedef IntType result_type;
  613. class param_type
  614. {
  615. public:
  616. typedef negative_binomial_distribution distribution_type;
  617. explicit param_type(result_type k = 1, double p = 0.5);
  618. result_type k() const;
  619. double p() const;
  620. friend bool operator==(const param_type& x, const param_type& y);
  621. friend bool operator!=(const param_type& x, const param_type& y);
  622. };
  623. // constructor and reset functions
  624. explicit negative_binomial_distribution(IntType k = 1, double p = 0.5); // before C++20
  625. negative_binomial_distribution() : negative_binomial_distribution(1) {} // C++20
  626. explicit negative_binomial_distribution(IntType k, double p = 0.5); // C++20
  627. explicit negative_binomial_distribution(const param_type& parm);
  628. void reset();
  629. // generating functions
  630. template<class URNG> result_type operator()(URNG& g);
  631. template<class URNG> result_type operator()(URNG& g, const param_type& parm);
  632. // property functions
  633. result_type k() const;
  634. double p() const;
  635. param_type param() const;
  636. void param(const param_type& parm);
  637. result_type min() const;
  638. result_type max() const;
  639. friend bool operator==(const negative_binomial_distribution& x,
  640. const negative_binomial_distribution& y);
  641. friend bool operator!=(const negative_binomial_distribution& x,
  642. const negative_binomial_distribution& y);
  643. template <class charT, class traits>
  644. friend
  645. basic_ostream<charT, traits>&
  646. operator<<(basic_ostream<charT, traits>& os,
  647. const negative_binomial_distribution& x);
  648. template <class charT, class traits>
  649. friend
  650. basic_istream<charT, traits>&
  651. operator>>(basic_istream<charT, traits>& is,
  652. negative_binomial_distribution& x);
  653. };
  654. template<class IntType = int>
  655. class poisson_distribution
  656. {
  657. public:
  658. // types
  659. typedef IntType result_type;
  660. class param_type
  661. {
  662. public:
  663. typedef poisson_distribution distribution_type;
  664. explicit param_type(double mean = 1.0);
  665. double mean() const;
  666. friend bool operator==(const param_type& x, const param_type& y);
  667. friend bool operator!=(const param_type& x, const param_type& y);
  668. };
  669. // constructors and reset functions
  670. explicit poisson_distribution(double mean = 1.0); // before C++20
  671. poisson_distribution() : poisson_distribution(1.0) {} // C++20
  672. explicit poisson_distribution(double mean); // C++20
  673. explicit poisson_distribution(const param_type& parm);
  674. void reset();
  675. // generating functions
  676. template<class URNG> result_type operator()(URNG& g);
  677. template<class URNG> result_type operator()(URNG& g, const param_type& parm);
  678. // property functions
  679. double mean() const;
  680. param_type param() const;
  681. void param(const param_type& parm);
  682. result_type min() const;
  683. result_type max() const;
  684. friend bool operator==(const poisson_distribution& x,
  685. const poisson_distribution& y);
  686. friend bool operator!=(const poisson_distribution& x,
  687. const poisson_distribution& y);
  688. template <class charT, class traits>
  689. friend
  690. basic_ostream<charT, traits>&
  691. operator<<(basic_ostream<charT, traits>& os,
  692. const poisson_distribution& x);
  693. template <class charT, class traits>
  694. friend
  695. basic_istream<charT, traits>&
  696. operator>>(basic_istream<charT, traits>& is,
  697. poisson_distribution& x);
  698. };
  699. template<class RealType = double>
  700. class exponential_distribution
  701. {
  702. public:
  703. // types
  704. typedef RealType result_type;
  705. class param_type
  706. {
  707. public:
  708. typedef exponential_distribution distribution_type;
  709. explicit param_type(result_type lambda = 1.0);
  710. result_type lambda() const;
  711. friend bool operator==(const param_type& x, const param_type& y);
  712. friend bool operator!=(const param_type& x, const param_type& y);
  713. };
  714. // constructors and reset functions
  715. explicit exponential_distribution(RealType lambda = 1.0); // before C++20
  716. exponential_distribution() : exponential_distribution(1.0) {} // C++20
  717. explicit exponential_distribution(RealType lambda); // C++20
  718. explicit exponential_distribution(const param_type& parm);
  719. void reset();
  720. // generating functions
  721. template<class URNG> result_type operator()(URNG& g);
  722. template<class URNG> result_type operator()(URNG& g, const param_type& parm);
  723. // property functions
  724. result_type lambda() const;
  725. param_type param() const;
  726. void param(const param_type& parm);
  727. result_type min() const;
  728. result_type max() const;
  729. friend bool operator==(const exponential_distribution& x,
  730. const exponential_distribution& y);
  731. friend bool operator!=(const exponential_distribution& x,
  732. const exponential_distribution& y);
  733. template <class charT, class traits>
  734. friend
  735. basic_ostream<charT, traits>&
  736. operator<<(basic_ostream<charT, traits>& os,
  737. const exponential_distribution& x);
  738. template <class charT, class traits>
  739. friend
  740. basic_istream<charT, traits>&
  741. operator>>(basic_istream<charT, traits>& is,
  742. exponential_distribution& x);
  743. };
  744. template<class RealType = double>
  745. class gamma_distribution
  746. {
  747. public:
  748. // types
  749. typedef RealType result_type;
  750. class param_type
  751. {
  752. public:
  753. typedef gamma_distribution distribution_type;
  754. explicit param_type(result_type alpha = 1, result_type beta = 1);
  755. result_type alpha() const;
  756. result_type beta() const;
  757. friend bool operator==(const param_type& x, const param_type& y);
  758. friend bool operator!=(const param_type& x, const param_type& y);
  759. };
  760. // constructors and reset functions
  761. explicit gamma_distribution(RealType alpha = 0.0, RealType beta = 1.0); // before C++20
  762. gamma_distribution() : gamma_distribution(0.0) {} // C++20
  763. explicit gamma_distribution(RealType alpha, RealType beta = 1.0); // C++20
  764. explicit gamma_distribution(const param_type& parm);
  765. void reset();
  766. // generating functions
  767. template<class URNG> result_type operator()(URNG& g);
  768. template<class URNG> result_type operator()(URNG& g, const param_type& parm);
  769. // property functions
  770. result_type alpha() const;
  771. result_type beta() const;
  772. param_type param() const;
  773. void param(const param_type& parm);
  774. result_type min() const;
  775. result_type max() const;
  776. friend bool operator==(const gamma_distribution& x,
  777. const gamma_distribution& y);
  778. friend bool operator!=(const gamma_distribution& x,
  779. const gamma_distribution& y);
  780. template <class charT, class traits>
  781. friend
  782. basic_ostream<charT, traits>&
  783. operator<<(basic_ostream<charT, traits>& os,
  784. const gamma_distribution& x);
  785. template <class charT, class traits>
  786. friend
  787. basic_istream<charT, traits>&
  788. operator>>(basic_istream<charT, traits>& is,
  789. gamma_distribution& x);
  790. };
  791. template<class RealType = double>
  792. class weibull_distribution
  793. {
  794. public:
  795. // types
  796. typedef RealType result_type;
  797. class param_type
  798. {
  799. public:
  800. typedef weibull_distribution distribution_type;
  801. explicit param_type(result_type alpha = 1, result_type beta = 1);
  802. result_type a() const;
  803. result_type b() const;
  804. friend bool operator==(const param_type& x, const param_type& y);
  805. friend bool operator!=(const param_type& x, const param_type& y);
  806. };
  807. // constructor and reset functions
  808. explicit weibull_distribution(RealType a = 1.0, RealType b = 1.0); // before C++20
  809. weibull_distribution() : weibull_distribution(1.0) {} // C++20
  810. explicit weibull_distribution(RealType a, RealType b = 1.0); // C++20
  811. explicit weibull_distribution(const param_type& parm);
  812. void reset();
  813. // generating functions
  814. template<class URNG> result_type operator()(URNG& g);
  815. template<class URNG> result_type operator()(URNG& g, const param_type& parm);
  816. // property functions
  817. result_type a() const;
  818. result_type b() const;
  819. param_type param() const;
  820. void param(const param_type& parm);
  821. result_type min() const;
  822. result_type max() const;
  823. friend bool operator==(const weibull_distribution& x,
  824. const weibull_distribution& y);
  825. friend bool operator!=(const weibull_distribution& x,
  826. const weibull_distribution& y);
  827. template <class charT, class traits>
  828. friend
  829. basic_ostream<charT, traits>&
  830. operator<<(basic_ostream<charT, traits>& os,
  831. const weibull_distribution& x);
  832. template <class charT, class traits>
  833. friend
  834. basic_istream<charT, traits>&
  835. operator>>(basic_istream<charT, traits>& is,
  836. weibull_distribution& x);
  837. };
  838. template<class RealType = double>
  839. class extreme_value_distribution
  840. {
  841. public:
  842. // types
  843. typedef RealType result_type;
  844. class param_type
  845. {
  846. public:
  847. typedef extreme_value_distribution distribution_type;
  848. explicit param_type(result_type a = 0, result_type b = 1);
  849. result_type a() const;
  850. result_type b() const;
  851. friend bool operator==(const param_type& x, const param_type& y);
  852. friend bool operator!=(const param_type& x, const param_type& y);
  853. };
  854. // constructor and reset functions
  855. explicit extreme_value_distribution(RealType a = 0.0, RealType b = 1.0); // before C++20
  856. extreme_value_distribution() : extreme_value_distribution(0.0) {} // C++20
  857. explicit extreme_value_distribution(RealType a, RealType b = 1.0); // C++20
  858. explicit extreme_value_distribution(const param_type& parm);
  859. void reset();
  860. // generating functions
  861. template<class URNG> result_type operator()(URNG& g);
  862. template<class URNG> result_type operator()(URNG& g, const param_type& parm);
  863. // property functions
  864. result_type a() const;
  865. result_type b() const;
  866. param_type param() const;
  867. void param(const param_type& parm);
  868. result_type min() const;
  869. result_type max() const;
  870. friend bool operator==(const extreme_value_distribution& x,
  871. const extreme_value_distribution& y);
  872. friend bool operator!=(const extreme_value_distribution& x,
  873. const extreme_value_distribution& y);
  874. template <class charT, class traits>
  875. friend
  876. basic_ostream<charT, traits>&
  877. operator<<(basic_ostream<charT, traits>& os,
  878. const extreme_value_distribution& x);
  879. template <class charT, class traits>
  880. friend
  881. basic_istream<charT, traits>&
  882. operator>>(basic_istream<charT, traits>& is,
  883. extreme_value_distribution& x);
  884. };
  885. template<class RealType = double>
  886. class normal_distribution
  887. {
  888. public:
  889. // types
  890. typedef RealType result_type;
  891. class param_type
  892. {
  893. public:
  894. typedef normal_distribution distribution_type;
  895. explicit param_type(result_type mean = 0, result_type stddev = 1);
  896. result_type mean() const;
  897. result_type stddev() const;
  898. friend bool operator==(const param_type& x, const param_type& y);
  899. friend bool operator!=(const param_type& x, const param_type& y);
  900. };
  901. // constructors and reset functions
  902. explicit normal_distribution(RealType mean = 0.0, RealType stddev = 1.0); // before C++20
  903. normal_distribution() : normal_distribution(0.0) {} // C++20
  904. explicit normal_distribution(RealType mean, RealType stddev = 1.0); // C++20
  905. explicit normal_distribution(const param_type& parm);
  906. void reset();
  907. // generating functions
  908. template<class URNG> result_type operator()(URNG& g);
  909. template<class URNG> result_type operator()(URNG& g, const param_type& parm);
  910. // property functions
  911. result_type mean() const;
  912. result_type stddev() const;
  913. param_type param() const;
  914. void param(const param_type& parm);
  915. result_type min() const;
  916. result_type max() const;
  917. friend bool operator==(const normal_distribution& x,
  918. const normal_distribution& y);
  919. friend bool operator!=(const normal_distribution& x,
  920. const normal_distribution& y);
  921. template <class charT, class traits>
  922. friend
  923. basic_ostream<charT, traits>&
  924. operator<<(basic_ostream<charT, traits>& os,
  925. const normal_distribution& x);
  926. template <class charT, class traits>
  927. friend
  928. basic_istream<charT, traits>&
  929. operator>>(basic_istream<charT, traits>& is,
  930. normal_distribution& x);
  931. };
  932. template<class RealType = double>
  933. class lognormal_distribution
  934. {
  935. public:
  936. // types
  937. typedef RealType result_type;
  938. class param_type
  939. {
  940. public:
  941. typedef lognormal_distribution distribution_type;
  942. explicit param_type(result_type m = 0, result_type s = 1);
  943. result_type m() const;
  944. result_type s() const;
  945. friend bool operator==(const param_type& x, const param_type& y);
  946. friend bool operator!=(const param_type& x, const param_type& y);
  947. };
  948. // constructor and reset functions
  949. explicit lognormal_distribution(RealType mean = 0.0, RealType stddev = 1.0); // before C++20
  950. lognormal_distribution() : lognormal_distribution(0.0) {} // C++20
  951. explicit lognormal_distribution(RealType mean, RealType stddev = 1.0); // C++20
  952. explicit lognormal_distribution(const param_type& parm);
  953. void reset();
  954. // generating functions
  955. template<class URNG> result_type operator()(URNG& g);
  956. template<class URNG> result_type operator()(URNG& g, const param_type& parm);
  957. // property functions
  958. result_type m() const;
  959. result_type s() const;
  960. param_type param() const;
  961. void param(const param_type& parm);
  962. result_type min() const;
  963. result_type max() const;
  964. friend bool operator==(const lognormal_distribution& x,
  965. const lognormal_distribution& y);
  966. friend bool operator!=(const lognormal_distribution& x,
  967. const lognormal_distribution& y);
  968. template <class charT, class traits>
  969. friend
  970. basic_ostream<charT, traits>&
  971. operator<<(basic_ostream<charT, traits>& os,
  972. const lognormal_distribution& x);
  973. template <class charT, class traits>
  974. friend
  975. basic_istream<charT, traits>&
  976. operator>>(basic_istream<charT, traits>& is,
  977. lognormal_distribution& x);
  978. };
  979. template<class RealType = double>
  980. class chi_squared_distribution
  981. {
  982. public:
  983. // types
  984. typedef RealType result_type;
  985. class param_type
  986. {
  987. public:
  988. typedef chi_squared_distribution distribution_type;
  989. explicit param_type(result_type n = 1);
  990. result_type n() const;
  991. friend bool operator==(const param_type& x, const param_type& y);
  992. friend bool operator!=(const param_type& x, const param_type& y);
  993. };
  994. // constructor and reset functions
  995. explicit chi_squared_distribution(RealType n = 1.0); // before C++20
  996. chi_squared_distribution() : chi_squared_distribution(1.0) {} // C++20
  997. explicit chi_squared_distribution(RealType n); // C++20
  998. explicit chi_squared_distribution(const param_type& parm);
  999. void reset();
  1000. // generating functions
  1001. template<class URNG> result_type operator()(URNG& g);
  1002. template<class URNG> result_type operator()(URNG& g, const param_type& parm);
  1003. // property functions
  1004. result_type n() const;
  1005. param_type param() const;
  1006. void param(const param_type& parm);
  1007. result_type min() const;
  1008. result_type max() const;
  1009. friend bool operator==(const chi_squared_distribution& x,
  1010. const chi_squared_distribution& y);
  1011. friend bool operator!=(const chi_squared_distribution& x,
  1012. const chi_squared_distribution& y);
  1013. template <class charT, class traits>
  1014. friend
  1015. basic_ostream<charT, traits>&
  1016. operator<<(basic_ostream<charT, traits>& os,
  1017. const chi_squared_distribution& x);
  1018. template <class charT, class traits>
  1019. friend
  1020. basic_istream<charT, traits>&
  1021. operator>>(basic_istream<charT, traits>& is,
  1022. chi_squared_distribution& x);
  1023. };
  1024. template<class RealType = double>
  1025. class cauchy_distribution
  1026. {
  1027. public:
  1028. // types
  1029. typedef RealType result_type;
  1030. class param_type
  1031. {
  1032. public:
  1033. typedef cauchy_distribution distribution_type;
  1034. explicit param_type(result_type a = 0, result_type b = 1);
  1035. result_type a() const;
  1036. result_type b() const;
  1037. friend bool operator==(const param_type& x, const param_type& y);
  1038. friend bool operator!=(const param_type& x, const param_type& y);
  1039. };
  1040. // constructor and reset functions
  1041. explicit cauchy_distribution(RealType a = 0.0, RealType b = 1.0); // before C++20
  1042. cauchy_distribution() : cauchy_distribution(0.0) {} // C++20
  1043. explicit cauchy_distribution(RealType a, RealType b = 1.0); // C++20
  1044. explicit cauchy_distribution(const param_type& parm);
  1045. void reset();
  1046. // generating functions
  1047. template<class URNG> result_type operator()(URNG& g);
  1048. template<class URNG> result_type operator()(URNG& g, const param_type& parm);
  1049. // property functions
  1050. result_type a() const;
  1051. result_type b() const;
  1052. param_type param() const;
  1053. void param(const param_type& parm);
  1054. result_type min() const;
  1055. result_type max() const;
  1056. friend bool operator==(const cauchy_distribution& x,
  1057. const cauchy_distribution& y);
  1058. friend bool operator!=(const cauchy_distribution& x,
  1059. const cauchy_distribution& y);
  1060. template <class charT, class traits>
  1061. friend
  1062. basic_ostream<charT, traits>&
  1063. operator<<(basic_ostream<charT, traits>& os,
  1064. const cauchy_distribution& x);
  1065. template <class charT, class traits>
  1066. friend
  1067. basic_istream<charT, traits>&
  1068. operator>>(basic_istream<charT, traits>& is,
  1069. cauchy_distribution& x);
  1070. };
  1071. template<class RealType = double>
  1072. class fisher_f_distribution
  1073. {
  1074. public:
  1075. // types
  1076. typedef RealType result_type;
  1077. class param_type
  1078. {
  1079. public:
  1080. typedef fisher_f_distribution distribution_type;
  1081. explicit param_type(result_type m = 1, result_type n = 1);
  1082. result_type m() const;
  1083. result_type n() const;
  1084. friend bool operator==(const param_type& x, const param_type& y);
  1085. friend bool operator!=(const param_type& x, const param_type& y);
  1086. };
  1087. // constructor and reset functions
  1088. explicit fisher_f_distribution(RealType m = 1.0, RealType n = 1.0); // before C++20
  1089. fisher_f_distribution() : fisher_f_distribution(1.0) {} // C++20
  1090. explicit fisher_f_distribution(RealType m, RealType n = 1.0); // C++20
  1091. explicit fisher_f_distribution(const param_type& parm);
  1092. void reset();
  1093. // generating functions
  1094. template<class URNG> result_type operator()(URNG& g);
  1095. template<class URNG> result_type operator()(URNG& g, const param_type& parm);
  1096. // property functions
  1097. result_type m() const;
  1098. result_type n() const;
  1099. param_type param() const;
  1100. void param(const param_type& parm);
  1101. result_type min() const;
  1102. result_type max() const;
  1103. friend bool operator==(const fisher_f_distribution& x,
  1104. const fisher_f_distribution& y);
  1105. friend bool operator!=(const fisher_f_distribution& x,
  1106. const fisher_f_distribution& y);
  1107. template <class charT, class traits>
  1108. friend
  1109. basic_ostream<charT, traits>&
  1110. operator<<(basic_ostream<charT, traits>& os,
  1111. const fisher_f_distribution& x);
  1112. template <class charT, class traits>
  1113. friend
  1114. basic_istream<charT, traits>&
  1115. operator>>(basic_istream<charT, traits>& is,
  1116. fisher_f_distribution& x);
  1117. };
  1118. template<class RealType = double>
  1119. class student_t_distribution
  1120. {
  1121. public:
  1122. // types
  1123. typedef RealType result_type;
  1124. class param_type
  1125. {
  1126. public:
  1127. typedef student_t_distribution distribution_type;
  1128. explicit param_type(result_type n = 1);
  1129. result_type n() const;
  1130. friend bool operator==(const param_type& x, const param_type& y);
  1131. friend bool operator!=(const param_type& x, const param_type& y);
  1132. };
  1133. // constructor and reset functions
  1134. explicit student_t_distribution(RealType n = 1.0); // before C++20
  1135. student_t_distribution() : student_t_distribution(1.0) {} // C++20
  1136. explicit student_t_distribution(RealType n); // C++20
  1137. explicit student_t_distribution(const param_type& parm);
  1138. void reset();
  1139. // generating functions
  1140. template<class URNG> result_type operator()(URNG& g);
  1141. template<class URNG> result_type operator()(URNG& g, const param_type& parm);
  1142. // property functions
  1143. result_type n() const;
  1144. param_type param() const;
  1145. void param(const param_type& parm);
  1146. result_type min() const;
  1147. result_type max() const;
  1148. friend bool operator==(const student_t_distribution& x,
  1149. const student_t_distribution& y);
  1150. friend bool operator!=(const student_t_distribution& x,
  1151. const student_t_distribution& y);
  1152. template <class charT, class traits>
  1153. friend
  1154. basic_ostream<charT, traits>&
  1155. operator<<(basic_ostream<charT, traits>& os,
  1156. const student_t_distribution& x);
  1157. template <class charT, class traits>
  1158. friend
  1159. basic_istream<charT, traits>&
  1160. operator>>(basic_istream<charT, traits>& is,
  1161. student_t_distribution& x);
  1162. };
  1163. template<class IntType = int>
  1164. class discrete_distribution
  1165. {
  1166. public:
  1167. // types
  1168. typedef IntType result_type;
  1169. class param_type
  1170. {
  1171. public:
  1172. typedef discrete_distribution distribution_type;
  1173. param_type();
  1174. template<class InputIterator>
  1175. param_type(InputIterator firstW, InputIterator lastW);
  1176. param_type(initializer_list<double> wl);
  1177. template<class UnaryOperation>
  1178. param_type(size_t nw, double xmin, double xmax, UnaryOperation fw);
  1179. vector<double> probabilities() const;
  1180. friend bool operator==(const param_type& x, const param_type& y);
  1181. friend bool operator!=(const param_type& x, const param_type& y);
  1182. };
  1183. // constructor and reset functions
  1184. discrete_distribution();
  1185. template<class InputIterator>
  1186. discrete_distribution(InputIterator firstW, InputIterator lastW);
  1187. discrete_distribution(initializer_list<double> wl);
  1188. template<class UnaryOperation>
  1189. discrete_distribution(size_t nw, double xmin, double xmax,
  1190. UnaryOperation fw);
  1191. explicit discrete_distribution(const param_type& parm);
  1192. void reset();
  1193. // generating functions
  1194. template<class URNG> result_type operator()(URNG& g);
  1195. template<class URNG> result_type operator()(URNG& g, const param_type& parm);
  1196. // property functions
  1197. vector<double> probabilities() const;
  1198. param_type param() const;
  1199. void param(const param_type& parm);
  1200. result_type min() const;
  1201. result_type max() const;
  1202. friend bool operator==(const discrete_distribution& x,
  1203. const discrete_distribution& y);
  1204. friend bool operator!=(const discrete_distribution& x,
  1205. const discrete_distribution& y);
  1206. template <class charT, class traits>
  1207. friend
  1208. basic_ostream<charT, traits>&
  1209. operator<<(basic_ostream<charT, traits>& os,
  1210. const discrete_distribution& x);
  1211. template <class charT, class traits>
  1212. friend
  1213. basic_istream<charT, traits>&
  1214. operator>>(basic_istream<charT, traits>& is,
  1215. discrete_distribution& x);
  1216. };
  1217. template<class RealType = double>
  1218. class piecewise_constant_distribution
  1219. {
  1220. // types
  1221. typedef RealType result_type;
  1222. class param_type
  1223. {
  1224. public:
  1225. typedef piecewise_constant_distribution distribution_type;
  1226. param_type();
  1227. template<class InputIteratorB, class InputIteratorW>
  1228. param_type(InputIteratorB firstB, InputIteratorB lastB,
  1229. InputIteratorW firstW);
  1230. template<class UnaryOperation>
  1231. param_type(initializer_list<result_type> bl, UnaryOperation fw);
  1232. template<class UnaryOperation>
  1233. param_type(size_t nw, result_type xmin, result_type xmax,
  1234. UnaryOperation fw);
  1235. vector<result_type> intervals() const;
  1236. vector<result_type> densities() const;
  1237. friend bool operator==(const param_type& x, const param_type& y);
  1238. friend bool operator!=(const param_type& x, const param_type& y);
  1239. };
  1240. // constructor and reset functions
  1241. piecewise_constant_distribution();
  1242. template<class InputIteratorB, class InputIteratorW>
  1243. piecewise_constant_distribution(InputIteratorB firstB,
  1244. InputIteratorB lastB,
  1245. InputIteratorW firstW);
  1246. template<class UnaryOperation>
  1247. piecewise_constant_distribution(initializer_list<result_type> bl,
  1248. UnaryOperation fw);
  1249. template<class UnaryOperation>
  1250. piecewise_constant_distribution(size_t nw, result_type xmin,
  1251. result_type xmax, UnaryOperation fw);
  1252. explicit piecewise_constant_distribution(const param_type& parm);
  1253. void reset();
  1254. // generating functions
  1255. template<class URNG> result_type operator()(URNG& g);
  1256. template<class URNG> result_type operator()(URNG& g, const param_type& parm);
  1257. // property functions
  1258. vector<result_type> intervals() const;
  1259. vector<result_type> densities() const;
  1260. param_type param() const;
  1261. void param(const param_type& parm);
  1262. result_type min() const;
  1263. result_type max() const;
  1264. friend bool operator==(const piecewise_constant_distribution& x,
  1265. const piecewise_constant_distribution& y);
  1266. friend bool operator!=(const piecewise_constant_distribution& x,
  1267. const piecewise_constant_distribution& y);
  1268. template <class charT, class traits>
  1269. friend
  1270. basic_ostream<charT, traits>&
  1271. operator<<(basic_ostream<charT, traits>& os,
  1272. const piecewise_constant_distribution& x);
  1273. template <class charT, class traits>
  1274. friend
  1275. basic_istream<charT, traits>&
  1276. operator>>(basic_istream<charT, traits>& is,
  1277. piecewise_constant_distribution& x);
  1278. };
  1279. template<class RealType = double>
  1280. class piecewise_linear_distribution
  1281. {
  1282. // types
  1283. typedef RealType result_type;
  1284. class param_type
  1285. {
  1286. public:
  1287. typedef piecewise_linear_distribution distribution_type;
  1288. param_type();
  1289. template<class InputIteratorB, class InputIteratorW>
  1290. param_type(InputIteratorB firstB, InputIteratorB lastB,
  1291. InputIteratorW firstW);
  1292. template<class UnaryOperation>
  1293. param_type(initializer_list<result_type> bl, UnaryOperation fw);
  1294. template<class UnaryOperation>
  1295. param_type(size_t nw, result_type xmin, result_type xmax,
  1296. UnaryOperation fw);
  1297. vector<result_type> intervals() const;
  1298. vector<result_type> densities() const;
  1299. friend bool operator==(const param_type& x, const param_type& y);
  1300. friend bool operator!=(const param_type& x, const param_type& y);
  1301. };
  1302. // constructor and reset functions
  1303. piecewise_linear_distribution();
  1304. template<class InputIteratorB, class InputIteratorW>
  1305. piecewise_linear_distribution(InputIteratorB firstB,
  1306. InputIteratorB lastB,
  1307. InputIteratorW firstW);
  1308. template<class UnaryOperation>
  1309. piecewise_linear_distribution(initializer_list<result_type> bl,
  1310. UnaryOperation fw);
  1311. template<class UnaryOperation>
  1312. piecewise_linear_distribution(size_t nw, result_type xmin,
  1313. result_type xmax, UnaryOperation fw);
  1314. explicit piecewise_linear_distribution(const param_type& parm);
  1315. void reset();
  1316. // generating functions
  1317. template<class URNG> result_type operator()(URNG& g);
  1318. template<class URNG> result_type operator()(URNG& g, const param_type& parm);
  1319. // property functions
  1320. vector<result_type> intervals() const;
  1321. vector<result_type> densities() const;
  1322. param_type param() const;
  1323. void param(const param_type& parm);
  1324. result_type min() const;
  1325. result_type max() const;
  1326. friend bool operator==(const piecewise_linear_distribution& x,
  1327. const piecewise_linear_distribution& y);
  1328. friend bool operator!=(const piecewise_linear_distribution& x,
  1329. const piecewise_linear_distribution& y);
  1330. template <class charT, class traits>
  1331. friend
  1332. basic_ostream<charT, traits>&
  1333. operator<<(basic_ostream<charT, traits>& os,
  1334. const piecewise_linear_distribution& x);
  1335. template <class charT, class traits>
  1336. friend
  1337. basic_istream<charT, traits>&
  1338. operator>>(basic_istream<charT, traits>& is,
  1339. piecewise_linear_distribution& x);
  1340. };
  1341. } // std
  1342. */
  1343. #include <__assert> // all public C++ headers provide the assertion handler
  1344. #include <__config>
  1345. #include <__random/bernoulli_distribution.h>
  1346. #include <__random/binomial_distribution.h>
  1347. #include <__random/cauchy_distribution.h>
  1348. #include <__random/chi_squared_distribution.h>
  1349. #include <__random/clamp_to_integral.h>
  1350. #include <__random/default_random_engine.h>
  1351. #include <__random/discard_block_engine.h>
  1352. #include <__random/discrete_distribution.h>
  1353. #include <__random/exponential_distribution.h>
  1354. #include <__random/extreme_value_distribution.h>
  1355. #include <__random/fisher_f_distribution.h>
  1356. #include <__random/gamma_distribution.h>
  1357. #include <__random/generate_canonical.h>
  1358. #include <__random/geometric_distribution.h>
  1359. #include <__random/independent_bits_engine.h>
  1360. #include <__random/is_seed_sequence.h>
  1361. #include <__random/is_valid.h>
  1362. #include <__random/knuth_b.h>
  1363. #include <__random/linear_congruential_engine.h>
  1364. #include <__random/log2.h>
  1365. #include <__random/lognormal_distribution.h>
  1366. #include <__random/mersenne_twister_engine.h>
  1367. #include <__random/negative_binomial_distribution.h>
  1368. #include <__random/normal_distribution.h>
  1369. #include <__random/piecewise_constant_distribution.h>
  1370. #include <__random/piecewise_linear_distribution.h>
  1371. #include <__random/poisson_distribution.h>
  1372. #include <__random/random_device.h>
  1373. #include <__random/ranlux.h>
  1374. #include <__random/seed_seq.h>
  1375. #include <__random/shuffle_order_engine.h>
  1376. #include <__random/student_t_distribution.h>
  1377. #include <__random/subtract_with_carry_engine.h>
  1378. #include <__random/uniform_int_distribution.h>
  1379. #include <__random/uniform_random_bit_generator.h>
  1380. #include <__random/uniform_real_distribution.h>
  1381. #include <__random/weibull_distribution.h>
  1382. #include <version>
  1383. // standard-mandated includes
  1384. // [rand.synopsis]
  1385. #include <initializer_list>
  1386. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  1387. # pragma GCC system_header
  1388. #endif
  1389. #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
  1390. # include <algorithm>
  1391. # include <climits>
  1392. # include <cmath>
  1393. # include <concepts>
  1394. # include <cstddef>
  1395. # include <cstdint>
  1396. # include <iosfwd>
  1397. # include <limits>
  1398. # include <numeric>
  1399. # include <string>
  1400. # include <type_traits>
  1401. # include <vector>
  1402. #endif
  1403. #endif // _LIBCPP_RANDOM