1 // Random number extensions -*- C++ -*-
3 // Copyright (C) 2012-2018 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
26 * This file is a GNU extension to the Standard C++ Library.
32 #pragma GCC system_header
34 #if __cplusplus < 201103L
35 # include <bits/c++0x_warning.h>
43 # include <emmintrin.h>
46 #if defined(_GLIBCXX_USE_C99_STDINT_TR1) && defined(UINT32_C)
48 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
50 _GLIBCXX_BEGIN_NAMESPACE_VERSION
52 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
54 /* Mersenne twister implementation optimized for vector operations.
56 * Reference: http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/
58 template<typename _UIntType, size_t __m,
59 size_t __pos1, size_t __sl1, size_t __sl2,
60 size_t __sr1, size_t __sr2,
61 uint32_t __msk1, uint32_t __msk2,
62 uint32_t __msk3, uint32_t __msk4,
63 uint32_t __parity1, uint32_t __parity2,
64 uint32_t __parity3, uint32_t __parity4>
65 class simd_fast_mersenne_twister_engine
67 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
68 "substituting _UIntType not an unsigned integral type");
69 static_assert(__sr1 < 32, "first right shift too large");
70 static_assert(__sr2 < 16, "second right shift too large");
71 static_assert(__sl1 < 32, "first left shift too large");
72 static_assert(__sl2 < 16, "second left shift too large");
75 typedef _UIntType result_type;
78 static constexpr size_t m_w = sizeof(result_type) * 8;
79 static constexpr size_t _M_nstate = __m / 128 + 1;
80 static constexpr size_t _M_nstate32 = _M_nstate * 4;
82 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
83 "substituting _UIntType not an unsigned integral type");
84 static_assert(__pos1 < _M_nstate, "POS1 not smaller than state size");
85 static_assert(16 % sizeof(_UIntType) == 0,
86 "UIntType size must divide 16");
89 static constexpr size_t state_size = _M_nstate * (16
90 / sizeof(result_type));
91 static constexpr result_type default_seed = 5489u;
93 // constructors and member function
95 simd_fast_mersenne_twister_engine(result_type __sd = default_seed)
98 template<typename _Sseq, typename = typename
99 std::enable_if<!std::is_same<_Sseq,
100 simd_fast_mersenne_twister_engine>::value>
103 simd_fast_mersenne_twister_engine(_Sseq& __q)
107 seed(result_type __sd = default_seed);
109 template<typename _Sseq>
110 typename std::enable_if<std::is_class<_Sseq>::value>::type
113 static constexpr result_type
117 static constexpr result_type
119 { return std::numeric_limits<result_type>::max(); }
122 discard(unsigned long long __z);
127 if (__builtin_expect(_M_pos >= state_size, 0))
130 return _M_stateT[_M_pos++];
133 template<typename _UIntType_2, size_t __m_2,
134 size_t __pos1_2, size_t __sl1_2, size_t __sl2_2,
135 size_t __sr1_2, size_t __sr2_2,
136 uint32_t __msk1_2, uint32_t __msk2_2,
137 uint32_t __msk3_2, uint32_t __msk4_2,
138 uint32_t __parity1_2, uint32_t __parity2_2,
139 uint32_t __parity3_2, uint32_t __parity4_2>
141 operator==(const simd_fast_mersenne_twister_engine<_UIntType_2,
142 __m_2, __pos1_2, __sl1_2, __sl2_2, __sr1_2, __sr2_2,
143 __msk1_2, __msk2_2, __msk3_2, __msk4_2,
144 __parity1_2, __parity2_2, __parity3_2, __parity4_2>& __lhs,
145 const simd_fast_mersenne_twister_engine<_UIntType_2,
146 __m_2, __pos1_2, __sl1_2, __sl2_2, __sr1_2, __sr2_2,
147 __msk1_2, __msk2_2, __msk3_2, __msk4_2,
148 __parity1_2, __parity2_2, __parity3_2, __parity4_2>& __rhs);
150 template<typename _UIntType_2, size_t __m_2,
151 size_t __pos1_2, size_t __sl1_2, size_t __sl2_2,
152 size_t __sr1_2, size_t __sr2_2,
153 uint32_t __msk1_2, uint32_t __msk2_2,
154 uint32_t __msk3_2, uint32_t __msk4_2,
155 uint32_t __parity1_2, uint32_t __parity2_2,
156 uint32_t __parity3_2, uint32_t __parity4_2,
157 typename _CharT, typename _Traits>
158 friend std::basic_ostream<_CharT, _Traits>&
159 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
160 const __gnu_cxx::simd_fast_mersenne_twister_engine
162 __m_2, __pos1_2, __sl1_2, __sl2_2, __sr1_2, __sr2_2,
163 __msk1_2, __msk2_2, __msk3_2, __msk4_2,
164 __parity1_2, __parity2_2, __parity3_2, __parity4_2>& __x);
166 template<typename _UIntType_2, size_t __m_2,
167 size_t __pos1_2, size_t __sl1_2, size_t __sl2_2,
168 size_t __sr1_2, size_t __sr2_2,
169 uint32_t __msk1_2, uint32_t __msk2_2,
170 uint32_t __msk3_2, uint32_t __msk4_2,
171 uint32_t __parity1_2, uint32_t __parity2_2,
172 uint32_t __parity3_2, uint32_t __parity4_2,
173 typename _CharT, typename _Traits>
174 friend std::basic_istream<_CharT, _Traits>&
175 operator>>(std::basic_istream<_CharT, _Traits>& __is,
176 __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType_2,
177 __m_2, __pos1_2, __sl1_2, __sl2_2, __sr1_2, __sr2_2,
178 __msk1_2, __msk2_2, __msk3_2, __msk4_2,
179 __parity1_2, __parity2_2, __parity3_2, __parity4_2>& __x);
185 __m128i _M_state[_M_nstate];
189 __Uint32x4_t _M_state[_M_nstate];
192 uint32_t _M_state32[_M_nstate32];
193 result_type _M_stateT[state_size];
194 } __attribute__ ((__aligned__ (16)));
197 void _M_gen_rand(void);
198 void _M_period_certification();
202 template<typename _UIntType, size_t __m,
203 size_t __pos1, size_t __sl1, size_t __sl2,
204 size_t __sr1, size_t __sr2,
205 uint32_t __msk1, uint32_t __msk2,
206 uint32_t __msk3, uint32_t __msk4,
207 uint32_t __parity1, uint32_t __parity2,
208 uint32_t __parity3, uint32_t __parity4>
210 operator!=(const __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType,
211 __m, __pos1, __sl1, __sl2, __sr1, __sr2, __msk1, __msk2, __msk3,
212 __msk4, __parity1, __parity2, __parity3, __parity4>& __lhs,
213 const __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType,
214 __m, __pos1, __sl1, __sl2, __sr1, __sr2, __msk1, __msk2, __msk3,
215 __msk4, __parity1, __parity2, __parity3, __parity4>& __rhs)
216 { return !(__lhs == __rhs); }
219 /* Definitions for the SIMD-oriented Fast Mersenne Twister as defined
220 * in the C implementation by Daito and Matsumoto, as both a 32-bit
221 * and 64-bit version.
223 typedef simd_fast_mersenne_twister_engine<uint32_t, 607, 2,
225 0xfdff37ffU, 0xef7f3f7dU,
226 0xff777b7dU, 0x7ff7fb2fU,
227 0x00000001U, 0x00000000U,
228 0x00000000U, 0x5986f054U>
231 typedef simd_fast_mersenne_twister_engine<uint64_t, 607, 2,
233 0xfdff37ffU, 0xef7f3f7dU,
234 0xff777b7dU, 0x7ff7fb2fU,
235 0x00000001U, 0x00000000U,
236 0x00000000U, 0x5986f054U>
240 typedef simd_fast_mersenne_twister_engine<uint32_t, 1279, 7,
242 0xf7fefffdU, 0x7fefcfffU,
243 0xaff3ef3fU, 0xb5ffff7fU,
244 0x00000001U, 0x00000000U,
245 0x00000000U, 0x20000000U>
248 typedef simd_fast_mersenne_twister_engine<uint64_t, 1279, 7,
250 0xf7fefffdU, 0x7fefcfffU,
251 0xaff3ef3fU, 0xb5ffff7fU,
252 0x00000001U, 0x00000000U,
253 0x00000000U, 0x20000000U>
257 typedef simd_fast_mersenne_twister_engine<uint32_t, 2281, 12,
259 0xbff7ffbfU, 0xfdfffffeU,
260 0xf7ffef7fU, 0xf2f7cbbfU,
261 0x00000001U, 0x00000000U,
262 0x00000000U, 0x41dfa600U>
265 typedef simd_fast_mersenne_twister_engine<uint64_t, 2281, 12,
267 0xbff7ffbfU, 0xfdfffffeU,
268 0xf7ffef7fU, 0xf2f7cbbfU,
269 0x00000001U, 0x00000000U,
270 0x00000000U, 0x41dfa600U>
274 typedef simd_fast_mersenne_twister_engine<uint32_t, 4253, 17,
276 0x9f7bffffU, 0x9fffff5fU,
277 0x3efffffbU, 0xfffff7bbU,
278 0xa8000001U, 0xaf5390a3U,
279 0xb740b3f8U, 0x6c11486dU>
282 typedef simd_fast_mersenne_twister_engine<uint64_t, 4253, 17,
284 0x9f7bffffU, 0x9fffff5fU,
285 0x3efffffbU, 0xfffff7bbU,
286 0xa8000001U, 0xaf5390a3U,
287 0xb740b3f8U, 0x6c11486dU>
291 typedef simd_fast_mersenne_twister_engine<uint32_t, 11213, 68,
293 0xeffff7fbU, 0xffffffefU,
294 0xdfdfbfffU, 0x7fffdbfdU,
295 0x00000001U, 0x00000000U,
296 0xe8148000U, 0xd0c7afa3U>
299 typedef simd_fast_mersenne_twister_engine<uint64_t, 11213, 68,
301 0xeffff7fbU, 0xffffffefU,
302 0xdfdfbfffU, 0x7fffdbfdU,
303 0x00000001U, 0x00000000U,
304 0xe8148000U, 0xd0c7afa3U>
308 typedef simd_fast_mersenne_twister_engine<uint32_t, 19937, 122,
310 0xdfffffefU, 0xddfecb7fU,
311 0xbffaffffU, 0xbffffff6U,
312 0x00000001U, 0x00000000U,
313 0x00000000U, 0x13c9e684U>
316 typedef simd_fast_mersenne_twister_engine<uint64_t, 19937, 122,
318 0xdfffffefU, 0xddfecb7fU,
319 0xbffaffffU, 0xbffffff6U,
320 0x00000001U, 0x00000000U,
321 0x00000000U, 0x13c9e684U>
325 typedef simd_fast_mersenne_twister_engine<uint32_t, 44497, 330,
327 0xeffffffbU, 0xdfbebfffU,
328 0xbfbf7befU, 0x9ffd7bffU,
329 0x00000001U, 0x00000000U,
330 0xa3ac4000U, 0xecc1327aU>
333 typedef simd_fast_mersenne_twister_engine<uint64_t, 44497, 330,
335 0xeffffffbU, 0xdfbebfffU,
336 0xbfbf7befU, 0x9ffd7bffU,
337 0x00000001U, 0x00000000U,
338 0xa3ac4000U, 0xecc1327aU>
342 typedef simd_fast_mersenne_twister_engine<uint32_t, 86243, 366,
344 0xfdbffbffU, 0xbff7ff3fU,
345 0xfd77efffU, 0xbf9ff3ffU,
346 0x00000001U, 0x00000000U,
347 0x00000000U, 0xe9528d85U>
350 typedef simd_fast_mersenne_twister_engine<uint64_t, 86243, 366,
352 0xfdbffbffU, 0xbff7ff3fU,
353 0xfd77efffU, 0xbf9ff3ffU,
354 0x00000001U, 0x00000000U,
355 0x00000000U, 0xe9528d85U>
359 typedef simd_fast_mersenne_twister_engine<uint32_t, 132049, 110,
361 0xffffbb5fU, 0xfb6ebf95U,
362 0xfffefffaU, 0xcff77fffU,
363 0x00000001U, 0x00000000U,
364 0xcb520000U, 0xc7e91c7dU>
367 typedef simd_fast_mersenne_twister_engine<uint64_t, 132049, 110,
369 0xffffbb5fU, 0xfb6ebf95U,
370 0xfffefffaU, 0xcff77fffU,
371 0x00000001U, 0x00000000U,
372 0xcb520000U, 0xc7e91c7dU>
376 typedef simd_fast_mersenne_twister_engine<uint32_t, 216091, 627,
378 0xbff7bff7U, 0xbfffffffU,
379 0xbffffa7fU, 0xffddfbfbU,
380 0xf8000001U, 0x89e80709U,
381 0x3bd2b64bU, 0x0c64b1e4U>
384 typedef simd_fast_mersenne_twister_engine<uint64_t, 216091, 627,
386 0xbff7bff7U, 0xbfffffffU,
387 0xbffffa7fU, 0xffddfbfbU,
388 0xf8000001U, 0x89e80709U,
389 0x3bd2b64bU, 0x0c64b1e4U>
392 #endif // __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
395 * @brief A beta continuous distribution for random numbers.
397 * The formula for the beta probability density function is:
399 * p(x|\alpha,\beta) = \frac{1}{B(\alpha,\beta)}
400 * x^{\alpha - 1} (1 - x)^{\beta - 1}
403 template<typename _RealType = double>
404 class beta_distribution
406 static_assert(std::is_floating_point<_RealType>::value,
407 "template argument not a floating point type");
410 /** The type of the range of the distribution. */
411 typedef _RealType result_type;
413 /** Parameter type. */
416 typedef beta_distribution<_RealType> distribution_type;
417 friend class beta_distribution<_RealType>;
420 param_type(_RealType __alpha_val = _RealType(1),
421 _RealType __beta_val = _RealType(1))
422 : _M_alpha(__alpha_val), _M_beta(__beta_val)
424 __glibcxx_assert(_M_alpha > _RealType(0));
425 __glibcxx_assert(_M_beta > _RealType(0));
437 operator==(const param_type& __p1, const param_type& __p2)
438 { return (__p1._M_alpha == __p2._M_alpha
439 && __p1._M_beta == __p2._M_beta); }
442 operator!=(const param_type& __p1, const param_type& __p2)
443 { return !(__p1 == __p2); }
455 * @brief Constructs a beta distribution with parameters
456 * @f$\alpha@f$ and @f$\beta@f$.
459 beta_distribution(_RealType __alpha_val = _RealType(1),
460 _RealType __beta_val = _RealType(1))
461 : _M_param(__alpha_val, __beta_val)
465 beta_distribution(const param_type& __p)
470 * @brief Resets the distribution state.
477 * @brief Returns the @f$\alpha@f$ of the distribution.
481 { return _M_param.alpha(); }
484 * @brief Returns the @f$\beta@f$ of the distribution.
488 { return _M_param.beta(); }
491 * @brief Returns the parameter set of the distribution.
498 * @brief Sets the parameter set of the distribution.
499 * @param __param The new parameter set of the distribution.
502 param(const param_type& __param)
503 { _M_param = __param; }
506 * @brief Returns the greatest lower bound value of the distribution.
510 { return result_type(0); }
513 * @brief Returns the least upper bound value of the distribution.
517 { return result_type(1); }
520 * @brief Generating functions.
522 template<typename _UniformRandomNumberGenerator>
524 operator()(_UniformRandomNumberGenerator& __urng)
525 { return this->operator()(__urng, _M_param); }
527 template<typename _UniformRandomNumberGenerator>
529 operator()(_UniformRandomNumberGenerator& __urng,
530 const param_type& __p);
532 template<typename _ForwardIterator,
533 typename _UniformRandomNumberGenerator>
535 __generate(_ForwardIterator __f, _ForwardIterator __t,
536 _UniformRandomNumberGenerator& __urng)
537 { this->__generate(__f, __t, __urng, _M_param); }
539 template<typename _ForwardIterator,
540 typename _UniformRandomNumberGenerator>
542 __generate(_ForwardIterator __f, _ForwardIterator __t,
543 _UniformRandomNumberGenerator& __urng,
544 const param_type& __p)
545 { this->__generate_impl(__f, __t, __urng, __p); }
547 template<typename _UniformRandomNumberGenerator>
549 __generate(result_type* __f, result_type* __t,
550 _UniformRandomNumberGenerator& __urng,
551 const param_type& __p)
552 { this->__generate_impl(__f, __t, __urng, __p); }
555 * @brief Return true if two beta distributions have the same
556 * parameters and the sequences that would be generated
560 operator==(const beta_distribution& __d1,
561 const beta_distribution& __d2)
562 { return __d1._M_param == __d2._M_param; }
565 * @brief Inserts a %beta_distribution random number distribution
566 * @p __x into the output stream @p __os.
568 * @param __os An output stream.
569 * @param __x A %beta_distribution random number distribution.
571 * @returns The output stream with the state of @p __x inserted or in
574 template<typename _RealType1, typename _CharT, typename _Traits>
575 friend std::basic_ostream<_CharT, _Traits>&
576 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
577 const __gnu_cxx::beta_distribution<_RealType1>& __x);
580 * @brief Extracts a %beta_distribution random number distribution
581 * @p __x from the input stream @p __is.
583 * @param __is An input stream.
584 * @param __x A %beta_distribution random number generator engine.
586 * @returns The input stream with @p __x extracted or in an error state.
588 template<typename _RealType1, typename _CharT, typename _Traits>
589 friend std::basic_istream<_CharT, _Traits>&
590 operator>>(std::basic_istream<_CharT, _Traits>& __is,
591 __gnu_cxx::beta_distribution<_RealType1>& __x);
594 template<typename _ForwardIterator,
595 typename _UniformRandomNumberGenerator>
597 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
598 _UniformRandomNumberGenerator& __urng,
599 const param_type& __p);
605 * @brief Return true if two beta distributions are different.
607 template<typename _RealType>
609 operator!=(const __gnu_cxx::beta_distribution<_RealType>& __d1,
610 const __gnu_cxx::beta_distribution<_RealType>& __d2)
611 { return !(__d1 == __d2); }
615 * @brief A multi-variate normal continuous distribution for random numbers.
617 * The formula for the normal probability density function is
619 * p(\overrightarrow{x}|\overrightarrow{\mu },\Sigma) =
620 * \frac{1}{\sqrt{(2\pi )^k\det(\Sigma))}}
621 * e^{-\frac{1}{2}(\overrightarrow{x}-\overrightarrow{\mu})^\text{T}
622 * \Sigma ^{-1}(\overrightarrow{x}-\overrightarrow{\mu})}
625 * where @f$\overrightarrow{x}@f$ and @f$\overrightarrow{\mu}@f$ are
626 * vectors of dimension @f$k@f$ and @f$\Sigma@f$ is the covariance
627 * matrix (which must be positive-definite).
629 template<std::size_t _Dimen, typename _RealType = double>
630 class normal_mv_distribution
632 static_assert(std::is_floating_point<_RealType>::value,
633 "template argument not a floating point type");
634 static_assert(_Dimen != 0, "dimension is zero");
637 /** The type of the range of the distribution. */
638 typedef std::array<_RealType, _Dimen> result_type;
639 /** Parameter type. */
642 static constexpr size_t _M_t_size = _Dimen * (_Dimen + 1) / 2;
645 typedef normal_mv_distribution<_Dimen, _RealType> distribution_type;
646 friend class normal_mv_distribution<_Dimen, _RealType>;
650 std::fill(_M_mean.begin(), _M_mean.end(), _RealType(0));
651 auto __it = _M_t.begin();
652 for (size_t __i = 0; __i < _Dimen; ++__i)
654 std::fill_n(__it, __i, _RealType(0));
656 *__it++ = _RealType(1);
660 template<typename _ForwardIterator1, typename _ForwardIterator2>
661 param_type(_ForwardIterator1 __meanbegin,
662 _ForwardIterator1 __meanend,
663 _ForwardIterator2 __varcovbegin,
664 _ForwardIterator2 __varcovend)
666 __glibcxx_function_requires(_ForwardIteratorConcept<
668 __glibcxx_function_requires(_ForwardIteratorConcept<
670 _GLIBCXX_DEBUG_ASSERT(std::distance(__meanbegin, __meanend)
672 const auto __dist = std::distance(__varcovbegin, __varcovend);
673 _GLIBCXX_DEBUG_ASSERT(__dist == _Dimen * _Dimen
674 || __dist == _Dimen * (_Dimen + 1) / 2
675 || __dist == _Dimen);
677 if (__dist == _Dimen * _Dimen)
678 _M_init_full(__meanbegin, __meanend, __varcovbegin, __varcovend);
679 else if (__dist == _Dimen * (_Dimen + 1) / 2)
680 _M_init_lower(__meanbegin, __meanend, __varcovbegin, __varcovend);
683 __glibcxx_assert(__dist == _Dimen);
684 _M_init_diagonal(__meanbegin, __meanend,
685 __varcovbegin, __varcovend);
689 param_type(std::initializer_list<_RealType> __mean,
690 std::initializer_list<_RealType> __varcov)
692 _GLIBCXX_DEBUG_ASSERT(__mean.size() <= _Dimen);
693 _GLIBCXX_DEBUG_ASSERT(__varcov.size() == _Dimen * _Dimen
694 || __varcov.size() == _Dimen * (_Dimen + 1) / 2
695 || __varcov.size() == _Dimen);
697 if (__varcov.size() == _Dimen * _Dimen)
698 _M_init_full(__mean.begin(), __mean.end(),
699 __varcov.begin(), __varcov.end());
700 else if (__varcov.size() == _Dimen * (_Dimen + 1) / 2)
701 _M_init_lower(__mean.begin(), __mean.end(),
702 __varcov.begin(), __varcov.end());
705 __glibcxx_assert(__varcov.size() == _Dimen);
706 _M_init_diagonal(__mean.begin(), __mean.end(),
707 __varcov.begin(), __varcov.end());
711 std::array<_RealType, _Dimen>
715 std::array<_RealType, _M_t_size>
720 operator==(const param_type& __p1, const param_type& __p2)
721 { return __p1._M_mean == __p2._M_mean && __p1._M_t == __p2._M_t; }
724 operator!=(const param_type& __p1, const param_type& __p2)
725 { return !(__p1 == __p2); }
728 template <typename _InputIterator1, typename _InputIterator2>
729 void _M_init_full(_InputIterator1 __meanbegin,
730 _InputIterator1 __meanend,
731 _InputIterator2 __varcovbegin,
732 _InputIterator2 __varcovend);
733 template <typename _InputIterator1, typename _InputIterator2>
734 void _M_init_lower(_InputIterator1 __meanbegin,
735 _InputIterator1 __meanend,
736 _InputIterator2 __varcovbegin,
737 _InputIterator2 __varcovend);
738 template <typename _InputIterator1, typename _InputIterator2>
739 void _M_init_diagonal(_InputIterator1 __meanbegin,
740 _InputIterator1 __meanend,
741 _InputIterator2 __varbegin,
742 _InputIterator2 __varend);
744 std::array<_RealType, _Dimen> _M_mean;
745 std::array<_RealType, _M_t_size> _M_t;
749 normal_mv_distribution()
750 : _M_param(), _M_nd()
753 template<typename _ForwardIterator1, typename _ForwardIterator2>
754 normal_mv_distribution(_ForwardIterator1 __meanbegin,
755 _ForwardIterator1 __meanend,
756 _ForwardIterator2 __varcovbegin,
757 _ForwardIterator2 __varcovend)
758 : _M_param(__meanbegin, __meanend, __varcovbegin, __varcovend),
762 normal_mv_distribution(std::initializer_list<_RealType> __mean,
763 std::initializer_list<_RealType> __varcov)
764 : _M_param(__mean, __varcov), _M_nd()
768 normal_mv_distribution(const param_type& __p)
769 : _M_param(__p), _M_nd()
773 * @brief Resets the distribution state.
780 * @brief Returns the mean of the distribution.
784 { return _M_param.mean(); }
787 * @brief Returns the compact form of the variance/covariance
788 * matrix of the distribution.
790 std::array<_RealType, _Dimen * (_Dimen + 1) / 2>
792 { return _M_param.varcov(); }
795 * @brief Returns the parameter set of the distribution.
802 * @brief Sets the parameter set of the distribution.
803 * @param __param The new parameter set of the distribution.
806 param(const param_type& __param)
807 { _M_param = __param; }
810 * @brief Returns the greatest lower bound value of the distribution.
815 __res.fill(std::numeric_limits<_RealType>::lowest());
819 * @brief Returns the least upper bound value of the distribution.
824 __res.fill(std::numeric_limits<_RealType>::max());
828 * @brief Generating functions.
830 template<typename _UniformRandomNumberGenerator>
832 operator()(_UniformRandomNumberGenerator& __urng)
833 { return this->operator()(__urng, _M_param); }
835 template<typename _UniformRandomNumberGenerator>
837 operator()(_UniformRandomNumberGenerator& __urng,
838 const param_type& __p);
840 template<typename _ForwardIterator,
841 typename _UniformRandomNumberGenerator>
843 __generate(_ForwardIterator __f, _ForwardIterator __t,
844 _UniformRandomNumberGenerator& __urng)
845 { return this->__generate_impl(__f, __t, __urng, _M_param); }
847 template<typename _ForwardIterator,
848 typename _UniformRandomNumberGenerator>
850 __generate(_ForwardIterator __f, _ForwardIterator __t,
851 _UniformRandomNumberGenerator& __urng,
852 const param_type& __p)
853 { return this->__generate_impl(__f, __t, __urng, __p); }
856 * @brief Return true if two multi-variant normal distributions have
857 * the same parameters and the sequences that would
858 * be generated are equal.
860 template<size_t _Dimen1, typename _RealType1>
863 __gnu_cxx::normal_mv_distribution<_Dimen1, _RealType1>&
866 __gnu_cxx::normal_mv_distribution<_Dimen1, _RealType1>&
870 * @brief Inserts a %normal_mv_distribution random number distribution
871 * @p __x into the output stream @p __os.
873 * @param __os An output stream.
874 * @param __x A %normal_mv_distribution random number distribution.
876 * @returns The output stream with the state of @p __x inserted or in
879 template<size_t _Dimen1, typename _RealType1,
880 typename _CharT, typename _Traits>
881 friend std::basic_ostream<_CharT, _Traits>&
882 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
884 __gnu_cxx::normal_mv_distribution<_Dimen1, _RealType1>&
888 * @brief Extracts a %normal_mv_distribution random number distribution
889 * @p __x from the input stream @p __is.
891 * @param __is An input stream.
892 * @param __x A %normal_mv_distribution random number generator engine.
894 * @returns The input stream with @p __x extracted or in an error
897 template<size_t _Dimen1, typename _RealType1,
898 typename _CharT, typename _Traits>
899 friend std::basic_istream<_CharT, _Traits>&
900 operator>>(std::basic_istream<_CharT, _Traits>& __is,
901 __gnu_cxx::normal_mv_distribution<_Dimen1, _RealType1>&
905 template<typename _ForwardIterator,
906 typename _UniformRandomNumberGenerator>
908 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
909 _UniformRandomNumberGenerator& __urng,
910 const param_type& __p);
913 std::normal_distribution<_RealType> _M_nd;
917 * @brief Return true if two multi-variate normal distributions are
920 template<size_t _Dimen, typename _RealType>
922 operator!=(const __gnu_cxx::normal_mv_distribution<_Dimen, _RealType>&
924 const __gnu_cxx::normal_mv_distribution<_Dimen, _RealType>&
926 { return !(__d1 == __d2); }
930 * @brief A Rice continuous distribution for random numbers.
932 * The formula for the Rice probability density function is
934 * p(x|\nu,\sigma) = \frac{x}{\sigma^2}
935 * \exp\left(-\frac{x^2+\nu^2}{2\sigma^2}\right)
936 * I_0\left(\frac{x \nu}{\sigma^2}\right)
938 * where @f$I_0(z)@f$ is the modified Bessel function of the first kind
939 * of order 0 and @f$\nu >= 0@f$ and @f$\sigma > 0@f$.
941 * <table border=1 cellpadding=10 cellspacing=0>
942 * <caption align=top>Distribution Statistics</caption>
943 * <tr><td>Mean</td><td>@f$\sqrt{\pi/2}L_{1/2}(-\nu^2/2\sigma^2)@f$</td></tr>
944 * <tr><td>Variance</td><td>@f$2\sigma^2 + \nu^2
945 * + (\pi\sigma^2/2)L^2_{1/2}(-\nu^2/2\sigma^2)@f$</td></tr>
946 * <tr><td>Range</td><td>@f$[0, \infty)@f$</td></tr>
948 * where @f$L_{1/2}(x)@f$ is the Laguerre polynomial of order 1/2.
950 template<typename _RealType = double>
954 static_assert(std::is_floating_point<_RealType>::value,
955 "template argument not a floating point type");
957 /** The type of the range of the distribution. */
958 typedef _RealType result_type;
960 /** Parameter type. */
963 typedef rice_distribution<result_type> distribution_type;
965 param_type(result_type __nu_val = result_type(0),
966 result_type __sigma_val = result_type(1))
967 : _M_nu(__nu_val), _M_sigma(__sigma_val)
969 __glibcxx_assert(_M_nu >= result_type(0));
970 __glibcxx_assert(_M_sigma > result_type(0));
982 operator==(const param_type& __p1, const param_type& __p2)
983 { return __p1._M_nu == __p2._M_nu && __p1._M_sigma == __p2._M_sigma; }
986 operator!=(const param_type& __p1, const param_type& __p2)
987 { return !(__p1 == __p2); }
990 void _M_initialize();
993 result_type _M_sigma;
997 * @brief Constructors.
1000 rice_distribution(result_type __nu_val = result_type(0),
1001 result_type __sigma_val = result_type(1))
1002 : _M_param(__nu_val, __sigma_val),
1003 _M_ndx(__nu_val, __sigma_val),
1004 _M_ndy(result_type(0), __sigma_val)
1008 rice_distribution(const param_type& __p)
1010 _M_ndx(__p.nu(), __p.sigma()),
1011 _M_ndy(result_type(0), __p.sigma())
1015 * @brief Resets the distribution state.
1025 * @brief Return the parameters of the distribution.
1029 { return _M_param.nu(); }
1033 { return _M_param.sigma(); }
1036 * @brief Returns the parameter set of the distribution.
1040 { return _M_param; }
1043 * @brief Sets the parameter set of the distribution.
1044 * @param __param The new parameter set of the distribution.
1047 param(const param_type& __param)
1048 { _M_param = __param; }
1051 * @brief Returns the greatest lower bound value of the distribution.
1055 { return result_type(0); }
1058 * @brief Returns the least upper bound value of the distribution.
1062 { return std::numeric_limits<result_type>::max(); }
1065 * @brief Generating functions.
1067 template<typename _UniformRandomNumberGenerator>
1069 operator()(_UniformRandomNumberGenerator& __urng)
1071 result_type __x = this->_M_ndx(__urng);
1072 result_type __y = this->_M_ndy(__urng);
1073 #if _GLIBCXX_USE_C99_MATH_TR1
1074 return std::hypot(__x, __y);
1076 return std::sqrt(__x * __x + __y * __y);
1080 template<typename _UniformRandomNumberGenerator>
1082 operator()(_UniformRandomNumberGenerator& __urng,
1083 const param_type& __p)
1085 typename std::normal_distribution<result_type>::param_type
1086 __px(__p.nu(), __p.sigma()), __py(result_type(0), __p.sigma());
1087 result_type __x = this->_M_ndx(__px, __urng);
1088 result_type __y = this->_M_ndy(__py, __urng);
1089 #if _GLIBCXX_USE_C99_MATH_TR1
1090 return std::hypot(__x, __y);
1092 return std::sqrt(__x * __x + __y * __y);
1096 template<typename _ForwardIterator,
1097 typename _UniformRandomNumberGenerator>
1099 __generate(_ForwardIterator __f, _ForwardIterator __t,
1100 _UniformRandomNumberGenerator& __urng)
1101 { this->__generate(__f, __t, __urng, _M_param); }
1103 template<typename _ForwardIterator,
1104 typename _UniformRandomNumberGenerator>
1106 __generate(_ForwardIterator __f, _ForwardIterator __t,
1107 _UniformRandomNumberGenerator& __urng,
1108 const param_type& __p)
1109 { this->__generate_impl(__f, __t, __urng, __p); }
1111 template<typename _UniformRandomNumberGenerator>
1113 __generate(result_type* __f, result_type* __t,
1114 _UniformRandomNumberGenerator& __urng,
1115 const param_type& __p)
1116 { this->__generate_impl(__f, __t, __urng, __p); }
1119 * @brief Return true if two Rice distributions have
1120 * the same parameters and the sequences that would
1121 * be generated are equal.
1124 operator==(const rice_distribution& __d1,
1125 const rice_distribution& __d2)
1126 { return (__d1._M_param == __d2._M_param
1127 && __d1._M_ndx == __d2._M_ndx
1128 && __d1._M_ndy == __d2._M_ndy); }
1131 * @brief Inserts a %rice_distribution random number distribution
1132 * @p __x into the output stream @p __os.
1134 * @param __os An output stream.
1135 * @param __x A %rice_distribution random number distribution.
1137 * @returns The output stream with the state of @p __x inserted or in
1140 template<typename _RealType1, typename _CharT, typename _Traits>
1141 friend std::basic_ostream<_CharT, _Traits>&
1142 operator<<(std::basic_ostream<_CharT, _Traits>&,
1143 const rice_distribution<_RealType1>&);
1146 * @brief Extracts a %rice_distribution random number distribution
1147 * @p __x from the input stream @p __is.
1149 * @param __is An input stream.
1150 * @param __x A %rice_distribution random number
1153 * @returns The input stream with @p __x extracted or in an error state.
1155 template<typename _RealType1, typename _CharT, typename _Traits>
1156 friend std::basic_istream<_CharT, _Traits>&
1157 operator>>(std::basic_istream<_CharT, _Traits>&,
1158 rice_distribution<_RealType1>&);
1161 template<typename _ForwardIterator,
1162 typename _UniformRandomNumberGenerator>
1164 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1165 _UniformRandomNumberGenerator& __urng,
1166 const param_type& __p);
1168 param_type _M_param;
1170 std::normal_distribution<result_type> _M_ndx;
1171 std::normal_distribution<result_type> _M_ndy;
1175 * @brief Return true if two Rice distributions are not equal.
1177 template<typename _RealType1>
1179 operator!=(const rice_distribution<_RealType1>& __d1,
1180 const rice_distribution<_RealType1>& __d2)
1181 { return !(__d1 == __d2); }
1185 * @brief A Nakagami continuous distribution for random numbers.
1187 * The formula for the Nakagami probability density function is
1189 * p(x|\mu,\omega) = \frac{2\mu^\mu}{\Gamma(\mu)\omega^\mu}
1190 * x^{2\mu-1}e^{-\mu x / \omega}
1192 * where @f$\Gamma(z)@f$ is the gamma function and @f$\mu >= 0.5@f$
1193 * and @f$\omega > 0@f$.
1195 template<typename _RealType = double>
1197 nakagami_distribution
1199 static_assert(std::is_floating_point<_RealType>::value,
1200 "template argument not a floating point type");
1203 /** The type of the range of the distribution. */
1204 typedef _RealType result_type;
1206 /** Parameter type. */
1209 typedef nakagami_distribution<result_type> distribution_type;
1211 param_type(result_type __mu_val = result_type(1),
1212 result_type __omega_val = result_type(1))
1213 : _M_mu(__mu_val), _M_omega(__omega_val)
1215 __glibcxx_assert(_M_mu >= result_type(0.5L));
1216 __glibcxx_assert(_M_omega > result_type(0));
1225 { return _M_omega; }
1228 operator==(const param_type& __p1, const param_type& __p2)
1229 { return __p1._M_mu == __p2._M_mu && __p1._M_omega == __p2._M_omega; }
1232 operator!=(const param_type& __p1, const param_type& __p2)
1233 { return !(__p1 == __p2); }
1236 void _M_initialize();
1239 result_type _M_omega;
1243 * @brief Constructors.
1246 nakagami_distribution(result_type __mu_val = result_type(1),
1247 result_type __omega_val = result_type(1))
1248 : _M_param(__mu_val, __omega_val),
1249 _M_gd(__mu_val, __omega_val / __mu_val)
1253 nakagami_distribution(const param_type& __p)
1255 _M_gd(__p.mu(), __p.omega() / __p.mu())
1259 * @brief Resets the distribution state.
1266 * @brief Return the parameters of the distribution.
1270 { return _M_param.mu(); }
1274 { return _M_param.omega(); }
1277 * @brief Returns the parameter set of the distribution.
1281 { return _M_param; }
1284 * @brief Sets the parameter set of the distribution.
1285 * @param __param The new parameter set of the distribution.
1288 param(const param_type& __param)
1289 { _M_param = __param; }
1292 * @brief Returns the greatest lower bound value of the distribution.
1296 { return result_type(0); }
1299 * @brief Returns the least upper bound value of the distribution.
1303 { return std::numeric_limits<result_type>::max(); }
1306 * @brief Generating functions.
1308 template<typename _UniformRandomNumberGenerator>
1310 operator()(_UniformRandomNumberGenerator& __urng)
1311 { return std::sqrt(this->_M_gd(__urng)); }
1313 template<typename _UniformRandomNumberGenerator>
1315 operator()(_UniformRandomNumberGenerator& __urng,
1316 const param_type& __p)
1318 typename std::gamma_distribution<result_type>::param_type
1319 __pg(__p.mu(), __p.omega() / __p.mu());
1320 return std::sqrt(this->_M_gd(__pg, __urng));
1323 template<typename _ForwardIterator,
1324 typename _UniformRandomNumberGenerator>
1326 __generate(_ForwardIterator __f, _ForwardIterator __t,
1327 _UniformRandomNumberGenerator& __urng)
1328 { this->__generate(__f, __t, __urng, _M_param); }
1330 template<typename _ForwardIterator,
1331 typename _UniformRandomNumberGenerator>
1333 __generate(_ForwardIterator __f, _ForwardIterator __t,
1334 _UniformRandomNumberGenerator& __urng,
1335 const param_type& __p)
1336 { this->__generate_impl(__f, __t, __urng, __p); }
1338 template<typename _UniformRandomNumberGenerator>
1340 __generate(result_type* __f, result_type* __t,
1341 _UniformRandomNumberGenerator& __urng,
1342 const param_type& __p)
1343 { this->__generate_impl(__f, __t, __urng, __p); }
1346 * @brief Return true if two Nakagami distributions have
1347 * the same parameters and the sequences that would
1348 * be generated are equal.
1351 operator==(const nakagami_distribution& __d1,
1352 const nakagami_distribution& __d2)
1353 { return (__d1._M_param == __d2._M_param
1354 && __d1._M_gd == __d2._M_gd); }
1357 * @brief Inserts a %nakagami_distribution random number distribution
1358 * @p __x into the output stream @p __os.
1360 * @param __os An output stream.
1361 * @param __x A %nakagami_distribution random number distribution.
1363 * @returns The output stream with the state of @p __x inserted or in
1366 template<typename _RealType1, typename _CharT, typename _Traits>
1367 friend std::basic_ostream<_CharT, _Traits>&
1368 operator<<(std::basic_ostream<_CharT, _Traits>&,
1369 const nakagami_distribution<_RealType1>&);
1372 * @brief Extracts a %nakagami_distribution random number distribution
1373 * @p __x from the input stream @p __is.
1375 * @param __is An input stream.
1376 * @param __x A %nakagami_distribution random number
1379 * @returns The input stream with @p __x extracted or in an error state.
1381 template<typename _RealType1, typename _CharT, typename _Traits>
1382 friend std::basic_istream<_CharT, _Traits>&
1383 operator>>(std::basic_istream<_CharT, _Traits>&,
1384 nakagami_distribution<_RealType1>&);
1387 template<typename _ForwardIterator,
1388 typename _UniformRandomNumberGenerator>
1390 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1391 _UniformRandomNumberGenerator& __urng,
1392 const param_type& __p);
1394 param_type _M_param;
1396 std::gamma_distribution<result_type> _M_gd;
1400 * @brief Return true if two Nakagami distributions are not equal.
1402 template<typename _RealType>
1404 operator!=(const nakagami_distribution<_RealType>& __d1,
1405 const nakagami_distribution<_RealType>& __d2)
1406 { return !(__d1 == __d2); }
1410 * @brief A Pareto continuous distribution for random numbers.
1412 * The formula for the Pareto cumulative probability function is
1414 * P(x|\alpha,\mu) = 1 - \left(\frac{\mu}{x}\right)^\alpha
1416 * The formula for the Pareto probability density function is
1418 * p(x|\alpha,\mu) = \frac{\alpha + 1}{\mu}
1419 * \left(\frac{\mu}{x}\right)^{\alpha + 1}
1421 * where @f$x >= \mu@f$ and @f$\mu > 0@f$, @f$\alpha > 0@f$.
1423 * <table border=1 cellpadding=10 cellspacing=0>
1424 * <caption align=top>Distribution Statistics</caption>
1425 * <tr><td>Mean</td><td>@f$\alpha \mu / (\alpha - 1)@f$
1426 * for @f$\alpha > 1@f$</td></tr>
1427 * <tr><td>Variance</td><td>@f$\alpha \mu^2 / [(\alpha - 1)^2(\alpha - 2)]@f$
1428 * for @f$\alpha > 2@f$</td></tr>
1429 * <tr><td>Range</td><td>@f$[\mu, \infty)@f$</td></tr>
1432 template<typename _RealType = double>
1436 static_assert(std::is_floating_point<_RealType>::value,
1437 "template argument not a floating point type");
1440 /** The type of the range of the distribution. */
1441 typedef _RealType result_type;
1443 /** Parameter type. */
1446 typedef pareto_distribution<result_type> distribution_type;
1448 param_type(result_type __alpha_val = result_type(1),
1449 result_type __mu_val = result_type(1))
1450 : _M_alpha(__alpha_val), _M_mu(__mu_val)
1452 __glibcxx_assert(_M_alpha > result_type(0));
1453 __glibcxx_assert(_M_mu > result_type(0));
1458 { return _M_alpha; }
1465 operator==(const param_type& __p1, const param_type& __p2)
1466 { return __p1._M_alpha == __p2._M_alpha && __p1._M_mu == __p2._M_mu; }
1469 operator!=(const param_type& __p1, const param_type& __p2)
1470 { return !(__p1 == __p2); }
1473 void _M_initialize();
1475 result_type _M_alpha;
1480 * @brief Constructors.
1483 pareto_distribution(result_type __alpha_val = result_type(1),
1484 result_type __mu_val = result_type(1))
1485 : _M_param(__alpha_val, __mu_val),
1490 pareto_distribution(const param_type& __p)
1496 * @brief Resets the distribution state.
1505 * @brief Return the parameters of the distribution.
1509 { return _M_param.alpha(); }
1513 { return _M_param.mu(); }
1516 * @brief Returns the parameter set of the distribution.
1520 { return _M_param; }
1523 * @brief Sets the parameter set of the distribution.
1524 * @param __param The new parameter set of the distribution.
1527 param(const param_type& __param)
1528 { _M_param = __param; }
1531 * @brief Returns the greatest lower bound value of the distribution.
1535 { return this->mu(); }
1538 * @brief Returns the least upper bound value of the distribution.
1542 { return std::numeric_limits<result_type>::max(); }
1545 * @brief Generating functions.
1547 template<typename _UniformRandomNumberGenerator>
1549 operator()(_UniformRandomNumberGenerator& __urng)
1551 return this->mu() * std::pow(this->_M_ud(__urng),
1552 -result_type(1) / this->alpha());
1555 template<typename _UniformRandomNumberGenerator>
1557 operator()(_UniformRandomNumberGenerator& __urng,
1558 const param_type& __p)
1560 return __p.mu() * std::pow(this->_M_ud(__urng),
1561 -result_type(1) / __p.alpha());
1564 template<typename _ForwardIterator,
1565 typename _UniformRandomNumberGenerator>
1567 __generate(_ForwardIterator __f, _ForwardIterator __t,
1568 _UniformRandomNumberGenerator& __urng)
1569 { this->__generate(__f, __t, __urng, _M_param); }
1571 template<typename _ForwardIterator,
1572 typename _UniformRandomNumberGenerator>
1574 __generate(_ForwardIterator __f, _ForwardIterator __t,
1575 _UniformRandomNumberGenerator& __urng,
1576 const param_type& __p)
1577 { this->__generate_impl(__f, __t, __urng, __p); }
1579 template<typename _UniformRandomNumberGenerator>
1581 __generate(result_type* __f, result_type* __t,
1582 _UniformRandomNumberGenerator& __urng,
1583 const param_type& __p)
1584 { this->__generate_impl(__f, __t, __urng, __p); }
1587 * @brief Return true if two Pareto distributions have
1588 * the same parameters and the sequences that would
1589 * be generated are equal.
1592 operator==(const pareto_distribution& __d1,
1593 const pareto_distribution& __d2)
1594 { return (__d1._M_param == __d2._M_param
1595 && __d1._M_ud == __d2._M_ud); }
1598 * @brief Inserts a %pareto_distribution random number distribution
1599 * @p __x into the output stream @p __os.
1601 * @param __os An output stream.
1602 * @param __x A %pareto_distribution random number distribution.
1604 * @returns The output stream with the state of @p __x inserted or in
1607 template<typename _RealType1, typename _CharT, typename _Traits>
1608 friend std::basic_ostream<_CharT, _Traits>&
1609 operator<<(std::basic_ostream<_CharT, _Traits>&,
1610 const pareto_distribution<_RealType1>&);
1613 * @brief Extracts a %pareto_distribution random number distribution
1614 * @p __x from the input stream @p __is.
1616 * @param __is An input stream.
1617 * @param __x A %pareto_distribution random number
1620 * @returns The input stream with @p __x extracted or in an error state.
1622 template<typename _RealType1, typename _CharT, typename _Traits>
1623 friend std::basic_istream<_CharT, _Traits>&
1624 operator>>(std::basic_istream<_CharT, _Traits>&,
1625 pareto_distribution<_RealType1>&);
1628 template<typename _ForwardIterator,
1629 typename _UniformRandomNumberGenerator>
1631 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1632 _UniformRandomNumberGenerator& __urng,
1633 const param_type& __p);
1635 param_type _M_param;
1637 std::uniform_real_distribution<result_type> _M_ud;
1641 * @brief Return true if two Pareto distributions are not equal.
1643 template<typename _RealType>
1645 operator!=(const pareto_distribution<_RealType>& __d1,
1646 const pareto_distribution<_RealType>& __d2)
1647 { return !(__d1 == __d2); }
1651 * @brief A K continuous distribution for random numbers.
1653 * The formula for the K probability density function is
1655 * p(x|\lambda, \mu, \nu) = \frac{2}{x}
1656 * \left(\frac{\lambda\nu x}{\mu}\right)^{\frac{\lambda + \nu}{2}}
1657 * \frac{1}{\Gamma(\lambda)\Gamma(\nu)}
1658 * K_{\nu - \lambda}\left(2\sqrt{\frac{\lambda\nu x}{\mu}}\right)
1660 * where @f$I_0(z)@f$ is the modified Bessel function of the second kind
1661 * of order @f$\nu - \lambda@f$ and @f$\lambda > 0@f$, @f$\mu > 0@f$
1662 * and @f$\nu > 0@f$.
1664 * <table border=1 cellpadding=10 cellspacing=0>
1665 * <caption align=top>Distribution Statistics</caption>
1666 * <tr><td>Mean</td><td>@f$\mu@f$</td></tr>
1667 * <tr><td>Variance</td><td>@f$\mu^2\frac{\lambda + \nu + 1}{\lambda\nu}@f$</td></tr>
1668 * <tr><td>Range</td><td>@f$[0, \infty)@f$</td></tr>
1671 template<typename _RealType = double>
1675 static_assert(std::is_floating_point<_RealType>::value,
1676 "template argument not a floating point type");
1679 /** The type of the range of the distribution. */
1680 typedef _RealType result_type;
1682 /** Parameter type. */
1685 typedef k_distribution<result_type> distribution_type;
1687 param_type(result_type __lambda_val = result_type(1),
1688 result_type __mu_val = result_type(1),
1689 result_type __nu_val = result_type(1))
1690 : _M_lambda(__lambda_val), _M_mu(__mu_val), _M_nu(__nu_val)
1692 __glibcxx_assert(_M_lambda > result_type(0));
1693 __glibcxx_assert(_M_mu > result_type(0));
1694 __glibcxx_assert(_M_nu > result_type(0));
1699 { return _M_lambda; }
1710 operator==(const param_type& __p1, const param_type& __p2)
1712 return __p1._M_lambda == __p2._M_lambda
1713 && __p1._M_mu == __p2._M_mu
1714 && __p1._M_nu == __p2._M_nu;
1718 operator!=(const param_type& __p1, const param_type& __p2)
1719 { return !(__p1 == __p2); }
1722 void _M_initialize();
1724 result_type _M_lambda;
1730 * @brief Constructors.
1733 k_distribution(result_type __lambda_val = result_type(1),
1734 result_type __mu_val = result_type(1),
1735 result_type __nu_val = result_type(1))
1736 : _M_param(__lambda_val, __mu_val, __nu_val),
1737 _M_gd1(__lambda_val, result_type(1) / __lambda_val),
1738 _M_gd2(__nu_val, __mu_val / __nu_val)
1742 k_distribution(const param_type& __p)
1744 _M_gd1(__p.lambda(), result_type(1) / __p.lambda()),
1745 _M_gd2(__p.nu(), __p.mu() / __p.nu())
1749 * @brief Resets the distribution state.
1759 * @brief Return the parameters of the distribution.
1763 { return _M_param.lambda(); }
1767 { return _M_param.mu(); }
1771 { return _M_param.nu(); }
1774 * @brief Returns the parameter set of the distribution.
1778 { return _M_param; }
1781 * @brief Sets the parameter set of the distribution.
1782 * @param __param The new parameter set of the distribution.
1785 param(const param_type& __param)
1786 { _M_param = __param; }
1789 * @brief Returns the greatest lower bound value of the distribution.
1793 { return result_type(0); }
1796 * @brief Returns the least upper bound value of the distribution.
1800 { return std::numeric_limits<result_type>::max(); }
1803 * @brief Generating functions.
1805 template<typename _UniformRandomNumberGenerator>
1807 operator()(_UniformRandomNumberGenerator&);
1809 template<typename _UniformRandomNumberGenerator>
1811 operator()(_UniformRandomNumberGenerator&, const param_type&);
1813 template<typename _ForwardIterator,
1814 typename _UniformRandomNumberGenerator>
1816 __generate(_ForwardIterator __f, _ForwardIterator __t,
1817 _UniformRandomNumberGenerator& __urng)
1818 { this->__generate(__f, __t, __urng, _M_param); }
1820 template<typename _ForwardIterator,
1821 typename _UniformRandomNumberGenerator>
1823 __generate(_ForwardIterator __f, _ForwardIterator __t,
1824 _UniformRandomNumberGenerator& __urng,
1825 const param_type& __p)
1826 { this->__generate_impl(__f, __t, __urng, __p); }
1828 template<typename _UniformRandomNumberGenerator>
1830 __generate(result_type* __f, result_type* __t,
1831 _UniformRandomNumberGenerator& __urng,
1832 const param_type& __p)
1833 { this->__generate_impl(__f, __t, __urng, __p); }
1836 * @brief Return true if two K distributions have
1837 * the same parameters and the sequences that would
1838 * be generated are equal.
1841 operator==(const k_distribution& __d1,
1842 const k_distribution& __d2)
1843 { return (__d1._M_param == __d2._M_param
1844 && __d1._M_gd1 == __d2._M_gd1
1845 && __d1._M_gd2 == __d2._M_gd2); }
1848 * @brief Inserts a %k_distribution random number distribution
1849 * @p __x into the output stream @p __os.
1851 * @param __os An output stream.
1852 * @param __x A %k_distribution random number distribution.
1854 * @returns The output stream with the state of @p __x inserted or in
1857 template<typename _RealType1, typename _CharT, typename _Traits>
1858 friend std::basic_ostream<_CharT, _Traits>&
1859 operator<<(std::basic_ostream<_CharT, _Traits>&,
1860 const k_distribution<_RealType1>&);
1863 * @brief Extracts a %k_distribution random number distribution
1864 * @p __x from the input stream @p __is.
1866 * @param __is An input stream.
1867 * @param __x A %k_distribution random number
1870 * @returns The input stream with @p __x extracted or in an error state.
1872 template<typename _RealType1, typename _CharT, typename _Traits>
1873 friend std::basic_istream<_CharT, _Traits>&
1874 operator>>(std::basic_istream<_CharT, _Traits>&,
1875 k_distribution<_RealType1>&);
1878 template<typename _ForwardIterator,
1879 typename _UniformRandomNumberGenerator>
1881 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1882 _UniformRandomNumberGenerator& __urng,
1883 const param_type& __p);
1885 param_type _M_param;
1887 std::gamma_distribution<result_type> _M_gd1;
1888 std::gamma_distribution<result_type> _M_gd2;
1892 * @brief Return true if two K distributions are not equal.
1894 template<typename _RealType>
1896 operator!=(const k_distribution<_RealType>& __d1,
1897 const k_distribution<_RealType>& __d2)
1898 { return !(__d1 == __d2); }
1902 * @brief An arcsine continuous distribution for random numbers.
1904 * The formula for the arcsine probability density function is
1906 * p(x|a,b) = \frac{1}{\pi \sqrt{(x - a)(b - x)}}
1908 * where @f$x >= a@f$ and @f$x <= b@f$.
1910 * <table border=1 cellpadding=10 cellspacing=0>
1911 * <caption align=top>Distribution Statistics</caption>
1912 * <tr><td>Mean</td><td>@f$ (a + b) / 2 @f$</td></tr>
1913 * <tr><td>Variance</td><td>@f$ (b - a)^2 / 8 @f$</td></tr>
1914 * <tr><td>Range</td><td>@f$[a, b]@f$</td></tr>
1917 template<typename _RealType = double>
1919 arcsine_distribution
1921 static_assert(std::is_floating_point<_RealType>::value,
1922 "template argument not a floating point type");
1925 /** The type of the range of the distribution. */
1926 typedef _RealType result_type;
1928 /** Parameter type. */
1931 typedef arcsine_distribution<result_type> distribution_type;
1933 param_type(result_type __a = result_type(0),
1934 result_type __b = result_type(1))
1935 : _M_a(__a), _M_b(__b)
1937 __glibcxx_assert(_M_a <= _M_b);
1949 operator==(const param_type& __p1, const param_type& __p2)
1950 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
1953 operator!=(const param_type& __p1, const param_type& __p2)
1954 { return !(__p1 == __p2); }
1957 void _M_initialize();
1964 * @brief Constructors.
1967 arcsine_distribution(result_type __a = result_type(0),
1968 result_type __b = result_type(1))
1969 : _M_param(__a, __b),
1970 _M_ud(-1.5707963267948966192313216916397514L,
1971 +1.5707963267948966192313216916397514L)
1975 arcsine_distribution(const param_type& __p)
1977 _M_ud(-1.5707963267948966192313216916397514L,
1978 +1.5707963267948966192313216916397514L)
1982 * @brief Resets the distribution state.
1989 * @brief Return the parameters of the distribution.
1993 { return _M_param.a(); }
1997 { return _M_param.b(); }
2000 * @brief Returns the parameter set of the distribution.
2004 { return _M_param; }
2007 * @brief Sets the parameter set of the distribution.
2008 * @param __param The new parameter set of the distribution.
2011 param(const param_type& __param)
2012 { _M_param = __param; }
2015 * @brief Returns the greatest lower bound value of the distribution.
2019 { return this->a(); }
2022 * @brief Returns the least upper bound value of the distribution.
2026 { return this->b(); }
2029 * @brief Generating functions.
2031 template<typename _UniformRandomNumberGenerator>
2033 operator()(_UniformRandomNumberGenerator& __urng)
2035 result_type __x = std::sin(this->_M_ud(__urng));
2036 return (__x * (this->b() - this->a())
2037 + this->a() + this->b()) / result_type(2);
2040 template<typename _UniformRandomNumberGenerator>
2042 operator()(_UniformRandomNumberGenerator& __urng,
2043 const param_type& __p)
2045 result_type __x = std::sin(this->_M_ud(__urng));
2046 return (__x * (__p.b() - __p.a())
2047 + __p.a() + __p.b()) / result_type(2);
2050 template<typename _ForwardIterator,
2051 typename _UniformRandomNumberGenerator>
2053 __generate(_ForwardIterator __f, _ForwardIterator __t,
2054 _UniformRandomNumberGenerator& __urng)
2055 { this->__generate(__f, __t, __urng, _M_param); }
2057 template<typename _ForwardIterator,
2058 typename _UniformRandomNumberGenerator>
2060 __generate(_ForwardIterator __f, _ForwardIterator __t,
2061 _UniformRandomNumberGenerator& __urng,
2062 const param_type& __p)
2063 { this->__generate_impl(__f, __t, __urng, __p); }
2065 template<typename _UniformRandomNumberGenerator>
2067 __generate(result_type* __f, result_type* __t,
2068 _UniformRandomNumberGenerator& __urng,
2069 const param_type& __p)
2070 { this->__generate_impl(__f, __t, __urng, __p); }
2073 * @brief Return true if two arcsine distributions have
2074 * the same parameters and the sequences that would
2075 * be generated are equal.
2078 operator==(const arcsine_distribution& __d1,
2079 const arcsine_distribution& __d2)
2080 { return (__d1._M_param == __d2._M_param
2081 && __d1._M_ud == __d2._M_ud); }
2084 * @brief Inserts a %arcsine_distribution random number distribution
2085 * @p __x into the output stream @p __os.
2087 * @param __os An output stream.
2088 * @param __x A %arcsine_distribution random number distribution.
2090 * @returns The output stream with the state of @p __x inserted or in
2093 template<typename _RealType1, typename _CharT, typename _Traits>
2094 friend std::basic_ostream<_CharT, _Traits>&
2095 operator<<(std::basic_ostream<_CharT, _Traits>&,
2096 const arcsine_distribution<_RealType1>&);
2099 * @brief Extracts a %arcsine_distribution random number distribution
2100 * @p __x from the input stream @p __is.
2102 * @param __is An input stream.
2103 * @param __x A %arcsine_distribution random number
2106 * @returns The input stream with @p __x extracted or in an error state.
2108 template<typename _RealType1, typename _CharT, typename _Traits>
2109 friend std::basic_istream<_CharT, _Traits>&
2110 operator>>(std::basic_istream<_CharT, _Traits>&,
2111 arcsine_distribution<_RealType1>&);
2114 template<typename _ForwardIterator,
2115 typename _UniformRandomNumberGenerator>
2117 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2118 _UniformRandomNumberGenerator& __urng,
2119 const param_type& __p);
2121 param_type _M_param;
2123 std::uniform_real_distribution<result_type> _M_ud;
2127 * @brief Return true if two arcsine distributions are not equal.
2129 template<typename _RealType>
2131 operator!=(const arcsine_distribution<_RealType>& __d1,
2132 const arcsine_distribution<_RealType>& __d2)
2133 { return !(__d1 == __d2); }
2137 * @brief A Hoyt continuous distribution for random numbers.
2139 * The formula for the Hoyt probability density function is
2141 * p(x|q,\omega) = \frac{(1 + q^2)x}{q\omega}
2142 * \exp\left(-\frac{(1 + q^2)^2 x^2}{4 q^2 \omega}\right)
2143 * I_0\left(\frac{(1 - q^4) x^2}{4 q^2 \omega}\right)
2145 * where @f$I_0(z)@f$ is the modified Bessel function of the first kind
2146 * of order 0 and @f$0 < q < 1@f$.
2148 * <table border=1 cellpadding=10 cellspacing=0>
2149 * <caption align=top>Distribution Statistics</caption>
2150 * <tr><td>Mean</td><td>@f$ \sqrt{\frac{2}{\pi}} \sqrt{\frac{\omega}{1 + q^2}}
2151 * E(1 - q^2) @f$</td></tr>
2152 * <tr><td>Variance</td><td>@f$ \omega \left(1 - \frac{2E^2(1 - q^2)}
2153 * {\pi (1 + q^2)}\right) @f$</td></tr>
2154 * <tr><td>Range</td><td>@f$[0, \infty)@f$</td></tr>
2156 * where @f$E(x)@f$ is the elliptic function of the second kind.
2158 template<typename _RealType = double>
2162 static_assert(std::is_floating_point<_RealType>::value,
2163 "template argument not a floating point type");
2166 /** The type of the range of the distribution. */
2167 typedef _RealType result_type;
2169 /** Parameter type. */
2172 typedef hoyt_distribution<result_type> distribution_type;
2174 param_type(result_type __q = result_type(0.5L),
2175 result_type __omega = result_type(1))
2176 : _M_q(__q), _M_omega(__omega)
2178 __glibcxx_assert(_M_q > result_type(0));
2179 __glibcxx_assert(_M_q < result_type(1));
2188 { return _M_omega; }
2191 operator==(const param_type& __p1, const param_type& __p2)
2192 { return __p1._M_q == __p2._M_q && __p1._M_omega == __p2._M_omega; }
2195 operator!=(const param_type& __p1, const param_type& __p2)
2196 { return !(__p1 == __p2); }
2199 void _M_initialize();
2202 result_type _M_omega;
2206 * @brief Constructors.
2209 hoyt_distribution(result_type __q = result_type(0.5L),
2210 result_type __omega = result_type(1))
2211 : _M_param(__q, __omega),
2212 _M_ad(result_type(0.5L) * (result_type(1) + __q * __q),
2213 result_type(0.5L) * (result_type(1) + __q * __q)
2215 _M_ed(result_type(1))
2219 hoyt_distribution(const param_type& __p)
2221 _M_ad(result_type(0.5L) * (result_type(1) + __p.q() * __p.q()),
2222 result_type(0.5L) * (result_type(1) + __p.q() * __p.q())
2223 / (__p.q() * __p.q())),
2224 _M_ed(result_type(1))
2228 * @brief Resets the distribution state.
2238 * @brief Return the parameters of the distribution.
2242 { return _M_param.q(); }
2246 { return _M_param.omega(); }
2249 * @brief Returns the parameter set of the distribution.
2253 { return _M_param; }
2256 * @brief Sets the parameter set of the distribution.
2257 * @param __param The new parameter set of the distribution.
2260 param(const param_type& __param)
2261 { _M_param = __param; }
2264 * @brief Returns the greatest lower bound value of the distribution.
2268 { return result_type(0); }
2271 * @brief Returns the least upper bound value of the distribution.
2275 { return std::numeric_limits<result_type>::max(); }
2278 * @brief Generating functions.
2280 template<typename _UniformRandomNumberGenerator>
2282 operator()(_UniformRandomNumberGenerator& __urng);
2284 template<typename _UniformRandomNumberGenerator>
2286 operator()(_UniformRandomNumberGenerator& __urng,
2287 const param_type& __p);
2289 template<typename _ForwardIterator,
2290 typename _UniformRandomNumberGenerator>
2292 __generate(_ForwardIterator __f, _ForwardIterator __t,
2293 _UniformRandomNumberGenerator& __urng)
2294 { this->__generate(__f, __t, __urng, _M_param); }
2296 template<typename _ForwardIterator,
2297 typename _UniformRandomNumberGenerator>
2299 __generate(_ForwardIterator __f, _ForwardIterator __t,
2300 _UniformRandomNumberGenerator& __urng,
2301 const param_type& __p)
2302 { this->__generate_impl(__f, __t, __urng, __p); }
2304 template<typename _UniformRandomNumberGenerator>
2306 __generate(result_type* __f, result_type* __t,
2307 _UniformRandomNumberGenerator& __urng,
2308 const param_type& __p)
2309 { this->__generate_impl(__f, __t, __urng, __p); }
2312 * @brief Return true if two Hoyt distributions have
2313 * the same parameters and the sequences that would
2314 * be generated are equal.
2317 operator==(const hoyt_distribution& __d1,
2318 const hoyt_distribution& __d2)
2319 { return (__d1._M_param == __d2._M_param
2320 && __d1._M_ad == __d2._M_ad
2321 && __d1._M_ed == __d2._M_ed); }
2324 * @brief Inserts a %hoyt_distribution random number distribution
2325 * @p __x into the output stream @p __os.
2327 * @param __os An output stream.
2328 * @param __x A %hoyt_distribution random number distribution.
2330 * @returns The output stream with the state of @p __x inserted or in
2333 template<typename _RealType1, typename _CharT, typename _Traits>
2334 friend std::basic_ostream<_CharT, _Traits>&
2335 operator<<(std::basic_ostream<_CharT, _Traits>&,
2336 const hoyt_distribution<_RealType1>&);
2339 * @brief Extracts a %hoyt_distribution random number distribution
2340 * @p __x from the input stream @p __is.
2342 * @param __is An input stream.
2343 * @param __x A %hoyt_distribution random number
2346 * @returns The input stream with @p __x extracted or in an error state.
2348 template<typename _RealType1, typename _CharT, typename _Traits>
2349 friend std::basic_istream<_CharT, _Traits>&
2350 operator>>(std::basic_istream<_CharT, _Traits>&,
2351 hoyt_distribution<_RealType1>&);
2354 template<typename _ForwardIterator,
2355 typename _UniformRandomNumberGenerator>
2357 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2358 _UniformRandomNumberGenerator& __urng,
2359 const param_type& __p);
2361 param_type _M_param;
2363 __gnu_cxx::arcsine_distribution<result_type> _M_ad;
2364 std::exponential_distribution<result_type> _M_ed;
2368 * @brief Return true if two Hoyt distributions are not equal.
2370 template<typename _RealType>
2372 operator!=(const hoyt_distribution<_RealType>& __d1,
2373 const hoyt_distribution<_RealType>& __d2)
2374 { return !(__d1 == __d2); }
2378 * @brief A triangular distribution for random numbers.
2380 * The formula for the triangular probability density function is
2383 * p(x|a,b,c) = | \frac{2(x-a)}{(c-a)(b-a)} for a <= x <= b
2384 * | \frac{2(c-x)}{(c-a)(c-b)} for b < x <= c
2388 * <table border=1 cellpadding=10 cellspacing=0>
2389 * <caption align=top>Distribution Statistics</caption>
2390 * <tr><td>Mean</td><td>@f$ \frac{a+b+c}{2} @f$</td></tr>
2391 * <tr><td>Variance</td><td>@f$ \frac{a^2+b^2+c^2-ab-ac-bc}
2393 * <tr><td>Range</td><td>@f$[a, c]@f$</td></tr>
2396 template<typename _RealType = double>
2397 class triangular_distribution
2399 static_assert(std::is_floating_point<_RealType>::value,
2400 "template argument not a floating point type");
2403 /** The type of the range of the distribution. */
2404 typedef _RealType result_type;
2406 /** Parameter type. */
2409 friend class triangular_distribution<_RealType>;
2412 param_type(_RealType __a = _RealType(0),
2413 _RealType __b = _RealType(0.5),
2414 _RealType __c = _RealType(1))
2415 : _M_a(__a), _M_b(__b), _M_c(__c)
2417 __glibcxx_assert(_M_a <= _M_b);
2418 __glibcxx_assert(_M_b <= _M_c);
2419 __glibcxx_assert(_M_a < _M_c);
2421 _M_r_ab = (_M_b - _M_a) / (_M_c - _M_a);
2422 _M_f_ab_ac = (_M_b - _M_a) * (_M_c - _M_a);
2423 _M_f_bc_ac = (_M_c - _M_b) * (_M_c - _M_a);
2439 operator==(const param_type& __p1, const param_type& __p2)
2441 return (__p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b
2442 && __p1._M_c == __p2._M_c);
2446 operator!=(const param_type& __p1, const param_type& __p2)
2447 { return !(__p1 == __p2); }
2455 _RealType _M_f_ab_ac;
2456 _RealType _M_f_bc_ac;
2460 * @brief Constructs a triangle distribution with parameters
2461 * @f$ a @f$, @f$ b @f$ and @f$ c @f$.
2464 triangular_distribution(result_type __a = result_type(0),
2465 result_type __b = result_type(0.5),
2466 result_type __c = result_type(1))
2467 : _M_param(__a, __b, __c)
2471 triangular_distribution(const param_type& __p)
2476 * @brief Resets the distribution state.
2483 * @brief Returns the @f$ a @f$ of the distribution.
2487 { return _M_param.a(); }
2490 * @brief Returns the @f$ b @f$ of the distribution.
2494 { return _M_param.b(); }
2497 * @brief Returns the @f$ c @f$ of the distribution.
2501 { return _M_param.c(); }
2504 * @brief Returns the parameter set of the distribution.
2508 { return _M_param; }
2511 * @brief Sets the parameter set of the distribution.
2512 * @param __param The new parameter set of the distribution.
2515 param(const param_type& __param)
2516 { _M_param = __param; }
2519 * @brief Returns the greatest lower bound value of the distribution.
2523 { return _M_param._M_a; }
2526 * @brief Returns the least upper bound value of the distribution.
2530 { return _M_param._M_c; }
2533 * @brief Generating functions.
2535 template<typename _UniformRandomNumberGenerator>
2537 operator()(_UniformRandomNumberGenerator& __urng)
2538 { return this->operator()(__urng, _M_param); }
2540 template<typename _UniformRandomNumberGenerator>
2542 operator()(_UniformRandomNumberGenerator& __urng,
2543 const param_type& __p)
2545 std::__detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2547 result_type __rnd = __aurng();
2548 if (__rnd <= __p._M_r_ab)
2549 return __p.a() + std::sqrt(__rnd * __p._M_f_ab_ac);
2551 return __p.c() - std::sqrt((result_type(1) - __rnd)
2555 template<typename _ForwardIterator,
2556 typename _UniformRandomNumberGenerator>
2558 __generate(_ForwardIterator __f, _ForwardIterator __t,
2559 _UniformRandomNumberGenerator& __urng)
2560 { this->__generate(__f, __t, __urng, _M_param); }
2562 template<typename _ForwardIterator,
2563 typename _UniformRandomNumberGenerator>
2565 __generate(_ForwardIterator __f, _ForwardIterator __t,
2566 _UniformRandomNumberGenerator& __urng,
2567 const param_type& __p)
2568 { this->__generate_impl(__f, __t, __urng, __p); }
2570 template<typename _UniformRandomNumberGenerator>
2572 __generate(result_type* __f, result_type* __t,
2573 _UniformRandomNumberGenerator& __urng,
2574 const param_type& __p)
2575 { this->__generate_impl(__f, __t, __urng, __p); }
2578 * @brief Return true if two triangle distributions have the same
2579 * parameters and the sequences that would be generated
2583 operator==(const triangular_distribution& __d1,
2584 const triangular_distribution& __d2)
2585 { return __d1._M_param == __d2._M_param; }
2588 * @brief Inserts a %triangular_distribution random number distribution
2589 * @p __x into the output stream @p __os.
2591 * @param __os An output stream.
2592 * @param __x A %triangular_distribution random number distribution.
2594 * @returns The output stream with the state of @p __x inserted or in
2597 template<typename _RealType1, typename _CharT, typename _Traits>
2598 friend std::basic_ostream<_CharT, _Traits>&
2599 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2600 const __gnu_cxx::triangular_distribution<_RealType1>& __x);
2603 * @brief Extracts a %triangular_distribution random number distribution
2604 * @p __x from the input stream @p __is.
2606 * @param __is An input stream.
2607 * @param __x A %triangular_distribution random number generator engine.
2609 * @returns The input stream with @p __x extracted or in an error state.
2611 template<typename _RealType1, typename _CharT, typename _Traits>
2612 friend std::basic_istream<_CharT, _Traits>&
2613 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2614 __gnu_cxx::triangular_distribution<_RealType1>& __x);
2617 template<typename _ForwardIterator,
2618 typename _UniformRandomNumberGenerator>
2620 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2621 _UniformRandomNumberGenerator& __urng,
2622 const param_type& __p);
2624 param_type _M_param;
2628 * @brief Return true if two triangle distributions are different.
2630 template<typename _RealType>
2632 operator!=(const __gnu_cxx::triangular_distribution<_RealType>& __d1,
2633 const __gnu_cxx::triangular_distribution<_RealType>& __d2)
2634 { return !(__d1 == __d2); }
2638 * @brief A von Mises distribution for random numbers.
2640 * The formula for the von Mises probability density function is
2642 * p(x|\mu,\kappa) = \frac{e^{\kappa \cos(x-\mu)}}
2643 * {2\pi I_0(\kappa)}
2646 * The generating functions use the method according to:
2648 * D. J. Best and N. I. Fisher, 1979. "Efficient Simulation of the
2649 * von Mises Distribution", Journal of the Royal Statistical Society.
2650 * Series C (Applied Statistics), Vol. 28, No. 2, pp. 152-157.
2652 * <table border=1 cellpadding=10 cellspacing=0>
2653 * <caption align=top>Distribution Statistics</caption>
2654 * <tr><td>Mean</td><td>@f$ \mu @f$</td></tr>
2655 * <tr><td>Variance</td><td>@f$ 1-I_1(\kappa)/I_0(\kappa) @f$</td></tr>
2656 * <tr><td>Range</td><td>@f$[-\pi, \pi]@f$</td></tr>
2659 template<typename _RealType = double>
2660 class von_mises_distribution
2662 static_assert(std::is_floating_point<_RealType>::value,
2663 "template argument not a floating point type");
2666 /** The type of the range of the distribution. */
2667 typedef _RealType result_type;
2668 /** Parameter type. */
2671 friend class von_mises_distribution<_RealType>;
2674 param_type(_RealType __mu = _RealType(0),
2675 _RealType __kappa = _RealType(1))
2676 : _M_mu(__mu), _M_kappa(__kappa)
2678 const _RealType __pi = __gnu_cxx::__math_constants<_RealType>::__pi;
2679 __glibcxx_assert(_M_mu >= -__pi && _M_mu <= __pi);
2680 __glibcxx_assert(_M_kappa >= _RealType(0));
2682 auto __tau = std::sqrt(_RealType(4) * _M_kappa * _M_kappa
2683 + _RealType(1)) + _RealType(1);
2684 auto __rho = ((__tau - std::sqrt(_RealType(2) * __tau))
2685 / (_RealType(2) * _M_kappa));
2686 _M_r = (_RealType(1) + __rho * __rho) / (_RealType(2) * __rho);
2695 { return _M_kappa; }
2698 operator==(const param_type& __p1, const param_type& __p2)
2699 { return __p1._M_mu == __p2._M_mu && __p1._M_kappa == __p2._M_kappa; }
2702 operator!=(const param_type& __p1, const param_type& __p2)
2703 { return !(__p1 == __p2); }
2712 * @brief Constructs a von Mises distribution with parameters
2713 * @f$\mu@f$ and @f$\kappa@f$.
2716 von_mises_distribution(result_type __mu = result_type(0),
2717 result_type __kappa = result_type(1))
2718 : _M_param(__mu, __kappa)
2722 von_mises_distribution(const param_type& __p)
2727 * @brief Resets the distribution state.
2734 * @brief Returns the @f$ \mu @f$ of the distribution.
2738 { return _M_param.mu(); }
2741 * @brief Returns the @f$ \kappa @f$ of the distribution.
2745 { return _M_param.kappa(); }
2748 * @brief Returns the parameter set of the distribution.
2752 { return _M_param; }
2755 * @brief Sets the parameter set of the distribution.
2756 * @param __param The new parameter set of the distribution.
2759 param(const param_type& __param)
2760 { _M_param = __param; }
2763 * @brief Returns the greatest lower bound value of the distribution.
2768 return -__gnu_cxx::__math_constants<result_type>::__pi;
2772 * @brief Returns the least upper bound value of the distribution.
2777 return __gnu_cxx::__math_constants<result_type>::__pi;
2781 * @brief Generating functions.
2783 template<typename _UniformRandomNumberGenerator>
2785 operator()(_UniformRandomNumberGenerator& __urng)
2786 { return this->operator()(__urng, _M_param); }
2788 template<typename _UniformRandomNumberGenerator>
2790 operator()(_UniformRandomNumberGenerator& __urng,
2791 const param_type& __p);
2793 template<typename _ForwardIterator,
2794 typename _UniformRandomNumberGenerator>
2796 __generate(_ForwardIterator __f, _ForwardIterator __t,
2797 _UniformRandomNumberGenerator& __urng)
2798 { this->__generate(__f, __t, __urng, _M_param); }
2800 template<typename _ForwardIterator,
2801 typename _UniformRandomNumberGenerator>
2803 __generate(_ForwardIterator __f, _ForwardIterator __t,
2804 _UniformRandomNumberGenerator& __urng,
2805 const param_type& __p)
2806 { this->__generate_impl(__f, __t, __urng, __p); }
2808 template<typename _UniformRandomNumberGenerator>
2810 __generate(result_type* __f, result_type* __t,
2811 _UniformRandomNumberGenerator& __urng,
2812 const param_type& __p)
2813 { this->__generate_impl(__f, __t, __urng, __p); }
2816 * @brief Return true if two von Mises distributions have the same
2817 * parameters and the sequences that would be generated
2821 operator==(const von_mises_distribution& __d1,
2822 const von_mises_distribution& __d2)
2823 { return __d1._M_param == __d2._M_param; }
2826 * @brief Inserts a %von_mises_distribution random number distribution
2827 * @p __x into the output stream @p __os.
2829 * @param __os An output stream.
2830 * @param __x A %von_mises_distribution random number distribution.
2832 * @returns The output stream with the state of @p __x inserted or in
2835 template<typename _RealType1, typename _CharT, typename _Traits>
2836 friend std::basic_ostream<_CharT, _Traits>&
2837 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2838 const __gnu_cxx::von_mises_distribution<_RealType1>& __x);
2841 * @brief Extracts a %von_mises_distribution random number distribution
2842 * @p __x from the input stream @p __is.
2844 * @param __is An input stream.
2845 * @param __x A %von_mises_distribution random number generator engine.
2847 * @returns The input stream with @p __x extracted or in an error state.
2849 template<typename _RealType1, typename _CharT, typename _Traits>
2850 friend std::basic_istream<_CharT, _Traits>&
2851 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2852 __gnu_cxx::von_mises_distribution<_RealType1>& __x);
2855 template<typename _ForwardIterator,
2856 typename _UniformRandomNumberGenerator>
2858 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2859 _UniformRandomNumberGenerator& __urng,
2860 const param_type& __p);
2862 param_type _M_param;
2866 * @brief Return true if two von Mises distributions are different.
2868 template<typename _RealType>
2870 operator!=(const __gnu_cxx::von_mises_distribution<_RealType>& __d1,
2871 const __gnu_cxx::von_mises_distribution<_RealType>& __d2)
2872 { return !(__d1 == __d2); }
2876 * @brief A discrete hypergeometric random number distribution.
2878 * The hypergeometric distribution is a discrete probability distribution
2879 * that describes the probability of @p k successes in @p n draws @a without
2880 * replacement from a finite population of size @p N containing exactly @p K
2883 * The formula for the hypergeometric probability density function is
2885 * p(k|N,K,n) = \frac{\binom{K}{k} \binom{N-K}{n-k}}{\binom{N}{n}}
2887 * where @f$N@f$ is the total population of the distribution,
2888 * @f$K@f$ is the total population of the distribution.
2890 * <table border=1 cellpadding=10 cellspacing=0>
2891 * <caption align=top>Distribution Statistics</caption>
2892 * <tr><td>Mean</td><td>@f$ n\frac{K}{N} @f$</td></tr>
2893 * <tr><td>Variance</td><td>@f$ n\frac{K}{N}\frac{N-K}{N}\frac{N-n}{N-1}
2895 * <tr><td>Range</td><td>@f$[max(0, n+K-N), min(K, n)]@f$</td></tr>
2898 template<typename _UIntType = unsigned int>
2899 class hypergeometric_distribution
2901 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
2902 "substituting _UIntType not an unsigned integral type");
2905 /** The type of the range of the distribution. */
2906 typedef _UIntType result_type;
2908 /** Parameter type. */
2911 typedef hypergeometric_distribution<_UIntType> distribution_type;
2912 friend class hypergeometric_distribution<_UIntType>;
2915 param_type(result_type __N = 10, result_type __K = 5,
2916 result_type __n = 1)
2917 : _M_N{__N}, _M_K{__K}, _M_n{__n}
2919 __glibcxx_assert(_M_N >= _M_K);
2920 __glibcxx_assert(_M_N >= _M_n);
2928 successful_size() const
2932 unsuccessful_size() const
2933 { return _M_N - _M_K; }
2940 operator==(const param_type& __p1, const param_type& __p2)
2941 { return (__p1._M_N == __p2._M_N)
2942 && (__p1._M_K == __p2._M_K)
2943 && (__p1._M_n == __p2._M_n); }
2946 operator!=(const param_type& __p1, const param_type& __p2)
2947 { return !(__p1 == __p2); }
2956 // constructors and member function
2958 hypergeometric_distribution(result_type __N = 10, result_type __K = 5,
2959 result_type __n = 1)
2960 : _M_param{__N, __K, __n}
2964 hypergeometric_distribution(const param_type& __p)
2969 * @brief Resets the distribution state.
2976 * @brief Returns the distribution parameter @p N,
2977 * the total number of items.
2981 { return this->_M_param.total_size(); }
2984 * @brief Returns the distribution parameter @p K,
2985 * the total number of successful items.
2988 successful_size() const
2989 { return this->_M_param.successful_size(); }
2992 * @brief Returns the total number of unsuccessful items @f$ N - K @f$.
2995 unsuccessful_size() const
2996 { return this->_M_param.unsuccessful_size(); }
2999 * @brief Returns the distribution parameter @p n,
3000 * the total number of draws.
3004 { return this->_M_param.total_draws(); }
3007 * @brief Returns the parameter set of the distribution.
3011 { return this->_M_param; }
3014 * @brief Sets the parameter set of the distribution.
3015 * @param __param The new parameter set of the distribution.
3018 param(const param_type& __param)
3019 { this->_M_param = __param; }
3022 * @brief Returns the greatest lower bound value of the distribution.
3027 using _IntType = typename std::make_signed<result_type>::type;
3028 return static_cast<result_type>(std::max(static_cast<_IntType>(0),
3029 static_cast<_IntType>(this->total_draws()
3030 - this->unsuccessful_size())));
3034 * @brief Returns the least upper bound value of the distribution.
3038 { return std::min(this->successful_size(), this->total_draws()); }
3041 * @brief Generating functions.
3043 template<typename _UniformRandomNumberGenerator>
3045 operator()(_UniformRandomNumberGenerator& __urng)
3046 { return this->operator()(__urng, this->_M_param); }
3048 template<typename _UniformRandomNumberGenerator>
3050 operator()(_UniformRandomNumberGenerator& __urng,
3051 const param_type& __p);
3053 template<typename _ForwardIterator,
3054 typename _UniformRandomNumberGenerator>
3056 __generate(_ForwardIterator __f, _ForwardIterator __t,
3057 _UniformRandomNumberGenerator& __urng)
3058 { this->__generate(__f, __t, __urng, this->_M_param); }
3060 template<typename _ForwardIterator,
3061 typename _UniformRandomNumberGenerator>
3063 __generate(_ForwardIterator __f, _ForwardIterator __t,
3064 _UniformRandomNumberGenerator& __urng,
3065 const param_type& __p)
3066 { this->__generate_impl(__f, __t, __urng, __p); }
3068 template<typename _UniformRandomNumberGenerator>
3070 __generate(result_type* __f, result_type* __t,
3071 _UniformRandomNumberGenerator& __urng,
3072 const param_type& __p)
3073 { this->__generate_impl(__f, __t, __urng, __p); }
3076 * @brief Return true if two hypergeometric distributions have the same
3077 * parameters and the sequences that would be generated
3081 operator==(const hypergeometric_distribution& __d1,
3082 const hypergeometric_distribution& __d2)
3083 { return __d1._M_param == __d2._M_param; }
3086 * @brief Inserts a %hypergeometric_distribution random number
3087 * distribution @p __x into the output stream @p __os.
3089 * @param __os An output stream.
3090 * @param __x A %hypergeometric_distribution random number
3093 * @returns The output stream with the state of @p __x inserted or in
3096 template<typename _UIntType1, typename _CharT, typename _Traits>
3097 friend std::basic_ostream<_CharT, _Traits>&
3098 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3099 const __gnu_cxx::hypergeometric_distribution<_UIntType1>&
3103 * @brief Extracts a %hypergeometric_distribution random number
3104 * distribution @p __x from the input stream @p __is.
3106 * @param __is An input stream.
3107 * @param __x A %hypergeometric_distribution random number generator
3110 * @returns The input stream with @p __x extracted or in an error
3113 template<typename _UIntType1, typename _CharT, typename _Traits>
3114 friend std::basic_istream<_CharT, _Traits>&
3115 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3116 __gnu_cxx::hypergeometric_distribution<_UIntType1>& __x);
3120 template<typename _ForwardIterator,
3121 typename _UniformRandomNumberGenerator>
3123 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3124 _UniformRandomNumberGenerator& __urng,
3125 const param_type& __p);
3127 param_type _M_param;
3131 * @brief Return true if two hypergeometric distributions are different.
3133 template<typename _UIntType>
3135 operator!=(const __gnu_cxx::hypergeometric_distribution<_UIntType>& __d1,
3136 const __gnu_cxx::hypergeometric_distribution<_UIntType>& __d2)
3137 { return !(__d1 == __d2); }
3140 * @brief A logistic continuous distribution for random numbers.
3142 * The formula for the logistic probability density function is
3144 * p(x|\a,\b) = \frac{e^{(x - a)/b}}{b[1 + e^{(x - a)/b}]^2}
3146 * where @f$b > 0@f$.
3148 * The formula for the logistic probability function is
3150 * cdf(x|\a,\b) = \frac{e^{(x - a)/b}}{1 + e^{(x - a)/b}}
3152 * where @f$b > 0@f$.
3154 * <table border=1 cellpadding=10 cellspacing=0>
3155 * <caption align=top>Distribution Statistics</caption>
3156 * <tr><td>Mean</td><td>@f$a@f$</td></tr>
3157 * <tr><td>Variance</td><td>@f$b^2\pi^2/3@f$</td></tr>
3158 * <tr><td>Range</td><td>@f$[0, \infty)@f$</td></tr>
3161 template<typename _RealType = double>
3163 logistic_distribution
3165 static_assert(std::is_floating_point<_RealType>::value,
3166 "template argument not a floating point type");
3169 /** The type of the range of the distribution. */
3170 typedef _RealType result_type;
3172 /** Parameter type. */
3175 typedef logistic_distribution<result_type> distribution_type;
3177 param_type(result_type __a = result_type(0),
3178 result_type __b = result_type(1))
3179 : _M_a(__a), _M_b(__b)
3181 __glibcxx_assert(_M_b > result_type(0));
3193 operator==(const param_type& __p1, const param_type& __p2)
3194 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
3197 operator!=(const param_type& __p1, const param_type& __p2)
3198 { return !(__p1 == __p2); }
3201 void _M_initialize();
3208 * @brief Constructors.
3211 logistic_distribution(result_type __a = result_type(0),
3212 result_type __b = result_type(1))
3213 : _M_param(__a, __b)
3217 logistic_distribution(const param_type& __p)
3222 * @brief Resets the distribution state.
3229 * @brief Return the parameters of the distribution.
3233 { return _M_param.a(); }
3237 { return _M_param.b(); }
3240 * @brief Returns the parameter set of the distribution.
3244 { return _M_param; }
3247 * @brief Sets the parameter set of the distribution.
3248 * @param __param The new parameter set of the distribution.
3251 param(const param_type& __param)
3252 { _M_param = __param; }
3255 * @brief Returns the greatest lower bound value of the distribution.
3259 { return -std::numeric_limits<result_type>::max(); }
3262 * @brief Returns the least upper bound value of the distribution.
3266 { return std::numeric_limits<result_type>::max(); }
3269 * @brief Generating functions.
3271 template<typename _UniformRandomNumberGenerator>
3273 operator()(_UniformRandomNumberGenerator& __urng)
3274 { return this->operator()(__urng, this->_M_param); }
3276 template<typename _UniformRandomNumberGenerator>
3278 operator()(_UniformRandomNumberGenerator&,
3281 template<typename _ForwardIterator,
3282 typename _UniformRandomNumberGenerator>
3284 __generate(_ForwardIterator __f, _ForwardIterator __t,
3285 _UniformRandomNumberGenerator& __urng)
3286 { this->__generate(__f, __t, __urng, this->param()); }
3288 template<typename _ForwardIterator,
3289 typename _UniformRandomNumberGenerator>
3291 __generate(_ForwardIterator __f, _ForwardIterator __t,
3292 _UniformRandomNumberGenerator& __urng,
3293 const param_type& __p)
3294 { this->__generate_impl(__f, __t, __urng, __p); }
3296 template<typename _UniformRandomNumberGenerator>
3298 __generate(result_type* __f, result_type* __t,
3299 _UniformRandomNumberGenerator& __urng,
3300 const param_type& __p)
3301 { this->__generate_impl(__f, __t, __urng, __p); }
3304 * @brief Return true if two logistic distributions have
3305 * the same parameters and the sequences that would
3306 * be generated are equal.
3308 template<typename _RealType1>
3310 operator==(const logistic_distribution<_RealType1>& __d1,
3311 const logistic_distribution<_RealType1>& __d2)
3312 { return __d1.param() == __d2.param(); }
3315 * @brief Inserts a %logistic_distribution random number distribution
3316 * @p __x into the output stream @p __os.
3318 * @param __os An output stream.
3319 * @param __x A %logistic_distribution random number distribution.
3321 * @returns The output stream with the state of @p __x inserted or in
3324 template<typename _RealType1, typename _CharT, typename _Traits>
3325 friend std::basic_ostream<_CharT, _Traits>&
3326 operator<<(std::basic_ostream<_CharT, _Traits>&,
3327 const logistic_distribution<_RealType1>&);
3330 * @brief Extracts a %logistic_distribution random number distribution
3331 * @p __x from the input stream @p __is.
3333 * @param __is An input stream.
3334 * @param __x A %logistic_distribution random number
3337 * @returns The input stream with @p __x extracted or in an error state.
3339 template<typename _RealType1, typename _CharT, typename _Traits>
3340 friend std::basic_istream<_CharT, _Traits>&
3341 operator>>(std::basic_istream<_CharT, _Traits>&,
3342 logistic_distribution<_RealType1>&);
3345 template<typename _ForwardIterator,
3346 typename _UniformRandomNumberGenerator>
3348 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3349 _UniformRandomNumberGenerator& __urng,
3350 const param_type& __p);
3352 param_type _M_param;
3356 * @brief Return true if two logistic distributions are not equal.
3358 template<typename _RealType1>
3360 operator!=(const logistic_distribution<_RealType1>& __d1,
3361 const logistic_distribution<_RealType1>& __d2)
3362 { return !(__d1 == __d2); }
3366 * @brief A distribution for random coordinates on a unit sphere.
3368 * The method used in the generation function is attributed by Donald Knuth
3369 * to G. W. Brown, Modern Mathematics for the Engineer (1956).
3371 template<std::size_t _Dimen, typename _RealType = double>
3372 class uniform_on_sphere_distribution
3374 static_assert(std::is_floating_point<_RealType>::value,
3375 "template argument not a floating point type");
3376 static_assert(_Dimen != 0, "dimension is zero");
3379 /** The type of the range of the distribution. */
3380 typedef std::array<_RealType, _Dimen> result_type;
3382 /** Parameter type. */
3390 operator==(const param_type&, const param_type&)
3394 operator!=(const param_type&, const param_type&)
3399 * @brief Constructs a uniform on sphere distribution.
3402 uniform_on_sphere_distribution()
3403 : _M_param(), _M_nd()
3407 uniform_on_sphere_distribution(const param_type& __p)
3408 : _M_param(__p), _M_nd()
3412 * @brief Resets the distribution state.
3419 * @brief Returns the parameter set of the distribution.
3423 { return _M_param; }
3426 * @brief Sets the parameter set of the distribution.
3427 * @param __param The new parameter set of the distribution.
3430 param(const param_type& __param)
3431 { _M_param = __param; }
3434 * @brief Returns the greatest lower bound value of the distribution.
3435 * This function makes no sense for this distribution.
3446 * @brief Returns the least upper bound value of the distribution.
3447 * This function makes no sense for this distribution.
3458 * @brief Generating functions.
3460 template<typename _UniformRandomNumberGenerator>
3462 operator()(_UniformRandomNumberGenerator& __urng)
3463 { return this->operator()(__urng, _M_param); }
3465 template<typename _UniformRandomNumberGenerator>
3467 operator()(_UniformRandomNumberGenerator& __urng,
3468 const param_type& __p);
3470 template<typename _ForwardIterator,
3471 typename _UniformRandomNumberGenerator>
3473 __generate(_ForwardIterator __f, _ForwardIterator __t,
3474 _UniformRandomNumberGenerator& __urng)
3475 { this->__generate(__f, __t, __urng, this->param()); }
3477 template<typename _ForwardIterator,
3478 typename _UniformRandomNumberGenerator>
3480 __generate(_ForwardIterator __f, _ForwardIterator __t,
3481 _UniformRandomNumberGenerator& __urng,
3482 const param_type& __p)
3483 { this->__generate_impl(__f, __t, __urng, __p); }
3485 template<typename _UniformRandomNumberGenerator>
3487 __generate(result_type* __f, result_type* __t,
3488 _UniformRandomNumberGenerator& __urng,
3489 const param_type& __p)
3490 { this->__generate_impl(__f, __t, __urng, __p); }
3493 * @brief Return true if two uniform on sphere distributions have
3494 * the same parameters and the sequences that would be
3495 * generated are equal.
3498 operator==(const uniform_on_sphere_distribution& __d1,
3499 const uniform_on_sphere_distribution& __d2)
3500 { return __d1._M_nd == __d2._M_nd; }
3503 * @brief Inserts a %uniform_on_sphere_distribution random number
3504 * distribution @p __x into the output stream @p __os.
3506 * @param __os An output stream.
3507 * @param __x A %uniform_on_sphere_distribution random number
3510 * @returns The output stream with the state of @p __x inserted or in
3513 template<size_t _Dimen1, typename _RealType1, typename _CharT,
3515 friend std::basic_ostream<_CharT, _Traits>&
3516 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3517 const __gnu_cxx::uniform_on_sphere_distribution<_Dimen1,
3522 * @brief Extracts a %uniform_on_sphere_distribution random number
3524 * @p __x from the input stream @p __is.
3526 * @param __is An input stream.
3527 * @param __x A %uniform_on_sphere_distribution random number
3530 * @returns The input stream with @p __x extracted or in an error state.
3532 template<std::size_t _Dimen1, typename _RealType1, typename _CharT,
3534 friend std::basic_istream<_CharT, _Traits>&
3535 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3536 __gnu_cxx::uniform_on_sphere_distribution<_Dimen1,
3540 template<typename _ForwardIterator,
3541 typename _UniformRandomNumberGenerator>
3543 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3544 _UniformRandomNumberGenerator& __urng,
3545 const param_type& __p);
3547 param_type _M_param;
3548 std::normal_distribution<_RealType> _M_nd;
3552 * @brief Return true if two uniform on sphere distributions are different.
3554 template<std::size_t _Dimen, typename _RealType>
3556 operator!=(const __gnu_cxx::uniform_on_sphere_distribution<_Dimen,
3558 const __gnu_cxx::uniform_on_sphere_distribution<_Dimen,
3560 { return !(__d1 == __d2); }
3564 * @brief A distribution for random coordinates inside a unit sphere.
3566 template<std::size_t _Dimen, typename _RealType = double>
3567 class uniform_inside_sphere_distribution
3569 static_assert(std::is_floating_point<_RealType>::value,
3570 "template argument not a floating point type");
3571 static_assert(_Dimen != 0, "dimension is zero");
3574 /** The type of the range of the distribution. */
3575 using result_type = std::array<_RealType, _Dimen>;
3577 /** Parameter type. */
3580 using distribution_type
3581 = uniform_inside_sphere_distribution<_Dimen, _RealType>;
3582 friend class uniform_inside_sphere_distribution<_Dimen, _RealType>;
3585 param_type(_RealType __radius = _RealType(1))
3586 : _M_radius(__radius)
3588 __glibcxx_assert(_M_radius > _RealType(0));
3593 { return _M_radius; }
3596 operator==(const param_type& __p1, const param_type& __p2)
3597 { return __p1._M_radius == __p2._M_radius; }
3600 operator!=(const param_type& __p1, const param_type& __p2)
3601 { return !(__p1 == __p2); }
3604 _RealType _M_radius;
3608 * @brief Constructors.
3611 uniform_inside_sphere_distribution(_RealType __radius = _RealType(1))
3612 : _M_param(__radius), _M_uosd()
3616 uniform_inside_sphere_distribution(const param_type& __p)
3617 : _M_param(__p), _M_uosd()
3621 * @brief Resets the distribution state.
3625 { _M_uosd.reset(); }
3628 * @brief Returns the @f$radius@f$ of the distribution.
3632 { return _M_param.radius(); }
3635 * @brief Returns the parameter set of the distribution.
3639 { return _M_param; }
3642 * @brief Sets the parameter set of the distribution.
3643 * @param __param The new parameter set of the distribution.
3646 param(const param_type& __param)
3647 { _M_param = __param; }
3650 * @brief Returns the greatest lower bound value of the distribution.
3651 * This function makes no sense for this distribution.
3662 * @brief Returns the least upper bound value of the distribution.
3663 * This function makes no sense for this distribution.
3674 * @brief Generating functions.
3676 template<typename _UniformRandomNumberGenerator>
3678 operator()(_UniformRandomNumberGenerator& __urng)
3679 { return this->operator()(__urng, _M_param); }
3681 template<typename _UniformRandomNumberGenerator>
3683 operator()(_UniformRandomNumberGenerator& __urng,
3684 const param_type& __p);
3686 template<typename _ForwardIterator,
3687 typename _UniformRandomNumberGenerator>
3689 __generate(_ForwardIterator __f, _ForwardIterator __t,
3690 _UniformRandomNumberGenerator& __urng)
3691 { this->__generate(__f, __t, __urng, this->param()); }
3693 template<typename _ForwardIterator,
3694 typename _UniformRandomNumberGenerator>
3696 __generate(_ForwardIterator __f, _ForwardIterator __t,
3697 _UniformRandomNumberGenerator& __urng,
3698 const param_type& __p)
3699 { this->__generate_impl(__f, __t, __urng, __p); }
3701 template<typename _UniformRandomNumberGenerator>
3703 __generate(result_type* __f, result_type* __t,
3704 _UniformRandomNumberGenerator& __urng,
3705 const param_type& __p)
3706 { this->__generate_impl(__f, __t, __urng, __p); }
3709 * @brief Return true if two uniform on sphere distributions have
3710 * the same parameters and the sequences that would be
3711 * generated are equal.
3714 operator==(const uniform_inside_sphere_distribution& __d1,
3715 const uniform_inside_sphere_distribution& __d2)
3716 { return __d1._M_param == __d2._M_param && __d1._M_uosd == __d2._M_uosd; }
3719 * @brief Inserts a %uniform_inside_sphere_distribution random number
3720 * distribution @p __x into the output stream @p __os.
3722 * @param __os An output stream.
3723 * @param __x A %uniform_inside_sphere_distribution random number
3726 * @returns The output stream with the state of @p __x inserted or in
3729 template<size_t _Dimen1, typename _RealType1, typename _CharT,
3731 friend std::basic_ostream<_CharT, _Traits>&
3732 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3733 const __gnu_cxx::uniform_inside_sphere_distribution<_Dimen1,
3738 * @brief Extracts a %uniform_inside_sphere_distribution random number
3740 * @p __x from the input stream @p __is.
3742 * @param __is An input stream.
3743 * @param __x A %uniform_inside_sphere_distribution random number
3746 * @returns The input stream with @p __x extracted or in an error state.
3748 template<std::size_t _Dimen1, typename _RealType1, typename _CharT,
3750 friend std::basic_istream<_CharT, _Traits>&
3751 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3752 __gnu_cxx::uniform_inside_sphere_distribution<_Dimen1,
3756 template<typename _ForwardIterator,
3757 typename _UniformRandomNumberGenerator>
3759 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3760 _UniformRandomNumberGenerator& __urng,
3761 const param_type& __p);
3763 param_type _M_param;
3764 uniform_on_sphere_distribution<_Dimen, _RealType> _M_uosd;
3768 * @brief Return true if two uniform on sphere distributions are different.
3770 template<std::size_t _Dimen, typename _RealType>
3772 operator!=(const __gnu_cxx::uniform_inside_sphere_distribution<_Dimen,
3774 const __gnu_cxx::uniform_inside_sphere_distribution<_Dimen,
3776 { return !(__d1 == __d2); }
3778 _GLIBCXX_END_NAMESPACE_VERSION
3779 } // namespace __gnu_cxx
3781 #include "ext/opt_random.h"
3782 #include "random.tcc"
3784 #endif // _GLIBCXX_USE_C99_STDINT_TR1 && UINT32_C
3788 #endif // _EXT_RANDOM