SourcePro® 2024.1 |
SourcePro® API Reference Guide |
Used to generate random numbers from a binomial distribution. More...
#include <rw/rand.h>
Public Member Functions | |
RWTRandBinomial (const Generator &g, size_t n=1, double p=0.5) | |
RWTRandBinomial (const RWTRandBinomial< Generator > &g) | |
RWTRandBinomial (size_t n=1, double p=0.5) | |
int | n () const |
virtual double | operator() () |
virtual size_t | operator() (double *out, size_t n) |
double | p () const |
void | setN (size_t n) |
void | setP (double p) |
Public Member Functions inherited from RWTRand< Generator > | |
RWTRand () | |
RWTRand (const Generator &g) | |
RWTRand (const RWTRand< Generator > &x) | |
Generator & | generator () |
const Generator & | generator () const |
void | setGenerator (const Generator &x) |
void | setGenerator (const RWTRand< Generator > &x) |
Class RWTRandBinomial generates random numbers from a binomial distribution:
\[ \begin{array}{l l l} f(x) & = \binom{n}{x} p^x(1-p)^{n-x}, & \text{x = 0, 1, ..., n} \\ & = \text{0} \hfill, & \text{elsewhere} \end{array} \]
where n
is the number of trials, and p
is the probability of success. The algorithm used to generate the random numbers begins with random numbers generated from a uniform distribution on the interval [0, 1]. Thus, the speed and statistical properties of the binomial random number generator may be changed by varying the Generator template parameter responsible for generating the uniformly distributed numbers.
The class Generator must be a function object whose function call operator returns a uniform random double between 0 and 1. The class RWRandGenerator supplied with the library may be used.
RWTRandBinomial< Generator >::RWTRandBinomial | ( | size_t | n = 1, |
double | p = 0.5 ) |
Constructs a generator with the number of trials = n and the probability of success = p.
RWTRandBinomial< Generator >::RWTRandBinomial | ( | const RWTRandBinomial< Generator > & | g | ) |
Constructs self as a copy of g.
RWTRandBinomial< Generator >::RWTRandBinomial | ( | const Generator & | g, |
size_t | n = 1, | ||
double | p = 0.5 ) |
Constructs a generator with underlying uniform [0, 1] generator g, number of trials = n, and probability of success = p.
|
inline |
Returns the number of trials for the distribution.
|
virtual |
Returns the next random number in the sequence.
Implements RWRandInterface.
|
virtual |
Assigns random numbers to n elements in out. Returns the number of random numbers generated.
Implements RWRandInterface.
|
inline |
Returns the probability of success for the distribution.
void RWTRandBinomial< Generator >::setN | ( | size_t | n | ) |
Sets the number of trials for the distribution to n.
void RWTRandBinomial< Generator >::setP | ( | double | p | ) |
Sets the probability of success for the distribution to p.
Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved. |