1 // Random number extensions -*- C++ -*-
3 // Copyright (C) 2012-2022 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");
88 template<typename _Sseq>
90 = typename std::enable_if<std::__detail::__is_seed_seq<
91 _Sseq, simd_fast_mersenne_twister_engine, result_type>::value
95 static constexpr size_t state_size = _M_nstate * (16
96 / sizeof(result_type));
97 static constexpr result_type default_seed = 5489u;
99 // constructors and member functions
101 simd_fast_mersenne_twister_engine()
102 : simd_fast_mersenne_twister_engine(default_seed)
106 simd_fast_mersenne_twister_engine(result_type __sd)
109 template<typename _Sseq, typename = _If_seed_seq<_Sseq>>
111 simd_fast_mersenne_twister_engine(_Sseq& __q)
115 seed(result_type __sd = default_seed);
117 template<typename _Sseq>
121 static constexpr result_type
125 static constexpr result_type
127 { return std::numeric_limits<result_type>::max(); }
130 discard(unsigned long long __z);
135 if (__builtin_expect(_M_pos >= state_size, 0))
138 return _M_stateT[_M_pos++];
141 template<typename _UIntType_2, size_t __m_2,
142 size_t __pos1_2, size_t __sl1_2, size_t __sl2_2,
143 size_t __sr1_2, size_t __sr2_2,
144 uint32_t __msk1_2, uint32_t __msk2_2,
145 uint32_t __msk3_2, uint32_t __msk4_2,
146 uint32_t __parity1_2, uint32_t __parity2_2,
147 uint32_t __parity3_2, uint32_t __parity4_2>
149 operator==(const simd_fast_mersenne_twister_engine<_UIntType_2,
150 __m_2, __pos1_2, __sl1_2, __sl2_2, __sr1_2, __sr2_2,
151 __msk1_2, __msk2_2, __msk3_2, __msk4_2,
152 __parity1_2, __parity2_2, __parity3_2, __parity4_2>& __lhs,
153 const simd_fast_mersenne_twister_engine<_UIntType_2,
154 __m_2, __pos1_2, __sl1_2, __sl2_2, __sr1_2, __sr2_2,
155 __msk1_2, __msk2_2, __msk3_2, __msk4_2,
156 __parity1_2, __parity2_2, __parity3_2, __parity4_2>& __rhs);
158 template<typename _UIntType_2, size_t __m_2,
159 size_t __pos1_2, size_t __sl1_2, size_t __sl2_2,
160 size_t __sr1_2, size_t __sr2_2,
161 uint32_t __msk1_2, uint32_t __msk2_2,
162 uint32_t __msk3_2, uint32_t __msk4_2,
163 uint32_t __parity1_2, uint32_t __parity2_2,
164 uint32_t __parity3_2, uint32_t __parity4_2,
165 typename _CharT, typename _Traits>
166 friend std::basic_ostream<_CharT, _Traits>&
167 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
168 const __gnu_cxx::simd_fast_mersenne_twister_engine
170 __m_2, __pos1_2, __sl1_2, __sl2_2, __sr1_2, __sr2_2,
171 __msk1_2, __msk2_2, __msk3_2, __msk4_2,
172 __parity1_2, __parity2_2, __parity3_2, __parity4_2>& __x);
174 template<typename _UIntType_2, size_t __m_2,
175 size_t __pos1_2, size_t __sl1_2, size_t __sl2_2,
176 size_t __sr1_2, size_t __sr2_2,
177 uint32_t __msk1_2, uint32_t __msk2_2,
178 uint32_t __msk3_2, uint32_t __msk4_2,
179 uint32_t __parity1_2, uint32_t __parity2_2,
180 uint32_t __parity3_2, uint32_t __parity4_2,
181 typename _CharT, typename _Traits>
182 friend std::basic_istream<_CharT, _Traits>&
183 operator>>(std::basic_istream<_CharT, _Traits>& __is,
184 __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType_2,
185 __m_2, __pos1_2, __sl1_2, __sl2_2, __sr1_2, __sr2_2,
186 __msk1_2, __msk2_2, __msk3_2, __msk4_2,
187 __parity1_2, __parity2_2, __parity3_2, __parity4_2>& __x);
193 __m128i _M_state[_M_nstate];
197 __Uint32x4_t _M_state[_M_nstate];
200 uint32_t _M_state32[_M_nstate32];
201 result_type _M_stateT[state_size];
202 } __attribute__ ((__aligned__ (16)));
205 void _M_gen_rand(void);
206 void _M_period_certification();
210 template<typename _UIntType, size_t __m,
211 size_t __pos1, size_t __sl1, size_t __sl2,
212 size_t __sr1, size_t __sr2,
213 uint32_t __msk1, uint32_t __msk2,
214 uint32_t __msk3, uint32_t __msk4,
215 uint32_t __parity1, uint32_t __parity2,
216 uint32_t __parity3, uint32_t __parity4>
218 operator!=(const __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType,
219 __m, __pos1, __sl1, __sl2, __sr1, __sr2, __msk1, __msk2, __msk3,
220 __msk4, __parity1, __parity2, __parity3, __parity4>& __lhs,
221 const __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType,
222 __m, __pos1, __sl1, __sl2, __sr1, __sr2, __msk1, __msk2, __msk3,
223 __msk4, __parity1, __parity2, __parity3, __parity4>& __rhs)
224 { return !(__lhs == __rhs); }
227 /* Definitions for the SIMD-oriented Fast Mersenne Twister as defined
228 * in the C implementation by Daito and Matsumoto, as both a 32-bit
229 * and 64-bit version.
231 typedef simd_fast_mersenne_twister_engine<uint32_t, 607, 2,
233 0xfdff37ffU, 0xef7f3f7dU,
234 0xff777b7dU, 0x7ff7fb2fU,
235 0x00000001U, 0x00000000U,
236 0x00000000U, 0x5986f054U>
239 typedef simd_fast_mersenne_twister_engine<uint64_t, 607, 2,
241 0xfdff37ffU, 0xef7f3f7dU,
242 0xff777b7dU, 0x7ff7fb2fU,
243 0x00000001U, 0x00000000U,
244 0x00000000U, 0x5986f054U>
248 typedef simd_fast_mersenne_twister_engine<uint32_t, 1279, 7,
250 0xf7fefffdU, 0x7fefcfffU,
251 0xaff3ef3fU, 0xb5ffff7fU,
252 0x00000001U, 0x00000000U,
253 0x00000000U, 0x20000000U>
256 typedef simd_fast_mersenne_twister_engine<uint64_t, 1279, 7,
258 0xf7fefffdU, 0x7fefcfffU,
259 0xaff3ef3fU, 0xb5ffff7fU,
260 0x00000001U, 0x00000000U,
261 0x00000000U, 0x20000000U>
265 typedef simd_fast_mersenne_twister_engine<uint32_t, 2281, 12,
267 0xbff7ffbfU, 0xfdfffffeU,
268 0xf7ffef7fU, 0xf2f7cbbfU,
269 0x00000001U, 0x00000000U,
270 0x00000000U, 0x41dfa600U>
273 typedef simd_fast_mersenne_twister_engine<uint64_t, 2281, 12,
275 0xbff7ffbfU, 0xfdfffffeU,
276 0xf7ffef7fU, 0xf2f7cbbfU,
277 0x00000001U, 0x00000000U,
278 0x00000000U, 0x41dfa600U>
282 typedef simd_fast_mersenne_twister_engine<uint32_t, 4253, 17,
284 0x9f7bffffU, 0x9fffff5fU,
285 0x3efffffbU, 0xfffff7bbU,
286 0xa8000001U, 0xaf5390a3U,
287 0xb740b3f8U, 0x6c11486dU>
290 typedef simd_fast_mersenne_twister_engine<uint64_t, 4253, 17,
292 0x9f7bffffU, 0x9fffff5fU,
293 0x3efffffbU, 0xfffff7bbU,
294 0xa8000001U, 0xaf5390a3U,
295 0xb740b3f8U, 0x6c11486dU>
299 typedef simd_fast_mersenne_twister_engine<uint32_t, 11213, 68,
301 0xeffff7fbU, 0xffffffefU,
302 0xdfdfbfffU, 0x7fffdbfdU,
303 0x00000001U, 0x00000000U,
304 0xe8148000U, 0xd0c7afa3U>
307 typedef simd_fast_mersenne_twister_engine<uint64_t, 11213, 68,
309 0xeffff7fbU, 0xffffffefU,
310 0xdfdfbfffU, 0x7fffdbfdU,
311 0x00000001U, 0x00000000U,
312 0xe8148000U, 0xd0c7afa3U>
316 typedef simd_fast_mersenne_twister_engine<uint32_t, 19937, 122,
318 0xdfffffefU, 0xddfecb7fU,
319 0xbffaffffU, 0xbffffff6U,
320 0x00000001U, 0x00000000U,
321 0x00000000U, 0x13c9e684U>
324 typedef simd_fast_mersenne_twister_engine<uint64_t, 19937, 122,
326 0xdfffffefU, 0xddfecb7fU,
327 0xbffaffffU, 0xbffffff6U,
328 0x00000001U, 0x00000000U,
329 0x00000000U, 0x13c9e684U>
333 typedef simd_fast_mersenne_twister_engine<uint32_t, 44497, 330,
335 0xeffffffbU, 0xdfbebfffU,
336 0xbfbf7befU, 0x9ffd7bffU,
337 0x00000001U, 0x00000000U,
338 0xa3ac4000U, 0xecc1327aU>
341 typedef simd_fast_mersenne_twister_engine<uint64_t, 44497, 330,
343 0xeffffffbU, 0xdfbebfffU,
344 0xbfbf7befU, 0x9ffd7bffU,
345 0x00000001U, 0x00000000U,
346 0xa3ac4000U, 0xecc1327aU>
350 typedef simd_fast_mersenne_twister_engine<uint32_t, 86243, 366,
352 0xfdbffbffU, 0xbff7ff3fU,
353 0xfd77efffU, 0xbf9ff3ffU,
354 0x00000001U, 0x00000000U,
355 0x00000000U, 0xe9528d85U>
358 typedef simd_fast_mersenne_twister_engine<uint64_t, 86243, 366,
360 0xfdbffbffU, 0xbff7ff3fU,
361 0xfd77efffU, 0xbf9ff3ffU,
362 0x00000001U, 0x00000000U,
363 0x00000000U, 0xe9528d85U>
367 typedef simd_fast_mersenne_twister_engine<uint32_t, 132049, 110,
369 0xffffbb5fU, 0xfb6ebf95U,
370 0xfffefffaU, 0xcff77fffU,
371 0x00000001U, 0x00000000U,
372 0xcb520000U, 0xc7e91c7dU>
375 typedef simd_fast_mersenne_twister_engine<uint64_t, 132049, 110,
377 0xffffbb5fU, 0xfb6ebf95U,
378 0xfffefffaU, 0xcff77fffU,
379 0x00000001U, 0x00000000U,
380 0xcb520000U, 0xc7e91c7dU>
384 typedef simd_fast_mersenne_twister_engine<uint32_t, 216091, 627,
386 0xbff7bff7U, 0xbfffffffU,
387 0xbffffa7fU, 0xffddfbfbU,
388 0xf8000001U, 0x89e80709U,
389 0x3bd2b64bU, 0x0c64b1e4U>
392 typedef simd_fast_mersenne_twister_engine<uint64_t, 216091, 627,
394 0xbff7bff7U, 0xbfffffffU,
395 0xbffffa7fU, 0xffddfbfbU,
396 0xf8000001U, 0x89e80709U,
397 0x3bd2b64bU, 0x0c64b1e4U>
400 #endif // __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
403 * @brief A beta continuous distribution for random numbers.
405 * The formula for the beta probability density function is:
407 * p(x|\alpha,\beta) = \frac{1}{B(\alpha,\beta)}
408 * x^{\alpha - 1} (1 - x)^{\beta - 1}
411 template<typename _RealType = double>
412 class beta_distribution
414 static_assert(std::is_floating_point<_RealType>::value,
415 "template argument not a floating point type");
418 /** The type of the range of the distribution. */
419 typedef _RealType result_type;
421 /** Parameter type. */
424 typedef beta_distribution<_RealType> distribution_type;
425 friend class beta_distribution<_RealType>;
427 param_type() : param_type(1) { }
430 param_type(_RealType __alpha_val, _RealType __beta_val = _RealType(1))
431 : _M_alpha(__alpha_val), _M_beta(__beta_val)
433 __glibcxx_assert(_M_alpha > _RealType(0));
434 __glibcxx_assert(_M_beta > _RealType(0));
446 operator==(const param_type& __p1, const param_type& __p2)
447 { return (__p1._M_alpha == __p2._M_alpha
448 && __p1._M_beta == __p2._M_beta); }
451 operator!=(const param_type& __p1, const param_type& __p2)
452 { return !(__p1 == __p2); }
463 beta_distribution() : beta_distribution(1.0) { }
466 * @brief Constructs a beta distribution with parameters
467 * @f$\alpha@f$ and @f$\beta@f$.
470 beta_distribution(_RealType __alpha_val,
471 _RealType __beta_val = _RealType(1))
472 : _M_param(__alpha_val, __beta_val)
476 beta_distribution(const param_type& __p)
481 * @brief Resets the distribution state.
488 * @brief Returns the @f$\alpha@f$ of the distribution.
492 { return _M_param.alpha(); }
495 * @brief Returns the @f$\beta@f$ of the distribution.
499 { return _M_param.beta(); }
502 * @brief Returns the parameter set of the distribution.
509 * @brief Sets the parameter set of the distribution.
510 * @param __param The new parameter set of the distribution.
513 param(const param_type& __param)
514 { _M_param = __param; }
517 * @brief Returns the greatest lower bound value of the distribution.
521 { return result_type(0); }
524 * @brief Returns the least upper bound value of the distribution.
528 { return result_type(1); }
531 * @brief Generating functions.
533 template<typename _UniformRandomNumberGenerator>
535 operator()(_UniformRandomNumberGenerator& __urng)
536 { return this->operator()(__urng, _M_param); }
538 template<typename _UniformRandomNumberGenerator>
540 operator()(_UniformRandomNumberGenerator& __urng,
541 const param_type& __p);
543 template<typename _ForwardIterator,
544 typename _UniformRandomNumberGenerator>
546 __generate(_ForwardIterator __f, _ForwardIterator __t,
547 _UniformRandomNumberGenerator& __urng)
548 { this->__generate(__f, __t, __urng, _M_param); }
550 template<typename _ForwardIterator,
551 typename _UniformRandomNumberGenerator>
553 __generate(_ForwardIterator __f, _ForwardIterator __t,
554 _UniformRandomNumberGenerator& __urng,
555 const param_type& __p)
556 { this->__generate_impl(__f, __t, __urng, __p); }
558 template<typename _UniformRandomNumberGenerator>
560 __generate(result_type* __f, result_type* __t,
561 _UniformRandomNumberGenerator& __urng,
562 const param_type& __p)
563 { this->__generate_impl(__f, __t, __urng, __p); }
566 * @brief Return true if two beta distributions have the same
567 * parameters and the sequences that would be generated
571 operator==(const beta_distribution& __d1,
572 const beta_distribution& __d2)
573 { return __d1._M_param == __d2._M_param; }
576 * @brief Inserts a %beta_distribution random number distribution
577 * @p __x into the output stream @p __os.
579 * @param __os An output stream.
580 * @param __x A %beta_distribution random number distribution.
582 * @returns The output stream with the state of @p __x inserted or in
585 template<typename _RealType1, typename _CharT, typename _Traits>
586 friend std::basic_ostream<_CharT, _Traits>&
587 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
588 const __gnu_cxx::beta_distribution<_RealType1>& __x);
591 * @brief Extracts a %beta_distribution random number distribution
592 * @p __x from the input stream @p __is.
594 * @param __is An input stream.
595 * @param __x A %beta_distribution random number generator engine.
597 * @returns The input stream with @p __x extracted or in an error state.
599 template<typename _RealType1, typename _CharT, typename _Traits>
600 friend std::basic_istream<_CharT, _Traits>&
601 operator>>(std::basic_istream<_CharT, _Traits>& __is,
602 __gnu_cxx::beta_distribution<_RealType1>& __x);
605 template<typename _ForwardIterator,
606 typename _UniformRandomNumberGenerator>
608 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
609 _UniformRandomNumberGenerator& __urng,
610 const param_type& __p);
616 * @brief Return true if two beta distributions are different.
618 template<typename _RealType>
620 operator!=(const __gnu_cxx::beta_distribution<_RealType>& __d1,
621 const __gnu_cxx::beta_distribution<_RealType>& __d2)
622 { return !(__d1 == __d2); }
626 * @brief A multi-variate normal continuous distribution for random numbers.
628 * The formula for the normal probability density function is
630 * p(\overrightarrow{x}|\overrightarrow{\mu },\Sigma) =
631 * \frac{1}{\sqrt{(2\pi )^k\det(\Sigma))}}
632 * e^{-\frac{1}{2}(\overrightarrow{x}-\overrightarrow{\mu})^\text{T}
633 * \Sigma ^{-1}(\overrightarrow{x}-\overrightarrow{\mu})}
636 * where @f$\overrightarrow{x}@f$ and @f$\overrightarrow{\mu}@f$ are
637 * vectors of dimension @f$k@f$ and @f$\Sigma@f$ is the covariance
638 * matrix (which must be positive-definite).
640 template<std::size_t _Dimen, typename _RealType = double>
641 class normal_mv_distribution
643 static_assert(std::is_floating_point<_RealType>::value,
644 "template argument not a floating point type");
645 static_assert(_Dimen != 0, "dimension is zero");
648 /** The type of the range of the distribution. */
649 typedef std::array<_RealType, _Dimen> result_type;
650 /** Parameter type. */
653 static constexpr size_t _M_t_size = _Dimen * (_Dimen + 1) / 2;
656 typedef normal_mv_distribution<_Dimen, _RealType> distribution_type;
657 friend class normal_mv_distribution<_Dimen, _RealType>;
661 std::fill(_M_mean.begin(), _M_mean.end(), _RealType(0));
662 auto __it = _M_t.begin();
663 for (size_t __i = 0; __i < _Dimen; ++__i)
665 std::fill_n(__it, __i, _RealType(0));
667 *__it++ = _RealType(1);
671 template<typename _ForwardIterator1, typename _ForwardIterator2>
672 param_type(_ForwardIterator1 __meanbegin,
673 _ForwardIterator1 __meanend,
674 _ForwardIterator2 __varcovbegin,
675 _ForwardIterator2 __varcovend)
677 __glibcxx_function_requires(_ForwardIteratorConcept<
679 __glibcxx_function_requires(_ForwardIteratorConcept<
681 _GLIBCXX_DEBUG_ASSERT(std::distance(__meanbegin, __meanend)
683 const auto __dist = std::distance(__varcovbegin, __varcovend);
684 _GLIBCXX_DEBUG_ASSERT(__dist == _Dimen * _Dimen
685 || __dist == _Dimen * (_Dimen + 1) / 2
686 || __dist == _Dimen);
688 if (__dist == _Dimen * _Dimen)
689 _M_init_full(__meanbegin, __meanend, __varcovbegin, __varcovend);
690 else if (__dist == _Dimen * (_Dimen + 1) / 2)
691 _M_init_lower(__meanbegin, __meanend, __varcovbegin, __varcovend);
694 __glibcxx_assert(__dist == _Dimen);
695 _M_init_diagonal(__meanbegin, __meanend,
696 __varcovbegin, __varcovend);
700 param_type(std::initializer_list<_RealType> __mean,
701 std::initializer_list<_RealType> __varcov)
703 _GLIBCXX_DEBUG_ASSERT(__mean.size() <= _Dimen);
704 _GLIBCXX_DEBUG_ASSERT(__varcov.size() == _Dimen * _Dimen
705 || __varcov.size() == _Dimen * (_Dimen + 1) / 2
706 || __varcov.size() == _Dimen);
708 if (__varcov.size() == _Dimen * _Dimen)
709 _M_init_full(__mean.begin(), __mean.end(),
710 __varcov.begin(), __varcov.end());
711 else if (__varcov.size() == _Dimen * (_Dimen + 1) / 2)
712 _M_init_lower(__mean.begin(), __mean.end(),
713 __varcov.begin(), __varcov.end());
716 __glibcxx_assert(__varcov.size() == _Dimen);
717 _M_init_diagonal(__mean.begin(), __mean.end(),
718 __varcov.begin(), __varcov.end());
722 std::array<_RealType, _Dimen>
726 std::array<_RealType, _M_t_size>
731 operator==(const param_type& __p1, const param_type& __p2)
732 { return __p1._M_mean == __p2._M_mean && __p1._M_t == __p2._M_t; }
735 operator!=(const param_type& __p1, const param_type& __p2)
736 { return !(__p1 == __p2); }
739 template <typename _InputIterator1, typename _InputIterator2>
740 void _M_init_full(_InputIterator1 __meanbegin,
741 _InputIterator1 __meanend,
742 _InputIterator2 __varcovbegin,
743 _InputIterator2 __varcovend);
744 template <typename _InputIterator1, typename _InputIterator2>
745 void _M_init_lower(_InputIterator1 __meanbegin,
746 _InputIterator1 __meanend,
747 _InputIterator2 __varcovbegin,
748 _InputIterator2 __varcovend);
749 template <typename _InputIterator1, typename _InputIterator2>
750 void _M_init_diagonal(_InputIterator1 __meanbegin,
751 _InputIterator1 __meanend,
752 _InputIterator2 __varbegin,
753 _InputIterator2 __varend);
755 // param_type constructors apply Cholesky decomposition to the
756 // varcov matrix in _M_init_full and _M_init_lower, but the
757 // varcov matrix output ot a stream is already decomposed, so
758 // we need means to restore it as-is when reading it back in.
759 template<size_t _Dimen1, typename _RealType1,
760 typename _CharT, typename _Traits>
761 friend std::basic_istream<_CharT, _Traits>&
762 operator>>(std::basic_istream<_CharT, _Traits>& __is,
763 __gnu_cxx::normal_mv_distribution<_Dimen1, _RealType1>&
765 param_type(std::array<_RealType, _Dimen> const &__mean,
766 std::array<_RealType, _M_t_size> const &__varcov)
767 : _M_mean (__mean), _M_t (__varcov)
770 std::array<_RealType, _Dimen> _M_mean;
771 std::array<_RealType, _M_t_size> _M_t;
775 normal_mv_distribution()
776 : _M_param(), _M_nd()
779 template<typename _ForwardIterator1, typename _ForwardIterator2>
780 normal_mv_distribution(_ForwardIterator1 __meanbegin,
781 _ForwardIterator1 __meanend,
782 _ForwardIterator2 __varcovbegin,
783 _ForwardIterator2 __varcovend)
784 : _M_param(__meanbegin, __meanend, __varcovbegin, __varcovend),
788 normal_mv_distribution(std::initializer_list<_RealType> __mean,
789 std::initializer_list<_RealType> __varcov)
790 : _M_param(__mean, __varcov), _M_nd()
794 normal_mv_distribution(const param_type& __p)
795 : _M_param(__p), _M_nd()
799 * @brief Resets the distribution state.
806 * @brief Returns the mean of the distribution.
810 { return _M_param.mean(); }
813 * @brief Returns the compact form of the variance/covariance
814 * matrix of the distribution.
816 std::array<_RealType, _Dimen * (_Dimen + 1) / 2>
818 { return _M_param.varcov(); }
821 * @brief Returns the parameter set of the distribution.
828 * @brief Sets the parameter set of the distribution.
829 * @param __param The new parameter set of the distribution.
832 param(const param_type& __param)
833 { _M_param = __param; }
836 * @brief Returns the greatest lower bound value of the distribution.
841 __res.fill(std::numeric_limits<_RealType>::lowest());
845 * @brief Returns the least upper bound value of the distribution.
850 __res.fill(std::numeric_limits<_RealType>::max());
854 * @brief Generating functions.
856 template<typename _UniformRandomNumberGenerator>
858 operator()(_UniformRandomNumberGenerator& __urng)
859 { return this->operator()(__urng, _M_param); }
861 template<typename _UniformRandomNumberGenerator>
863 operator()(_UniformRandomNumberGenerator& __urng,
864 const param_type& __p);
866 template<typename _ForwardIterator,
867 typename _UniformRandomNumberGenerator>
869 __generate(_ForwardIterator __f, _ForwardIterator __t,
870 _UniformRandomNumberGenerator& __urng)
871 { return this->__generate_impl(__f, __t, __urng, _M_param); }
873 template<typename _ForwardIterator,
874 typename _UniformRandomNumberGenerator>
876 __generate(_ForwardIterator __f, _ForwardIterator __t,
877 _UniformRandomNumberGenerator& __urng,
878 const param_type& __p)
879 { return this->__generate_impl(__f, __t, __urng, __p); }
882 * @brief Return true if two multi-variant normal distributions have
883 * the same parameters and the sequences that would
884 * be generated are equal.
886 template<size_t _Dimen1, typename _RealType1>
889 __gnu_cxx::normal_mv_distribution<_Dimen1, _RealType1>&
892 __gnu_cxx::normal_mv_distribution<_Dimen1, _RealType1>&
896 * @brief Inserts a %normal_mv_distribution random number distribution
897 * @p __x into the output stream @p __os.
899 * @param __os An output stream.
900 * @param __x A %normal_mv_distribution random number distribution.
902 * @returns The output stream with the state of @p __x inserted or in
905 template<size_t _Dimen1, typename _RealType1,
906 typename _CharT, typename _Traits>
907 friend std::basic_ostream<_CharT, _Traits>&
908 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
910 __gnu_cxx::normal_mv_distribution<_Dimen1, _RealType1>&
914 * @brief Extracts a %normal_mv_distribution random number distribution
915 * @p __x from the input stream @p __is.
917 * @param __is An input stream.
918 * @param __x A %normal_mv_distribution random number generator engine.
920 * @returns The input stream with @p __x extracted or in an error
923 template<size_t _Dimen1, typename _RealType1,
924 typename _CharT, typename _Traits>
925 friend std::basic_istream<_CharT, _Traits>&
926 operator>>(std::basic_istream<_CharT, _Traits>& __is,
927 __gnu_cxx::normal_mv_distribution<_Dimen1, _RealType1>&
931 template<typename _ForwardIterator,
932 typename _UniformRandomNumberGenerator>
934 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
935 _UniformRandomNumberGenerator& __urng,
936 const param_type& __p);
939 std::normal_distribution<_RealType> _M_nd;
943 * @brief Return true if two multi-variate normal distributions are
946 template<size_t _Dimen, typename _RealType>
948 operator!=(const __gnu_cxx::normal_mv_distribution<_Dimen, _RealType>&
950 const __gnu_cxx::normal_mv_distribution<_Dimen, _RealType>&
952 { return !(__d1 == __d2); }
956 * @brief A Rice continuous distribution for random numbers.
958 * The formula for the Rice probability density function is
960 * p(x|\nu,\sigma) = \frac{x}{\sigma^2}
961 * \exp\left(-\frac{x^2+\nu^2}{2\sigma^2}\right)
962 * I_0\left(\frac{x \nu}{\sigma^2}\right)
964 * where @f$I_0(z)@f$ is the modified Bessel function of the first kind
965 * of order 0 and @f$\nu >= 0@f$ and @f$\sigma > 0@f$.
967 * <table border=1 cellpadding=10 cellspacing=0>
968 * <caption align=top>Distribution Statistics</caption>
969 * <tr><td>Mean</td><td>@f$\sqrt{\pi/2}L_{1/2}(-\nu^2/2\sigma^2)@f$</td></tr>
970 * <tr><td>Variance</td><td>@f$2\sigma^2 + \nu^2
971 * + (\pi\sigma^2/2)L^2_{1/2}(-\nu^2/2\sigma^2)@f$</td></tr>
972 * <tr><td>Range</td><td>@f$[0, \infty)@f$</td></tr>
974 * where @f$L_{1/2}(x)@f$ is the Laguerre polynomial of order 1/2.
976 template<typename _RealType = double>
980 static_assert(std::is_floating_point<_RealType>::value,
981 "template argument not a floating point type");
983 /** The type of the range of the distribution. */
984 typedef _RealType result_type;
986 /** Parameter type. */
989 typedef rice_distribution<result_type> distribution_type;
991 param_type() : param_type(0) { }
993 param_type(result_type __nu_val,
994 result_type __sigma_val = result_type(1))
995 : _M_nu(__nu_val), _M_sigma(__sigma_val)
997 __glibcxx_assert(_M_nu >= result_type(0));
998 __glibcxx_assert(_M_sigma > result_type(0));
1007 { return _M_sigma; }
1010 operator==(const param_type& __p1, const param_type& __p2)
1011 { return __p1._M_nu == __p2._M_nu && __p1._M_sigma == __p2._M_sigma; }
1014 operator!=(const param_type& __p1, const param_type& __p2)
1015 { return !(__p1 == __p2); }
1018 void _M_initialize();
1021 result_type _M_sigma;
1025 * @brief Constructors.
1029 rice_distribution() : rice_distribution(0) { }
1032 rice_distribution(result_type __nu_val,
1033 result_type __sigma_val = result_type(1))
1034 : _M_param(__nu_val, __sigma_val),
1035 _M_ndx(__nu_val, __sigma_val),
1036 _M_ndy(result_type(0), __sigma_val)
1040 rice_distribution(const param_type& __p)
1042 _M_ndx(__p.nu(), __p.sigma()),
1043 _M_ndy(result_type(0), __p.sigma())
1049 * @brief Resets the distribution state.
1059 * @brief Return the parameters of the distribution.
1063 { return _M_param.nu(); }
1067 { return _M_param.sigma(); }
1070 * @brief Returns the parameter set of the distribution.
1074 { return _M_param; }
1077 * @brief Sets the parameter set of the distribution.
1078 * @param __param The new parameter set of the distribution.
1081 param(const param_type& __param)
1082 { _M_param = __param; }
1085 * @brief Returns the greatest lower bound value of the distribution.
1089 { return result_type(0); }
1092 * @brief Returns the least upper bound value of the distribution.
1096 { return std::numeric_limits<result_type>::max(); }
1099 * @brief Generating functions.
1101 template<typename _UniformRandomNumberGenerator>
1103 operator()(_UniformRandomNumberGenerator& __urng)
1105 result_type __x = this->_M_ndx(__urng);
1106 result_type __y = this->_M_ndy(__urng);
1107 #if _GLIBCXX_USE_C99_MATH_TR1
1108 return std::hypot(__x, __y);
1110 return std::sqrt(__x * __x + __y * __y);
1114 template<typename _UniformRandomNumberGenerator>
1116 operator()(_UniformRandomNumberGenerator& __urng,
1117 const param_type& __p)
1119 typename std::normal_distribution<result_type>::param_type
1120 __px(__p.nu(), __p.sigma()), __py(result_type(0), __p.sigma());
1121 result_type __x = this->_M_ndx(__px, __urng);
1122 result_type __y = this->_M_ndy(__py, __urng);
1123 #if _GLIBCXX_USE_C99_MATH_TR1
1124 return std::hypot(__x, __y);
1126 return std::sqrt(__x * __x + __y * __y);
1130 template<typename _ForwardIterator,
1131 typename _UniformRandomNumberGenerator>
1133 __generate(_ForwardIterator __f, _ForwardIterator __t,
1134 _UniformRandomNumberGenerator& __urng)
1135 { this->__generate(__f, __t, __urng, _M_param); }
1137 template<typename _ForwardIterator,
1138 typename _UniformRandomNumberGenerator>
1140 __generate(_ForwardIterator __f, _ForwardIterator __t,
1141 _UniformRandomNumberGenerator& __urng,
1142 const param_type& __p)
1143 { this->__generate_impl(__f, __t, __urng, __p); }
1145 template<typename _UniformRandomNumberGenerator>
1147 __generate(result_type* __f, result_type* __t,
1148 _UniformRandomNumberGenerator& __urng,
1149 const param_type& __p)
1150 { this->__generate_impl(__f, __t, __urng, __p); }
1153 * @brief Return true if two Rice distributions have
1154 * the same parameters and the sequences that would
1155 * be generated are equal.
1158 operator==(const rice_distribution& __d1,
1159 const rice_distribution& __d2)
1160 { return (__d1._M_param == __d2._M_param
1161 && __d1._M_ndx == __d2._M_ndx
1162 && __d1._M_ndy == __d2._M_ndy); }
1165 * @brief Inserts a %rice_distribution random number distribution
1166 * @p __x into the output stream @p __os.
1168 * @param __os An output stream.
1169 * @param __x A %rice_distribution random number distribution.
1171 * @returns The output stream with the state of @p __x inserted or in
1174 template<typename _RealType1, typename _CharT, typename _Traits>
1175 friend std::basic_ostream<_CharT, _Traits>&
1176 operator<<(std::basic_ostream<_CharT, _Traits>&,
1177 const rice_distribution<_RealType1>&);
1180 * @brief Extracts a %rice_distribution random number distribution
1181 * @p __x from the input stream @p __is.
1183 * @param __is An input stream.
1184 * @param __x A %rice_distribution random number
1187 * @returns The input stream with @p __x extracted or in an error state.
1189 template<typename _RealType1, typename _CharT, typename _Traits>
1190 friend std::basic_istream<_CharT, _Traits>&
1191 operator>>(std::basic_istream<_CharT, _Traits>&,
1192 rice_distribution<_RealType1>&);
1195 template<typename _ForwardIterator,
1196 typename _UniformRandomNumberGenerator>
1198 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1199 _UniformRandomNumberGenerator& __urng,
1200 const param_type& __p);
1202 param_type _M_param;
1204 std::normal_distribution<result_type> _M_ndx;
1205 std::normal_distribution<result_type> _M_ndy;
1209 * @brief Return true if two Rice distributions are not equal.
1211 template<typename _RealType1>
1213 operator!=(const rice_distribution<_RealType1>& __d1,
1214 const rice_distribution<_RealType1>& __d2)
1215 { return !(__d1 == __d2); }
1219 * @brief A Nakagami continuous distribution for random numbers.
1221 * The formula for the Nakagami probability density function is
1223 * p(x|\mu,\omega) = \frac{2\mu^\mu}{\Gamma(\mu)\omega^\mu}
1224 * x^{2\mu-1}e^{-\mu x / \omega}
1226 * where @f$\Gamma(z)@f$ is the gamma function and @f$\mu >= 0.5@f$
1227 * and @f$\omega > 0@f$.
1229 template<typename _RealType = double>
1231 nakagami_distribution
1233 static_assert(std::is_floating_point<_RealType>::value,
1234 "template argument not a floating point type");
1237 /** The type of the range of the distribution. */
1238 typedef _RealType result_type;
1240 /** Parameter type. */
1243 typedef nakagami_distribution<result_type> distribution_type;
1245 param_type() : param_type(1) { }
1247 param_type(result_type __mu_val,
1248 result_type __omega_val = result_type(1))
1249 : _M_mu(__mu_val), _M_omega(__omega_val)
1251 __glibcxx_assert(_M_mu >= result_type(0.5L));
1252 __glibcxx_assert(_M_omega > result_type(0));
1261 { return _M_omega; }
1264 operator==(const param_type& __p1, const param_type& __p2)
1265 { return __p1._M_mu == __p2._M_mu && __p1._M_omega == __p2._M_omega; }
1268 operator!=(const param_type& __p1, const param_type& __p2)
1269 { return !(__p1 == __p2); }
1272 void _M_initialize();
1275 result_type _M_omega;
1279 * @brief Constructors.
1283 nakagami_distribution() : nakagami_distribution(1) { }
1286 nakagami_distribution(result_type __mu_val,
1287 result_type __omega_val = result_type(1))
1288 : _M_param(__mu_val, __omega_val),
1289 _M_gd(__mu_val, __omega_val / __mu_val)
1293 nakagami_distribution(const param_type& __p)
1295 _M_gd(__p.mu(), __p.omega() / __p.mu())
1301 * @brief Resets the distribution state.
1308 * @brief Return the parameters of the distribution.
1312 { return _M_param.mu(); }
1316 { return _M_param.omega(); }
1319 * @brief Returns the parameter set of the distribution.
1323 { return _M_param; }
1326 * @brief Sets the parameter set of the distribution.
1327 * @param __param The new parameter set of the distribution.
1330 param(const param_type& __param)
1331 { _M_param = __param; }
1334 * @brief Returns the greatest lower bound value of the distribution.
1338 { return result_type(0); }
1341 * @brief Returns the least upper bound value of the distribution.
1345 { return std::numeric_limits<result_type>::max(); }
1348 * @brief Generating functions.
1350 template<typename _UniformRandomNumberGenerator>
1352 operator()(_UniformRandomNumberGenerator& __urng)
1353 { return std::sqrt(this->_M_gd(__urng)); }
1355 template<typename _UniformRandomNumberGenerator>
1357 operator()(_UniformRandomNumberGenerator& __urng,
1358 const param_type& __p)
1360 typename std::gamma_distribution<result_type>::param_type
1361 __pg(__p.mu(), __p.omega() / __p.mu());
1362 return std::sqrt(this->_M_gd(__pg, __urng));
1365 template<typename _ForwardIterator,
1366 typename _UniformRandomNumberGenerator>
1368 __generate(_ForwardIterator __f, _ForwardIterator __t,
1369 _UniformRandomNumberGenerator& __urng)
1370 { this->__generate(__f, __t, __urng, _M_param); }
1372 template<typename _ForwardIterator,
1373 typename _UniformRandomNumberGenerator>
1375 __generate(_ForwardIterator __f, _ForwardIterator __t,
1376 _UniformRandomNumberGenerator& __urng,
1377 const param_type& __p)
1378 { this->__generate_impl(__f, __t, __urng, __p); }
1380 template<typename _UniformRandomNumberGenerator>
1382 __generate(result_type* __f, result_type* __t,
1383 _UniformRandomNumberGenerator& __urng,
1384 const param_type& __p)
1385 { this->__generate_impl(__f, __t, __urng, __p); }
1388 * @brief Return true if two Nakagami distributions have
1389 * the same parameters and the sequences that would
1390 * be generated are equal.
1393 operator==(const nakagami_distribution& __d1,
1394 const nakagami_distribution& __d2)
1395 { return (__d1._M_param == __d2._M_param
1396 && __d1._M_gd == __d2._M_gd); }
1399 * @brief Inserts a %nakagami_distribution random number distribution
1400 * @p __x into the output stream @p __os.
1402 * @param __os An output stream.
1403 * @param __x A %nakagami_distribution random number distribution.
1405 * @returns The output stream with the state of @p __x inserted or in
1408 template<typename _RealType1, typename _CharT, typename _Traits>
1409 friend std::basic_ostream<_CharT, _Traits>&
1410 operator<<(std::basic_ostream<_CharT, _Traits>&,
1411 const nakagami_distribution<_RealType1>&);
1414 * @brief Extracts a %nakagami_distribution random number distribution
1415 * @p __x from the input stream @p __is.
1417 * @param __is An input stream.
1418 * @param __x A %nakagami_distribution random number
1421 * @returns The input stream with @p __x extracted or in an error state.
1423 template<typename _RealType1, typename _CharT, typename _Traits>
1424 friend std::basic_istream<_CharT, _Traits>&
1425 operator>>(std::basic_istream<_CharT, _Traits>&,
1426 nakagami_distribution<_RealType1>&);
1429 template<typename _ForwardIterator,
1430 typename _UniformRandomNumberGenerator>
1432 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1433 _UniformRandomNumberGenerator& __urng,
1434 const param_type& __p);
1436 param_type _M_param;
1438 std::gamma_distribution<result_type> _M_gd;
1442 * @brief Return true if two Nakagami distributions are not equal.
1444 template<typename _RealType>
1446 operator!=(const nakagami_distribution<_RealType>& __d1,
1447 const nakagami_distribution<_RealType>& __d2)
1448 { return !(__d1 == __d2); }
1452 * @brief A Pareto continuous distribution for random numbers.
1454 * The formula for the Pareto cumulative probability function is
1456 * P(x|\alpha,\mu) = 1 - \left(\frac{\mu}{x}\right)^\alpha
1458 * The formula for the Pareto probability density function is
1460 * p(x|\alpha,\mu) = \frac{\alpha + 1}{\mu}
1461 * \left(\frac{\mu}{x}\right)^{\alpha + 1}
1463 * where @f$x >= \mu@f$ and @f$\mu > 0@f$, @f$\alpha > 0@f$.
1465 * <table border=1 cellpadding=10 cellspacing=0>
1466 * <caption align=top>Distribution Statistics</caption>
1467 * <tr><td>Mean</td><td>@f$\alpha \mu / (\alpha - 1)@f$
1468 * for @f$\alpha > 1@f$</td></tr>
1469 * <tr><td>Variance</td><td>@f$\alpha \mu^2 / [(\alpha - 1)^2(\alpha - 2)]@f$
1470 * for @f$\alpha > 2@f$</td></tr>
1471 * <tr><td>Range</td><td>@f$[\mu, \infty)@f$</td></tr>
1474 template<typename _RealType = double>
1478 static_assert(std::is_floating_point<_RealType>::value,
1479 "template argument not a floating point type");
1482 /** The type of the range of the distribution. */
1483 typedef _RealType result_type;
1485 /** Parameter type. */
1488 typedef pareto_distribution<result_type> distribution_type;
1490 param_type() : param_type(1) { }
1492 param_type(result_type __alpha_val,
1493 result_type __mu_val = result_type(1))
1494 : _M_alpha(__alpha_val), _M_mu(__mu_val)
1496 __glibcxx_assert(_M_alpha > result_type(0));
1497 __glibcxx_assert(_M_mu > result_type(0));
1502 { return _M_alpha; }
1509 operator==(const param_type& __p1, const param_type& __p2)
1510 { return __p1._M_alpha == __p2._M_alpha && __p1._M_mu == __p2._M_mu; }
1513 operator!=(const param_type& __p1, const param_type& __p2)
1514 { return !(__p1 == __p2); }
1517 void _M_initialize();
1519 result_type _M_alpha;
1524 * @brief Constructors.
1528 pareto_distribution() : pareto_distribution(1) { }
1531 pareto_distribution(result_type __alpha_val,
1532 result_type __mu_val = result_type(1))
1533 : _M_param(__alpha_val, __mu_val),
1538 pareto_distribution(const param_type& __p)
1546 * @brief Resets the distribution state.
1555 * @brief Return the parameters of the distribution.
1559 { return _M_param.alpha(); }
1563 { return _M_param.mu(); }
1566 * @brief Returns the parameter set of the distribution.
1570 { return _M_param; }
1573 * @brief Sets the parameter set of the distribution.
1574 * @param __param The new parameter set of the distribution.
1577 param(const param_type& __param)
1578 { _M_param = __param; }
1581 * @brief Returns the greatest lower bound value of the distribution.
1585 { return this->mu(); }
1588 * @brief Returns the least upper bound value of the distribution.
1592 { return std::numeric_limits<result_type>::max(); }
1595 * @brief Generating functions.
1597 template<typename _UniformRandomNumberGenerator>
1599 operator()(_UniformRandomNumberGenerator& __urng)
1601 return this->mu() * std::pow(this->_M_ud(__urng),
1602 -result_type(1) / this->alpha());
1605 template<typename _UniformRandomNumberGenerator>
1607 operator()(_UniformRandomNumberGenerator& __urng,
1608 const param_type& __p)
1610 return __p.mu() * std::pow(this->_M_ud(__urng),
1611 -result_type(1) / __p.alpha());
1614 template<typename _ForwardIterator,
1615 typename _UniformRandomNumberGenerator>
1617 __generate(_ForwardIterator __f, _ForwardIterator __t,
1618 _UniformRandomNumberGenerator& __urng)
1619 { this->__generate(__f, __t, __urng, _M_param); }
1621 template<typename _ForwardIterator,
1622 typename _UniformRandomNumberGenerator>
1624 __generate(_ForwardIterator __f, _ForwardIterator __t,
1625 _UniformRandomNumberGenerator& __urng,
1626 const param_type& __p)
1627 { this->__generate_impl(__f, __t, __urng, __p); }
1629 template<typename _UniformRandomNumberGenerator>
1631 __generate(result_type* __f, result_type* __t,
1632 _UniformRandomNumberGenerator& __urng,
1633 const param_type& __p)
1634 { this->__generate_impl(__f, __t, __urng, __p); }
1637 * @brief Return true if two Pareto distributions have
1638 * the same parameters and the sequences that would
1639 * be generated are equal.
1642 operator==(const pareto_distribution& __d1,
1643 const pareto_distribution& __d2)
1644 { return (__d1._M_param == __d2._M_param
1645 && __d1._M_ud == __d2._M_ud); }
1648 * @brief Inserts a %pareto_distribution random number distribution
1649 * @p __x into the output stream @p __os.
1651 * @param __os An output stream.
1652 * @param __x A %pareto_distribution random number distribution.
1654 * @returns The output stream with the state of @p __x inserted or in
1657 template<typename _RealType1, typename _CharT, typename _Traits>
1658 friend std::basic_ostream<_CharT, _Traits>&
1659 operator<<(std::basic_ostream<_CharT, _Traits>&,
1660 const pareto_distribution<_RealType1>&);
1663 * @brief Extracts a %pareto_distribution random number distribution
1664 * @p __x from the input stream @p __is.
1666 * @param __is An input stream.
1667 * @param __x A %pareto_distribution random number
1670 * @returns The input stream with @p __x extracted or in an error state.
1672 template<typename _RealType1, typename _CharT, typename _Traits>
1673 friend std::basic_istream<_CharT, _Traits>&
1674 operator>>(std::basic_istream<_CharT, _Traits>&,
1675 pareto_distribution<_RealType1>&);
1678 template<typename _ForwardIterator,
1679 typename _UniformRandomNumberGenerator>
1681 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1682 _UniformRandomNumberGenerator& __urng,
1683 const param_type& __p);
1685 param_type _M_param;
1687 std::uniform_real_distribution<result_type> _M_ud;
1691 * @brief Return true if two Pareto distributions are not equal.
1693 template<typename _RealType>
1695 operator!=(const pareto_distribution<_RealType>& __d1,
1696 const pareto_distribution<_RealType>& __d2)
1697 { return !(__d1 == __d2); }
1701 * @brief A K continuous distribution for random numbers.
1703 * The formula for the K probability density function is
1705 * p(x|\lambda, \mu, \nu) = \frac{2}{x}
1706 * \left(\frac{\lambda\nu x}{\mu}\right)^{\frac{\lambda + \nu}{2}}
1707 * \frac{1}{\Gamma(\lambda)\Gamma(\nu)}
1708 * K_{\nu - \lambda}\left(2\sqrt{\frac{\lambda\nu x}{\mu}}\right)
1710 * where @f$I_0(z)@f$ is the modified Bessel function of the second kind
1711 * of order @f$\nu - \lambda@f$ and @f$\lambda > 0@f$, @f$\mu > 0@f$
1712 * and @f$\nu > 0@f$.
1714 * <table border=1 cellpadding=10 cellspacing=0>
1715 * <caption align=top>Distribution Statistics</caption>
1716 * <tr><td>Mean</td><td>@f$\mu@f$</td></tr>
1717 * <tr><td>Variance</td><td>@f$\mu^2\frac{\lambda + \nu + 1}{\lambda\nu}@f$</td></tr>
1718 * <tr><td>Range</td><td>@f$[0, \infty)@f$</td></tr>
1721 template<typename _RealType = double>
1725 static_assert(std::is_floating_point<_RealType>::value,
1726 "template argument not a floating point type");
1729 /** The type of the range of the distribution. */
1730 typedef _RealType result_type;
1732 /** Parameter type. */
1735 typedef k_distribution<result_type> distribution_type;
1737 param_type() : param_type(1) { }
1739 param_type(result_type __lambda_val,
1740 result_type __mu_val = result_type(1),
1741 result_type __nu_val = result_type(1))
1742 : _M_lambda(__lambda_val), _M_mu(__mu_val), _M_nu(__nu_val)
1744 __glibcxx_assert(_M_lambda > result_type(0));
1745 __glibcxx_assert(_M_mu > result_type(0));
1746 __glibcxx_assert(_M_nu > result_type(0));
1751 { return _M_lambda; }
1762 operator==(const param_type& __p1, const param_type& __p2)
1764 return __p1._M_lambda == __p2._M_lambda
1765 && __p1._M_mu == __p2._M_mu
1766 && __p1._M_nu == __p2._M_nu;
1770 operator!=(const param_type& __p1, const param_type& __p2)
1771 { return !(__p1 == __p2); }
1774 void _M_initialize();
1776 result_type _M_lambda;
1782 * @brief Constructors.
1786 k_distribution() : k_distribution(1) { }
1789 k_distribution(result_type __lambda_val,
1790 result_type __mu_val = result_type(1),
1791 result_type __nu_val = result_type(1))
1792 : _M_param(__lambda_val, __mu_val, __nu_val),
1793 _M_gd1(__lambda_val, result_type(1) / __lambda_val),
1794 _M_gd2(__nu_val, __mu_val / __nu_val)
1798 k_distribution(const param_type& __p)
1800 _M_gd1(__p.lambda(), result_type(1) / __p.lambda()),
1801 _M_gd2(__p.nu(), __p.mu() / __p.nu())
1807 * @brief Resets the distribution state.
1817 * @brief Return the parameters of the distribution.
1821 { return _M_param.lambda(); }
1825 { return _M_param.mu(); }
1829 { return _M_param.nu(); }
1832 * @brief Returns the parameter set of the distribution.
1836 { return _M_param; }
1839 * @brief Sets the parameter set of the distribution.
1840 * @param __param The new parameter set of the distribution.
1843 param(const param_type& __param)
1844 { _M_param = __param; }
1847 * @brief Returns the greatest lower bound value of the distribution.
1851 { return result_type(0); }
1854 * @brief Returns the least upper bound value of the distribution.
1858 { return std::numeric_limits<result_type>::max(); }
1861 * @brief Generating functions.
1863 template<typename _UniformRandomNumberGenerator>
1865 operator()(_UniformRandomNumberGenerator&);
1867 template<typename _UniformRandomNumberGenerator>
1869 operator()(_UniformRandomNumberGenerator&, const param_type&);
1871 template<typename _ForwardIterator,
1872 typename _UniformRandomNumberGenerator>
1874 __generate(_ForwardIterator __f, _ForwardIterator __t,
1875 _UniformRandomNumberGenerator& __urng)
1876 { this->__generate(__f, __t, __urng, _M_param); }
1878 template<typename _ForwardIterator,
1879 typename _UniformRandomNumberGenerator>
1881 __generate(_ForwardIterator __f, _ForwardIterator __t,
1882 _UniformRandomNumberGenerator& __urng,
1883 const param_type& __p)
1884 { this->__generate_impl(__f, __t, __urng, __p); }
1886 template<typename _UniformRandomNumberGenerator>
1888 __generate(result_type* __f, result_type* __t,
1889 _UniformRandomNumberGenerator& __urng,
1890 const param_type& __p)
1891 { this->__generate_impl(__f, __t, __urng, __p); }
1894 * @brief Return true if two K distributions have
1895 * the same parameters and the sequences that would
1896 * be generated are equal.
1899 operator==(const k_distribution& __d1,
1900 const k_distribution& __d2)
1901 { return (__d1._M_param == __d2._M_param
1902 && __d1._M_gd1 == __d2._M_gd1
1903 && __d1._M_gd2 == __d2._M_gd2); }
1906 * @brief Inserts a %k_distribution random number distribution
1907 * @p __x into the output stream @p __os.
1909 * @param __os An output stream.
1910 * @param __x A %k_distribution random number distribution.
1912 * @returns The output stream with the state of @p __x inserted or in
1915 template<typename _RealType1, typename _CharT, typename _Traits>
1916 friend std::basic_ostream<_CharT, _Traits>&
1917 operator<<(std::basic_ostream<_CharT, _Traits>&,
1918 const k_distribution<_RealType1>&);
1921 * @brief Extracts a %k_distribution random number distribution
1922 * @p __x from the input stream @p __is.
1924 * @param __is An input stream.
1925 * @param __x A %k_distribution random number
1928 * @returns The input stream with @p __x extracted or in an error state.
1930 template<typename _RealType1, typename _CharT, typename _Traits>
1931 friend std::basic_istream<_CharT, _Traits>&
1932 operator>>(std::basic_istream<_CharT, _Traits>&,
1933 k_distribution<_RealType1>&);
1936 template<typename _ForwardIterator,
1937 typename _UniformRandomNumberGenerator>
1939 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1940 _UniformRandomNumberGenerator& __urng,
1941 const param_type& __p);
1943 param_type _M_param;
1945 std::gamma_distribution<result_type> _M_gd1;
1946 std::gamma_distribution<result_type> _M_gd2;
1950 * @brief Return true if two K distributions are not equal.
1952 template<typename _RealType>
1954 operator!=(const k_distribution<_RealType>& __d1,
1955 const k_distribution<_RealType>& __d2)
1956 { return !(__d1 == __d2); }
1960 * @brief An arcsine continuous distribution for random numbers.
1962 * The formula for the arcsine probability density function is
1964 * p(x|a,b) = \frac{1}{\pi \sqrt{(x - a)(b - x)}}
1966 * where @f$x >= a@f$ and @f$x <= b@f$.
1968 * <table border=1 cellpadding=10 cellspacing=0>
1969 * <caption align=top>Distribution Statistics</caption>
1970 * <tr><td>Mean</td><td>@f$ (a + b) / 2 @f$</td></tr>
1971 * <tr><td>Variance</td><td>@f$ (b - a)^2 / 8 @f$</td></tr>
1972 * <tr><td>Range</td><td>@f$[a, b]@f$</td></tr>
1975 template<typename _RealType = double>
1977 arcsine_distribution
1979 static_assert(std::is_floating_point<_RealType>::value,
1980 "template argument not a floating point type");
1983 /** The type of the range of the distribution. */
1984 typedef _RealType result_type;
1986 /** Parameter type. */
1989 typedef arcsine_distribution<result_type> distribution_type;
1991 param_type() : param_type(0) { }
1993 param_type(result_type __a, result_type __b = result_type(1))
1994 : _M_a(__a), _M_b(__b)
1996 __glibcxx_assert(_M_a <= _M_b);
2008 operator==(const param_type& __p1, const param_type& __p2)
2009 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
2012 operator!=(const param_type& __p1, const param_type& __p2)
2013 { return !(__p1 == __p2); }
2016 void _M_initialize();
2023 * @brief Constructors.
2027 arcsine_distribution() : arcsine_distribution(0) { }
2030 arcsine_distribution(result_type __a, result_type __b = result_type(1))
2031 : _M_param(__a, __b),
2032 _M_ud(-1.5707963267948966192313216916397514L,
2033 +1.5707963267948966192313216916397514L)
2037 arcsine_distribution(const param_type& __p)
2039 _M_ud(-1.5707963267948966192313216916397514L,
2040 +1.5707963267948966192313216916397514L)
2046 * @brief Resets the distribution state.
2053 * @brief Return the parameters of the distribution.
2057 { return _M_param.a(); }
2061 { return _M_param.b(); }
2064 * @brief Returns the parameter set of the distribution.
2068 { return _M_param; }
2071 * @brief Sets the parameter set of the distribution.
2072 * @param __param The new parameter set of the distribution.
2075 param(const param_type& __param)
2076 { _M_param = __param; }
2079 * @brief Returns the greatest lower bound value of the distribution.
2083 { return this->a(); }
2086 * @brief Returns the least upper bound value of the distribution.
2090 { return this->b(); }
2093 * @brief Generating functions.
2095 template<typename _UniformRandomNumberGenerator>
2097 operator()(_UniformRandomNumberGenerator& __urng)
2099 result_type __x = std::sin(this->_M_ud(__urng));
2100 return (__x * (this->b() - this->a())
2101 + this->a() + this->b()) / result_type(2);
2104 template<typename _UniformRandomNumberGenerator>
2106 operator()(_UniformRandomNumberGenerator& __urng,
2107 const param_type& __p)
2109 result_type __x = std::sin(this->_M_ud(__urng));
2110 return (__x * (__p.b() - __p.a())
2111 + __p.a() + __p.b()) / result_type(2);
2114 template<typename _ForwardIterator,
2115 typename _UniformRandomNumberGenerator>
2117 __generate(_ForwardIterator __f, _ForwardIterator __t,
2118 _UniformRandomNumberGenerator& __urng)
2119 { this->__generate(__f, __t, __urng, _M_param); }
2121 template<typename _ForwardIterator,
2122 typename _UniformRandomNumberGenerator>
2124 __generate(_ForwardIterator __f, _ForwardIterator __t,
2125 _UniformRandomNumberGenerator& __urng,
2126 const param_type& __p)
2127 { this->__generate_impl(__f, __t, __urng, __p); }
2129 template<typename _UniformRandomNumberGenerator>
2131 __generate(result_type* __f, result_type* __t,
2132 _UniformRandomNumberGenerator& __urng,
2133 const param_type& __p)
2134 { this->__generate_impl(__f, __t, __urng, __p); }
2137 * @brief Return true if two arcsine distributions have
2138 * the same parameters and the sequences that would
2139 * be generated are equal.
2142 operator==(const arcsine_distribution& __d1,
2143 const arcsine_distribution& __d2)
2144 { return (__d1._M_param == __d2._M_param
2145 && __d1._M_ud == __d2._M_ud); }
2148 * @brief Inserts a %arcsine_distribution random number distribution
2149 * @p __x into the output stream @p __os.
2151 * @param __os An output stream.
2152 * @param __x A %arcsine_distribution random number distribution.
2154 * @returns The output stream with the state of @p __x inserted or in
2157 template<typename _RealType1, typename _CharT, typename _Traits>
2158 friend std::basic_ostream<_CharT, _Traits>&
2159 operator<<(std::basic_ostream<_CharT, _Traits>&,
2160 const arcsine_distribution<_RealType1>&);
2163 * @brief Extracts a %arcsine_distribution random number distribution
2164 * @p __x from the input stream @p __is.
2166 * @param __is An input stream.
2167 * @param __x A %arcsine_distribution random number
2170 * @returns The input stream with @p __x extracted or in an error state.
2172 template<typename _RealType1, typename _CharT, typename _Traits>
2173 friend std::basic_istream<_CharT, _Traits>&
2174 operator>>(std::basic_istream<_CharT, _Traits>&,
2175 arcsine_distribution<_RealType1>&);
2178 template<typename _ForwardIterator,
2179 typename _UniformRandomNumberGenerator>
2181 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2182 _UniformRandomNumberGenerator& __urng,
2183 const param_type& __p);
2185 param_type _M_param;
2187 std::uniform_real_distribution<result_type> _M_ud;
2191 * @brief Return true if two arcsine distributions are not equal.
2193 template<typename _RealType>
2195 operator!=(const arcsine_distribution<_RealType>& __d1,
2196 const arcsine_distribution<_RealType>& __d2)
2197 { return !(__d1 == __d2); }
2201 * @brief A Hoyt continuous distribution for random numbers.
2203 * The formula for the Hoyt probability density function is
2205 * p(x|q,\omega) = \frac{(1 + q^2)x}{q\omega}
2206 * \exp\left(-\frac{(1 + q^2)^2 x^2}{4 q^2 \omega}\right)
2207 * I_0\left(\frac{(1 - q^4) x^2}{4 q^2 \omega}\right)
2209 * where @f$I_0(z)@f$ is the modified Bessel function of the first kind
2210 * of order 0 and @f$0 < q < 1@f$.
2212 * <table border=1 cellpadding=10 cellspacing=0>
2213 * <caption align=top>Distribution Statistics</caption>
2214 * <tr><td>Mean</td><td>@f$ \sqrt{\frac{2}{\pi}} \sqrt{\frac{\omega}{1 + q^2}}
2215 * E(1 - q^2) @f$</td></tr>
2216 * <tr><td>Variance</td><td>@f$ \omega \left(1 - \frac{2E^2(1 - q^2)}
2217 * {\pi (1 + q^2)}\right) @f$</td></tr>
2218 * <tr><td>Range</td><td>@f$[0, \infty)@f$</td></tr>
2220 * where @f$E(x)@f$ is the elliptic function of the second kind.
2222 template<typename _RealType = double>
2226 static_assert(std::is_floating_point<_RealType>::value,
2227 "template argument not a floating point type");
2230 /** The type of the range of the distribution. */
2231 typedef _RealType result_type;
2233 /** Parameter type. */
2236 typedef hoyt_distribution<result_type> distribution_type;
2238 param_type() : param_type(0.5) { }
2240 param_type(result_type __q, result_type __omega = result_type(1))
2241 : _M_q(__q), _M_omega(__omega)
2243 __glibcxx_assert(_M_q > result_type(0));
2244 __glibcxx_assert(_M_q < result_type(1));
2253 { return _M_omega; }
2256 operator==(const param_type& __p1, const param_type& __p2)
2257 { return __p1._M_q == __p2._M_q && __p1._M_omega == __p2._M_omega; }
2260 operator!=(const param_type& __p1, const param_type& __p2)
2261 { return !(__p1 == __p2); }
2264 void _M_initialize();
2267 result_type _M_omega;
2271 * @brief Constructors.
2275 hoyt_distribution() : hoyt_distribution(0.5) { }
2278 hoyt_distribution(result_type __q, result_type __omega = result_type(1))
2279 : _M_param(__q, __omega),
2280 _M_ad(result_type(0.5L) * (result_type(1) + __q * __q),
2281 result_type(0.5L) * (result_type(1) + __q * __q)
2283 _M_ed(result_type(1))
2287 hoyt_distribution(const param_type& __p)
2289 _M_ad(result_type(0.5L) * (result_type(1) + __p.q() * __p.q()),
2290 result_type(0.5L) * (result_type(1) + __p.q() * __p.q())
2291 / (__p.q() * __p.q())),
2292 _M_ed(result_type(1))
2296 * @brief Resets the distribution state.
2306 * @brief Return the parameters of the distribution.
2310 { return _M_param.q(); }
2314 { return _M_param.omega(); }
2317 * @brief Returns the parameter set of the distribution.
2321 { return _M_param; }
2324 * @brief Sets the parameter set of the distribution.
2325 * @param __param The new parameter set of the distribution.
2328 param(const param_type& __param)
2329 { _M_param = __param; }
2332 * @brief Returns the greatest lower bound value of the distribution.
2336 { return result_type(0); }
2339 * @brief Returns the least upper bound value of the distribution.
2343 { return std::numeric_limits<result_type>::max(); }
2346 * @brief Generating functions.
2348 template<typename _UniformRandomNumberGenerator>
2350 operator()(_UniformRandomNumberGenerator& __urng);
2352 template<typename _UniformRandomNumberGenerator>
2354 operator()(_UniformRandomNumberGenerator& __urng,
2355 const param_type& __p);
2357 template<typename _ForwardIterator,
2358 typename _UniformRandomNumberGenerator>
2360 __generate(_ForwardIterator __f, _ForwardIterator __t,
2361 _UniformRandomNumberGenerator& __urng)
2362 { this->__generate(__f, __t, __urng, _M_param); }
2364 template<typename _ForwardIterator,
2365 typename _UniformRandomNumberGenerator>
2367 __generate(_ForwardIterator __f, _ForwardIterator __t,
2368 _UniformRandomNumberGenerator& __urng,
2369 const param_type& __p)
2370 { this->__generate_impl(__f, __t, __urng, __p); }
2372 template<typename _UniformRandomNumberGenerator>
2374 __generate(result_type* __f, result_type* __t,
2375 _UniformRandomNumberGenerator& __urng,
2376 const param_type& __p)
2377 { this->__generate_impl(__f, __t, __urng, __p); }
2380 * @brief Return true if two Hoyt distributions have
2381 * the same parameters and the sequences that would
2382 * be generated are equal.
2385 operator==(const hoyt_distribution& __d1,
2386 const hoyt_distribution& __d2)
2387 { return (__d1._M_param == __d2._M_param
2388 && __d1._M_ad == __d2._M_ad
2389 && __d1._M_ed == __d2._M_ed); }
2392 * @brief Inserts a %hoyt_distribution random number distribution
2393 * @p __x into the output stream @p __os.
2395 * @param __os An output stream.
2396 * @param __x A %hoyt_distribution random number distribution.
2398 * @returns The output stream with the state of @p __x inserted or in
2401 template<typename _RealType1, typename _CharT, typename _Traits>
2402 friend std::basic_ostream<_CharT, _Traits>&
2403 operator<<(std::basic_ostream<_CharT, _Traits>&,
2404 const hoyt_distribution<_RealType1>&);
2407 * @brief Extracts a %hoyt_distribution random number distribution
2408 * @p __x from the input stream @p __is.
2410 * @param __is An input stream.
2411 * @param __x A %hoyt_distribution random number
2414 * @returns The input stream with @p __x extracted or in an error state.
2416 template<typename _RealType1, typename _CharT, typename _Traits>
2417 friend std::basic_istream<_CharT, _Traits>&
2418 operator>>(std::basic_istream<_CharT, _Traits>&,
2419 hoyt_distribution<_RealType1>&);
2422 template<typename _ForwardIterator,
2423 typename _UniformRandomNumberGenerator>
2425 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2426 _UniformRandomNumberGenerator& __urng,
2427 const param_type& __p);
2429 param_type _M_param;
2431 __gnu_cxx::arcsine_distribution<result_type> _M_ad;
2432 std::exponential_distribution<result_type> _M_ed;
2436 * @brief Return true if two Hoyt distributions are not equal.
2438 template<typename _RealType>
2440 operator!=(const hoyt_distribution<_RealType>& __d1,
2441 const hoyt_distribution<_RealType>& __d2)
2442 { return !(__d1 == __d2); }
2446 * @brief A triangular distribution for random numbers.
2448 * The formula for the triangular probability density function is
2451 * p(x|a,b,c) = | \frac{2(x-a)}{(c-a)(b-a)} for a <= x <= b
2452 * | \frac{2(c-x)}{(c-a)(c-b)} for b < x <= c
2456 * <table border=1 cellpadding=10 cellspacing=0>
2457 * <caption align=top>Distribution Statistics</caption>
2458 * <tr><td>Mean</td><td>@f$ \frac{a+b+c}{2} @f$</td></tr>
2459 * <tr><td>Variance</td><td>@f$ \frac{a^2+b^2+c^2-ab-ac-bc}
2461 * <tr><td>Range</td><td>@f$[a, c]@f$</td></tr>
2464 template<typename _RealType = double>
2465 class triangular_distribution
2467 static_assert(std::is_floating_point<_RealType>::value,
2468 "template argument not a floating point type");
2471 /** The type of the range of the distribution. */
2472 typedef _RealType result_type;
2474 /** Parameter type. */
2477 friend class triangular_distribution<_RealType>;
2479 param_type() : param_type(0) { }
2482 param_type(_RealType __a,
2483 _RealType __b = _RealType(0.5),
2484 _RealType __c = _RealType(1))
2485 : _M_a(__a), _M_b(__b), _M_c(__c)
2487 __glibcxx_assert(_M_a <= _M_b);
2488 __glibcxx_assert(_M_b <= _M_c);
2489 __glibcxx_assert(_M_a < _M_c);
2491 _M_r_ab = (_M_b - _M_a) / (_M_c - _M_a);
2492 _M_f_ab_ac = (_M_b - _M_a) * (_M_c - _M_a);
2493 _M_f_bc_ac = (_M_c - _M_b) * (_M_c - _M_a);
2509 operator==(const param_type& __p1, const param_type& __p2)
2511 return (__p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b
2512 && __p1._M_c == __p2._M_c);
2516 operator!=(const param_type& __p1, const param_type& __p2)
2517 { return !(__p1 == __p2); }
2525 _RealType _M_f_ab_ac;
2526 _RealType _M_f_bc_ac;
2529 triangular_distribution() : triangular_distribution(0.0) { }
2532 * @brief Constructs a triangle distribution with parameters
2533 * @f$ a @f$, @f$ b @f$ and @f$ c @f$.
2536 triangular_distribution(result_type __a,
2537 result_type __b = result_type(0.5),
2538 result_type __c = result_type(1))
2539 : _M_param(__a, __b, __c)
2543 triangular_distribution(const param_type& __p)
2548 * @brief Resets the distribution state.
2555 * @brief Returns the @f$ a @f$ of the distribution.
2559 { return _M_param.a(); }
2562 * @brief Returns the @f$ b @f$ of the distribution.
2566 { return _M_param.b(); }
2569 * @brief Returns the @f$ c @f$ of the distribution.
2573 { return _M_param.c(); }
2576 * @brief Returns the parameter set of the distribution.
2580 { return _M_param; }
2583 * @brief Sets the parameter set of the distribution.
2584 * @param __param The new parameter set of the distribution.
2587 param(const param_type& __param)
2588 { _M_param = __param; }
2591 * @brief Returns the greatest lower bound value of the distribution.
2595 { return _M_param._M_a; }
2598 * @brief Returns the least upper bound value of the distribution.
2602 { return _M_param._M_c; }
2605 * @brief Generating functions.
2607 template<typename _UniformRandomNumberGenerator>
2609 operator()(_UniformRandomNumberGenerator& __urng)
2610 { return this->operator()(__urng, _M_param); }
2612 template<typename _UniformRandomNumberGenerator>
2614 operator()(_UniformRandomNumberGenerator& __urng,
2615 const param_type& __p)
2617 std::__detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2619 result_type __rnd = __aurng();
2620 if (__rnd <= __p._M_r_ab)
2621 return __p.a() + std::sqrt(__rnd * __p._M_f_ab_ac);
2623 return __p.c() - std::sqrt((result_type(1) - __rnd)
2627 template<typename _ForwardIterator,
2628 typename _UniformRandomNumberGenerator>
2630 __generate(_ForwardIterator __f, _ForwardIterator __t,
2631 _UniformRandomNumberGenerator& __urng)
2632 { this->__generate(__f, __t, __urng, _M_param); }
2634 template<typename _ForwardIterator,
2635 typename _UniformRandomNumberGenerator>
2637 __generate(_ForwardIterator __f, _ForwardIterator __t,
2638 _UniformRandomNumberGenerator& __urng,
2639 const param_type& __p)
2640 { this->__generate_impl(__f, __t, __urng, __p); }
2642 template<typename _UniformRandomNumberGenerator>
2644 __generate(result_type* __f, result_type* __t,
2645 _UniformRandomNumberGenerator& __urng,
2646 const param_type& __p)
2647 { this->__generate_impl(__f, __t, __urng, __p); }
2650 * @brief Return true if two triangle distributions have the same
2651 * parameters and the sequences that would be generated
2655 operator==(const triangular_distribution& __d1,
2656 const triangular_distribution& __d2)
2657 { return __d1._M_param == __d2._M_param; }
2660 * @brief Inserts a %triangular_distribution random number distribution
2661 * @p __x into the output stream @p __os.
2663 * @param __os An output stream.
2664 * @param __x A %triangular_distribution random number distribution.
2666 * @returns The output stream with the state of @p __x inserted or in
2669 template<typename _RealType1, typename _CharT, typename _Traits>
2670 friend std::basic_ostream<_CharT, _Traits>&
2671 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2672 const __gnu_cxx::triangular_distribution<_RealType1>& __x);
2675 * @brief Extracts a %triangular_distribution random number distribution
2676 * @p __x from the input stream @p __is.
2678 * @param __is An input stream.
2679 * @param __x A %triangular_distribution random number generator engine.
2681 * @returns The input stream with @p __x extracted or in an error state.
2683 template<typename _RealType1, typename _CharT, typename _Traits>
2684 friend std::basic_istream<_CharT, _Traits>&
2685 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2686 __gnu_cxx::triangular_distribution<_RealType1>& __x);
2689 template<typename _ForwardIterator,
2690 typename _UniformRandomNumberGenerator>
2692 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2693 _UniformRandomNumberGenerator& __urng,
2694 const param_type& __p);
2696 param_type _M_param;
2700 * @brief Return true if two triangle distributions are different.
2702 template<typename _RealType>
2704 operator!=(const __gnu_cxx::triangular_distribution<_RealType>& __d1,
2705 const __gnu_cxx::triangular_distribution<_RealType>& __d2)
2706 { return !(__d1 == __d2); }
2710 * @brief A von Mises distribution for random numbers.
2712 * The formula for the von Mises probability density function is
2714 * p(x|\mu,\kappa) = \frac{e^{\kappa \cos(x-\mu)}}
2715 * {2\pi I_0(\kappa)}
2718 * The generating functions use the method according to:
2720 * D. J. Best and N. I. Fisher, 1979. "Efficient Simulation of the
2721 * von Mises Distribution", Journal of the Royal Statistical Society.
2722 * Series C (Applied Statistics), Vol. 28, No. 2, pp. 152-157.
2724 * <table border=1 cellpadding=10 cellspacing=0>
2725 * <caption align=top>Distribution Statistics</caption>
2726 * <tr><td>Mean</td><td>@f$ \mu @f$</td></tr>
2727 * <tr><td>Variance</td><td>@f$ 1-I_1(\kappa)/I_0(\kappa) @f$</td></tr>
2728 * <tr><td>Range</td><td>@f$[-\pi, \pi]@f$</td></tr>
2731 template<typename _RealType = double>
2732 class von_mises_distribution
2734 static_assert(std::is_floating_point<_RealType>::value,
2735 "template argument not a floating point type");
2738 /** The type of the range of the distribution. */
2739 typedef _RealType result_type;
2741 /** Parameter type. */
2744 friend class von_mises_distribution<_RealType>;
2746 param_type() : param_type(0) { }
2749 param_type(_RealType __mu, _RealType __kappa = _RealType(1))
2750 : _M_mu(__mu), _M_kappa(__kappa)
2752 const _RealType __pi = __gnu_cxx::__math_constants<_RealType>::__pi;
2753 __glibcxx_assert(_M_mu >= -__pi && _M_mu <= __pi);
2754 __glibcxx_assert(_M_kappa >= _RealType(0));
2756 auto __tau = std::sqrt(_RealType(4) * _M_kappa * _M_kappa
2757 + _RealType(1)) + _RealType(1);
2758 auto __rho = ((__tau - std::sqrt(_RealType(2) * __tau))
2759 / (_RealType(2) * _M_kappa));
2760 _M_r = (_RealType(1) + __rho * __rho) / (_RealType(2) * __rho);
2769 { return _M_kappa; }
2772 operator==(const param_type& __p1, const param_type& __p2)
2773 { return __p1._M_mu == __p2._M_mu && __p1._M_kappa == __p2._M_kappa; }
2776 operator!=(const param_type& __p1, const param_type& __p2)
2777 { return !(__p1 == __p2); }
2785 von_mises_distribution() : von_mises_distribution(0.0) { }
2788 * @brief Constructs a von Mises distribution with parameters
2789 * @f$\mu@f$ and @f$\kappa@f$.
2792 von_mises_distribution(result_type __mu,
2793 result_type __kappa = result_type(1))
2794 : _M_param(__mu, __kappa)
2798 von_mises_distribution(const param_type& __p)
2803 * @brief Resets the distribution state.
2810 * @brief Returns the @f$ \mu @f$ of the distribution.
2814 { return _M_param.mu(); }
2817 * @brief Returns the @f$ \kappa @f$ of the distribution.
2821 { return _M_param.kappa(); }
2824 * @brief Returns the parameter set of the distribution.
2828 { return _M_param; }
2831 * @brief Sets the parameter set of the distribution.
2832 * @param __param The new parameter set of the distribution.
2835 param(const param_type& __param)
2836 { _M_param = __param; }
2839 * @brief Returns the greatest lower bound value of the distribution.
2844 return -__gnu_cxx::__math_constants<result_type>::__pi;
2848 * @brief Returns the least upper bound value of the distribution.
2853 return __gnu_cxx::__math_constants<result_type>::__pi;
2857 * @brief Generating functions.
2859 template<typename _UniformRandomNumberGenerator>
2861 operator()(_UniformRandomNumberGenerator& __urng)
2862 { return this->operator()(__urng, _M_param); }
2864 template<typename _UniformRandomNumberGenerator>
2866 operator()(_UniformRandomNumberGenerator& __urng,
2867 const param_type& __p);
2869 template<typename _ForwardIterator,
2870 typename _UniformRandomNumberGenerator>
2872 __generate(_ForwardIterator __f, _ForwardIterator __t,
2873 _UniformRandomNumberGenerator& __urng)
2874 { this->__generate(__f, __t, __urng, _M_param); }
2876 template<typename _ForwardIterator,
2877 typename _UniformRandomNumberGenerator>
2879 __generate(_ForwardIterator __f, _ForwardIterator __t,
2880 _UniformRandomNumberGenerator& __urng,
2881 const param_type& __p)
2882 { this->__generate_impl(__f, __t, __urng, __p); }
2884 template<typename _UniformRandomNumberGenerator>
2886 __generate(result_type* __f, result_type* __t,
2887 _UniformRandomNumberGenerator& __urng,
2888 const param_type& __p)
2889 { this->__generate_impl(__f, __t, __urng, __p); }
2892 * @brief Return true if two von Mises distributions have the same
2893 * parameters and the sequences that would be generated
2897 operator==(const von_mises_distribution& __d1,
2898 const von_mises_distribution& __d2)
2899 { return __d1._M_param == __d2._M_param; }
2902 * @brief Inserts a %von_mises_distribution random number distribution
2903 * @p __x into the output stream @p __os.
2905 * @param __os An output stream.
2906 * @param __x A %von_mises_distribution random number distribution.
2908 * @returns The output stream with the state of @p __x inserted or in
2911 template<typename _RealType1, typename _CharT, typename _Traits>
2912 friend std::basic_ostream<_CharT, _Traits>&
2913 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2914 const __gnu_cxx::von_mises_distribution<_RealType1>& __x);
2917 * @brief Extracts a %von_mises_distribution random number distribution
2918 * @p __x from the input stream @p __is.
2920 * @param __is An input stream.
2921 * @param __x A %von_mises_distribution random number generator engine.
2923 * @returns The input stream with @p __x extracted or in an error state.
2925 template<typename _RealType1, typename _CharT, typename _Traits>
2926 friend std::basic_istream<_CharT, _Traits>&
2927 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2928 __gnu_cxx::von_mises_distribution<_RealType1>& __x);
2931 template<typename _ForwardIterator,
2932 typename _UniformRandomNumberGenerator>
2934 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2935 _UniformRandomNumberGenerator& __urng,
2936 const param_type& __p);
2938 param_type _M_param;
2942 * @brief Return true if two von Mises distributions are different.
2944 template<typename _RealType>
2946 operator!=(const __gnu_cxx::von_mises_distribution<_RealType>& __d1,
2947 const __gnu_cxx::von_mises_distribution<_RealType>& __d2)
2948 { return !(__d1 == __d2); }
2952 * @brief A discrete hypergeometric random number distribution.
2954 * The hypergeometric distribution is a discrete probability distribution
2955 * that describes the probability of @p k successes in @p n draws @a without
2956 * replacement from a finite population of size @p N containing exactly @p K
2959 * The formula for the hypergeometric probability density function is
2961 * p(k|N,K,n) = \frac{\binom{K}{k} \binom{N-K}{n-k}}{\binom{N}{n}}
2963 * where @f$N@f$ is the total population of the distribution,
2964 * @f$K@f$ is the total population of the distribution.
2966 * <table border=1 cellpadding=10 cellspacing=0>
2967 * <caption align=top>Distribution Statistics</caption>
2968 * <tr><td>Mean</td><td>@f$ n\frac{K}{N} @f$</td></tr>
2969 * <tr><td>Variance</td><td>@f$ n\frac{K}{N}\frac{N-K}{N}\frac{N-n}{N-1}
2971 * <tr><td>Range</td><td>@f$[max(0, n+K-N), min(K, n)]@f$</td></tr>
2974 template<typename _UIntType = unsigned int>
2975 class hypergeometric_distribution
2977 static_assert(std::is_unsigned<_UIntType>::value, "template argument "
2978 "substituting _UIntType not an unsigned integral type");
2981 /** The type of the range of the distribution. */
2982 typedef _UIntType result_type;
2984 /** Parameter type. */
2987 typedef hypergeometric_distribution<_UIntType> distribution_type;
2988 friend class hypergeometric_distribution<_UIntType>;
2990 param_type() : param_type(10) { }
2993 param_type(result_type __N, result_type __K = 5,
2994 result_type __n = 1)
2995 : _M_N{__N}, _M_K{__K}, _M_n{__n}
2997 __glibcxx_assert(_M_N >= _M_K);
2998 __glibcxx_assert(_M_N >= _M_n);
3006 successful_size() const
3010 unsuccessful_size() const
3011 { return _M_N - _M_K; }
3018 operator==(const param_type& __p1, const param_type& __p2)
3019 { return (__p1._M_N == __p2._M_N)
3020 && (__p1._M_K == __p2._M_K)
3021 && (__p1._M_n == __p2._M_n); }
3024 operator!=(const param_type& __p1, const param_type& __p2)
3025 { return !(__p1 == __p2); }
3034 // constructors and member functions
3036 hypergeometric_distribution() : hypergeometric_distribution(10) { }
3039 hypergeometric_distribution(result_type __N, result_type __K = 5,
3040 result_type __n = 1)
3041 : _M_param{__N, __K, __n}
3045 hypergeometric_distribution(const param_type& __p)
3050 * @brief Resets the distribution state.
3057 * @brief Returns the distribution parameter @p N,
3058 * the total number of items.
3062 { return this->_M_param.total_size(); }
3065 * @brief Returns the distribution parameter @p K,
3066 * the total number of successful items.
3069 successful_size() const
3070 { return this->_M_param.successful_size(); }
3073 * @brief Returns the total number of unsuccessful items @f$ N - K @f$.
3076 unsuccessful_size() const
3077 { return this->_M_param.unsuccessful_size(); }
3080 * @brief Returns the distribution parameter @p n,
3081 * the total number of draws.
3085 { return this->_M_param.total_draws(); }
3088 * @brief Returns the parameter set of the distribution.
3092 { return this->_M_param; }
3095 * @brief Sets the parameter set of the distribution.
3096 * @param __param The new parameter set of the distribution.
3099 param(const param_type& __param)
3100 { this->_M_param = __param; }
3103 * @brief Returns the greatest lower bound value of the distribution.
3108 using _IntType = typename std::make_signed<result_type>::type;
3109 return static_cast<result_type>(std::max(static_cast<_IntType>(0),
3110 static_cast<_IntType>(this->total_draws()
3111 - this->unsuccessful_size())));
3115 * @brief Returns the least upper bound value of the distribution.
3119 { return std::min(this->successful_size(), this->total_draws()); }
3122 * @brief Generating functions.
3124 template<typename _UniformRandomNumberGenerator>
3126 operator()(_UniformRandomNumberGenerator& __urng)
3127 { return this->operator()(__urng, this->_M_param); }
3129 template<typename _UniformRandomNumberGenerator>
3131 operator()(_UniformRandomNumberGenerator& __urng,
3132 const param_type& __p);
3134 template<typename _ForwardIterator,
3135 typename _UniformRandomNumberGenerator>
3137 __generate(_ForwardIterator __f, _ForwardIterator __t,
3138 _UniformRandomNumberGenerator& __urng)
3139 { this->__generate(__f, __t, __urng, this->_M_param); }
3141 template<typename _ForwardIterator,
3142 typename _UniformRandomNumberGenerator>
3144 __generate(_ForwardIterator __f, _ForwardIterator __t,
3145 _UniformRandomNumberGenerator& __urng,
3146 const param_type& __p)
3147 { this->__generate_impl(__f, __t, __urng, __p); }
3149 template<typename _UniformRandomNumberGenerator>
3151 __generate(result_type* __f, result_type* __t,
3152 _UniformRandomNumberGenerator& __urng,
3153 const param_type& __p)
3154 { this->__generate_impl(__f, __t, __urng, __p); }
3157 * @brief Return true if two hypergeometric distributions have the same
3158 * parameters and the sequences that would be generated
3162 operator==(const hypergeometric_distribution& __d1,
3163 const hypergeometric_distribution& __d2)
3164 { return __d1._M_param == __d2._M_param; }
3167 * @brief Inserts a %hypergeometric_distribution random number
3168 * distribution @p __x into the output stream @p __os.
3170 * @param __os An output stream.
3171 * @param __x A %hypergeometric_distribution random number
3174 * @returns The output stream with the state of @p __x inserted or in
3177 template<typename _UIntType1, typename _CharT, typename _Traits>
3178 friend std::basic_ostream<_CharT, _Traits>&
3179 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3180 const __gnu_cxx::hypergeometric_distribution<_UIntType1>&
3184 * @brief Extracts a %hypergeometric_distribution random number
3185 * distribution @p __x from the input stream @p __is.
3187 * @param __is An input stream.
3188 * @param __x A %hypergeometric_distribution random number generator
3191 * @returns The input stream with @p __x extracted or in an error
3194 template<typename _UIntType1, typename _CharT, typename _Traits>
3195 friend std::basic_istream<_CharT, _Traits>&
3196 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3197 __gnu_cxx::hypergeometric_distribution<_UIntType1>& __x);
3201 template<typename _ForwardIterator,
3202 typename _UniformRandomNumberGenerator>
3204 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3205 _UniformRandomNumberGenerator& __urng,
3206 const param_type& __p);
3208 param_type _M_param;
3212 * @brief Return true if two hypergeometric distributions are different.
3214 template<typename _UIntType>
3216 operator!=(const __gnu_cxx::hypergeometric_distribution<_UIntType>& __d1,
3217 const __gnu_cxx::hypergeometric_distribution<_UIntType>& __d2)
3218 { return !(__d1 == __d2); }
3221 * @brief A logistic continuous distribution for random numbers.
3223 * The formula for the logistic probability density function is
3225 * p(x|\a,\b) = \frac{e^{(x - a)/b}}{b[1 + e^{(x - a)/b}]^2}
3227 * where @f$b > 0@f$.
3229 * The formula for the logistic probability function is
3231 * cdf(x|\a,\b) = \frac{e^{(x - a)/b}}{1 + e^{(x - a)/b}}
3233 * where @f$b > 0@f$.
3235 * <table border=1 cellpadding=10 cellspacing=0>
3236 * <caption align=top>Distribution Statistics</caption>
3237 * <tr><td>Mean</td><td>@f$a@f$</td></tr>
3238 * <tr><td>Variance</td><td>@f$b^2\pi^2/3@f$</td></tr>
3239 * <tr><td>Range</td><td>@f$[0, \infty)@f$</td></tr>
3242 template<typename _RealType = double>
3244 logistic_distribution
3246 static_assert(std::is_floating_point<_RealType>::value,
3247 "template argument not a floating point type");
3250 /** The type of the range of the distribution. */
3251 typedef _RealType result_type;
3253 /** Parameter type. */
3256 typedef logistic_distribution<result_type> distribution_type;
3258 param_type() : param_type(0) { }
3261 param_type(result_type __a, result_type __b = result_type(1))
3262 : _M_a(__a), _M_b(__b)
3264 __glibcxx_assert(_M_b > result_type(0));
3276 operator==(const param_type& __p1, const param_type& __p2)
3277 { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; }
3280 operator!=(const param_type& __p1, const param_type& __p2)
3281 { return !(__p1 == __p2); }
3284 void _M_initialize();
3291 * @brief Constructors.
3294 logistic_distribution() : logistic_distribution(0.0) { }
3297 logistic_distribution(result_type __a, result_type __b = result_type(1))
3298 : _M_param(__a, __b)
3302 logistic_distribution(const param_type& __p)
3309 * @brief Resets the distribution state.
3316 * @brief Return the parameters of the distribution.
3320 { return _M_param.a(); }
3324 { return _M_param.b(); }
3327 * @brief Returns the parameter set of the distribution.
3331 { return _M_param; }
3334 * @brief Sets the parameter set of the distribution.
3335 * @param __param The new parameter set of the distribution.
3338 param(const param_type& __param)
3339 { _M_param = __param; }
3342 * @brief Returns the greatest lower bound value of the distribution.
3346 { return -std::numeric_limits<result_type>::max(); }
3349 * @brief Returns the least upper bound value of the distribution.
3353 { return std::numeric_limits<result_type>::max(); }
3356 * @brief Generating functions.
3358 template<typename _UniformRandomNumberGenerator>
3360 operator()(_UniformRandomNumberGenerator& __urng)
3361 { return this->operator()(__urng, this->_M_param); }
3363 template<typename _UniformRandomNumberGenerator>
3365 operator()(_UniformRandomNumberGenerator&,
3368 template<typename _ForwardIterator,
3369 typename _UniformRandomNumberGenerator>
3371 __generate(_ForwardIterator __f, _ForwardIterator __t,
3372 _UniformRandomNumberGenerator& __urng)
3373 { this->__generate(__f, __t, __urng, this->param()); }
3375 template<typename _ForwardIterator,
3376 typename _UniformRandomNumberGenerator>
3378 __generate(_ForwardIterator __f, _ForwardIterator __t,
3379 _UniformRandomNumberGenerator& __urng,
3380 const param_type& __p)
3381 { this->__generate_impl(__f, __t, __urng, __p); }
3383 template<typename _UniformRandomNumberGenerator>
3385 __generate(result_type* __f, result_type* __t,
3386 _UniformRandomNumberGenerator& __urng,
3387 const param_type& __p)
3388 { this->__generate_impl(__f, __t, __urng, __p); }
3391 * @brief Return true if two logistic distributions have
3392 * the same parameters and the sequences that would
3393 * be generated are equal.
3395 template<typename _RealType1>
3397 operator==(const logistic_distribution<_RealType1>& __d1,
3398 const logistic_distribution<_RealType1>& __d2)
3399 { return __d1.param() == __d2.param(); }
3402 * @brief Inserts a %logistic_distribution random number distribution
3403 * @p __x into the output stream @p __os.
3405 * @param __os An output stream.
3406 * @param __x A %logistic_distribution random number distribution.
3408 * @returns The output stream with the state of @p __x inserted or in
3411 template<typename _RealType1, typename _CharT, typename _Traits>
3412 friend std::basic_ostream<_CharT, _Traits>&
3413 operator<<(std::basic_ostream<_CharT, _Traits>&,
3414 const logistic_distribution<_RealType1>&);
3417 * @brief Extracts a %logistic_distribution random number distribution
3418 * @p __x from the input stream @p __is.
3420 * @param __is An input stream.
3421 * @param __x A %logistic_distribution random number
3424 * @returns The input stream with @p __x extracted or in an error state.
3426 template<typename _RealType1, typename _CharT, typename _Traits>
3427 friend std::basic_istream<_CharT, _Traits>&
3428 operator>>(std::basic_istream<_CharT, _Traits>&,
3429 logistic_distribution<_RealType1>&);
3432 template<typename _ForwardIterator,
3433 typename _UniformRandomNumberGenerator>
3435 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3436 _UniformRandomNumberGenerator& __urng,
3437 const param_type& __p);
3439 param_type _M_param;
3443 * @brief Return true if two logistic distributions are not equal.
3445 template<typename _RealType1>
3447 operator!=(const logistic_distribution<_RealType1>& __d1,
3448 const logistic_distribution<_RealType1>& __d2)
3449 { return !(__d1 == __d2); }
3453 * @brief A distribution for random coordinates on a unit sphere.
3455 * The method used in the generation function is attributed by Donald Knuth
3456 * to G. W. Brown, Modern Mathematics for the Engineer (1956).
3458 template<std::size_t _Dimen, typename _RealType = double>
3459 class uniform_on_sphere_distribution
3461 static_assert(std::is_floating_point<_RealType>::value,
3462 "template argument not a floating point type");
3463 static_assert(_Dimen != 0, "dimension is zero");
3466 /** The type of the range of the distribution. */
3467 typedef std::array<_RealType, _Dimen> result_type;
3469 /** Parameter type. */
3475 operator==(const param_type&, const param_type&)
3479 operator!=(const param_type&, const param_type&)
3484 * @brief Constructs a uniform on sphere distribution.
3486 uniform_on_sphere_distribution()
3487 : _M_param(), _M_nd()
3491 uniform_on_sphere_distribution(const param_type& __p)
3492 : _M_param(__p), _M_nd()
3496 * @brief Resets the distribution state.
3503 * @brief Returns the parameter set of the distribution.
3507 { return _M_param; }
3510 * @brief Sets the parameter set of the distribution.
3511 * @param __param The new parameter set of the distribution.
3514 param(const param_type& __param)
3515 { _M_param = __param; }
3518 * @brief Returns the greatest lower bound value of the distribution.
3519 * This function makes no sense for this distribution.
3530 * @brief Returns the least upper bound value of the distribution.
3531 * This function makes no sense for this distribution.
3542 * @brief Generating functions.
3544 template<typename _UniformRandomNumberGenerator>
3546 operator()(_UniformRandomNumberGenerator& __urng)
3547 { return this->operator()(__urng, _M_param); }
3549 template<typename _UniformRandomNumberGenerator>
3551 operator()(_UniformRandomNumberGenerator& __urng,
3552 const param_type& __p);
3554 template<typename _ForwardIterator,
3555 typename _UniformRandomNumberGenerator>
3557 __generate(_ForwardIterator __f, _ForwardIterator __t,
3558 _UniformRandomNumberGenerator& __urng)
3559 { this->__generate(__f, __t, __urng, this->param()); }
3561 template<typename _ForwardIterator,
3562 typename _UniformRandomNumberGenerator>
3564 __generate(_ForwardIterator __f, _ForwardIterator __t,
3565 _UniformRandomNumberGenerator& __urng,
3566 const param_type& __p)
3567 { this->__generate_impl(__f, __t, __urng, __p); }
3569 template<typename _UniformRandomNumberGenerator>
3571 __generate(result_type* __f, result_type* __t,
3572 _UniformRandomNumberGenerator& __urng,
3573 const param_type& __p)
3574 { this->__generate_impl(__f, __t, __urng, __p); }
3577 * @brief Return true if two uniform on sphere distributions have
3578 * the same parameters and the sequences that would be
3579 * generated are equal.
3582 operator==(const uniform_on_sphere_distribution& __d1,
3583 const uniform_on_sphere_distribution& __d2)
3584 { return __d1._M_nd == __d2._M_nd; }
3587 * @brief Inserts a %uniform_on_sphere_distribution random number
3588 * distribution @p __x into the output stream @p __os.
3590 * @param __os An output stream.
3591 * @param __x A %uniform_on_sphere_distribution random number
3594 * @returns The output stream with the state of @p __x inserted or in
3597 template<size_t _Dimen1, typename _RealType1, typename _CharT,
3599 friend std::basic_ostream<_CharT, _Traits>&
3600 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3601 const __gnu_cxx::uniform_on_sphere_distribution<_Dimen1,
3606 * @brief Extracts a %uniform_on_sphere_distribution random number
3608 * @p __x from the input stream @p __is.
3610 * @param __is An input stream.
3611 * @param __x A %uniform_on_sphere_distribution random number
3614 * @returns The input stream with @p __x extracted or in an error state.
3616 template<std::size_t _Dimen1, typename _RealType1, typename _CharT,
3618 friend std::basic_istream<_CharT, _Traits>&
3619 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3620 __gnu_cxx::uniform_on_sphere_distribution<_Dimen1,
3624 template<typename _ForwardIterator,
3625 typename _UniformRandomNumberGenerator>
3627 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3628 _UniformRandomNumberGenerator& __urng,
3629 const param_type& __p);
3631 param_type _M_param;
3632 std::normal_distribution<_RealType> _M_nd;
3636 * @brief Return true if two uniform on sphere distributions are different.
3638 template<std::size_t _Dimen, typename _RealType>
3640 operator!=(const __gnu_cxx::uniform_on_sphere_distribution<_Dimen,
3642 const __gnu_cxx::uniform_on_sphere_distribution<_Dimen,
3644 { return !(__d1 == __d2); }
3648 * @brief A distribution for random coordinates inside a unit sphere.
3650 template<std::size_t _Dimen, typename _RealType = double>
3651 class uniform_inside_sphere_distribution
3653 static_assert(std::is_floating_point<_RealType>::value,
3654 "template argument not a floating point type");
3655 static_assert(_Dimen != 0, "dimension is zero");
3658 /** The type of the range of the distribution. */
3659 using result_type = std::array<_RealType, _Dimen>;
3661 /** Parameter type. */
3664 using distribution_type
3665 = uniform_inside_sphere_distribution<_Dimen, _RealType>;
3666 friend class uniform_inside_sphere_distribution<_Dimen, _RealType>;
3668 param_type() : param_type(1.0) { }
3671 param_type(_RealType __radius)
3672 : _M_radius(__radius)
3674 __glibcxx_assert(_M_radius > _RealType(0));
3679 { return _M_radius; }
3682 operator==(const param_type& __p1, const param_type& __p2)
3683 { return __p1._M_radius == __p2._M_radius; }
3686 operator!=(const param_type& __p1, const param_type& __p2)
3687 { return !(__p1 == __p2); }
3690 _RealType _M_radius;
3694 * @brief Constructors.
3698 uniform_inside_sphere_distribution()
3699 : uniform_inside_sphere_distribution(1.0)
3703 uniform_inside_sphere_distribution(_RealType __radius)
3704 : _M_param(__radius), _M_uosd()
3708 uniform_inside_sphere_distribution(const param_type& __p)
3709 : _M_param(__p), _M_uosd()
3715 * @brief Resets the distribution state.
3719 { _M_uosd.reset(); }
3722 * @brief Returns the @f$radius@f$ of the distribution.
3726 { return _M_param.radius(); }
3729 * @brief Returns the parameter set of the distribution.
3733 { return _M_param; }
3736 * @brief Sets the parameter set of the distribution.
3737 * @param __param The new parameter set of the distribution.
3740 param(const param_type& __param)
3741 { _M_param = __param; }
3744 * @brief Returns the greatest lower bound value of the distribution.
3745 * This function makes no sense for this distribution.
3756 * @brief Returns the least upper bound value of the distribution.
3757 * This function makes no sense for this distribution.
3768 * @brief Generating functions.
3770 template<typename _UniformRandomNumberGenerator>
3772 operator()(_UniformRandomNumberGenerator& __urng)
3773 { return this->operator()(__urng, _M_param); }
3775 template<typename _UniformRandomNumberGenerator>
3777 operator()(_UniformRandomNumberGenerator& __urng,
3778 const param_type& __p);
3780 template<typename _ForwardIterator,
3781 typename _UniformRandomNumberGenerator>
3783 __generate(_ForwardIterator __f, _ForwardIterator __t,
3784 _UniformRandomNumberGenerator& __urng)
3785 { this->__generate(__f, __t, __urng, this->param()); }
3787 template<typename _ForwardIterator,
3788 typename _UniformRandomNumberGenerator>
3790 __generate(_ForwardIterator __f, _ForwardIterator __t,
3791 _UniformRandomNumberGenerator& __urng,
3792 const param_type& __p)
3793 { this->__generate_impl(__f, __t, __urng, __p); }
3795 template<typename _UniformRandomNumberGenerator>
3797 __generate(result_type* __f, result_type* __t,
3798 _UniformRandomNumberGenerator& __urng,
3799 const param_type& __p)
3800 { this->__generate_impl(__f, __t, __urng, __p); }
3803 * @brief Return true if two uniform on sphere distributions have
3804 * the same parameters and the sequences that would be
3805 * generated are equal.
3808 operator==(const uniform_inside_sphere_distribution& __d1,
3809 const uniform_inside_sphere_distribution& __d2)
3810 { return __d1._M_param == __d2._M_param && __d1._M_uosd == __d2._M_uosd; }
3813 * @brief Inserts a %uniform_inside_sphere_distribution random number
3814 * distribution @p __x into the output stream @p __os.
3816 * @param __os An output stream.
3817 * @param __x A %uniform_inside_sphere_distribution random number
3820 * @returns The output stream with the state of @p __x inserted or in
3823 template<size_t _Dimen1, typename _RealType1, typename _CharT,
3825 friend std::basic_ostream<_CharT, _Traits>&
3826 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3827 const __gnu_cxx::uniform_inside_sphere_distribution<_Dimen1,
3832 * @brief Extracts a %uniform_inside_sphere_distribution random number
3834 * @p __x from the input stream @p __is.
3836 * @param __is An input stream.
3837 * @param __x A %uniform_inside_sphere_distribution random number
3840 * @returns The input stream with @p __x extracted or in an error state.
3842 template<std::size_t _Dimen1, typename _RealType1, typename _CharT,
3844 friend std::basic_istream<_CharT, _Traits>&
3845 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3846 __gnu_cxx::uniform_inside_sphere_distribution<_Dimen1,
3850 template<typename _ForwardIterator,
3851 typename _UniformRandomNumberGenerator>
3853 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3854 _UniformRandomNumberGenerator& __urng,
3855 const param_type& __p);
3857 param_type _M_param;
3858 uniform_on_sphere_distribution<_Dimen, _RealType> _M_uosd;
3862 * @brief Return true if two uniform on sphere distributions are different.
3864 template<std::size_t _Dimen, typename _RealType>
3866 operator!=(const __gnu_cxx::uniform_inside_sphere_distribution<_Dimen,
3868 const __gnu_cxx::uniform_inside_sphere_distribution<_Dimen,
3870 { return !(__d1 == __d2); }
3872 _GLIBCXX_END_NAMESPACE_VERSION
3873 } // namespace __gnu_cxx
3875 #include <ext/opt_random.h>
3876 #include <ext/random.tcc>
3878 #endif // _GLIBCXX_USE_C99_STDINT_TR1 && UINT32_C
3882 #endif // _EXT_RANDOM