gdstats
gdstats is a Godot Engine library providing a collection of pseudorandom number generators for various statistical distributions. It includes implementations for discrete and continuous distributions, optimized for speed via inversion techniques.
https://github.com/droxpopuli/gdstatsPreview Images


gdstats: Advanced Statistical Distributions for Godot
gdstats is a valuable addition to any Godot project requiring nuanced random number generation. This library provides a suite of pseudorandom number generators, each designed to simulate common statistical distributions. Whether you're modeling game mechanics, simulating environmental effects, or creating procedural content, gdstats offers the tools you need.
Discrete Distributions
The library includes several discrete distributions, useful for generating integer-based random numbers:
-
randi_bernoulli(p)
: Simulates a Bernoulli trial, returning 1 or 0 based on the probabilityp
. -
randi_binomial(p, n)
: Returns the number of successes inn
Bernoulli trials, each with probabilityp
. -
randi_geometric(p)
: Returns the number of trials needed to achieve the first success in a series of Bernoulli trials with probabilityp
. -
randi_poisson(lambda)
: Approximates a Poisson distribution, modeling the number of events occurring in a fixed interval of time or space. -
randv_histogram(values, probabilities)
: Generates a random value from a custom distribution defined by a list of values and their corresponding probabilities. -
randi_pseudo(c)
: Mimics the Warcraft3/Dota style of "fair" number generators, increasing the probability of an event occurring after each failure.
Continuous Distributions
For generating floating-point random numbers, gdstats provides the following continuous distributions:
-
randf_uniform(a, b)
: Returns a uniformly distributed random number betweena
andb
. -
randf_exponential(lambda)
: Simulates an exponential distribution, modeling the time between events in a Poisson process. -
randf_erlang(k, lambda)
: Represents the sum ofk
exponential distributions, often used to model the time untilk
events occur in a Poisson process. -
randf_gaussian()/randf_normal()
: Generates random numbers from a normal (Gaussian) distribution.
gdstats aims to provide fast and efficient implementations of these distributions, making it a practical choice for game developers seeking realistic and varied random number generation.