Generates Bernoulli distributed random values.


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

Devices supported: Host, CPU, and GPU.

Include Files

  • oneapi/mkl/rng.hpp


The oneapi::mkl::rng::bernoulli class object is used in the oneapi::mkl::rng::generate function to provide Bernoulli distributed random numbers with probability p of a single trial success, where

p∈R; 0 ≤  p  ≤ 1.

A variate is called Bernoulli distributed, if after a trial it is equal to 1 with probability of success p, and to 0 with probability 1 - p.

The probability distribution is given by:

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

The cumulative distribution function is as follows:


Intel’s compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice. Notice revision #20110804

This notice covers the following instruction sets: SSE2, SSE4.2, AVX2, AVX-512.

Template Parameters

typename_IntType = std::int32_t

Type of the produced values. The specific values are as follows: std::int32_t std::uint32_t

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

Generation method. The specific values are as follows: oneapi::mkl::rng::bernoulli_method::icdf See brief descriptions of the methods in Distributions Template Parameter Method Values

Input Parameters






Success probability p of a trial.