Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
Infinity::Engine::PoissonDistribution< IntType > Class Template Reference

Platform-independent Poisson distribution. More...

#include <PRNGDistribution.hpp>

Classes

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

Public Types

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

Public Member Functions

 PoissonDistribution ()
 Default constructor. Creates Poisson distribution with mean=1.0.
 
 PoissonDistribution (double mean)
 Constructs a Poisson distribution with specified mean.
 
 PoissonDistribution (const param_type &param)
 Constructs from a parameter set.
 
void reset ()
 Resets the distribution state.
 
double mean () const
 Gets the mean (rate) parameter.
 
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 (0).
 
result_type max () const
 Gets the theoretical maximum value (unbounded).
 
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 PoissonDistribution &lhs, const PoissonDistribution &rhs)
 
bool operator!= (const PoissonDistribution &lhs, const PoissonDistribution &rhs)
 

Detailed Description

template<typename IntType = int>
class Infinity::Engine::PoissonDistribution< IntType >

Platform-independent Poisson distribution.

Produces integer counts of events occurring in a fixed interval when events happen independently at a constant average rate. Uses normal approximation for large means, Knuth's algorithm for small means.

The Poisson distribution is fundamental for modeling count data where events occur randomly over time or space: number of calls per hour, defects per item, particles detected per second, customers arriving per minute, or any process where events occur randomly at a constant average rate.

Template Parameters
IntTypeInteger type for the result

Example usage:

PRNG rng(12345);
// Average 5 customers per hour
PoissonDistribution<int> customers(5.0);
int arrivals = customers(rng);
// Radioactive decay events (low rate)
PoissonDistribution<int> decay_events(2.3);
int detections = decay_events(rng);
// Web server requests per second
PoissonDistribution<int> requests(15.0);
int request_count = requests(rng);
// Procedural generation: enemy spawns per region
int enemy_count = spawns(rng);
Pseudo-random number generator for procedural generation.
Definition PRNG.hpp:48
Platform-independent Poisson distribution.
Definition PRNGDistribution.hpp:3083
Note
Returns non-negative integers.
Mean = Variance = mean parameter (equal mean and variance is characteristic).
Uses Knuth's method for mean < 10, normal approximation for mean >= 10.
For very large means (>100), normal approximation is highly accurate.

Member Typedef Documentation

◆ result_type

template<typename IntType = int>
using Infinity::Engine::PoissonDistribution< IntType >::result_type = IntType

The type of values produced by the distribution.

Constructor & Destructor Documentation

◆ PoissonDistribution() [1/3]

template<typename IntType = int>
Infinity::Engine::PoissonDistribution< IntType >::PoissonDistribution ( )
inline

Default constructor. Creates Poisson distribution with mean=1.0.

◆ PoissonDistribution() [2/3]

template<typename IntType = int>
Infinity::Engine::PoissonDistribution< IntType >::PoissonDistribution ( double  mean)
inlineexplicit

Constructs a Poisson distribution with specified mean.

Parameters
meanMean number of events (rate parameter)

◆ PoissonDistribution() [3/3]

template<typename IntType = int>
Infinity::Engine::PoissonDistribution< IntType >::PoissonDistribution ( const param_type param)
inlineexplicit

Constructs from a parameter set.

Parameters
paramThe distribution parameters

Member Function Documentation

◆ max()

template<typename IntType = int>
result_type Infinity::Engine::PoissonDistribution< IntType >::max ( ) const
inline

Gets the theoretical maximum value (unbounded).

◆ mean()

template<typename IntType = int>
double Infinity::Engine::PoissonDistribution< IntType >::mean ( ) const
inline

Gets the mean (rate) parameter.

◆ min()

template<typename IntType = int>
result_type Infinity::Engine::PoissonDistribution< IntType >::min ( ) const
inline

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

◆ operator()() [1/2]

template<typename IntType = int>
template<typename Generator >
result_type Infinity::Engine::PoissonDistribution< IntType >::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
A random count of events

◆ operator()() [2/2]

template<typename IntType = int>
template<typename Generator >
result_type Infinity::Engine::PoissonDistribution< IntType >::operator() ( Generator &  g,
const param_type param 
)
inline

Generates the next random value using provided parameters.

Uses two methods depending on the mean:

  1. Normal approximation (mean >= 10): Uses Normal(mean, sqrt(mean)) with continuity correction. Fast and accurate for large means.
  2. Knuth's method (mean < 10): Simulates the Poisson process by generating uniform random values and multiplying them until their product falls below e^(-mean). The count of multiplications gives the Poisson value.

    Algorithm: Generate U1, U2, ... ~ Uniform(0,1) Count k such that U1*U2*...*Uk > e^(-mean) Return k-1

Template Parameters
GeneratorThe random number generator type (e.g., PRNG)
Parameters
gThe random number generator
paramThe distribution parameters to use for this generation
Returns
A random count of events with mean param.mean()

◆ param() [1/2]

template<typename IntType = int>
param_type Infinity::Engine::PoissonDistribution< IntType >::param ( ) const
inline

Gets the current parameter set.

◆ param() [2/2]

template<typename IntType = int>
void Infinity::Engine::PoissonDistribution< IntType >::param ( const param_type param)
inline

Sets new parameters for the distribution.

Recreates the normal distribution for approximation if needed.

Parameters
paramThe new distribution parameters

◆ reset()

template<typename IntType = int>
void Infinity::Engine::PoissonDistribution< IntType >::reset ( )
inline

Resets the distribution state.

Resets the underlying normal distribution if it's being used for approximation.

Friends And Related Symbol Documentation

◆ operator!=

template<typename IntType = int>
bool operator!= ( const PoissonDistribution< IntType > &  lhs,
const PoissonDistribution< IntType > &  rhs 
)
friend

◆ operator==

template<typename IntType = int>
bool operator== ( const PoissonDistribution< IntType > &  lhs,
const PoissonDistribution< IntType > &  rhs 
)
friend