# bernoulli#

Class is used for generation of Bernoulli distributed integer types random numbers.

Description

The class object is used in the oneapi::mkl::rng::generate() function to provide random numbers Bernoulli distributed with probability $$p$$ of a single trial success, where $$p \in R; 0 \leq p; p \leq 1$$.

The probability distribution is given by:

$P(X = 1) = p$
$P(X = 0) = 1 - p$

The cumulative distribution function is as follows:

$\begin{split}F_{p}(x) = \left\{ \begin{array}{rcl} 0, x < 0 \\ 1 - p, 0 \leq x < 1, x \in R \\ 1, x \ge 1 \end{array}\right.\end{split}$

## class bernoulli#

Syntax

namespace oneapi::mkl::rng {
template<typename IntType = std::int32_t, typename Method = bernoulli_method::by_default>
class bernoulli {
public:
using method_type = Method;
using result_type = IntType;
bernoulli();
explicit bernoulli(float p);
float p() const;
};
}


Template parameters

typename IntType
Type of the produced values. Supported types:
• std::int32_t

• std::uint32_t

typename Method = oneapi::mkl::rng::bernoulli_method::by_default

Transformation method, which will be used for generation. Supported types:

• oneapi::mkl::rng::bernoulli_method::by_default

• oneapi::mkl::rng::bernoulli_method::icdf

See description of the methods in Distributions methods template parameter.

Class Members

Routine

Description

bernoulli()

Default constructor

explicit bernoulli(float p)

Constructor with parameters

float p() const

Method to obtain probability p

Member types

bernoulli::method_type = Method


Description

The type which defines transformation method for generation.

bernoulli::result_type = IntType


Description

The type which defines type of generated random numbers.

Constructors

bernoulli::bernoulli()


Description

Default constructor for distribution, parameters set as p = 0.5f.

explicit bernoulli::bernoulli(float p)


Description

Constructor with parameters. p is a probability.

Throws

oneapi::mkl::invalid_argument

Exception is thrown when p > 1.0f, or p < 0.0f

Characteristics

float p() const


Return Value

Returns the distribution parameter p - probability.

Parent topic: Distributions