qmegas / php-rand-custom-distribution
Random number generator with custom distribution
1.0.1
2022-06-30 19:45 UTC
Requires
- php: >=7.0
This package is not auto-updated.
Last update: 2025-05-16 09:38:12 UTC
README
Standard PHP functions like rand
or mt_rand
generate random numbers with normal distribution, however sometimes it
required to generate random numbers with different distribution, for example binomial distribution.
Installation
composer require qmegas/php-rand-custom-distribution
Requirements
PHP >= 7.0
Simple Example
$generator = new \Qmegas\RandomGenerator(50, 150, function(float $i) { return $i * 100; }); echo $generator->getNumber();
Class constractor receives 3 arguments: low-high bounds of generated numbers and distribution function. Distribution function receives float argument between 0 and 1 and should return some integer value >= 0, see additional examples for better understanding.