Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
Infinity::Engine::BernoulliDistribution Class Reference

Platform-independent Bernoulli distribution. More...

#include <PRNGDistribution.hpp>

Classes

struct  param_type
 Parameter set for the distribution. More...
 

Public Types

using result_type = bool
 The type of values produced by the distribution.
 

Public Member Functions

 BernoulliDistribution ()
 Default constructor. Creates fair Bernoulli distribution (p=0.5).
 
 BernoulliDistribution (double p)
 Constructs a Bernoulli distribution with specified success probability.
 
 BernoulliDistribution (const param_type &param)
 Constructs from a parameter set.
 
void reset ()
 Resets the distribution state.
 
double p () const
 Gets the success probability.
 
param_type param () const
 Gets the current parameter set.
 
void param (const param_type &param)
 Sets new parameters for the distribution.
 
result_type min () const
 Gets the minimum value that can be generated (false).
 
result_type max () const
 Gets the maximum value that can be generated (true).
 
template<typename Generator >
result_type operator() (Generator &g)
 Generates the next random value using stored parameters.
 
template<typename Generator >
result_type operator() (Generator &g, const param_type &param)
 Generates the next random value using provided parameters.
 

Friends

bool operator== (const BernoulliDistribution &lhs, const BernoulliDistribution &rhs)
 
bool operator!= (const BernoulliDistribution &lhs, const BernoulliDistribution &rhs)
 

Detailed Description

Platform-independent Bernoulli distribution.

Produces boolean values according to a Bernoulli trial with success probability p. This is the fundamental building block for discrete probability - a single trial with two possible outcomes (success/failure, true/false, heads/tails).

The Bernoulli distribution is the simplest discrete distribution and forms the basis for many other distributions including binomial, geometric, and negative binomial. It's used for coin flips, binary decisions, success/failure events, or any single trial with two possible outcomes.

Example usage:

PRNG rng(12345);
// Fair coin flip (p=0.5)
BernoulliDistribution fair_coin(0.5);
bool heads = fair_coin(rng);
// Biased coin (70% chance of success)
bool success = biased(rng);
// Simulate 100 trials
int successes = 0;
for (int i = 0; i < 100; ++i) {
if (trial(rng)) successes++;
}
// Model random events in procedural generation
BernoulliDistribution spawn_chance(0.05); // 5% spawn rate
if (spawn_chance(rng)) {
// Spawn entity
}
Platform-independent Bernoulli distribution.
Definition PRNGDistribution.hpp:2486
Pseudo-random number generator for procedural generation.
Definition PRNG.hpp:48
Note
Returns true with probability p, false with probability (1-p).
Mean = p, Variance = p(1-p).
Maximum variance occurs at p = 0.5 with variance = 0.25.

Member Typedef Documentation

◆ result_type

The type of values produced by the distribution.

Constructor & Destructor Documentation

◆ BernoulliDistribution() [1/3]

Infinity::Engine::BernoulliDistribution::BernoulliDistribution ( )
inline

Default constructor. Creates fair Bernoulli distribution (p=0.5).

◆ BernoulliDistribution() [2/3]

Infinity::Engine::BernoulliDistribution::BernoulliDistribution ( double  p)
inlineexplicit

Constructs a Bernoulli distribution with specified success probability.

Parameters
pProbability of success (true)

◆ BernoulliDistribution() [3/3]

Infinity::Engine::BernoulliDistribution::BernoulliDistribution ( const param_type param)
inlineexplicit

Constructs from a parameter set.

Parameters
paramThe distribution parameters

Member Function Documentation

◆ max()

result_type Infinity::Engine::BernoulliDistribution::max ( ) const
inline

Gets the maximum value that can be generated (true).

◆ min()

result_type Infinity::Engine::BernoulliDistribution::min ( ) const
inline

Gets the minimum value that can be generated (false).

◆ operator()() [1/2]

template<typename Generator >
result_type Infinity::Engine::BernoulliDistribution::operator() ( Generator &  g)
inline

Generates the next random value using stored parameters.

Template Parameters
GeneratorThe random number generator type (e.g., PRNG)
Parameters
gThe random number generator
Returns
true with probability p, false with probability (1-p)

◆ operator()() [2/2]

template<typename Generator >
result_type Infinity::Engine::BernoulliDistribution::operator() ( Generator &  g,
const param_type param 
)
inline

Generates the next random value using provided parameters.

Generates a uniform random value and compares it to the success probability. Returns true if the uniform value is less than p.

Template Parameters
GeneratorThe random number generator type (e.g., PRNG)
Parameters
gThe random number generator
paramThe distribution parameters to use for this generation
Returns
true with probability param.p(), false otherwise

◆ p()

double Infinity::Engine::BernoulliDistribution::p ( ) const
inline

Gets the success probability.

◆ param() [1/2]

param_type Infinity::Engine::BernoulliDistribution::param ( ) const
inline

Gets the current parameter set.

◆ param() [2/2]

void Infinity::Engine::BernoulliDistribution::param ( const param_type param)
inline

Sets new parameters for the distribution.

◆ reset()

void Infinity::Engine::BernoulliDistribution::reset ( )
inline

Resets the distribution state.

No-op for Bernoulli distribution as it maintains no internal state.

Friends And Related Symbol Documentation

◆ operator!=

bool operator!= ( const BernoulliDistribution lhs,
const BernoulliDistribution rhs 
)
friend

◆ operator==

bool operator== ( const BernoulliDistribution lhs,
const BernoulliDistribution rhs 
)
friend