- tmp/tmpw5eghois/{from.md → to.md} +217 -269
tmp/tmpw5eghois/{from.md → to.md}
RENAMED
|
@@ -1,47 +1,46 @@
|
|
| 1 |
### Random number distribution class templates <a id="rand.dist">[[rand.dist]]</a>
|
| 2 |
|
| 3 |
#### In general <a id="rand.dist.general">[[rand.dist.general]]</a>
|
| 4 |
|
| 5 |
-
Each type instantiated from a class template specified in this
|
| 6 |
-
[[rand.dist]]
|
| 7 |
-
distribution
|
| 8 |
|
| 9 |
-
Descriptions are provided in this
|
| 10 |
distribution operations that are not described in [[rand.req.dist]] or
|
| 11 |
for operations where there is additional semantic information. In
|
| 12 |
particular, declarations for copy constructors, for copy assignment
|
| 13 |
operators, for streaming operators, and for equality and inequality
|
| 14 |
operators are not shown in the synopses.
|
| 15 |
|
| 16 |
The algorithms for producing each of the specified distributions are
|
| 17 |
*implementation-defined*.
|
| 18 |
|
| 19 |
The value of each probability density function p(z) and of each discrete
|
| 20 |
-
probability function P(zᵢ) specified in this
|
| 21 |
outside its stated domain.
|
| 22 |
|
| 23 |
#### Uniform distributions <a id="rand.dist.uni">[[rand.dist.uni]]</a>
|
| 24 |
|
| 25 |
##### Class template `uniform_int_distribution` <a id="rand.dist.uni.int">[[rand.dist.uni.int]]</a>
|
| 26 |
|
| 27 |
A `uniform_int_distribution` random number distribution produces random
|
| 28 |
integers i, a ≤ i ≤ b, distributed according to the constant discrete
|
| 29 |
-
probability function $$
|
| 30 |
-
P(i\,|\,a,b) = 1 / (b - a + 1)
|
| 31 |
-
\; \mbox{.}$$
|
| 32 |
|
| 33 |
``` cpp
|
| 34 |
template<class IntType = int>
|
| 35 |
class uniform_int_distribution {
|
| 36 |
public:
|
| 37 |
// types
|
| 38 |
using result_type = IntType;
|
| 39 |
using param_type = unspecified;
|
| 40 |
|
| 41 |
// constructors and reset functions
|
| 42 |
-
|
|
|
|
| 43 |
explicit uniform_int_distribution(const param_type& parm);
|
| 44 |
void reset();
|
| 45 |
|
| 46 |
// generating functions
|
| 47 |
template<class URBG>
|
|
@@ -58,17 +57,17 @@ template<class IntType = int>
|
|
| 58 |
result_type max() const;
|
| 59 |
};
|
| 60 |
```
|
| 61 |
|
| 62 |
``` cpp
|
| 63 |
-
explicit uniform_int_distribution(IntType a
|
| 64 |
```
|
| 65 |
|
| 66 |
-
*
|
| 67 |
|
| 68 |
-
*
|
| 69 |
-
|
| 70 |
|
| 71 |
``` cpp
|
| 72 |
result_type a() const;
|
| 73 |
```
|
| 74 |
|
|
@@ -84,13 +83,11 @@ constructed.
|
|
| 84 |
|
| 85 |
##### Class template `uniform_real_distribution` <a id="rand.dist.uni.real">[[rand.dist.uni.real]]</a>
|
| 86 |
|
| 87 |
A `uniform_real_distribution` random number distribution produces random
|
| 88 |
numbers x, a ≤ x < b, distributed according to the constant probability
|
| 89 |
-
density function $$
|
| 90 |
-
p(x\,|\,a,b) = 1 / (b - a)
|
| 91 |
-
\; \mbox{.}$$
|
| 92 |
|
| 93 |
[*Note 1*: This implies that p(x | a,b) is undefined when
|
| 94 |
`a == b`. — *end note*]
|
| 95 |
|
| 96 |
``` cpp
|
|
@@ -100,11 +97,12 @@ template<class RealType = double>
|
|
| 100 |
// types
|
| 101 |
using result_type = RealType;
|
| 102 |
using param_type = unspecified;
|
| 103 |
|
| 104 |
// constructors and reset functions
|
| 105 |
-
|
|
|
|
| 106 |
explicit uniform_real_distribution(const param_type& parm);
|
| 107 |
void reset();
|
| 108 |
|
| 109 |
// generating functions
|
| 110 |
template<class URBG>
|
|
@@ -121,17 +119,18 @@ template<class RealType = double>
|
|
| 121 |
result_type max() const;
|
| 122 |
};
|
| 123 |
```
|
| 124 |
|
| 125 |
``` cpp
|
| 126 |
-
explicit uniform_real_distribution(RealType a
|
| 127 |
```
|
| 128 |
|
| 129 |
-
*
|
|
|
|
| 130 |
|
| 131 |
-
*
|
| 132 |
-
|
| 133 |
|
| 134 |
``` cpp
|
| 135 |
result_type a() const;
|
| 136 |
```
|
| 137 |
|
|
@@ -148,27 +147,26 @@ constructed.
|
|
| 148 |
#### Bernoulli distributions <a id="rand.dist.bern">[[rand.dist.bern]]</a>
|
| 149 |
|
| 150 |
##### Class `bernoulli_distribution` <a id="rand.dist.bern.bernoulli">[[rand.dist.bern.bernoulli]]</a>
|
| 151 |
|
| 152 |
A `bernoulli_distribution` random number distribution produces `bool`
|
| 153 |
-
values b distributed according to the discrete probability function
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
\end{array}\right.
|
| 159 |
-
\; \mbox{.}$$
|
| 160 |
|
| 161 |
``` cpp
|
| 162 |
class bernoulli_distribution {
|
| 163 |
public:
|
| 164 |
// types
|
| 165 |
using result_type = bool;
|
| 166 |
using param_type = unspecified;
|
| 167 |
|
| 168 |
// constructors and reset functions
|
| 169 |
-
|
|
|
|
| 170 |
explicit bernoulli_distribution(const param_type& parm);
|
| 171 |
void reset();
|
| 172 |
|
| 173 |
// generating functions
|
| 174 |
template<class URBG>
|
|
@@ -184,17 +182,16 @@ public:
|
|
| 184 |
result_type max() const;
|
| 185 |
};
|
| 186 |
```
|
| 187 |
|
| 188 |
``` cpp
|
| 189 |
-
explicit bernoulli_distribution(double p
|
| 190 |
```
|
| 191 |
|
| 192 |
-
*
|
| 193 |
|
| 194 |
-
*
|
| 195 |
-
to the parameter of the distribution.
|
| 196 |
|
| 197 |
``` cpp
|
| 198 |
double p() const;
|
| 199 |
```
|
| 200 |
|
|
@@ -203,25 +200,23 @@ constructed.
|
|
| 203 |
|
| 204 |
##### Class template `binomial_distribution` <a id="rand.dist.bern.bin">[[rand.dist.bern.bin]]</a>
|
| 205 |
|
| 206 |
A `binomial_distribution` random number distribution produces integer
|
| 207 |
values i ≥ 0 distributed according to the discrete probability function
|
| 208 |
-
$$
|
| 209 |
-
P(i\,|\,t,p)
|
| 210 |
-
= \binom{t}{i} \cdot p^i \cdot (1-p)^{t-i}
|
| 211 |
-
\; \mbox{.}$$
|
| 212 |
|
| 213 |
``` cpp
|
| 214 |
template<class IntType = int>
|
| 215 |
class binomial_distribution {
|
| 216 |
public:
|
| 217 |
// types
|
| 218 |
using result_type = IntType;
|
| 219 |
using param_type = unspecified;
|
| 220 |
|
| 221 |
// constructors and reset functions
|
| 222 |
-
|
|
|
|
| 223 |
explicit binomial_distribution(const param_type& parm);
|
| 224 |
void reset();
|
| 225 |
|
| 226 |
// generating functions
|
| 227 |
template<class URBG>
|
|
@@ -238,17 +233,17 @@ template<class IntType = int>
|
|
| 238 |
result_type max() const;
|
| 239 |
};
|
| 240 |
```
|
| 241 |
|
| 242 |
``` cpp
|
| 243 |
-
explicit binomial_distribution(IntType t
|
| 244 |
```
|
| 245 |
|
| 246 |
-
*
|
| 247 |
|
| 248 |
-
*
|
| 249 |
-
|
| 250 |
|
| 251 |
``` cpp
|
| 252 |
IntType t() const;
|
| 253 |
```
|
| 254 |
|
|
@@ -264,25 +259,23 @@ constructed.
|
|
| 264 |
|
| 265 |
##### Class template `geometric_distribution` <a id="rand.dist.bern.geo">[[rand.dist.bern.geo]]</a>
|
| 266 |
|
| 267 |
A `geometric_distribution` random number distribution produces integer
|
| 268 |
values i ≥ 0 distributed according to the discrete probability function
|
| 269 |
-
$$
|
| 270 |
-
P(i\,|\,p)
|
| 271 |
-
= p \cdot (1-p)^{i}
|
| 272 |
-
\; \mbox{.}$$
|
| 273 |
|
| 274 |
``` cpp
|
| 275 |
template<class IntType = int>
|
| 276 |
class geometric_distribution {
|
| 277 |
public:
|
| 278 |
// types
|
| 279 |
using result_type = IntType;
|
| 280 |
using param_type = unspecified;
|
| 281 |
|
| 282 |
// constructors and reset functions
|
| 283 |
-
|
|
|
|
| 284 |
explicit geometric_distribution(const param_type& parm);
|
| 285 |
void reset();
|
| 286 |
|
| 287 |
// generating functions
|
| 288 |
template<class URBG>
|
|
@@ -298,17 +291,16 @@ template<class IntType = int>
|
|
| 298 |
result_type max() const;
|
| 299 |
};
|
| 300 |
```
|
| 301 |
|
| 302 |
``` cpp
|
| 303 |
-
explicit geometric_distribution(double p
|
| 304 |
```
|
| 305 |
|
| 306 |
-
*
|
| 307 |
|
| 308 |
-
*
|
| 309 |
-
to the parameter of the distribution.
|
| 310 |
|
| 311 |
``` cpp
|
| 312 |
double p() const;
|
| 313 |
```
|
| 314 |
|
|
@@ -317,14 +309,12 @@ constructed.
|
|
| 317 |
|
| 318 |
##### Class template `negative_binomial_distribution` <a id="rand.dist.bern.negbin">[[rand.dist.bern.negbin]]</a>
|
| 319 |
|
| 320 |
A `negative_binomial_distribution` random number distribution produces
|
| 321 |
random integers i ≥ 0 distributed according to the discrete probability
|
| 322 |
-
function
|
| 323 |
-
|
| 324 |
-
= \binom{k+i-1}{i} \cdot p^k \cdot (1-p)^i
|
| 325 |
-
\; \mbox{.}$$
|
| 326 |
|
| 327 |
[*Note 1*: This implies that P(i | k,p) is undefined when
|
| 328 |
`p == 1`. — *end note*]
|
| 329 |
|
| 330 |
``` cpp
|
|
@@ -334,11 +324,12 @@ template<class IntType = int>
|
|
| 334 |
// types
|
| 335 |
using result_type = IntType;
|
| 336 |
using param_type = unspecified;
|
| 337 |
|
| 338 |
// constructor and reset functions
|
| 339 |
-
|
|
|
|
| 340 |
explicit negative_binomial_distribution(const param_type& parm);
|
| 341 |
void reset();
|
| 342 |
|
| 343 |
// generating functions
|
| 344 |
template<class URBG>
|
|
@@ -355,17 +346,17 @@ template<class IntType = int>
|
|
| 355 |
result_type max() const;
|
| 356 |
};
|
| 357 |
```
|
| 358 |
|
| 359 |
``` cpp
|
| 360 |
-
explicit negative_binomial_distribution(IntType k
|
| 361 |
```
|
| 362 |
|
| 363 |
-
*
|
| 364 |
|
| 365 |
-
*
|
| 366 |
-
|
| 367 |
|
| 368 |
``` cpp
|
| 369 |
IntType k() const;
|
| 370 |
```
|
| 371 |
|
|
@@ -383,16 +374,12 @@ constructed.
|
|
| 383 |
|
| 384 |
##### Class template `poisson_distribution` <a id="rand.dist.pois.poisson">[[rand.dist.pois.poisson]]</a>
|
| 385 |
|
| 386 |
A `poisson_distribution` random number distribution produces integer
|
| 387 |
values i ≥ 0 distributed according to the discrete probability function
|
| 388 |
-
$$
|
| 389 |
-
|
| 390 |
-
= \frac{ e^{-\mu} \mu^{i} }
|
| 391 |
-
{ i\,! }
|
| 392 |
-
\; \mbox{.}$$ The distribution parameter μ is also known as this
|
| 393 |
-
distribution’s *mean* .
|
| 394 |
|
| 395 |
``` cpp
|
| 396 |
template<class IntType = int>
|
| 397 |
class poisson_distribution
|
| 398 |
{
|
|
@@ -400,11 +387,12 @@ template<class IntType = int>
|
|
| 400 |
// types
|
| 401 |
using result_type = IntType;
|
| 402 |
using param_type = unspecified;
|
| 403 |
|
| 404 |
// constructors and reset functions
|
| 405 |
-
|
|
|
|
| 406 |
explicit poisson_distribution(const param_type& parm);
|
| 407 |
void reset();
|
| 408 |
|
| 409 |
// generating functions
|
| 410 |
template<class URBG>
|
|
@@ -420,17 +408,16 @@ template<class IntType = int>
|
|
| 420 |
result_type max() const;
|
| 421 |
};
|
| 422 |
```
|
| 423 |
|
| 424 |
``` cpp
|
| 425 |
-
explicit poisson_distribution(double mean
|
| 426 |
```
|
| 427 |
|
| 428 |
-
*
|
| 429 |
|
| 430 |
-
*
|
| 431 |
-
corresponds to the parameter of the distribution.
|
| 432 |
|
| 433 |
``` cpp
|
| 434 |
double mean() const;
|
| 435 |
```
|
| 436 |
|
|
@@ -439,25 +426,23 @@ constructed.
|
|
| 439 |
|
| 440 |
##### Class template `exponential_distribution` <a id="rand.dist.pois.exp">[[rand.dist.pois.exp]]</a>
|
| 441 |
|
| 442 |
An `exponential_distribution` random number distribution produces random
|
| 443 |
numbers x > 0 distributed according to the probability density function
|
| 444 |
-
$$
|
| 445 |
-
p(x\,|\,\lambda)
|
| 446 |
-
= \lambda e^{-\lambda x}
|
| 447 |
-
\; \mbox{.}$$
|
| 448 |
|
| 449 |
``` cpp
|
| 450 |
template<class RealType = double>
|
| 451 |
class exponential_distribution {
|
| 452 |
public:
|
| 453 |
// types
|
| 454 |
using result_type = RealType;
|
| 455 |
using param_type = unspecified;
|
| 456 |
|
| 457 |
// constructors and reset functions
|
| 458 |
-
|
|
|
|
| 459 |
explicit exponential_distribution(const param_type& parm);
|
| 460 |
void reset();
|
| 461 |
|
| 462 |
// generating functions
|
| 463 |
template<class URBG>
|
|
@@ -473,17 +458,16 @@ template<class RealType = double>
|
|
| 473 |
result_type max() const;
|
| 474 |
};
|
| 475 |
```
|
| 476 |
|
| 477 |
``` cpp
|
| 478 |
-
explicit exponential_distribution(RealType lambda
|
| 479 |
```
|
| 480 |
|
| 481 |
-
*
|
| 482 |
|
| 483 |
-
*
|
| 484 |
-
corresponds to the parameter of the distribution.
|
| 485 |
|
| 486 |
``` cpp
|
| 487 |
RealType lambda() const;
|
| 488 |
```
|
| 489 |
|
|
@@ -492,26 +476,25 @@ constructed.
|
|
| 492 |
|
| 493 |
##### Class template `gamma_distribution` <a id="rand.dist.pois.gamma">[[rand.dist.pois.gamma]]</a>
|
| 494 |
|
| 495 |
A `gamma_distribution` random number distribution produces random
|
| 496 |
numbers x > 0 distributed according to the probability density function
|
| 497 |
-
$$
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
\, \cdot \, x^{\, \alpha-1}
|
| 501 |
-
\; \mbox{.}$$
|
| 502 |
|
| 503 |
``` cpp
|
| 504 |
template<class RealType = double>
|
| 505 |
class gamma_distribution {
|
| 506 |
public:
|
| 507 |
// types
|
| 508 |
using result_type = RealType;
|
| 509 |
using param_type = unspecified;
|
| 510 |
|
| 511 |
// constructors and reset functions
|
| 512 |
-
|
|
|
|
| 513 |
explicit gamma_distribution(const param_type& parm);
|
| 514 |
void reset();
|
| 515 |
|
| 516 |
// generating functions
|
| 517 |
template<class URBG>
|
|
@@ -528,17 +511,17 @@ template<class RealType = double>
|
|
| 528 |
result_type max() const;
|
| 529 |
};
|
| 530 |
```
|
| 531 |
|
| 532 |
``` cpp
|
| 533 |
-
explicit gamma_distribution(RealType alpha
|
| 534 |
```
|
| 535 |
|
| 536 |
-
*
|
| 537 |
|
| 538 |
-
*
|
| 539 |
-
|
| 540 |
|
| 541 |
``` cpp
|
| 542 |
RealType alpha() const;
|
| 543 |
```
|
| 544 |
|
|
@@ -554,27 +537,26 @@ constructed.
|
|
| 554 |
|
| 555 |
##### Class template `weibull_distribution` <a id="rand.dist.pois.weibull">[[rand.dist.pois.weibull]]</a>
|
| 556 |
|
| 557 |
A `weibull_distribution` random number distribution produces random
|
| 558 |
numbers x ≥ 0 distributed according to the probability density function
|
| 559 |
-
$$
|
| 560 |
-
p(x\,|\,a,b)
|
| 561 |
-
= \frac{a}{b}
|
| 562 |
\cdot \left(\frac{x}{b}\right)^{a-1}
|
| 563 |
\cdot \, \exp\left( -\left(\frac{x}{b}\right)^a\right)
|
| 564 |
-
\
|
| 565 |
|
| 566 |
``` cpp
|
| 567 |
template<class RealType = double>
|
| 568 |
class weibull_distribution {
|
| 569 |
public:
|
| 570 |
// types
|
| 571 |
using result_type = RealType;
|
| 572 |
using param_type = unspecified;
|
| 573 |
|
| 574 |
// constructor and reset functions
|
| 575 |
-
|
|
|
|
| 576 |
explicit weibull_distribution(const param_type& parm);
|
| 577 |
void reset();
|
| 578 |
|
| 579 |
// generating functions
|
| 580 |
template<class URBG>
|
|
@@ -591,17 +573,17 @@ template<class RealType = double>
|
|
| 591 |
result_type max() const;
|
| 592 |
};
|
| 593 |
```
|
| 594 |
|
| 595 |
``` cpp
|
| 596 |
-
explicit weibull_distribution(RealType a
|
| 597 |
```
|
| 598 |
|
| 599 |
-
*
|
| 600 |
|
| 601 |
-
*
|
| 602 |
-
|
| 603 |
|
| 604 |
``` cpp
|
| 605 |
RealType a() const;
|
| 606 |
```
|
| 607 |
|
|
@@ -617,28 +599,25 @@ constructed.
|
|
| 617 |
|
| 618 |
##### Class template `extreme_value_distribution` <a id="rand.dist.pois.extreme">[[rand.dist.pois.extreme]]</a>
|
| 619 |
|
| 620 |
An `extreme_value_distribution` random number distribution produces
|
| 621 |
random numbers x distributed according to the probability density
|
| 622 |
-
function[^6] $$
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
\cdot \exp\left( \frac{a-x}{b}
|
| 626 |
-
\,-\, \exp\left(\frac{a-x}{b}\right)
|
| 627 |
-
\right)
|
| 628 |
-
\; \mbox{.}$$
|
| 629 |
|
| 630 |
``` cpp
|
| 631 |
template<class RealType = double>
|
| 632 |
class extreme_value_distribution {
|
| 633 |
public:
|
| 634 |
// types
|
| 635 |
using result_type = RealType;
|
| 636 |
using param_type = unspecified;
|
| 637 |
|
| 638 |
// constructor and reset functions
|
| 639 |
-
|
|
|
|
| 640 |
explicit extreme_value_distribution(const param_type& parm);
|
| 641 |
void reset();
|
| 642 |
|
| 643 |
// generating functions
|
| 644 |
template<class URBG>
|
|
@@ -655,17 +634,17 @@ template<class RealType = double>
|
|
| 655 |
result_type max() const;
|
| 656 |
};
|
| 657 |
```
|
| 658 |
|
| 659 |
``` cpp
|
| 660 |
-
explicit extreme_value_distribution(RealType a
|
| 661 |
```
|
| 662 |
|
| 663 |
-
*
|
| 664 |
|
| 665 |
-
*
|
| 666 |
-
|
| 667 |
|
| 668 |
``` cpp
|
| 669 |
RealType a() const;
|
| 670 |
```
|
| 671 |
|
|
@@ -691,11 +670,11 @@ numbers x distributed according to the probability density function $$%
|
|
| 691 |
% e^{-(x-\mu)^2 / (2\sigma^2)}
|
| 692 |
\exp{\left(- \, \frac{(x - \mu)^2}
|
| 693 |
{2 \sigma^2}
|
| 694 |
\right)
|
| 695 |
}
|
| 696 |
-
|
| 697 |
distribution’s *mean* and *standard deviation* .
|
| 698 |
|
| 699 |
``` cpp
|
| 700 |
template<class RealType = double>
|
| 701 |
class normal_distribution {
|
|
@@ -703,11 +682,12 @@ template<class RealType = double>
|
|
| 703 |
// types
|
| 704 |
using result_type = RealType;
|
| 705 |
using param_type = unspecified;
|
| 706 |
|
| 707 |
// constructors and reset functions
|
| 708 |
-
|
|
|
|
| 709 |
explicit normal_distribution(const param_type& parm);
|
| 710 |
void reset();
|
| 711 |
|
| 712 |
// generating functions
|
| 713 |
template<class URBG>
|
|
@@ -724,17 +704,17 @@ template<class RealType = double>
|
|
| 724 |
result_type max() const;
|
| 725 |
};
|
| 726 |
```
|
| 727 |
|
| 728 |
``` cpp
|
| 729 |
-
explicit normal_distribution(RealType mean
|
| 730 |
```
|
| 731 |
|
| 732 |
-
*
|
| 733 |
|
| 734 |
-
*
|
| 735 |
-
|
| 736 |
|
| 737 |
``` cpp
|
| 738 |
RealType mean() const;
|
| 739 |
```
|
| 740 |
|
|
@@ -750,31 +730,25 @@ constructed.
|
|
| 750 |
|
| 751 |
##### Class template `lognormal_distribution` <a id="rand.dist.norm.lognormal">[[rand.dist.norm.lognormal]]</a>
|
| 752 |
|
| 753 |
A `lognormal_distribution` random number distribution produces random
|
| 754 |
numbers x > 0 distributed according to the probability density function
|
| 755 |
-
$$
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
{s x \sqrt{2 \pi}}
|
| 759 |
-
\cdot
|
| 760 |
-
\exp{\left(- \, \frac{(\ln{x} - m)^2}
|
| 761 |
-
{2 s^2}
|
| 762 |
-
\right)
|
| 763 |
-
}
|
| 764 |
-
\; \mbox{.}$$
|
| 765 |
|
| 766 |
``` cpp
|
| 767 |
template<class RealType = double>
|
| 768 |
class lognormal_distribution {
|
| 769 |
public:
|
| 770 |
// types
|
| 771 |
using result_type = RealType;
|
| 772 |
using param_type = unspecified;
|
| 773 |
|
| 774 |
// constructor and reset functions
|
| 775 |
-
|
|
|
|
| 776 |
explicit lognormal_distribution(const param_type& parm);
|
| 777 |
void reset();
|
| 778 |
|
| 779 |
// generating functions
|
| 780 |
template<class URBG>
|
|
@@ -791,17 +765,17 @@ template<class RealType = double>
|
|
| 791 |
result_type max() const;
|
| 792 |
};
|
| 793 |
```
|
| 794 |
|
| 795 |
``` cpp
|
| 796 |
-
explicit lognormal_distribution(RealType m
|
| 797 |
```
|
| 798 |
|
| 799 |
-
*
|
| 800 |
|
| 801 |
-
*
|
| 802 |
-
|
| 803 |
|
| 804 |
``` cpp
|
| 805 |
RealType m() const;
|
| 806 |
```
|
| 807 |
|
|
@@ -817,26 +791,23 @@ constructed.
|
|
| 817 |
|
| 818 |
##### Class template `chi_squared_distribution` <a id="rand.dist.norm.chisq">[[rand.dist.norm.chisq]]</a>
|
| 819 |
|
| 820 |
A `chi_squared_distribution` random number distribution produces random
|
| 821 |
numbers x > 0 distributed according to the probability density function
|
| 822 |
-
$$
|
| 823 |
-
p(x\,|\,n)
|
| 824 |
-
= \frac{ x^{(n/2)-1} \cdot e^{-x/2}}
|
| 825 |
-
{\Gamma(n/2) \cdot 2^{n/2}}
|
| 826 |
-
\; \mbox{.}$$
|
| 827 |
|
| 828 |
``` cpp
|
| 829 |
template<class RealType = double>
|
| 830 |
class chi_squared_distribution {
|
| 831 |
public:
|
| 832 |
// types
|
| 833 |
using result_type = RealType;
|
| 834 |
using param_type = unspecified;
|
| 835 |
|
| 836 |
// constructor and reset functions
|
| 837 |
-
|
|
|
|
| 838 |
explicit chi_squared_distribution(const param_type& parm);
|
| 839 |
void reset();
|
| 840 |
|
| 841 |
// generating functions
|
| 842 |
template<class URBG>
|
|
@@ -852,17 +823,16 @@ template<class RealType = double>
|
|
| 852 |
result_type max() const;
|
| 853 |
};
|
| 854 |
```
|
| 855 |
|
| 856 |
``` cpp
|
| 857 |
-
explicit chi_squared_distribution(RealType n
|
| 858 |
```
|
| 859 |
|
| 860 |
-
*
|
| 861 |
|
| 862 |
-
*
|
| 863 |
-
corresponds to the parameter of the distribution.
|
| 864 |
|
| 865 |
``` cpp
|
| 866 |
RealType n() const;
|
| 867 |
```
|
| 868 |
|
|
@@ -870,25 +840,24 @@ RealType n() const;
|
|
| 870 |
constructed.
|
| 871 |
|
| 872 |
##### Class template `cauchy_distribution` <a id="rand.dist.norm.cauchy">[[rand.dist.norm.cauchy]]</a>
|
| 873 |
|
| 874 |
A `cauchy_distribution` random number distribution produces random
|
| 875 |
-
numbers x distributed according to the probability density function
|
| 876 |
-
|
| 877 |
-
= \left( \pi b \left( 1 + \left( \frac{x-a}{b} \right)^2 \;\right)\right)^{-1}
|
| 878 |
-
\; \mbox{.}$$
|
| 879 |
|
| 880 |
``` cpp
|
| 881 |
template<class RealType = double>
|
| 882 |
class cauchy_distribution {
|
| 883 |
public:
|
| 884 |
// types
|
| 885 |
using result_type = RealType;
|
| 886 |
using param_type = unspecified;
|
| 887 |
|
| 888 |
// constructor and reset functions
|
| 889 |
-
|
|
|
|
| 890 |
explicit cauchy_distribution(const param_type& parm);
|
| 891 |
void reset();
|
| 892 |
|
| 893 |
// generating functions
|
| 894 |
template<class URBG>
|
|
@@ -905,17 +874,17 @@ template<class RealType = double>
|
|
| 905 |
result_type max() const;
|
| 906 |
};
|
| 907 |
```
|
| 908 |
|
| 909 |
``` cpp
|
| 910 |
-
explicit cauchy_distribution(RealType a
|
| 911 |
```
|
| 912 |
|
| 913 |
-
*
|
| 914 |
|
| 915 |
-
*
|
| 916 |
-
|
| 917 |
|
| 918 |
``` cpp
|
| 919 |
RealType a() const;
|
| 920 |
```
|
| 921 |
|
|
@@ -931,32 +900,27 @@ constructed.
|
|
| 931 |
|
| 932 |
##### Class template `fisher_f_distribution` <a id="rand.dist.norm.f">[[rand.dist.norm.f]]</a>
|
| 933 |
|
| 934 |
A `fisher_f_distribution` random number distribution produces random
|
| 935 |
numbers x ≥ 0 distributed according to the probability density function
|
| 936 |
-
$$
|
| 937 |
-
|
| 938 |
-
|
| 939 |
-
|
| 940 |
-
|
| 941 |
-
\left(\frac{m}{n}\right)^{m/2}
|
| 942 |
-
\cdot
|
| 943 |
-
x^{(m/2)-1}
|
| 944 |
-
\cdot
|
| 945 |
-
{\left( 1 + \frac{m x}{n} \right)}^{-(m+n)/2}
|
| 946 |
-
\; \mbox{.}$$
|
| 947 |
|
| 948 |
``` cpp
|
| 949 |
template<class RealType = double>
|
| 950 |
class fisher_f_distribution {
|
| 951 |
public:
|
| 952 |
// types
|
| 953 |
using result_type = RealType;
|
| 954 |
using param_type = unspecified;
|
| 955 |
|
| 956 |
// constructor and reset functions
|
| 957 |
-
|
|
|
|
| 958 |
explicit fisher_f_distribution(const param_type& parm);
|
| 959 |
void reset();
|
| 960 |
|
| 961 |
// generating functions
|
| 962 |
template<class URBG>
|
|
@@ -973,17 +937,17 @@ template<class RealType = double>
|
|
| 973 |
result_type max() const;
|
| 974 |
};
|
| 975 |
```
|
| 976 |
|
| 977 |
``` cpp
|
| 978 |
-
explicit fisher_f_distribution(RealType m
|
| 979 |
```
|
| 980 |
|
| 981 |
-
*
|
| 982 |
|
| 983 |
-
*
|
| 984 |
-
|
| 985 |
|
| 986 |
``` cpp
|
| 987 |
RealType m() const;
|
| 988 |
```
|
| 989 |
|
|
@@ -998,29 +962,27 @@ RealType n() const;
|
|
| 998 |
constructed.
|
| 999 |
|
| 1000 |
##### Class template `student_t_distribution` <a id="rand.dist.norm.t">[[rand.dist.norm.t]]</a>
|
| 1001 |
|
| 1002 |
A `student_t_distribution` random number distribution produces random
|
| 1003 |
-
numbers x distributed according to the probability density function
|
| 1004 |
-
|
| 1005 |
-
|
| 1006 |
-
{\sqrt{n \pi}}
|
| 1007 |
-
\cdot \frac{\Gamma\big((n+1)/2\big)}
|
| 1008 |
-
{\Gamma(n/2)}
|
| 1009 |
\cdot \left(1 + \frac{x^2}{n} \right)^{-(n+1)/2}
|
| 1010 |
-
\
|
| 1011 |
|
| 1012 |
``` cpp
|
| 1013 |
template<class RealType = double>
|
| 1014 |
class student_t_distribution {
|
| 1015 |
public:
|
| 1016 |
// types
|
| 1017 |
using result_type = RealType;
|
| 1018 |
using param_type = unspecified;
|
| 1019 |
|
| 1020 |
// constructor and reset functions
|
| 1021 |
-
|
|
|
|
| 1022 |
explicit student_t_distribution(const param_type& parm);
|
| 1023 |
void reset();
|
| 1024 |
|
| 1025 |
// generating functions
|
| 1026 |
template<class URBG>
|
|
@@ -1036,17 +998,16 @@ template<class RealType = double>
|
|
| 1036 |
result_type max() const;
|
| 1037 |
};
|
| 1038 |
```
|
| 1039 |
|
| 1040 |
``` cpp
|
| 1041 |
-
explicit student_t_distribution(RealType n
|
| 1042 |
```
|
| 1043 |
|
| 1044 |
-
*
|
| 1045 |
|
| 1046 |
-
*
|
| 1047 |
-
to the parameter of the distribution.
|
| 1048 |
|
| 1049 |
``` cpp
|
| 1050 |
RealType n() const;
|
| 1051 |
```
|
| 1052 |
|
|
@@ -1057,20 +1018,17 @@ constructed.
|
|
| 1057 |
|
| 1058 |
##### Class template `discrete_distribution` <a id="rand.dist.samp.discrete">[[rand.dist.samp.discrete]]</a>
|
| 1059 |
|
| 1060 |
A `discrete_distribution` random number distribution produces random
|
| 1061 |
integers i, 0 ≤ i < n, distributed according to the discrete probability
|
| 1062 |
-
function $$
|
| 1063 |
-
P(i\,|\,p_0,\ldots,p_{n-1})
|
| 1064 |
-
= p_i
|
| 1065 |
-
\; \mbox{.}$$
|
| 1066 |
|
| 1067 |
Unless specified otherwise, the distribution parameters are calculated
|
| 1068 |
-
as:
|
| 1069 |
-
|
| 1070 |
-
non-
|
| 1071 |
-
0 < S =
|
| 1072 |
|
| 1073 |
``` cpp
|
| 1074 |
template<class IntType = int>
|
| 1075 |
class discrete_distribution {
|
| 1076 |
public:
|
|
@@ -1116,15 +1074,18 @@ p₀ = 1.
|
|
| 1116 |
``` cpp
|
| 1117 |
template<class InputIterator>
|
| 1118 |
discrete_distribution(InputIterator firstW, InputIterator lastW);
|
| 1119 |
```
|
| 1120 |
|
| 1121 |
-
*
|
| 1122 |
-
|
| 1123 |
-
`
|
| 1124 |
-
|
| 1125 |
-
|
|
|
|
|
|
|
|
|
|
| 1126 |
|
| 1127 |
*Effects:* Constructs a `discrete_distribution` object with
|
| 1128 |
probabilities given by the formula above.
|
| 1129 |
|
| 1130 |
``` cpp
|
|
@@ -1136,22 +1097,22 @@ discrete_distribution(initializer_list<double> wl);
|
|
| 1136 |
``` cpp
|
| 1137 |
template<class UnaryOperation>
|
| 1138 |
discrete_distribution(size_t nw, double xmin, double xmax, UnaryOperation fw);
|
| 1139 |
```
|
| 1140 |
|
| 1141 |
-
*
|
| 1142 |
-
|
| 1143 |
-
|
| 1144 |
-
|
| 1145 |
-
|
| 1146 |
|
| 1147 |
*Effects:* Constructs a `discrete_distribution` object with
|
| 1148 |
probabilities given by the formula above, using the following values: If
|
| 1149 |
`nw` = 0, let w₀ = 1. Otherwise, let wₖ = `fw`(`xmin` + k ⋅ δ + δ / 2)
|
| 1150 |
for k = 0, …, n - 1.
|
| 1151 |
|
| 1152 |
-
*Complexity:* The number of invocations of `fw`
|
| 1153 |
|
| 1154 |
``` cpp
|
| 1155 |
vector<double> probabilities() const;
|
| 1156 |
```
|
| 1157 |
|
|
@@ -1162,27 +1123,21 @@ k = 0, …, n-1.
|
|
| 1162 |
##### Class template `piecewise_constant_distribution` <a id="rand.dist.samp.pconst">[[rand.dist.samp.pconst]]</a>
|
| 1163 |
|
| 1164 |
A `piecewise_constant_distribution` random number distribution produces
|
| 1165 |
random numbers x, b₀ ≤ x < bₙ, uniformly distributed over each
|
| 1166 |
subinterval [ bᵢ, bᵢ₊₁ ) according to the probability density function
|
| 1167 |
-
$$
|
| 1168 |
-
|
| 1169 |
-
= \rho_i
|
| 1170 |
-
\; \mbox{,}
|
| 1171 |
-
\mbox{ for } b_i \le x < b_{i+1}
|
| 1172 |
-
\; \mbox{.}$$
|
| 1173 |
|
| 1174 |
The n + 1 distribution parameters bᵢ, also known as this distribution’s
|
| 1175 |
-
*interval boundaries* , shall satisfy the relation
|
| 1176 |
-
i = 0, …, n-1. Unless specified otherwise, the remaining n
|
| 1177 |
-
parameters are calculated as:
|
| 1178 |
-
|
| 1179 |
-
|
| 1180 |
-
|
| 1181 |
-
|
| 1182 |
-
non-infinity. Moreover, the following relation shall hold:
|
| 1183 |
-
0 < S = w₀ + ⋯ + wₙ₋₁.
|
| 1184 |
|
| 1185 |
``` cpp
|
| 1186 |
template<class RealType = double>
|
| 1187 |
class piecewise_constant_distribution {
|
| 1188 |
public:
|
|
@@ -1230,59 +1185,60 @@ n = 1, ρ₀ = 1, b₀ = 0, and b₁ = 1.
|
|
| 1230 |
template<class InputIteratorB, class InputIteratorW>
|
| 1231 |
piecewise_constant_distribution(InputIteratorB firstB, InputIteratorB lastB,
|
| 1232 |
InputIteratorW firstW);
|
| 1233 |
```
|
| 1234 |
|
| 1235 |
-
*
|
| 1236 |
-
|
| 1237 |
-
|
| 1238 |
-
`iterator_traits<
|
| 1239 |
-
|
| 1240 |
-
|
| 1241 |
-
|
| 1242 |
-
|
| 1243 |
-
|
| 1244 |
-
|
|
|
|
|
|
|
|
|
|
| 1245 |
|
| 1246 |
*Effects:* Constructs a `piecewise_constant_distribution` object with
|
| 1247 |
parameters as specified above.
|
| 1248 |
|
| 1249 |
``` cpp
|
| 1250 |
template<class UnaryOperation>
|
| 1251 |
piecewise_constant_distribution(initializer_list<RealType> bl, UnaryOperation fw);
|
| 1252 |
```
|
| 1253 |
|
| 1254 |
-
*
|
| 1255 |
-
|
| 1256 |
-
`double`. Moreover, `double` shall be convertible to the type of
|
| 1257 |
-
`UnaryOperation`’s sole parameter.
|
| 1258 |
|
| 1259 |
*Effects:* Constructs a `piecewise_constant_distribution` object with
|
| 1260 |
parameters taken or calculated from the following values: If
|
| 1261 |
`bl.size()` < 2, let n = 1, w₀ = 1, b₀ = 0, and b₁ = 1. Otherwise, let
|
| 1262 |
[`bl.begin()`, `bl.end()`) form a sequence b₀, …, bₙ, and let
|
| 1263 |
wₖ = `fw`((bₖ₊₁ + bₖ) / 2) for k = 0, …, n - 1.
|
| 1264 |
|
| 1265 |
-
*Complexity:* The number of invocations of `fw`
|
| 1266 |
|
| 1267 |
``` cpp
|
| 1268 |
template<class UnaryOperation>
|
| 1269 |
piecewise_constant_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw);
|
| 1270 |
```
|
| 1271 |
|
| 1272 |
-
*
|
| 1273 |
-
|
| 1274 |
-
|
| 1275 |
-
|
| 1276 |
-
|
| 1277 |
|
| 1278 |
*Effects:* Constructs a `piecewise_constant_distribution` object with
|
| 1279 |
parameters taken or calculated from the following values: Let
|
| 1280 |
bₖ = `xmin` + k ⋅ δ for k = 0, …, n, and wₖ = `fw`(bₖ + δ / 2) for
|
| 1281 |
k = 0, …, n - 1.
|
| 1282 |
|
| 1283 |
-
*Complexity:* The number of invocations of `fw`
|
| 1284 |
|
| 1285 |
``` cpp
|
| 1286 |
vector<result_type> intervals() const;
|
| 1287 |
```
|
| 1288 |
|
|
@@ -1300,29 +1256,24 @@ k = 0, …, n-1.
|
|
| 1300 |
|
| 1301 |
##### Class template `piecewise_linear_distribution` <a id="rand.dist.samp.plinear">[[rand.dist.samp.plinear]]</a>
|
| 1302 |
|
| 1303 |
A `piecewise_linear_distribution` random number distribution produces
|
| 1304 |
random numbers x, b₀ ≤ x < bₙ, distributed over each subinterval
|
| 1305 |
-
[
|
| 1306 |
-
|
| 1307 |
-
|
| 1308 |
+ \rho_{i+1} \cdot {\frac{x - b_i}{b_{i+1} - b_i}}
|
| 1309 |
-
\
|
| 1310 |
-
\mbox{ for } b_i \le x < b_{i+1}
|
| 1311 |
-
\; \mbox{.}$$
|
| 1312 |
|
| 1313 |
The n + 1 distribution parameters bᵢ, also known as this distribution’s
|
| 1314 |
*interval boundaries* , shall satisfy the relation bᵢ < bᵢ₊₁ for
|
| 1315 |
i = 0, …, n - 1. Unless specified otherwise, the remaining n + 1
|
| 1316 |
-
distribution parameters are calculated as
|
| 1317 |
-
|
| 1318 |
-
|
| 1319 |
-
|
| 1320 |
-
|
| 1321 |
-
0 < S = \frac{1}{2}
|
| 1322 |
-
\cdot \sum_{k=0}^{n-1} (w_k + w_{k+1}) \cdot (b_{k+1} - b_k)
|
| 1323 |
-
\; \mbox{.}$$
|
| 1324 |
|
| 1325 |
``` cpp
|
| 1326 |
template<class RealType = double>
|
| 1327 |
class piecewise_linear_distribution {
|
| 1328 |
public:
|
|
@@ -1369,58 +1320,55 @@ n = 1, ρ₀ = ρ₁ = 1, b₀ = 0, and b₁ = 1.
|
|
| 1369 |
template<class InputIteratorB, class InputIteratorW>
|
| 1370 |
piecewise_linear_distribution(InputIteratorB firstB, InputIteratorB lastB,
|
| 1371 |
InputIteratorW firstW);
|
| 1372 |
```
|
| 1373 |
|
| 1374 |
-
*
|
| 1375 |
-
|
| 1376 |
-
|
| 1377 |
-
`
|
| 1378 |
-
|
| 1379 |
-
|
| 1380 |
-
|
| 1381 |
-
|
| 1382 |
-
|
| 1383 |
-
n+1, and any wₖ for k ≥ n+1 shall be ignored by the distribution.
|
| 1384 |
|
| 1385 |
*Effects:* Constructs a `piecewise_linear_distribution` object with
|
| 1386 |
parameters as specified above.
|
| 1387 |
|
| 1388 |
``` cpp
|
| 1389 |
template<class UnaryOperation>
|
| 1390 |
piecewise_linear_distribution(initializer_list<RealType> bl, UnaryOperation fw);
|
| 1391 |
```
|
| 1392 |
|
| 1393 |
-
*
|
| 1394 |
-
|
| 1395 |
-
`double`. Moreover, `double` shall be convertible to the type of
|
| 1396 |
-
`UnaryOperation`’s sole parameter.
|
| 1397 |
|
| 1398 |
*Effects:* Constructs a `piecewise_linear_distribution` object with
|
| 1399 |
parameters taken or calculated from the following values: If
|
| 1400 |
`bl.size()` < 2, let n = 1, ρ₀ = ρ₁ = 1, b₀ = 0, and b₁ = 1. Otherwise,
|
| 1401 |
let [`bl.begin(),` `bl.end()`) form a sequence b₀, …, bₙ, and let
|
| 1402 |
wₖ = `fw`(bₖ) for k = 0, …, n.
|
| 1403 |
|
| 1404 |
-
*Complexity:* The number of invocations of `fw`
|
| 1405 |
|
| 1406 |
``` cpp
|
| 1407 |
template<class UnaryOperation>
|
| 1408 |
piecewise_linear_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw);
|
| 1409 |
```
|
| 1410 |
|
| 1411 |
-
*
|
| 1412 |
-
|
| 1413 |
-
|
| 1414 |
-
|
| 1415 |
-
|
| 1416 |
|
| 1417 |
*Effects:* Constructs a `piecewise_linear_distribution` object with
|
| 1418 |
parameters taken or calculated from the following values: Let
|
| 1419 |
bₖ = `xmin` + k ⋅ δ for k = 0, …, n, and wₖ = `fw`(bₖ) for k = 0, …, n.
|
| 1420 |
|
| 1421 |
-
*Complexity:* The number of invocations of `fw`
|
| 1422 |
|
| 1423 |
``` cpp
|
| 1424 |
vector<result_type> intervals() const;
|
| 1425 |
```
|
| 1426 |
|
|
|
|
| 1 |
### Random number distribution class templates <a id="rand.dist">[[rand.dist]]</a>
|
| 2 |
|
| 3 |
#### In general <a id="rand.dist.general">[[rand.dist.general]]</a>
|
| 4 |
|
| 5 |
+
Each type instantiated from a class template specified in this
|
| 6 |
+
subclause [[rand.dist]] meets the requirements of a random number
|
| 7 |
+
distribution [[rand.req.dist]] type.
|
| 8 |
|
| 9 |
+
Descriptions are provided in this subclause [[rand.dist]] only for
|
| 10 |
distribution operations that are not described in [[rand.req.dist]] or
|
| 11 |
for operations where there is additional semantic information. In
|
| 12 |
particular, declarations for copy constructors, for copy assignment
|
| 13 |
operators, for streaming operators, and for equality and inequality
|
| 14 |
operators are not shown in the synopses.
|
| 15 |
|
| 16 |
The algorithms for producing each of the specified distributions are
|
| 17 |
*implementation-defined*.
|
| 18 |
|
| 19 |
The value of each probability density function p(z) and of each discrete
|
| 20 |
+
probability function P(zᵢ) specified in this subclause is 0 everywhere
|
| 21 |
outside its stated domain.
|
| 22 |
|
| 23 |
#### Uniform distributions <a id="rand.dist.uni">[[rand.dist.uni]]</a>
|
| 24 |
|
| 25 |
##### Class template `uniform_int_distribution` <a id="rand.dist.uni.int">[[rand.dist.uni.int]]</a>
|
| 26 |
|
| 27 |
A `uniform_int_distribution` random number distribution produces random
|
| 28 |
integers i, a ≤ i ≤ b, distributed according to the constant discrete
|
| 29 |
+
probability function $$P(i\,|\,a,b) = 1 / (b - a + 1) \text{ .}$$
|
|
|
|
|
|
|
| 30 |
|
| 31 |
``` cpp
|
| 32 |
template<class IntType = int>
|
| 33 |
class uniform_int_distribution {
|
| 34 |
public:
|
| 35 |
// types
|
| 36 |
using result_type = IntType;
|
| 37 |
using param_type = unspecified;
|
| 38 |
|
| 39 |
// constructors and reset functions
|
| 40 |
+
uniform_int_distribution() : uniform_int_distribution(0) {}
|
| 41 |
+
explicit uniform_int_distribution(IntType a, IntType b = numeric_limits<IntType>::max());
|
| 42 |
explicit uniform_int_distribution(const param_type& parm);
|
| 43 |
void reset();
|
| 44 |
|
| 45 |
// generating functions
|
| 46 |
template<class URBG>
|
|
|
|
| 57 |
result_type max() const;
|
| 58 |
};
|
| 59 |
```
|
| 60 |
|
| 61 |
``` cpp
|
| 62 |
+
explicit uniform_int_distribution(IntType a, IntType b = numeric_limits<IntType>::max());
|
| 63 |
```
|
| 64 |
|
| 65 |
+
*Preconditions:* `a` ≤ `b`.
|
| 66 |
|
| 67 |
+
*Remarks:* `a` and `b` correspond to the respective parameters of the
|
| 68 |
+
distribution.
|
| 69 |
|
| 70 |
``` cpp
|
| 71 |
result_type a() const;
|
| 72 |
```
|
| 73 |
|
|
|
|
| 83 |
|
| 84 |
##### Class template `uniform_real_distribution` <a id="rand.dist.uni.real">[[rand.dist.uni.real]]</a>
|
| 85 |
|
| 86 |
A `uniform_real_distribution` random number distribution produces random
|
| 87 |
numbers x, a ≤ x < b, distributed according to the constant probability
|
| 88 |
+
density function $$p(x\,|\,a,b) = 1 / (b - a) \text{ .}$$
|
|
|
|
|
|
|
| 89 |
|
| 90 |
[*Note 1*: This implies that p(x | a,b) is undefined when
|
| 91 |
`a == b`. — *end note*]
|
| 92 |
|
| 93 |
``` cpp
|
|
|
|
| 97 |
// types
|
| 98 |
using result_type = RealType;
|
| 99 |
using param_type = unspecified;
|
| 100 |
|
| 101 |
// constructors and reset functions
|
| 102 |
+
uniform_real_distribution() : uniform_real_distribution(0.0) {}
|
| 103 |
+
explicit uniform_real_distribution(RealType a, RealType b = 1.0);
|
| 104 |
explicit uniform_real_distribution(const param_type& parm);
|
| 105 |
void reset();
|
| 106 |
|
| 107 |
// generating functions
|
| 108 |
template<class URBG>
|
|
|
|
| 119 |
result_type max() const;
|
| 120 |
};
|
| 121 |
```
|
| 122 |
|
| 123 |
``` cpp
|
| 124 |
+
explicit uniform_real_distribution(RealType a, RealType b = 1.0);
|
| 125 |
```
|
| 126 |
|
| 127 |
+
*Preconditions:* `a` ≤ `b` and
|
| 128 |
+
`b` - `a` ≤ `numeric_limits<RealType>::max()`.
|
| 129 |
|
| 130 |
+
*Remarks:* `a` and `b` correspond to the respective parameters of the
|
| 131 |
+
distribution.
|
| 132 |
|
| 133 |
``` cpp
|
| 134 |
result_type a() const;
|
| 135 |
```
|
| 136 |
|
|
|
|
| 147 |
#### Bernoulli distributions <a id="rand.dist.bern">[[rand.dist.bern]]</a>
|
| 148 |
|
| 149 |
##### Class `bernoulli_distribution` <a id="rand.dist.bern.bernoulli">[[rand.dist.bern.bernoulli]]</a>
|
| 150 |
|
| 151 |
A `bernoulli_distribution` random number distribution produces `bool`
|
| 152 |
+
values b distributed according to the discrete probability function
|
| 153 |
+
$$P(b\,|\,p) = \left\{ \begin{array}{ll}
|
| 154 |
+
p & \text{ if $b = \tcode{true}$, or} \\
|
| 155 |
+
1 - p & \text{ if $b = \tcode{false}$.}
|
| 156 |
+
\end{array}\right.$$
|
|
|
|
|
|
|
| 157 |
|
| 158 |
``` cpp
|
| 159 |
class bernoulli_distribution {
|
| 160 |
public:
|
| 161 |
// types
|
| 162 |
using result_type = bool;
|
| 163 |
using param_type = unspecified;
|
| 164 |
|
| 165 |
// constructors and reset functions
|
| 166 |
+
bernoulli_distribution() : bernoulli_distribution(0.5) {}
|
| 167 |
+
explicit bernoulli_distribution(double p);
|
| 168 |
explicit bernoulli_distribution(const param_type& parm);
|
| 169 |
void reset();
|
| 170 |
|
| 171 |
// generating functions
|
| 172 |
template<class URBG>
|
|
|
|
| 182 |
result_type max() const;
|
| 183 |
};
|
| 184 |
```
|
| 185 |
|
| 186 |
``` cpp
|
| 187 |
+
explicit bernoulli_distribution(double p);
|
| 188 |
```
|
| 189 |
|
| 190 |
+
*Preconditions:* 0 ≤ `p` ≤ 1.
|
| 191 |
|
| 192 |
+
*Remarks:* `p` corresponds to the parameter of the distribution.
|
|
|
|
| 193 |
|
| 194 |
``` cpp
|
| 195 |
double p() const;
|
| 196 |
```
|
| 197 |
|
|
|
|
| 200 |
|
| 201 |
##### Class template `binomial_distribution` <a id="rand.dist.bern.bin">[[rand.dist.bern.bin]]</a>
|
| 202 |
|
| 203 |
A `binomial_distribution` random number distribution produces integer
|
| 204 |
values i ≥ 0 distributed according to the discrete probability function
|
| 205 |
+
$$P(i\,|\,t,p) = \binom{t}{i} \cdot p^i \cdot (1-p)^{t-i} \text{ .}$$
|
|
|
|
|
|
|
|
|
|
| 206 |
|
| 207 |
``` cpp
|
| 208 |
template<class IntType = int>
|
| 209 |
class binomial_distribution {
|
| 210 |
public:
|
| 211 |
// types
|
| 212 |
using result_type = IntType;
|
| 213 |
using param_type = unspecified;
|
| 214 |
|
| 215 |
// constructors and reset functions
|
| 216 |
+
binomial_distribution() : binomial_distribution(1) {}
|
| 217 |
+
explicit binomial_distribution(IntType t, double p = 0.5);
|
| 218 |
explicit binomial_distribution(const param_type& parm);
|
| 219 |
void reset();
|
| 220 |
|
| 221 |
// generating functions
|
| 222 |
template<class URBG>
|
|
|
|
| 233 |
result_type max() const;
|
| 234 |
};
|
| 235 |
```
|
| 236 |
|
| 237 |
``` cpp
|
| 238 |
+
explicit binomial_distribution(IntType t, double p = 0.5);
|
| 239 |
```
|
| 240 |
|
| 241 |
+
*Preconditions:* 0 ≤ `p` ≤ 1 and 0 ≤ `t`.
|
| 242 |
|
| 243 |
+
*Remarks:* `t` and `p` correspond to the respective parameters of the
|
| 244 |
+
distribution.
|
| 245 |
|
| 246 |
``` cpp
|
| 247 |
IntType t() const;
|
| 248 |
```
|
| 249 |
|
|
|
|
| 259 |
|
| 260 |
##### Class template `geometric_distribution` <a id="rand.dist.bern.geo">[[rand.dist.bern.geo]]</a>
|
| 261 |
|
| 262 |
A `geometric_distribution` random number distribution produces integer
|
| 263 |
values i ≥ 0 distributed according to the discrete probability function
|
| 264 |
+
$$P(i\,|\,p) = p \cdot (1-p)^{i} \text{ .}$$
|
|
|
|
|
|
|
|
|
|
| 265 |
|
| 266 |
``` cpp
|
| 267 |
template<class IntType = int>
|
| 268 |
class geometric_distribution {
|
| 269 |
public:
|
| 270 |
// types
|
| 271 |
using result_type = IntType;
|
| 272 |
using param_type = unspecified;
|
| 273 |
|
| 274 |
// constructors and reset functions
|
| 275 |
+
geometric_distribution() : geometric_distribution(0.5) {}
|
| 276 |
+
explicit geometric_distribution(double p);
|
| 277 |
explicit geometric_distribution(const param_type& parm);
|
| 278 |
void reset();
|
| 279 |
|
| 280 |
// generating functions
|
| 281 |
template<class URBG>
|
|
|
|
| 291 |
result_type max() const;
|
| 292 |
};
|
| 293 |
```
|
| 294 |
|
| 295 |
``` cpp
|
| 296 |
+
explicit geometric_distribution(double p);
|
| 297 |
```
|
| 298 |
|
| 299 |
+
*Preconditions:* 0 < `p` < 1.
|
| 300 |
|
| 301 |
+
*Remarks:* `p` corresponds to the parameter of the distribution.
|
|
|
|
| 302 |
|
| 303 |
``` cpp
|
| 304 |
double p() const;
|
| 305 |
```
|
| 306 |
|
|
|
|
| 309 |
|
| 310 |
##### Class template `negative_binomial_distribution` <a id="rand.dist.bern.negbin">[[rand.dist.bern.negbin]]</a>
|
| 311 |
|
| 312 |
A `negative_binomial_distribution` random number distribution produces
|
| 313 |
random integers i ≥ 0 distributed according to the discrete probability
|
| 314 |
+
function
|
| 315 |
+
$$P(i\,|\,k,p) = \binom{k+i-1}{i} \cdot p^k \cdot (1-p)^i \text{ .}$$
|
|
|
|
|
|
|
| 316 |
|
| 317 |
[*Note 1*: This implies that P(i | k,p) is undefined when
|
| 318 |
`p == 1`. — *end note*]
|
| 319 |
|
| 320 |
``` cpp
|
|
|
|
| 324 |
// types
|
| 325 |
using result_type = IntType;
|
| 326 |
using param_type = unspecified;
|
| 327 |
|
| 328 |
// constructor and reset functions
|
| 329 |
+
negative_binomial_distribution() : negative_binomial_distribution(1) {}
|
| 330 |
+
explicit negative_binomial_distribution(IntType k, double p = 0.5);
|
| 331 |
explicit negative_binomial_distribution(const param_type& parm);
|
| 332 |
void reset();
|
| 333 |
|
| 334 |
// generating functions
|
| 335 |
template<class URBG>
|
|
|
|
| 346 |
result_type max() const;
|
| 347 |
};
|
| 348 |
```
|
| 349 |
|
| 350 |
``` cpp
|
| 351 |
+
explicit negative_binomial_distribution(IntType k, double p = 0.5);
|
| 352 |
```
|
| 353 |
|
| 354 |
+
*Preconditions:* 0 < `p` ≤ 1 and 0 < `k`.
|
| 355 |
|
| 356 |
+
*Remarks:* `k` and `p` correspond to the respective parameters of the
|
| 357 |
+
distribution.
|
| 358 |
|
| 359 |
``` cpp
|
| 360 |
IntType k() const;
|
| 361 |
```
|
| 362 |
|
|
|
|
| 374 |
|
| 375 |
##### Class template `poisson_distribution` <a id="rand.dist.pois.poisson">[[rand.dist.pois.poisson]]</a>
|
| 376 |
|
| 377 |
A `poisson_distribution` random number distribution produces integer
|
| 378 |
values i ≥ 0 distributed according to the discrete probability function
|
| 379 |
+
$$P(i\,|\,\mu) = \frac{e^{-\mu} \mu^{i}}{i\,!} \text{ .}$$ The
|
| 380 |
+
distribution parameter μ is also known as this distribution’s *mean* .
|
|
|
|
|
|
|
|
|
|
|
|
|
| 381 |
|
| 382 |
``` cpp
|
| 383 |
template<class IntType = int>
|
| 384 |
class poisson_distribution
|
| 385 |
{
|
|
|
|
| 387 |
// types
|
| 388 |
using result_type = IntType;
|
| 389 |
using param_type = unspecified;
|
| 390 |
|
| 391 |
// constructors and reset functions
|
| 392 |
+
poisson_distribution() : poisson_distribution(1.0) {}
|
| 393 |
+
explicit poisson_distribution(double mean);
|
| 394 |
explicit poisson_distribution(const param_type& parm);
|
| 395 |
void reset();
|
| 396 |
|
| 397 |
// generating functions
|
| 398 |
template<class URBG>
|
|
|
|
| 408 |
result_type max() const;
|
| 409 |
};
|
| 410 |
```
|
| 411 |
|
| 412 |
``` cpp
|
| 413 |
+
explicit poisson_distribution(double mean);
|
| 414 |
```
|
| 415 |
|
| 416 |
+
*Preconditions:* 0 < `mean`.
|
| 417 |
|
| 418 |
+
*Remarks:* `mean` corresponds to the parameter of the distribution.
|
|
|
|
| 419 |
|
| 420 |
``` cpp
|
| 421 |
double mean() const;
|
| 422 |
```
|
| 423 |
|
|
|
|
| 426 |
|
| 427 |
##### Class template `exponential_distribution` <a id="rand.dist.pois.exp">[[rand.dist.pois.exp]]</a>
|
| 428 |
|
| 429 |
An `exponential_distribution` random number distribution produces random
|
| 430 |
numbers x > 0 distributed according to the probability density function
|
| 431 |
+
$$p(x\,|\,\lambda) = \lambda e^{-\lambda x} \text{ .}$$
|
|
|
|
|
|
|
|
|
|
| 432 |
|
| 433 |
``` cpp
|
| 434 |
template<class RealType = double>
|
| 435 |
class exponential_distribution {
|
| 436 |
public:
|
| 437 |
// types
|
| 438 |
using result_type = RealType;
|
| 439 |
using param_type = unspecified;
|
| 440 |
|
| 441 |
// constructors and reset functions
|
| 442 |
+
exponential_distribution() : exponential_distribution(1.0) {}
|
| 443 |
+
explicit exponential_distribution(RealType lambda);
|
| 444 |
explicit exponential_distribution(const param_type& parm);
|
| 445 |
void reset();
|
| 446 |
|
| 447 |
// generating functions
|
| 448 |
template<class URBG>
|
|
|
|
| 458 |
result_type max() const;
|
| 459 |
};
|
| 460 |
```
|
| 461 |
|
| 462 |
``` cpp
|
| 463 |
+
explicit exponential_distribution(RealType lambda);
|
| 464 |
```
|
| 465 |
|
| 466 |
+
*Preconditions:* 0 < `lambda`.
|
| 467 |
|
| 468 |
+
*Remarks:* `lambda` corresponds to the parameter of the distribution.
|
|
|
|
| 469 |
|
| 470 |
``` cpp
|
| 471 |
RealType lambda() const;
|
| 472 |
```
|
| 473 |
|
|
|
|
| 476 |
|
| 477 |
##### Class template `gamma_distribution` <a id="rand.dist.pois.gamma">[[rand.dist.pois.gamma]]</a>
|
| 478 |
|
| 479 |
A `gamma_distribution` random number distribution produces random
|
| 480 |
numbers x > 0 distributed according to the probability density function
|
| 481 |
+
$$p(x\,|\,\alpha,\beta) =
|
| 482 |
+
\frac{e^{-x/\beta}}{\beta^{\alpha} \cdot \Gamma(\alpha)} \, \cdot \, x^{\, \alpha-1}
|
| 483 |
+
\text{ .}$$
|
|
|
|
|
|
|
| 484 |
|
| 485 |
``` cpp
|
| 486 |
template<class RealType = double>
|
| 487 |
class gamma_distribution {
|
| 488 |
public:
|
| 489 |
// types
|
| 490 |
using result_type = RealType;
|
| 491 |
using param_type = unspecified;
|
| 492 |
|
| 493 |
// constructors and reset functions
|
| 494 |
+
gamma_distribution() : gamma_distribution(1.0) {}
|
| 495 |
+
explicit gamma_distribution(RealType alpha, RealType beta = 1.0);
|
| 496 |
explicit gamma_distribution(const param_type& parm);
|
| 497 |
void reset();
|
| 498 |
|
| 499 |
// generating functions
|
| 500 |
template<class URBG>
|
|
|
|
| 511 |
result_type max() const;
|
| 512 |
};
|
| 513 |
```
|
| 514 |
|
| 515 |
``` cpp
|
| 516 |
+
explicit gamma_distribution(RealType alpha, RealType beta = 1.0);
|
| 517 |
```
|
| 518 |
|
| 519 |
+
*Preconditions:* 0 < `alpha` and 0 < `beta`.
|
| 520 |
|
| 521 |
+
*Remarks:* `alpha` and `beta` correspond to the parameters of the
|
| 522 |
+
distribution.
|
| 523 |
|
| 524 |
``` cpp
|
| 525 |
RealType alpha() const;
|
| 526 |
```
|
| 527 |
|
|
|
|
| 537 |
|
| 538 |
##### Class template `weibull_distribution` <a id="rand.dist.pois.weibull">[[rand.dist.pois.weibull]]</a>
|
| 539 |
|
| 540 |
A `weibull_distribution` random number distribution produces random
|
| 541 |
numbers x ≥ 0 distributed according to the probability density function
|
| 542 |
+
$$p(x\,|\,a,b) = \frac{a}{b}
|
|
|
|
|
|
|
| 543 |
\cdot \left(\frac{x}{b}\right)^{a-1}
|
| 544 |
\cdot \, \exp\left( -\left(\frac{x}{b}\right)^a\right)
|
| 545 |
+
\text{ .}$$
|
| 546 |
|
| 547 |
``` cpp
|
| 548 |
template<class RealType = double>
|
| 549 |
class weibull_distribution {
|
| 550 |
public:
|
| 551 |
// types
|
| 552 |
using result_type = RealType;
|
| 553 |
using param_type = unspecified;
|
| 554 |
|
| 555 |
// constructor and reset functions
|
| 556 |
+
weibull_distribution() : weibull_distribution(1.0) {}
|
| 557 |
+
explicit weibull_distribution(RealType a, RealType b = 1.0);
|
| 558 |
explicit weibull_distribution(const param_type& parm);
|
| 559 |
void reset();
|
| 560 |
|
| 561 |
// generating functions
|
| 562 |
template<class URBG>
|
|
|
|
| 573 |
result_type max() const;
|
| 574 |
};
|
| 575 |
```
|
| 576 |
|
| 577 |
``` cpp
|
| 578 |
+
explicit weibull_distribution(RealType a, RealType b = 1.0);
|
| 579 |
```
|
| 580 |
|
| 581 |
+
*Preconditions:* 0 < `a` and 0 < `b`.
|
| 582 |
|
| 583 |
+
*Remarks:* `a` and `b` correspond to the respective parameters of the
|
| 584 |
+
distribution.
|
| 585 |
|
| 586 |
``` cpp
|
| 587 |
RealType a() const;
|
| 588 |
```
|
| 589 |
|
|
|
|
| 599 |
|
| 600 |
##### Class template `extreme_value_distribution` <a id="rand.dist.pois.extreme">[[rand.dist.pois.extreme]]</a>
|
| 601 |
|
| 602 |
An `extreme_value_distribution` random number distribution produces
|
| 603 |
random numbers x distributed according to the probability density
|
| 604 |
+
function[^6] $$p(x\,|\,a,b) = \frac{1}{b}
|
| 605 |
+
\cdot \exp\left(\frac{a-x}{b} - \exp\left(\frac{a-x}{b}\right)\right)
|
| 606 |
+
\text{ .}$$
|
|
|
|
|
|
|
|
|
|
|
|
|
| 607 |
|
| 608 |
``` cpp
|
| 609 |
template<class RealType = double>
|
| 610 |
class extreme_value_distribution {
|
| 611 |
public:
|
| 612 |
// types
|
| 613 |
using result_type = RealType;
|
| 614 |
using param_type = unspecified;
|
| 615 |
|
| 616 |
// constructor and reset functions
|
| 617 |
+
extreme_value_distribution() : extreme_value_distribution(0.0) {}
|
| 618 |
+
explicit extreme_value_distribution(RealType a, RealType b = 1.0);
|
| 619 |
explicit extreme_value_distribution(const param_type& parm);
|
| 620 |
void reset();
|
| 621 |
|
| 622 |
// generating functions
|
| 623 |
template<class URBG>
|
|
|
|
| 634 |
result_type max() const;
|
| 635 |
};
|
| 636 |
```
|
| 637 |
|
| 638 |
``` cpp
|
| 639 |
+
explicit extreme_value_distribution(RealType a, RealType b = 1.0);
|
| 640 |
```
|
| 641 |
|
| 642 |
+
*Preconditions:* 0 < `b`.
|
| 643 |
|
| 644 |
+
*Remarks:* `a` and `b` correspond to the respective parameters of the
|
| 645 |
+
distribution.
|
| 646 |
|
| 647 |
``` cpp
|
| 648 |
RealType a() const;
|
| 649 |
```
|
| 650 |
|
|
|
|
| 670 |
% e^{-(x-\mu)^2 / (2\sigma^2)}
|
| 671 |
\exp{\left(- \, \frac{(x - \mu)^2}
|
| 672 |
{2 \sigma^2}
|
| 673 |
\right)
|
| 674 |
}
|
| 675 |
+
\text{ .}$$ The distribution parameters μ and σ are also known as this
|
| 676 |
distribution’s *mean* and *standard deviation* .
|
| 677 |
|
| 678 |
``` cpp
|
| 679 |
template<class RealType = double>
|
| 680 |
class normal_distribution {
|
|
|
|
| 682 |
// types
|
| 683 |
using result_type = RealType;
|
| 684 |
using param_type = unspecified;
|
| 685 |
|
| 686 |
// constructors and reset functions
|
| 687 |
+
normal_distribution() : normal_distribution(0.0) {}
|
| 688 |
+
explicit normal_distribution(RealType mean, RealType stddev = 1.0);
|
| 689 |
explicit normal_distribution(const param_type& parm);
|
| 690 |
void reset();
|
| 691 |
|
| 692 |
// generating functions
|
| 693 |
template<class URBG>
|
|
|
|
| 704 |
result_type max() const;
|
| 705 |
};
|
| 706 |
```
|
| 707 |
|
| 708 |
``` cpp
|
| 709 |
+
explicit normal_distribution(RealType mean, RealType stddev = 1.0);
|
| 710 |
```
|
| 711 |
|
| 712 |
+
*Preconditions:* 0 < `stddev`.
|
| 713 |
|
| 714 |
+
*Remarks:* `mean` and `stddev` correspond to the respective parameters
|
| 715 |
+
of the distribution.
|
| 716 |
|
| 717 |
``` cpp
|
| 718 |
RealType mean() const;
|
| 719 |
```
|
| 720 |
|
|
|
|
| 730 |
|
| 731 |
##### Class template `lognormal_distribution` <a id="rand.dist.norm.lognormal">[[rand.dist.norm.lognormal]]</a>
|
| 732 |
|
| 733 |
A `lognormal_distribution` random number distribution produces random
|
| 734 |
numbers x > 0 distributed according to the probability density function
|
| 735 |
+
$$p(x\,|\,m,s) = \frac{1}{s x \sqrt{2 \pi}}
|
| 736 |
+
\cdot \exp{\left(-\frac{(\ln{x} - m)^2}{2 s^2}\right)}
|
| 737 |
+
\text{ .}$$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 738 |
|
| 739 |
``` cpp
|
| 740 |
template<class RealType = double>
|
| 741 |
class lognormal_distribution {
|
| 742 |
public:
|
| 743 |
// types
|
| 744 |
using result_type = RealType;
|
| 745 |
using param_type = unspecified;
|
| 746 |
|
| 747 |
// constructor and reset functions
|
| 748 |
+
lognormal_distribution() : lognormal_distribution(0.0) {}
|
| 749 |
+
explicit lognormal_distribution(RealType m, RealType s = 1.0);
|
| 750 |
explicit lognormal_distribution(const param_type& parm);
|
| 751 |
void reset();
|
| 752 |
|
| 753 |
// generating functions
|
| 754 |
template<class URBG>
|
|
|
|
| 765 |
result_type max() const;
|
| 766 |
};
|
| 767 |
```
|
| 768 |
|
| 769 |
``` cpp
|
| 770 |
+
explicit lognormal_distribution(RealType m, RealType s = 1.0);
|
| 771 |
```
|
| 772 |
|
| 773 |
+
*Preconditions:* 0 < `s`.
|
| 774 |
|
| 775 |
+
*Remarks:* `m` and `s` correspond to the respective parameters of the
|
| 776 |
+
distribution.
|
| 777 |
|
| 778 |
``` cpp
|
| 779 |
RealType m() const;
|
| 780 |
```
|
| 781 |
|
|
|
|
| 791 |
|
| 792 |
##### Class template `chi_squared_distribution` <a id="rand.dist.norm.chisq">[[rand.dist.norm.chisq]]</a>
|
| 793 |
|
| 794 |
A `chi_squared_distribution` random number distribution produces random
|
| 795 |
numbers x > 0 distributed according to the probability density function
|
| 796 |
+
$$p(x\,|\,n) = \frac{x^{(n/2)-1} \cdot e^{-x/2}}{\Gamma(n/2) \cdot 2^{n/2}} \text{ .}$$
|
|
|
|
|
|
|
|
|
|
|
|
|
| 797 |
|
| 798 |
``` cpp
|
| 799 |
template<class RealType = double>
|
| 800 |
class chi_squared_distribution {
|
| 801 |
public:
|
| 802 |
// types
|
| 803 |
using result_type = RealType;
|
| 804 |
using param_type = unspecified;
|
| 805 |
|
| 806 |
// constructor and reset functions
|
| 807 |
+
chi_squared_distribution() : chi_squared_distribution(1.0) {}
|
| 808 |
+
explicit chi_squared_distribution(RealType n);
|
| 809 |
explicit chi_squared_distribution(const param_type& parm);
|
| 810 |
void reset();
|
| 811 |
|
| 812 |
// generating functions
|
| 813 |
template<class URBG>
|
|
|
|
| 823 |
result_type max() const;
|
| 824 |
};
|
| 825 |
```
|
| 826 |
|
| 827 |
``` cpp
|
| 828 |
+
explicit chi_squared_distribution(RealType n);
|
| 829 |
```
|
| 830 |
|
| 831 |
+
*Preconditions:* 0 < `n`.
|
| 832 |
|
| 833 |
+
*Remarks:* `n` corresponds to the parameter of the distribution.
|
|
|
|
| 834 |
|
| 835 |
``` cpp
|
| 836 |
RealType n() const;
|
| 837 |
```
|
| 838 |
|
|
|
|
| 840 |
constructed.
|
| 841 |
|
| 842 |
##### Class template `cauchy_distribution` <a id="rand.dist.norm.cauchy">[[rand.dist.norm.cauchy]]</a>
|
| 843 |
|
| 844 |
A `cauchy_distribution` random number distribution produces random
|
| 845 |
+
numbers x distributed according to the probability density function
|
| 846 |
+
$$p(x\,|\,a,b) = \left(\pi b \left(1 + \left(\frac{x-a}{b} \right)^2 \, \right)\right)^{-1} \text{ .}$$
|
|
|
|
|
|
|
| 847 |
|
| 848 |
``` cpp
|
| 849 |
template<class RealType = double>
|
| 850 |
class cauchy_distribution {
|
| 851 |
public:
|
| 852 |
// types
|
| 853 |
using result_type = RealType;
|
| 854 |
using param_type = unspecified;
|
| 855 |
|
| 856 |
// constructor and reset functions
|
| 857 |
+
cauchy_distribution() : cauchy_distribution(0.0) {}
|
| 858 |
+
explicit cauchy_distribution(RealType a, RealType b = 1.0);
|
| 859 |
explicit cauchy_distribution(const param_type& parm);
|
| 860 |
void reset();
|
| 861 |
|
| 862 |
// generating functions
|
| 863 |
template<class URBG>
|
|
|
|
| 874 |
result_type max() const;
|
| 875 |
};
|
| 876 |
```
|
| 877 |
|
| 878 |
``` cpp
|
| 879 |
+
explicit cauchy_distribution(RealType a, RealType b = 1.0);
|
| 880 |
```
|
| 881 |
|
| 882 |
+
*Preconditions:* 0 < `b`.
|
| 883 |
|
| 884 |
+
*Remarks:* `a` and `b` correspond to the respective parameters of the
|
| 885 |
+
distribution.
|
| 886 |
|
| 887 |
``` cpp
|
| 888 |
RealType a() const;
|
| 889 |
```
|
| 890 |
|
|
|
|
| 900 |
|
| 901 |
##### Class template `fisher_f_distribution` <a id="rand.dist.norm.f">[[rand.dist.norm.f]]</a>
|
| 902 |
|
| 903 |
A `fisher_f_distribution` random number distribution produces random
|
| 904 |
numbers x ≥ 0 distributed according to the probability density function
|
| 905 |
+
$$p(x\,|\,m,n) = \frac{\Gamma\big((m+n)/2\big)}{\Gamma(m/2) \; \Gamma(n/2)}
|
| 906 |
+
\cdot \left(\frac{m}{n}\right)^{m/2}
|
| 907 |
+
\cdot x^{(m/2)-1}
|
| 908 |
+
\cdot \left(1 + \frac{m x}{n}\right)^{-(m + n)/2}
|
| 909 |
+
\text{ .}$$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 910 |
|
| 911 |
``` cpp
|
| 912 |
template<class RealType = double>
|
| 913 |
class fisher_f_distribution {
|
| 914 |
public:
|
| 915 |
// types
|
| 916 |
using result_type = RealType;
|
| 917 |
using param_type = unspecified;
|
| 918 |
|
| 919 |
// constructor and reset functions
|
| 920 |
+
fisher_f_distribution() : fisher_f_distribution(1.0) {}
|
| 921 |
+
explicit fisher_f_distribution(RealType m, RealType n = 1.0);
|
| 922 |
explicit fisher_f_distribution(const param_type& parm);
|
| 923 |
void reset();
|
| 924 |
|
| 925 |
// generating functions
|
| 926 |
template<class URBG>
|
|
|
|
| 937 |
result_type max() const;
|
| 938 |
};
|
| 939 |
```
|
| 940 |
|
| 941 |
``` cpp
|
| 942 |
+
explicit fisher_f_distribution(RealType m, RealType n = 1);
|
| 943 |
```
|
| 944 |
|
| 945 |
+
*Preconditions:* 0 < `m` and 0 < `n`.
|
| 946 |
|
| 947 |
+
*Remarks:* `m` and `n` correspond to the respective parameters of the
|
| 948 |
+
distribution.
|
| 949 |
|
| 950 |
``` cpp
|
| 951 |
RealType m() const;
|
| 952 |
```
|
| 953 |
|
|
|
|
| 962 |
constructed.
|
| 963 |
|
| 964 |
##### Class template `student_t_distribution` <a id="rand.dist.norm.t">[[rand.dist.norm.t]]</a>
|
| 965 |
|
| 966 |
A `student_t_distribution` random number distribution produces random
|
| 967 |
+
numbers x distributed according to the probability density function
|
| 968 |
+
$$p(x\,|\,n) = \frac{1}{\sqrt{n \pi}}
|
| 969 |
+
\cdot \frac{\Gamma\big((n+1)/2\big)}{\Gamma(n/2)}
|
|
|
|
|
|
|
|
|
|
| 970 |
\cdot \left(1 + \frac{x^2}{n} \right)^{-(n+1)/2}
|
| 971 |
+
\text{ .}$$
|
| 972 |
|
| 973 |
``` cpp
|
| 974 |
template<class RealType = double>
|
| 975 |
class student_t_distribution {
|
| 976 |
public:
|
| 977 |
// types
|
| 978 |
using result_type = RealType;
|
| 979 |
using param_type = unspecified;
|
| 980 |
|
| 981 |
// constructor and reset functions
|
| 982 |
+
student_t_distribution() : student_t_distribution(1.0) {}
|
| 983 |
+
explicit student_t_distribution(RealType n);
|
| 984 |
explicit student_t_distribution(const param_type& parm);
|
| 985 |
void reset();
|
| 986 |
|
| 987 |
// generating functions
|
| 988 |
template<class URBG>
|
|
|
|
| 998 |
result_type max() const;
|
| 999 |
};
|
| 1000 |
```
|
| 1001 |
|
| 1002 |
``` cpp
|
| 1003 |
+
explicit student_t_distribution(RealType n);
|
| 1004 |
```
|
| 1005 |
|
| 1006 |
+
*Preconditions:* 0 < `n`.
|
| 1007 |
|
| 1008 |
+
*Remarks:* `n` corresponds to the parameter of the distribution.
|
|
|
|
| 1009 |
|
| 1010 |
``` cpp
|
| 1011 |
RealType n() const;
|
| 1012 |
```
|
| 1013 |
|
|
|
|
| 1018 |
|
| 1019 |
##### Class template `discrete_distribution` <a id="rand.dist.samp.discrete">[[rand.dist.samp.discrete]]</a>
|
| 1020 |
|
| 1021 |
A `discrete_distribution` random number distribution produces random
|
| 1022 |
integers i, 0 ≤ i < n, distributed according to the discrete probability
|
| 1023 |
+
function $$P(i \,|\, p_0, \dotsc, p_{n-1}) = p_i \text{ .}$$
|
|
|
|
|
|
|
|
|
|
| 1024 |
|
| 1025 |
Unless specified otherwise, the distribution parameters are calculated
|
| 1026 |
+
as: pₖ = {wₖ / S} for k = 0, …, n - 1, in which the values wₖ, commonly
|
| 1027 |
+
known as the *weights* , shall be non-negative, non-NaN, and
|
| 1028 |
+
non-infinity. Moreover, the following relation shall hold:
|
| 1029 |
+
$0 < S = w_0 + \dotsb + w_{n - 1}$.
|
| 1030 |
|
| 1031 |
``` cpp
|
| 1032 |
template<class IntType = int>
|
| 1033 |
class discrete_distribution {
|
| 1034 |
public:
|
|
|
|
| 1074 |
``` cpp
|
| 1075 |
template<class InputIterator>
|
| 1076 |
discrete_distribution(InputIterator firstW, InputIterator lastW);
|
| 1077 |
```
|
| 1078 |
|
| 1079 |
+
*Mandates:*
|
| 1080 |
+
`is_convertible_v<iterator_traits<InputIterator>::value_type, double>`
|
| 1081 |
+
is `true`.
|
| 1082 |
+
|
| 1083 |
+
*Preconditions:* `InputIterator` meets the *Cpp17InputIterator*
|
| 1084 |
+
requirements [[input.iterators]]. If `firstW == lastW`, let n = 1 and
|
| 1085 |
+
w₀ = 1. Otherwise, [`firstW`, `lastW`) forms a sequence w of length
|
| 1086 |
+
n > 0.
|
| 1087 |
|
| 1088 |
*Effects:* Constructs a `discrete_distribution` object with
|
| 1089 |
probabilities given by the formula above.
|
| 1090 |
|
| 1091 |
``` cpp
|
|
|
|
| 1097 |
``` cpp
|
| 1098 |
template<class UnaryOperation>
|
| 1099 |
discrete_distribution(size_t nw, double xmin, double xmax, UnaryOperation fw);
|
| 1100 |
```
|
| 1101 |
|
| 1102 |
+
*Mandates:* `is_invocable_r_v<double, UnaryOperation&, double>` is
|
| 1103 |
+
`true`.
|
| 1104 |
+
|
| 1105 |
+
*Preconditions:* If `nw` = 0, let n = 1, otherwise let n = `nw`. The
|
| 1106 |
+
relation 0 < δ = (`xmax` - `xmin`) / n holds.
|
| 1107 |
|
| 1108 |
*Effects:* Constructs a `discrete_distribution` object with
|
| 1109 |
probabilities given by the formula above, using the following values: If
|
| 1110 |
`nw` = 0, let w₀ = 1. Otherwise, let wₖ = `fw`(`xmin` + k ⋅ δ + δ / 2)
|
| 1111 |
for k = 0, …, n - 1.
|
| 1112 |
|
| 1113 |
+
*Complexity:* The number of invocations of `fw` does not exceed n.
|
| 1114 |
|
| 1115 |
``` cpp
|
| 1116 |
vector<double> probabilities() const;
|
| 1117 |
```
|
| 1118 |
|
|
|
|
| 1123 |
##### Class template `piecewise_constant_distribution` <a id="rand.dist.samp.pconst">[[rand.dist.samp.pconst]]</a>
|
| 1124 |
|
| 1125 |
A `piecewise_constant_distribution` random number distribution produces
|
| 1126 |
random numbers x, b₀ ≤ x < bₙ, uniformly distributed over each
|
| 1127 |
subinterval [ bᵢ, bᵢ₊₁ ) according to the probability density function
|
| 1128 |
+
$$p(x \,|\, b_0, \dotsc, b_n, \; \rho_0, \dotsc, \rho_{n-1}) = \rho_i
|
| 1129 |
+
\text{ , for $b_i \le x < b_{i+1}$.}$$
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1130 |
|
| 1131 |
The n + 1 distribution parameters bᵢ, also known as this distribution’s
|
| 1132 |
+
*interval boundaries* , shall satisfy the relation $b_i < b_{i + 1}$ for
|
| 1133 |
+
i = 0, …, n - 1. Unless specified otherwise, the remaining n
|
| 1134 |
+
distribution parameters are calculated as:
|
| 1135 |
+
$$\rho_k = \frac{w_k}{S \cdot (b_{k+1}-b_k)} \text{ for } k = 0, \dotsc, n - 1 \text{ ,}$$
|
| 1136 |
+
in which the values wₖ, commonly known as the *weights* , shall be
|
| 1137 |
+
non-negative, non-NaN, and non-infinity. Moreover, the following
|
| 1138 |
+
relation shall hold: 0 < S = w₀ + … + wₙ₋₁.
|
|
|
|
|
|
|
| 1139 |
|
| 1140 |
``` cpp
|
| 1141 |
template<class RealType = double>
|
| 1142 |
class piecewise_constant_distribution {
|
| 1143 |
public:
|
|
|
|
| 1185 |
template<class InputIteratorB, class InputIteratorW>
|
| 1186 |
piecewise_constant_distribution(InputIteratorB firstB, InputIteratorB lastB,
|
| 1187 |
InputIteratorW firstW);
|
| 1188 |
```
|
| 1189 |
|
| 1190 |
+
*Mandates:* Both of
|
| 1191 |
+
|
| 1192 |
+
- `is_convertible_v<iterator_traits<InputIteratorB>::value_type, double>`
|
| 1193 |
+
- `is_convertible_v<iterator_traits<InputIteratorW>::value_type, double>`
|
| 1194 |
+
|
| 1195 |
+
are `true`.
|
| 1196 |
+
|
| 1197 |
+
*Preconditions:* `InputIteratorB` and `InputIteratorW` each meet the
|
| 1198 |
+
*Cpp17InputIterator* requirements [[input.iterators]]. If
|
| 1199 |
+
`firstB == lastB` or `++firstB == lastB`, let n = 1, w₀ = 1, b₀ = 0, and
|
| 1200 |
+
b₁ = 1. Otherwise, [`firstB`, `lastB`) forms a sequence b of length n+1,
|
| 1201 |
+
the length of the sequence w starting from `firstW` is at least n, and
|
| 1202 |
+
any wₖ for k ≥ n are ignored by the distribution.
|
| 1203 |
|
| 1204 |
*Effects:* Constructs a `piecewise_constant_distribution` object with
|
| 1205 |
parameters as specified above.
|
| 1206 |
|
| 1207 |
``` cpp
|
| 1208 |
template<class UnaryOperation>
|
| 1209 |
piecewise_constant_distribution(initializer_list<RealType> bl, UnaryOperation fw);
|
| 1210 |
```
|
| 1211 |
|
| 1212 |
+
*Mandates:* `is_invocable_r_v<double, UnaryOperation&, double>` is
|
| 1213 |
+
`true`.
|
|
|
|
|
|
|
| 1214 |
|
| 1215 |
*Effects:* Constructs a `piecewise_constant_distribution` object with
|
| 1216 |
parameters taken or calculated from the following values: If
|
| 1217 |
`bl.size()` < 2, let n = 1, w₀ = 1, b₀ = 0, and b₁ = 1. Otherwise, let
|
| 1218 |
[`bl.begin()`, `bl.end()`) form a sequence b₀, …, bₙ, and let
|
| 1219 |
wₖ = `fw`((bₖ₊₁ + bₖ) / 2) for k = 0, …, n - 1.
|
| 1220 |
|
| 1221 |
+
*Complexity:* The number of invocations of `fw` does not exceed n.
|
| 1222 |
|
| 1223 |
``` cpp
|
| 1224 |
template<class UnaryOperation>
|
| 1225 |
piecewise_constant_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw);
|
| 1226 |
```
|
| 1227 |
|
| 1228 |
+
*Mandates:* `is_invocable_r_v<double, UnaryOperation&, double>` is
|
| 1229 |
+
`true`.
|
| 1230 |
+
|
| 1231 |
+
*Preconditions:* If `nw` = 0, let n = 1, otherwise let n = `nw`. The
|
| 1232 |
+
relation 0 < δ = (`xmax` - `xmin`) / n holds.
|
| 1233 |
|
| 1234 |
*Effects:* Constructs a `piecewise_constant_distribution` object with
|
| 1235 |
parameters taken or calculated from the following values: Let
|
| 1236 |
bₖ = `xmin` + k ⋅ δ for k = 0, …, n, and wₖ = `fw`(bₖ + δ / 2) for
|
| 1237 |
k = 0, …, n - 1.
|
| 1238 |
|
| 1239 |
+
*Complexity:* The number of invocations of `fw` does not exceed n.
|
| 1240 |
|
| 1241 |
``` cpp
|
| 1242 |
vector<result_type> intervals() const;
|
| 1243 |
```
|
| 1244 |
|
|
|
|
| 1256 |
|
| 1257 |
##### Class template `piecewise_linear_distribution` <a id="rand.dist.samp.plinear">[[rand.dist.samp.plinear]]</a>
|
| 1258 |
|
| 1259 |
A `piecewise_linear_distribution` random number distribution produces
|
| 1260 |
random numbers x, b₀ ≤ x < bₙ, distributed over each subinterval
|
| 1261 |
+
[bᵢ, bᵢ₊₁) according to the probability density function
|
| 1262 |
+
$$p(x \,|\, b_0, \dotsc, b_n, \; \rho_0, \dotsc, \rho_n)
|
| 1263 |
+
= \rho_{i} \cdot {\frac{b_{i+1} - x}{b_{i+1} - b_i}}
|
| 1264 |
+ \rho_{i+1} \cdot {\frac{x - b_i}{b_{i+1} - b_i}}
|
| 1265 |
+
\text{ , for $b_i \le x < b_{i+1}$.}$$
|
|
|
|
|
|
|
| 1266 |
|
| 1267 |
The n + 1 distribution parameters bᵢ, also known as this distribution’s
|
| 1268 |
*interval boundaries* , shall satisfy the relation bᵢ < bᵢ₊₁ for
|
| 1269 |
i = 0, …, n - 1. Unless specified otherwise, the remaining n + 1
|
| 1270 |
+
distribution parameters are calculated as ρₖ = {wₖ / S} for k = 0, …, n,
|
| 1271 |
+
in which the values wₖ, commonly known as the *weights at boundaries* ,
|
| 1272 |
+
shall be non-negative, non-NaN, and non-infinity. Moreover, the
|
| 1273 |
+
following relation shall hold:
|
| 1274 |
+
$$0 < S = \frac{1}{2} \cdot \sum_{k=0}^{n-1} (w_k + w_{k+1}) \cdot (b_{k+1} - b_k) \text{ .}$$
|
|
|
|
|
|
|
|
|
|
| 1275 |
|
| 1276 |
``` cpp
|
| 1277 |
template<class RealType = double>
|
| 1278 |
class piecewise_linear_distribution {
|
| 1279 |
public:
|
|
|
|
| 1320 |
template<class InputIteratorB, class InputIteratorW>
|
| 1321 |
piecewise_linear_distribution(InputIteratorB firstB, InputIteratorB lastB,
|
| 1322 |
InputIteratorW firstW);
|
| 1323 |
```
|
| 1324 |
|
| 1325 |
+
*Mandates:* `is_invocable_r_v<double, UnaryOperation&, double>` is
|
| 1326 |
+
`true`.
|
| 1327 |
+
|
| 1328 |
+
*Preconditions:* `InputIteratorB` and `InputIteratorW` each meet the
|
| 1329 |
+
*Cpp17InputIterator* requirements [[input.iterators]]. If
|
| 1330 |
+
`firstB == lastB` or `++firstB == lastB`, let n = 1, ρ₀ = ρ₁ = 1,
|
| 1331 |
+
b₀ = 0, and b₁ = 1. Otherwise, [`firstB`, `lastB`) forms a sequence b of
|
| 1332 |
+
length n+1, the length of the sequence w starting from `firstW` is at
|
| 1333 |
+
least n+1, and any wₖ for k ≥ n + 1 are ignored by the distribution.
|
|
|
|
| 1334 |
|
| 1335 |
*Effects:* Constructs a `piecewise_linear_distribution` object with
|
| 1336 |
parameters as specified above.
|
| 1337 |
|
| 1338 |
``` cpp
|
| 1339 |
template<class UnaryOperation>
|
| 1340 |
piecewise_linear_distribution(initializer_list<RealType> bl, UnaryOperation fw);
|
| 1341 |
```
|
| 1342 |
|
| 1343 |
+
*Mandates:* `is_invocable_r_v<double, UnaryOperation&, double>` is
|
| 1344 |
+
`true`.
|
|
|
|
|
|
|
| 1345 |
|
| 1346 |
*Effects:* Constructs a `piecewise_linear_distribution` object with
|
| 1347 |
parameters taken or calculated from the following values: If
|
| 1348 |
`bl.size()` < 2, let n = 1, ρ₀ = ρ₁ = 1, b₀ = 0, and b₁ = 1. Otherwise,
|
| 1349 |
let [`bl.begin(),` `bl.end()`) form a sequence b₀, …, bₙ, and let
|
| 1350 |
wₖ = `fw`(bₖ) for k = 0, …, n.
|
| 1351 |
|
| 1352 |
+
*Complexity:* The number of invocations of `fw` does not exceed n+1.
|
| 1353 |
|
| 1354 |
``` cpp
|
| 1355 |
template<class UnaryOperation>
|
| 1356 |
piecewise_linear_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw);
|
| 1357 |
```
|
| 1358 |
|
| 1359 |
+
*Mandates:* `is_invocable_r_v<double, UnaryOperation&, double>` is
|
| 1360 |
+
`true`.
|
| 1361 |
+
|
| 1362 |
+
*Preconditions:* If `nw` = 0, let n = 1, otherwise let n = `nw`. The
|
| 1363 |
+
relation 0 < δ = (`xmax` - `xmin`) / n holds.
|
| 1364 |
|
| 1365 |
*Effects:* Constructs a `piecewise_linear_distribution` object with
|
| 1366 |
parameters taken or calculated from the following values: Let
|
| 1367 |
bₖ = `xmin` + k ⋅ δ for k = 0, …, n, and wₖ = `fw`(bₖ) for k = 0, …, n.
|
| 1368 |
|
| 1369 |
+
*Complexity:* The number of invocations of `fw` does not exceed n+1.
|
| 1370 |
|
| 1371 |
``` cpp
|
| 1372 |
vector<result_type> intervals() const;
|
| 1373 |
```
|
| 1374 |
|