Class template bernoulli_distribution

| Home | Libraries | People | FAQ | More

## Class template bernoulli_distribution

boost::compute::bernoulli_distribution — Produces random boolean values according to the following discrete probability function with parameter p : P(true/p) = p and P(false/p) = (1 - p)

## Synopsis

    // In header: <boost/compute/random/bernoulli_distribution.hpp>

    template<typename RealType = float>
    class bernoulli_distribution {
    public:
      // construct/copy/destruct
      bernoulli_distribution(RealType = 0.5f);
      ~bernoulli_distribution();

      // public member functions
      RealType p() const;
      template<typename OutputIterator, typename Generator>
        void generate(OutputIterator, OutputIterator, Generator &,
                      command_queue &);
    };

## Description

The following example shows how to setup a bernoulli distribution to produce random boolean values with parameter p = 0.25

    // initialize the default random engine
    boost::compute::default_random_engine engine(queue);

    // setup the bernoulli distribution to produce booleans
    // with parameter p = 0.25
    boost::compute::bernoulli_distribution<float> distribution(0.25f);

    // generate the random values and store them to 'vec'
    distribution.generate(vec.begin(), vec.end(), engine, queue);

### `bernoulli_distribution` public construct/copy/destruct

1.     bernoulli_distribution(RealType p = 0.5f);

   Creates a new bernoulli distribution.

2.     ~bernoulli_distribution();

   Destroys the `bernoulli_distribution` object.

### `bernoulli_distribution` public member functions

1.     RealType p() const;

   Returns the value of the parameter p.

2.     template<typename OutputIterator, typename Generator>
         void generate(OutputIterator first, OutputIterator last,
                       Generator & generator, command_queue & queue);

   Generates bernoulli distributed booleans and stores them in the range [`first`, `last`).