2 //===----------------------------------------------------------------------===//
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
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_RANDOM
11 #define _LIBCPP_RANDOM
16 #include <initializer_list>
20 // [rand.req.urng], uniform random bit generator requirements
22 concept uniform_random_bit_generator = see below; // C++20
26 template <class UIntType, UIntType a, UIntType c, UIntType m>
27 class linear_congruential_engine
31 typedef UIntType result_type;
33 // engine characteristics
34 static constexpr result_type multiplier = a;
35 static constexpr result_type increment = c;
36 static constexpr result_type modulus = m;
37 static constexpr result_type min() { return c == 0u ? 1u: 0u;}
38 static constexpr result_type max() { return m - 1u;}
39 static constexpr result_type default_seed = 1u;
41 // constructors and seeding functions
42 explicit linear_congruential_engine(result_type s = default_seed); // before C++20
43 linear_congruential_engine() : linear_congruential_engine(default_seed) {} // C++20
44 explicit linear_congruential_engine(result_type s); // C++20
45 template<class Sseq> explicit linear_congruential_engine(Sseq& q);
46 void seed(result_type s = default_seed);
47 template<class Sseq> void seed(Sseq& q);
49 // generating functions
50 result_type operator()();
51 void discard(unsigned long long z);
54 template <class UIntType, UIntType a, UIntType c, UIntType m>
56 operator==(const linear_congruential_engine<UIntType, a, c, m>& x,
57 const linear_congruential_engine<UIntType, a, c, m>& y);
59 template <class UIntType, UIntType a, UIntType c, UIntType m>
61 operator!=(const linear_congruential_engine<UIntType, a, c, m>& x,
62 const linear_congruential_engine<UIntType, a, c, m>& y);
64 template <class charT, class traits,
65 class UIntType, UIntType a, UIntType c, UIntType m>
66 basic_ostream<charT, traits>&
67 operator<<(basic_ostream<charT, traits>& os,
68 const linear_congruential_engine<UIntType, a, c, m>& x);
70 template <class charT, class traits,
71 class UIntType, UIntType a, UIntType c, UIntType m>
72 basic_istream<charT, traits>&
73 operator>>(basic_istream<charT, traits>& is,
74 linear_congruential_engine<UIntType, a, c, m>& x);
76 template <class UIntType, size_t w, size_t n, size_t m, size_t r,
77 UIntType a, size_t u, UIntType d, size_t s,
78 UIntType b, size_t t, UIntType c, size_t l, UIntType f>
79 class mersenne_twister_engine
83 typedef UIntType result_type;
85 // engine characteristics
86 static constexpr size_t word_size = w;
87 static constexpr size_t state_size = n;
88 static constexpr size_t shift_size = m;
89 static constexpr size_t mask_bits = r;
90 static constexpr result_type xor_mask = a;
91 static constexpr size_t tempering_u = u;
92 static constexpr result_type tempering_d = d;
93 static constexpr size_t tempering_s = s;
94 static constexpr result_type tempering_b = b;
95 static constexpr size_t tempering_t = t;
96 static constexpr result_type tempering_c = c;
97 static constexpr size_t tempering_l = l;
98 static constexpr result_type initialization_multiplier = f;
99 static constexpr result_type min () { return 0; }
100 static constexpr result_type max() { return 2^w - 1; }
101 static constexpr result_type default_seed = 5489u;
103 // constructors and seeding functions
104 explicit mersenne_twister_engine(result_type s = default_seed); // before C++20
105 mersenne_twister_engine() : mersenne_twister_engine(default_seed) {} // C++20
106 explicit mersenne_twister_engine(result_type s); // C++20
107 template<class Sseq> explicit mersenne_twister_engine(Sseq& q);
108 void seed(result_type value = default_seed);
109 template<class Sseq> void seed(Sseq& q);
111 // generating functions
112 result_type operator()();
113 void discard(unsigned long long z);
116 template <class UIntType, size_t w, size_t n, size_t m, size_t r,
117 UIntType a, size_t u, UIntType d, size_t s,
118 UIntType b, size_t t, UIntType c, size_t l, UIntType f>
121 const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x,
122 const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& y);
124 template <class UIntType, size_t w, size_t n, size_t m, size_t r,
125 UIntType a, size_t u, UIntType d, size_t s,
126 UIntType b, size_t t, UIntType c, size_t l, UIntType f>
129 const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x,
130 const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& y);
132 template <class charT, class traits,
133 class UIntType, size_t w, size_t n, size_t m, size_t r,
134 UIntType a, size_t u, UIntType d, size_t s,
135 UIntType b, size_t t, UIntType c, size_t l, UIntType f>
136 basic_ostream<charT, traits>&
137 operator<<(basic_ostream<charT, traits>& os,
138 const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x);
140 template <class charT, class traits,
141 class UIntType, size_t w, size_t n, size_t m, size_t r,
142 UIntType a, size_t u, UIntType d, size_t s,
143 UIntType b, size_t t, UIntType c, size_t l, UIntType f>
144 basic_istream<charT, traits>&
145 operator>>(basic_istream<charT, traits>& is,
146 mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x);
148 template<class UIntType, size_t w, size_t s, size_t r>
149 class subtract_with_carry_engine
153 typedef UIntType result_type;
155 // engine characteristics
156 static constexpr size_t word_size = w;
157 static constexpr size_t short_lag = s;
158 static constexpr size_t long_lag = r;
159 static constexpr result_type min() { return 0; }
160 static constexpr result_type max() { return m-1; }
161 static constexpr result_type default_seed = 19780503u;
163 // constructors and seeding functions
164 explicit subtract_with_carry_engine(result_type value = default_seed); // before C++20
165 subtract_with_carry_engine() : subtract_with_carry_engine(default_seed) {} // C++20
166 explicit subtract_with_carry_engine(result_type value); // C++20
167 template<class Sseq> explicit subtract_with_carry_engine(Sseq& q);
168 void seed(result_type value = default_seed);
169 template<class Sseq> void seed(Sseq& q);
171 // generating functions
172 result_type operator()();
173 void discard(unsigned long long z);
176 template<class UIntType, size_t w, size_t s, size_t r>
179 const subtract_with_carry_engine<UIntType, w, s, r>& x,
180 const subtract_with_carry_engine<UIntType, w, s, r>& y);
182 template<class UIntType, size_t w, size_t s, size_t r>
185 const subtract_with_carry_engine<UIntType, w, s, r>& x,
186 const subtract_with_carry_engine<UIntType, w, s, r>& y);
188 template <class charT, class traits,
189 class UIntType, size_t w, size_t s, size_t r>
190 basic_ostream<charT, traits>&
191 operator<<(basic_ostream<charT, traits>& os,
192 const subtract_with_carry_engine<UIntType, w, s, r>& x);
194 template <class charT, class traits,
195 class UIntType, size_t w, size_t s, size_t r>
196 basic_istream<charT, traits>&
197 operator>>(basic_istream<charT, traits>& is,
198 subtract_with_carry_engine<UIntType, w, s, r>& x);
200 template<class Engine, size_t p, size_t r>
201 class discard_block_engine
205 typedef typename Engine::result_type result_type;
207 // engine characteristics
208 static constexpr size_t block_size = p;
209 static constexpr size_t used_block = r;
210 static constexpr result_type min() { return Engine::min(); }
211 static constexpr result_type max() { return Engine::max(); }
213 // constructors and seeding functions
214 discard_block_engine();
215 explicit discard_block_engine(const Engine& e);
216 explicit discard_block_engine(Engine&& e);
217 explicit discard_block_engine(result_type s);
218 template<class Sseq> explicit discard_block_engine(Sseq& q);
220 void seed(result_type s);
221 template<class Sseq> void seed(Sseq& q);
223 // generating functions
224 result_type operator()();
225 void discard(unsigned long long z);
227 // property functions
228 const Engine& base() const noexcept;
231 template<class Engine, size_t p, size_t r>
234 const discard_block_engine<Engine, p, r>& x,
235 const discard_block_engine<Engine, p, r>& y);
237 template<class Engine, size_t p, size_t r>
240 const discard_block_engine<Engine, p, r>& x,
241 const discard_block_engine<Engine, p, r>& y);
243 template <class charT, class traits,
244 class Engine, size_t p, size_t r>
245 basic_ostream<charT, traits>&
246 operator<<(basic_ostream<charT, traits>& os,
247 const discard_block_engine<Engine, p, r>& x);
249 template <class charT, class traits,
250 class Engine, size_t p, size_t r>
251 basic_istream<charT, traits>&
252 operator>>(basic_istream<charT, traits>& is,
253 discard_block_engine<Engine, p, r>& x);
255 template<class Engine, size_t w, class UIntType>
256 class independent_bits_engine
260 typedef UIntType result_type;
262 // engine characteristics
263 static constexpr result_type min() { return 0; }
264 static constexpr result_type max() { return 2^w - 1; }
266 // constructors and seeding functions
267 independent_bits_engine();
268 explicit independent_bits_engine(const Engine& e);
269 explicit independent_bits_engine(Engine&& e);
270 explicit independent_bits_engine(result_type s);
271 template<class Sseq> explicit independent_bits_engine(Sseq& q);
273 void seed(result_type s);
274 template<class Sseq> void seed(Sseq& q);
276 // generating functions
277 result_type operator()(); void discard(unsigned long long z);
279 // property functions
280 const Engine& base() const noexcept;
283 template<class Engine, size_t w, class UIntType>
286 const independent_bits_engine<Engine, w, UIntType>& x,
287 const independent_bits_engine<Engine, w, UIntType>& y);
289 template<class Engine, size_t w, class UIntType>
292 const independent_bits_engine<Engine, w, UIntType>& x,
293 const independent_bits_engine<Engine, w, UIntType>& y);
295 template <class charT, class traits,
296 class Engine, size_t w, class UIntType>
297 basic_ostream<charT, traits>&
298 operator<<(basic_ostream<charT, traits>& os,
299 const independent_bits_engine<Engine, w, UIntType>& x);
301 template <class charT, class traits,
302 class Engine, size_t w, class UIntType>
303 basic_istream<charT, traits>&
304 operator>>(basic_istream<charT, traits>& is,
305 independent_bits_engine<Engine, w, UIntType>& x);
307 template<class Engine, size_t k>
308 class shuffle_order_engine
312 typedef typename Engine::result_type result_type;
314 // engine characteristics
315 static constexpr size_t table_size = k;
316 static constexpr result_type min() { return Engine::min; }
317 static constexpr result_type max() { return Engine::max; }
319 // constructors and seeding functions
320 shuffle_order_engine();
321 explicit shuffle_order_engine(const Engine& e);
322 explicit shuffle_order_engine(Engine&& e);
323 explicit shuffle_order_engine(result_type s);
324 template<class Sseq> explicit shuffle_order_engine(Sseq& q);
326 void seed(result_type s);
327 template<class Sseq> void seed(Sseq& q);
329 // generating functions
330 result_type operator()();
331 void discard(unsigned long long z);
333 // property functions
334 const Engine& base() const noexcept;
337 template<class Engine, size_t k>
340 const shuffle_order_engine<Engine, k>& x,
341 const shuffle_order_engine<Engine, k>& y);
343 template<class Engine, size_t k>
346 const shuffle_order_engine<Engine, k>& x,
347 const shuffle_order_engine<Engine, k>& y);
349 template <class charT, class traits,
350 class Engine, size_t k>
351 basic_ostream<charT, traits>&
352 operator<<(basic_ostream<charT, traits>& os,
353 const shuffle_order_engine<Engine, k>& x);
355 template <class charT, class traits,
356 class Engine, size_t k>
357 basic_istream<charT, traits>&
358 operator>>(basic_istream<charT, traits>& is,
359 shuffle_order_engine<Engine, k>& x);
361 typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647>
363 typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647>
365 typedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31,
370 18, 1812433253> mt19937;
371 typedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31,
373 29, 0x5555555555555555,
374 17, 0x71d67fffeda60000,
375 37, 0xfff7eee000000000,
376 43, 6364136223846793005> mt19937_64;
377 typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> ranlux24_base;
378 typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> ranlux48_base;
379 typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24;
380 typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48;
381 typedef shuffle_order_engine<minstd_rand0, 256> knuth_b;
382 typedef minstd_rand default_random_engine;
390 typedef unsigned int result_type;
392 // generator characteristics
393 static constexpr result_type min() { return numeric_limits<result_type>::min(); }
394 static constexpr result_type max() { return numeric_limits<result_type>::max(); }
397 explicit random_device(const string& token = implementation-defined); // before C++20
398 random_device() : random_device(implementation-defined) {} // C++20
399 explicit random_device(const string& token); // C++20
401 // generating functions
402 result_type operator()();
404 // property functions
405 double entropy() const noexcept;
408 random_device(const random_device& ) = delete;
409 void operator=(const random_device& ) = delete;
418 typedef uint_least32_t result_type;
423 seed_seq(initializer_list<T> il);
424 template<class InputIterator>
425 seed_seq(InputIterator begin, InputIterator end);
427 // generating functions
428 template<class RandomAccessIterator>
429 void generate(RandomAccessIterator begin, RandomAccessIterator end);
431 // property functions
433 template<class OutputIterator>
434 void param(OutputIterator dest) const;
437 seed_seq(const seed_seq&) = delete;
438 void operator=(const seed_seq& ) = delete;
441 template<class RealType, size_t bits, class URNG>
442 RealType generate_canonical(URNG& g);
446 template<class IntType = int>
447 class uniform_int_distribution
451 typedef IntType result_type;
456 typedef uniform_int_distribution distribution_type;
458 explicit param_type(IntType a = 0,
459 IntType b = numeric_limits<IntType>::max());
461 result_type a() const;
462 result_type b() const;
464 friend bool operator==(const param_type& x, const param_type& y);
465 friend bool operator!=(const param_type& x, const param_type& y);
468 // constructors and reset functions
469 explicit uniform_int_distribution(IntType a = 0,
470 IntType b = numeric_limits<IntType>::max()); // before C++20
471 uniform_int_distribution() : uniform_int_distribution(0) {} // C++20
472 explicit uniform_int_distribution(IntType a,
473 IntType b = numeric_limits<IntType>::max()); // C++20
474 explicit uniform_int_distribution(const param_type& parm);
477 // generating functions
478 template<class URNG> result_type operator()(URNG& g);
479 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
481 // property functions
482 result_type a() const;
483 result_type b() const;
485 param_type param() const;
486 void param(const param_type& parm);
488 result_type min() const;
489 result_type max() const;
491 friend bool operator==(const uniform_int_distribution& x,
492 const uniform_int_distribution& y);
493 friend bool operator!=(const uniform_int_distribution& x,
494 const uniform_int_distribution& y);
496 template <class charT, class traits>
498 basic_ostream<charT, traits>&
499 operator<<(basic_ostream<charT, traits>& os,
500 const uniform_int_distribution& x);
502 template <class charT, class traits>
504 basic_istream<charT, traits>&
505 operator>>(basic_istream<charT, traits>& is,
506 uniform_int_distribution& x);
509 template<class RealType = double>
510 class uniform_real_distribution
514 typedef RealType result_type;
519 typedef uniform_real_distribution distribution_type;
521 explicit param_type(RealType a = 0,
524 result_type a() const;
525 result_type b() const;
527 friend bool operator==(const param_type& x, const param_type& y);
528 friend bool operator!=(const param_type& x, const param_type& y);
531 // constructors and reset functions
532 explicit uniform_real_distribution(RealType a = 0.0, RealType b = 1.0); // before C++20
533 uniform_real_distribution() : uniform_real_distribution(0.0) {} // C++20
534 explicit uniform_real_distribution(RealType a, RealType b = 1.0); // C++20
535 explicit uniform_real_distribution(const param_type& parm);
538 // generating functions
539 template<class URNG> result_type operator()(URNG& g);
540 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
542 // property functions
543 result_type a() const;
544 result_type b() const;
546 param_type param() const;
547 void param(const param_type& parm);
549 result_type min() const;
550 result_type max() const;
552 friend bool operator==(const uniform_real_distribution& x,
553 const uniform_real_distribution& y);
554 friend bool operator!=(const uniform_real_distribution& x,
555 const uniform_real_distribution& y);
557 template <class charT, class traits>
559 basic_ostream<charT, traits>&
560 operator<<(basic_ostream<charT, traits>& os,
561 const uniform_real_distribution& x);
563 template <class charT, class traits>
565 basic_istream<charT, traits>&
566 operator>>(basic_istream<charT, traits>& is,
567 uniform_real_distribution& x);
570 class bernoulli_distribution
574 typedef bool result_type;
579 typedef bernoulli_distribution distribution_type;
581 explicit param_type(double p = 0.5);
585 friend bool operator==(const param_type& x, const param_type& y);
586 friend bool operator!=(const param_type& x, const param_type& y);
589 // constructors and reset functions
590 explicit bernoulli_distribution(double p = 0.5); // before C++20
591 bernoulli_distribution() : bernoulli_distribution(0.5) {} // C++20
592 explicit bernoulli_distribution(double p); // C++20
593 explicit bernoulli_distribution(const param_type& parm);
596 // generating functions
597 template<class URNG> result_type operator()(URNG& g);
598 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
600 // property functions
603 param_type param() const;
604 void param(const param_type& parm);
606 result_type min() const;
607 result_type max() const;
609 friend bool operator==(const bernoulli_distribution& x,
610 const bernoulli_distribution& y);
611 friend bool operator!=(const bernoulli_distribution& x,
612 const bernoulli_distribution& y);
614 template <class charT, class traits>
616 basic_ostream<charT, traits>&
617 operator<<(basic_ostream<charT, traits>& os,
618 const bernoulli_distribution& x);
620 template <class charT, class traits>
622 basic_istream<charT, traits>&
623 operator>>(basic_istream<charT, traits>& is,
624 bernoulli_distribution& x);
627 template<class IntType = int>
628 class binomial_distribution
632 typedef IntType result_type;
637 typedef binomial_distribution distribution_type;
639 explicit param_type(IntType t = 1, double p = 0.5);
644 friend bool operator==(const param_type& x, const param_type& y);
645 friend bool operator!=(const param_type& x, const param_type& y);
648 // constructors and reset functions
649 explicit binomial_distribution(IntType t = 1, double p = 0.5); // before C++20
650 binomial_distribution() : binomial_distribution(1) {} // C++20
651 explicit binomial_distribution(IntType t, double p = 0.5); // C++20
652 explicit binomial_distribution(const param_type& parm);
655 // generating functions
656 template<class URNG> result_type operator()(URNG& g);
657 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
659 // property functions
663 param_type param() const;
664 void param(const param_type& parm);
666 result_type min() const;
667 result_type max() const;
669 friend bool operator==(const binomial_distribution& x,
670 const binomial_distribution& y);
671 friend bool operator!=(const binomial_distribution& x,
672 const binomial_distribution& y);
674 template <class charT, class traits>
676 basic_ostream<charT, traits>&
677 operator<<(basic_ostream<charT, traits>& os,
678 const binomial_distribution& x);
680 template <class charT, class traits>
682 basic_istream<charT, traits>&
683 operator>>(basic_istream<charT, traits>& is,
684 binomial_distribution& x);
687 template<class IntType = int>
688 class geometric_distribution
692 typedef IntType result_type;
697 typedef geometric_distribution distribution_type;
699 explicit param_type(double p = 0.5);
703 friend bool operator==(const param_type& x, const param_type& y);
704 friend bool operator!=(const param_type& x, const param_type& y);
707 // constructors and reset functions
708 explicit geometric_distribution(double p = 0.5); // before C++20
709 geometric_distribution() : geometric_distribution(0.5) {} // C++20
710 explicit geometric_distribution(double p); // C++20
711 explicit geometric_distribution(const param_type& parm);
714 // generating functions
715 template<class URNG> result_type operator()(URNG& g);
716 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
718 // property functions
721 param_type param() const;
722 void param(const param_type& parm);
724 result_type min() const;
725 result_type max() const;
727 friend bool operator==(const geometric_distribution& x,
728 const geometric_distribution& y);
729 friend bool operator!=(const geometric_distribution& x,
730 const geometric_distribution& y);
732 template <class charT, class traits>
734 basic_ostream<charT, traits>&
735 operator<<(basic_ostream<charT, traits>& os,
736 const geometric_distribution& x);
738 template <class charT, class traits>
740 basic_istream<charT, traits>&
741 operator>>(basic_istream<charT, traits>& is,
742 geometric_distribution& x);
745 template<class IntType = int>
746 class negative_binomial_distribution
750 typedef IntType result_type;
755 typedef negative_binomial_distribution distribution_type;
757 explicit param_type(result_type k = 1, double p = 0.5);
759 result_type k() const;
762 friend bool operator==(const param_type& x, const param_type& y);
763 friend bool operator!=(const param_type& x, const param_type& y);
766 // constructor and reset functions
767 explicit negative_binomial_distribution(IntType k = 1, double p = 0.5); // before C++20
768 negative_binomial_distribution() : negative_binomial_distribution(1) {} // C++20
769 explicit negative_binomial_distribution(IntType k, double p = 0.5); // C++20
770 explicit negative_binomial_distribution(const param_type& parm);
773 // generating functions
774 template<class URNG> result_type operator()(URNG& g);
775 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
777 // property functions
778 result_type k() const;
781 param_type param() const;
782 void param(const param_type& parm);
784 result_type min() const;
785 result_type max() const;
787 friend bool operator==(const negative_binomial_distribution& x,
788 const negative_binomial_distribution& y);
789 friend bool operator!=(const negative_binomial_distribution& x,
790 const negative_binomial_distribution& y);
792 template <class charT, class traits>
794 basic_ostream<charT, traits>&
795 operator<<(basic_ostream<charT, traits>& os,
796 const negative_binomial_distribution& x);
798 template <class charT, class traits>
800 basic_istream<charT, traits>&
801 operator>>(basic_istream<charT, traits>& is,
802 negative_binomial_distribution& x);
805 template<class IntType = int>
806 class poisson_distribution
810 typedef IntType result_type;
815 typedef poisson_distribution distribution_type;
817 explicit param_type(double mean = 1.0);
821 friend bool operator==(const param_type& x, const param_type& y);
822 friend bool operator!=(const param_type& x, const param_type& y);
825 // constructors and reset functions
826 explicit poisson_distribution(double mean = 1.0); // before C++20
827 poisson_distribution() : poisson_distribution(1.0) {} // C++20
828 explicit poisson_distribution(double mean); // C++20
829 explicit poisson_distribution(const param_type& parm);
832 // generating functions
833 template<class URNG> result_type operator()(URNG& g);
834 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
836 // property functions
839 param_type param() const;
840 void param(const param_type& parm);
842 result_type min() const;
843 result_type max() const;
845 friend bool operator==(const poisson_distribution& x,
846 const poisson_distribution& y);
847 friend bool operator!=(const poisson_distribution& x,
848 const poisson_distribution& y);
850 template <class charT, class traits>
852 basic_ostream<charT, traits>&
853 operator<<(basic_ostream<charT, traits>& os,
854 const poisson_distribution& x);
856 template <class charT, class traits>
858 basic_istream<charT, traits>&
859 operator>>(basic_istream<charT, traits>& is,
860 poisson_distribution& x);
863 template<class RealType = double>
864 class exponential_distribution
868 typedef RealType result_type;
873 typedef exponential_distribution distribution_type;
875 explicit param_type(result_type lambda = 1.0);
877 result_type lambda() const;
879 friend bool operator==(const param_type& x, const param_type& y);
880 friend bool operator!=(const param_type& x, const param_type& y);
883 // constructors and reset functions
884 explicit exponential_distribution(RealType lambda = 1.0); // before C++20
885 exponential_distribution() : exponential_distribution(1.0) {} // C++20
886 explicit exponential_distribution(RealType lambda); // C++20
887 explicit exponential_distribution(const param_type& parm);
890 // generating functions
891 template<class URNG> result_type operator()(URNG& g);
892 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
894 // property functions
895 result_type lambda() const;
897 param_type param() const;
898 void param(const param_type& parm);
900 result_type min() const;
901 result_type max() const;
903 friend bool operator==(const exponential_distribution& x,
904 const exponential_distribution& y);
905 friend bool operator!=(const exponential_distribution& x,
906 const exponential_distribution& y);
908 template <class charT, class traits>
910 basic_ostream<charT, traits>&
911 operator<<(basic_ostream<charT, traits>& os,
912 const exponential_distribution& x);
914 template <class charT, class traits>
916 basic_istream<charT, traits>&
917 operator>>(basic_istream<charT, traits>& is,
918 exponential_distribution& x);
921 template<class RealType = double>
922 class gamma_distribution
926 typedef RealType result_type;
931 typedef gamma_distribution distribution_type;
933 explicit param_type(result_type alpha = 1, result_type beta = 1);
935 result_type alpha() const;
936 result_type beta() const;
938 friend bool operator==(const param_type& x, const param_type& y);
939 friend bool operator!=(const param_type& x, const param_type& y);
942 // constructors and reset functions
943 explicit gamma_distribution(RealType alpha = 0.0, RealType beta = 1.0); // before C++20
944 gamma_distribution() : gamma_distribution(0.0) {} // C++20
945 explicit gamma_distribution(RealType alpha, RealType beta = 1.0); // C++20
946 explicit gamma_distribution(const param_type& parm);
949 // generating functions
950 template<class URNG> result_type operator()(URNG& g);
951 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
953 // property functions
954 result_type alpha() const;
955 result_type beta() const;
957 param_type param() const;
958 void param(const param_type& parm);
960 result_type min() const;
961 result_type max() const;
963 friend bool operator==(const gamma_distribution& x,
964 const gamma_distribution& y);
965 friend bool operator!=(const gamma_distribution& x,
966 const gamma_distribution& y);
968 template <class charT, class traits>
970 basic_ostream<charT, traits>&
971 operator<<(basic_ostream<charT, traits>& os,
972 const gamma_distribution& x);
974 template <class charT, class traits>
976 basic_istream<charT, traits>&
977 operator>>(basic_istream<charT, traits>& is,
978 gamma_distribution& x);
981 template<class RealType = double>
982 class weibull_distribution
986 typedef RealType result_type;
991 typedef weibull_distribution distribution_type;
993 explicit param_type(result_type alpha = 1, result_type beta = 1);
995 result_type a() const;
996 result_type b() const;
998 friend bool operator==(const param_type& x, const param_type& y);
999 friend bool operator!=(const param_type& x, const param_type& y);
1002 // constructor and reset functions
1003 explicit weibull_distribution(RealType a = 1.0, RealType b = 1.0); // before C++20
1004 weibull_distribution() : weibull_distribution(1.0) {} // C++20
1005 explicit weibull_distribution(RealType a, RealType b = 1.0); // C++20
1006 explicit weibull_distribution(const param_type& parm);
1009 // generating functions
1010 template<class URNG> result_type operator()(URNG& g);
1011 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
1013 // property functions
1014 result_type a() const;
1015 result_type b() const;
1017 param_type param() const;
1018 void param(const param_type& parm);
1020 result_type min() const;
1021 result_type max() const;
1023 friend bool operator==(const weibull_distribution& x,
1024 const weibull_distribution& y);
1025 friend bool operator!=(const weibull_distribution& x,
1026 const weibull_distribution& y);
1028 template <class charT, class traits>
1030 basic_ostream<charT, traits>&
1031 operator<<(basic_ostream<charT, traits>& os,
1032 const weibull_distribution& x);
1034 template <class charT, class traits>
1036 basic_istream<charT, traits>&
1037 operator>>(basic_istream<charT, traits>& is,
1038 weibull_distribution& x);
1041 template<class RealType = double>
1042 class extreme_value_distribution
1046 typedef RealType result_type;
1051 typedef extreme_value_distribution distribution_type;
1053 explicit param_type(result_type a = 0, result_type b = 1);
1055 result_type a() const;
1056 result_type b() const;
1058 friend bool operator==(const param_type& x, const param_type& y);
1059 friend bool operator!=(const param_type& x, const param_type& y);
1062 // constructor and reset functions
1063 explicit extreme_value_distribution(RealType a = 0.0, RealType b = 1.0); // before C++20
1064 extreme_value_distribution() : extreme_value_distribution(0.0) {} // C++20
1065 explicit extreme_value_distribution(RealType a, RealType b = 1.0); // C++20
1066 explicit extreme_value_distribution(const param_type& parm);
1069 // generating functions
1070 template<class URNG> result_type operator()(URNG& g);
1071 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
1073 // property functions
1074 result_type a() const;
1075 result_type b() const;
1077 param_type param() const;
1078 void param(const param_type& parm);
1080 result_type min() const;
1081 result_type max() const;
1083 friend bool operator==(const extreme_value_distribution& x,
1084 const extreme_value_distribution& y);
1085 friend bool operator!=(const extreme_value_distribution& x,
1086 const extreme_value_distribution& y);
1088 template <class charT, class traits>
1090 basic_ostream<charT, traits>&
1091 operator<<(basic_ostream<charT, traits>& os,
1092 const extreme_value_distribution& x);
1094 template <class charT, class traits>
1096 basic_istream<charT, traits>&
1097 operator>>(basic_istream<charT, traits>& is,
1098 extreme_value_distribution& x);
1101 template<class RealType = double>
1102 class normal_distribution
1106 typedef RealType result_type;
1111 typedef normal_distribution distribution_type;
1113 explicit param_type(result_type mean = 0, result_type stddev = 1);
1115 result_type mean() const;
1116 result_type stddev() const;
1118 friend bool operator==(const param_type& x, const param_type& y);
1119 friend bool operator!=(const param_type& x, const param_type& y);
1122 // constructors and reset functions
1123 explicit normal_distribution(RealType mean = 0.0, RealType stddev = 1.0); // before C++20
1124 normal_distribution() : normal_distribution(0.0) {} // C++20
1125 explicit normal_distribution(RealType mean, RealType stddev = 1.0); // C++20
1126 explicit normal_distribution(const param_type& parm);
1129 // generating functions
1130 template<class URNG> result_type operator()(URNG& g);
1131 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
1133 // property functions
1134 result_type mean() const;
1135 result_type stddev() const;
1137 param_type param() const;
1138 void param(const param_type& parm);
1140 result_type min() const;
1141 result_type max() const;
1143 friend bool operator==(const normal_distribution& x,
1144 const normal_distribution& y);
1145 friend bool operator!=(const normal_distribution& x,
1146 const normal_distribution& y);
1148 template <class charT, class traits>
1150 basic_ostream<charT, traits>&
1151 operator<<(basic_ostream<charT, traits>& os,
1152 const normal_distribution& x);
1154 template <class charT, class traits>
1156 basic_istream<charT, traits>&
1157 operator>>(basic_istream<charT, traits>& is,
1158 normal_distribution& x);
1161 template<class RealType = double>
1162 class lognormal_distribution
1166 typedef RealType result_type;
1171 typedef lognormal_distribution distribution_type;
1173 explicit param_type(result_type m = 0, result_type s = 1);
1175 result_type m() const;
1176 result_type s() const;
1178 friend bool operator==(const param_type& x, const param_type& y);
1179 friend bool operator!=(const param_type& x, const param_type& y);
1182 // constructor and reset functions
1183 explicit lognormal_distribution(RealType mean = 0.0, RealType stddev = 1.0); // before C++20
1184 lognormal_distribution() : lognormal_distribution(0.0) {} // C++20
1185 explicit lognormal_distribution(RealType mean, RealType stddev = 1.0); // C++20
1186 explicit lognormal_distribution(const param_type& parm);
1189 // generating functions
1190 template<class URNG> result_type operator()(URNG& g);
1191 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
1193 // property functions
1194 result_type m() const;
1195 result_type s() const;
1197 param_type param() const;
1198 void param(const param_type& parm);
1200 result_type min() const;
1201 result_type max() const;
1203 friend bool operator==(const lognormal_distribution& x,
1204 const lognormal_distribution& y);
1205 friend bool operator!=(const lognormal_distribution& x,
1206 const lognormal_distribution& y);
1208 template <class charT, class traits>
1210 basic_ostream<charT, traits>&
1211 operator<<(basic_ostream<charT, traits>& os,
1212 const lognormal_distribution& x);
1214 template <class charT, class traits>
1216 basic_istream<charT, traits>&
1217 operator>>(basic_istream<charT, traits>& is,
1218 lognormal_distribution& x);
1221 template<class RealType = double>
1222 class chi_squared_distribution
1226 typedef RealType result_type;
1231 typedef chi_squared_distribution distribution_type;
1233 explicit param_type(result_type n = 1);
1235 result_type n() 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);
1241 // constructor and reset functions
1242 explicit chi_squared_distribution(RealType n = 1.0); // before C++20
1243 chi_squared_distribution() : chi_squared_distribution(1.0) {} // C++20
1244 explicit chi_squared_distribution(RealType n); // C++20
1245 explicit chi_squared_distribution(const param_type& parm);
1248 // generating functions
1249 template<class URNG> result_type operator()(URNG& g);
1250 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
1252 // property functions
1253 result_type n() const;
1255 param_type param() const;
1256 void param(const param_type& parm);
1258 result_type min() const;
1259 result_type max() const;
1261 friend bool operator==(const chi_squared_distribution& x,
1262 const chi_squared_distribution& y);
1263 friend bool operator!=(const chi_squared_distribution& x,
1264 const chi_squared_distribution& y);
1266 template <class charT, class traits>
1268 basic_ostream<charT, traits>&
1269 operator<<(basic_ostream<charT, traits>& os,
1270 const chi_squared_distribution& x);
1272 template <class charT, class traits>
1274 basic_istream<charT, traits>&
1275 operator>>(basic_istream<charT, traits>& is,
1276 chi_squared_distribution& x);
1279 template<class RealType = double>
1280 class cauchy_distribution
1284 typedef RealType result_type;
1289 typedef cauchy_distribution distribution_type;
1291 explicit param_type(result_type a = 0, result_type b = 1);
1293 result_type a() const;
1294 result_type b() const;
1296 friend bool operator==(const param_type& x, const param_type& y);
1297 friend bool operator!=(const param_type& x, const param_type& y);
1300 // constructor and reset functions
1301 explicit cauchy_distribution(RealType a = 0.0, RealType b = 1.0); // before C++20
1302 cauchy_distribution() : cauchy_distribution(0.0) {} // C++20
1303 explicit cauchy_distribution(RealType a, RealType b = 1.0); // C++20
1304 explicit cauchy_distribution(const param_type& parm);
1307 // generating functions
1308 template<class URNG> result_type operator()(URNG& g);
1309 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
1311 // property functions
1312 result_type a() const;
1313 result_type b() const;
1315 param_type param() const;
1316 void param(const param_type& parm);
1318 result_type min() const;
1319 result_type max() const;
1321 friend bool operator==(const cauchy_distribution& x,
1322 const cauchy_distribution& y);
1323 friend bool operator!=(const cauchy_distribution& x,
1324 const cauchy_distribution& y);
1326 template <class charT, class traits>
1328 basic_ostream<charT, traits>&
1329 operator<<(basic_ostream<charT, traits>& os,
1330 const cauchy_distribution& x);
1332 template <class charT, class traits>
1334 basic_istream<charT, traits>&
1335 operator>>(basic_istream<charT, traits>& is,
1336 cauchy_distribution& x);
1339 template<class RealType = double>
1340 class fisher_f_distribution
1344 typedef RealType result_type;
1349 typedef fisher_f_distribution distribution_type;
1351 explicit param_type(result_type m = 1, result_type n = 1);
1353 result_type m() const;
1354 result_type n() const;
1356 friend bool operator==(const param_type& x, const param_type& y);
1357 friend bool operator!=(const param_type& x, const param_type& y);
1360 // constructor and reset functions
1361 explicit fisher_f_distribution(RealType m = 1.0, RealType n = 1.0); // before C++20
1362 fisher_f_distribution() : fisher_f_distribution(1.0) {} // C++20
1363 explicit fisher_f_distribution(RealType m, RealType n = 1.0); // C++20
1364 explicit fisher_f_distribution(const param_type& parm);
1367 // generating functions
1368 template<class URNG> result_type operator()(URNG& g);
1369 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
1371 // property functions
1372 result_type m() const;
1373 result_type n() const;
1375 param_type param() const;
1376 void param(const param_type& parm);
1378 result_type min() const;
1379 result_type max() const;
1381 friend bool operator==(const fisher_f_distribution& x,
1382 const fisher_f_distribution& y);
1383 friend bool operator!=(const fisher_f_distribution& x,
1384 const fisher_f_distribution& y);
1386 template <class charT, class traits>
1388 basic_ostream<charT, traits>&
1389 operator<<(basic_ostream<charT, traits>& os,
1390 const fisher_f_distribution& x);
1392 template <class charT, class traits>
1394 basic_istream<charT, traits>&
1395 operator>>(basic_istream<charT, traits>& is,
1396 fisher_f_distribution& x);
1399 template<class RealType = double>
1400 class student_t_distribution
1404 typedef RealType result_type;
1409 typedef student_t_distribution distribution_type;
1411 explicit param_type(result_type n = 1);
1413 result_type n() const;
1415 friend bool operator==(const param_type& x, const param_type& y);
1416 friend bool operator!=(const param_type& x, const param_type& y);
1419 // constructor and reset functions
1420 explicit student_t_distribution(RealType n = 1.0); // before C++20
1421 student_t_distribution() : student_t_distribution(1.0) {} // C++20
1422 explicit student_t_distribution(RealType n); // C++20
1423 explicit student_t_distribution(const param_type& parm);
1426 // generating functions
1427 template<class URNG> result_type operator()(URNG& g);
1428 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
1430 // property functions
1431 result_type n() const;
1433 param_type param() const;
1434 void param(const param_type& parm);
1436 result_type min() const;
1437 result_type max() const;
1439 friend bool operator==(const student_t_distribution& x,
1440 const student_t_distribution& y);
1441 friend bool operator!=(const student_t_distribution& x,
1442 const student_t_distribution& y);
1444 template <class charT, class traits>
1446 basic_ostream<charT, traits>&
1447 operator<<(basic_ostream<charT, traits>& os,
1448 const student_t_distribution& x);
1450 template <class charT, class traits>
1452 basic_istream<charT, traits>&
1453 operator>>(basic_istream<charT, traits>& is,
1454 student_t_distribution& x);
1457 template<class IntType = int>
1458 class discrete_distribution
1462 typedef IntType result_type;
1467 typedef discrete_distribution distribution_type;
1470 template<class InputIterator>
1471 param_type(InputIterator firstW, InputIterator lastW);
1472 param_type(initializer_list<double> wl);
1473 template<class UnaryOperation>
1474 param_type(size_t nw, double xmin, double xmax, UnaryOperation fw);
1476 vector<double> probabilities() const;
1478 friend bool operator==(const param_type& x, const param_type& y);
1479 friend bool operator!=(const param_type& x, const param_type& y);
1482 // constructor and reset functions
1483 discrete_distribution();
1484 template<class InputIterator>
1485 discrete_distribution(InputIterator firstW, InputIterator lastW);
1486 discrete_distribution(initializer_list<double> wl);
1487 template<class UnaryOperation>
1488 discrete_distribution(size_t nw, double xmin, double xmax,
1490 explicit discrete_distribution(const param_type& parm);
1493 // generating functions
1494 template<class URNG> result_type operator()(URNG& g);
1495 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
1497 // property functions
1498 vector<double> probabilities() const;
1500 param_type param() const;
1501 void param(const param_type& parm);
1503 result_type min() const;
1504 result_type max() const;
1506 friend bool operator==(const discrete_distribution& x,
1507 const discrete_distribution& y);
1508 friend bool operator!=(const discrete_distribution& x,
1509 const discrete_distribution& y);
1511 template <class charT, class traits>
1513 basic_ostream<charT, traits>&
1514 operator<<(basic_ostream<charT, traits>& os,
1515 const discrete_distribution& x);
1517 template <class charT, class traits>
1519 basic_istream<charT, traits>&
1520 operator>>(basic_istream<charT, traits>& is,
1521 discrete_distribution& x);
1524 template<class RealType = double>
1525 class piecewise_constant_distribution
1528 typedef RealType result_type;
1533 typedef piecewise_constant_distribution distribution_type;
1536 template<class InputIteratorB, class InputIteratorW>
1537 param_type(InputIteratorB firstB, InputIteratorB lastB,
1538 InputIteratorW firstW);
1539 template<class UnaryOperation>
1540 param_type(initializer_list<result_type> bl, UnaryOperation fw);
1541 template<class UnaryOperation>
1542 param_type(size_t nw, result_type xmin, result_type xmax,
1545 vector<result_type> intervals() const;
1546 vector<result_type> densities() const;
1548 friend bool operator==(const param_type& x, const param_type& y);
1549 friend bool operator!=(const param_type& x, const param_type& y);
1552 // constructor and reset functions
1553 piecewise_constant_distribution();
1554 template<class InputIteratorB, class InputIteratorW>
1555 piecewise_constant_distribution(InputIteratorB firstB,
1556 InputIteratorB lastB,
1557 InputIteratorW firstW);
1558 template<class UnaryOperation>
1559 piecewise_constant_distribution(initializer_list<result_type> bl,
1561 template<class UnaryOperation>
1562 piecewise_constant_distribution(size_t nw, result_type xmin,
1563 result_type xmax, UnaryOperation fw);
1564 explicit piecewise_constant_distribution(const param_type& parm);
1567 // generating functions
1568 template<class URNG> result_type operator()(URNG& g);
1569 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
1571 // property functions
1572 vector<result_type> intervals() const;
1573 vector<result_type> densities() const;
1575 param_type param() const;
1576 void param(const param_type& parm);
1578 result_type min() const;
1579 result_type max() const;
1581 friend bool operator==(const piecewise_constant_distribution& x,
1582 const piecewise_constant_distribution& y);
1583 friend bool operator!=(const piecewise_constant_distribution& x,
1584 const piecewise_constant_distribution& y);
1586 template <class charT, class traits>
1588 basic_ostream<charT, traits>&
1589 operator<<(basic_ostream<charT, traits>& os,
1590 const piecewise_constant_distribution& x);
1592 template <class charT, class traits>
1594 basic_istream<charT, traits>&
1595 operator>>(basic_istream<charT, traits>& is,
1596 piecewise_constant_distribution& x);
1599 template<class RealType = double>
1600 class piecewise_linear_distribution
1603 typedef RealType result_type;
1608 typedef piecewise_linear_distribution distribution_type;
1611 template<class InputIteratorB, class InputIteratorW>
1612 param_type(InputIteratorB firstB, InputIteratorB lastB,
1613 InputIteratorW firstW);
1614 template<class UnaryOperation>
1615 param_type(initializer_list<result_type> bl, UnaryOperation fw);
1616 template<class UnaryOperation>
1617 param_type(size_t nw, result_type xmin, result_type xmax,
1620 vector<result_type> intervals() const;
1621 vector<result_type> densities() const;
1623 friend bool operator==(const param_type& x, const param_type& y);
1624 friend bool operator!=(const param_type& x, const param_type& y);
1627 // constructor and reset functions
1628 piecewise_linear_distribution();
1629 template<class InputIteratorB, class InputIteratorW>
1630 piecewise_linear_distribution(InputIteratorB firstB,
1631 InputIteratorB lastB,
1632 InputIteratorW firstW);
1634 template<class UnaryOperation>
1635 piecewise_linear_distribution(initializer_list<result_type> bl,
1638 template<class UnaryOperation>
1639 piecewise_linear_distribution(size_t nw, result_type xmin,
1640 result_type xmax, UnaryOperation fw);
1642 explicit piecewise_linear_distribution(const param_type& parm);
1645 // generating functions
1646 template<class URNG> result_type operator()(URNG& g);
1647 template<class URNG> result_type operator()(URNG& g, const param_type& parm);
1649 // property functions
1650 vector<result_type> intervals() const;
1651 vector<result_type> densities() const;
1653 param_type param() const;
1654 void param(const param_type& parm);
1656 result_type min() const;
1657 result_type max() const;
1659 friend bool operator==(const piecewise_linear_distribution& x,
1660 const piecewise_linear_distribution& y);
1661 friend bool operator!=(const piecewise_linear_distribution& x,
1662 const piecewise_linear_distribution& y);
1664 template <class charT, class traits>
1666 basic_ostream<charT, traits>&
1667 operator<<(basic_ostream<charT, traits>& os,
1668 const piecewise_linear_distribution& x);
1670 template <class charT, class traits>
1672 basic_istream<charT, traits>&
1673 operator>>(basic_istream<charT, traits>& is,
1674 piecewise_linear_distribution& x);
1680 #include <__assert> // all public C++ headers provide the assertion handler
1682 #include <__random/bernoulli_distribution.h>
1683 #include <__random/binomial_distribution.h>
1684 #include <__random/cauchy_distribution.h>
1685 #include <__random/chi_squared_distribution.h>
1686 #include <__random/clamp_to_integral.h>
1687 #include <__random/default_random_engine.h>
1688 #include <__random/discard_block_engine.h>
1689 #include <__random/discrete_distribution.h>
1690 #include <__random/exponential_distribution.h>
1691 #include <__random/extreme_value_distribution.h>
1692 #include <__random/fisher_f_distribution.h>
1693 #include <__random/gamma_distribution.h>
1694 #include <__random/generate_canonical.h>
1695 #include <__random/geometric_distribution.h>
1696 #include <__random/independent_bits_engine.h>
1697 #include <__random/is_seed_sequence.h>
1698 #include <__random/is_valid.h>
1699 #include <__random/knuth_b.h>
1700 #include <__random/linear_congruential_engine.h>
1701 #include <__random/log2.h>
1702 #include <__random/lognormal_distribution.h>
1703 #include <__random/mersenne_twister_engine.h>
1704 #include <__random/negative_binomial_distribution.h>
1705 #include <__random/normal_distribution.h>
1706 #include <__random/piecewise_constant_distribution.h>
1707 #include <__random/piecewise_linear_distribution.h>
1708 #include <__random/poisson_distribution.h>
1709 #include <__random/random_device.h>
1710 #include <__random/ranlux.h>
1711 #include <__random/seed_seq.h>
1712 #include <__random/shuffle_order_engine.h>
1713 #include <__random/student_t_distribution.h>
1714 #include <__random/subtract_with_carry_engine.h>
1715 #include <__random/uniform_int_distribution.h>
1716 #include <__random/uniform_random_bit_generator.h>
1717 #include <__random/uniform_real_distribution.h>
1718 #include <__random/weibull_distribution.h>
1721 // standard-mandated includes
1724 #include <initializer_list>
1726 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1727 # pragma GCC system_header
1730 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1731 # include <algorithm>
1734 # include <concepts>
1742 # include <type_traits>
1746 #endif // _LIBCPP_RANDOM