emonkak / random
A random number generator library
Installs: 22 129
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 4
Forks: 1
Open Issues: 1
Requires
- php: >=7.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^7.0
- vimeo/psalm: ~3.11.0
README
This library provides pseudo-random number generators and probability distributions.
Requirements
- PHP 7.1 or higher
Licence
MIT Licence
Example
use Emonkak\Random\Engine\MT19937Engine; use Emonkak\Random\Distribution\NormalDistribution; $seed = 100; // Initial seed $engine = new MT19937Engine($seed); // 32bit Mersenne Twister engine $distribution = new NormalDistribution(0, 1); // Standard normal distribution // Generate a random number with the normal distribution. $distribution->generate($engine);
Engine
-
KnuthBEngine
-
LinearCongruentialEngine
-
MinstdRand0Engine
-
MinstdRandEngine
-
MT19937Engine
The random generator engine according to Mersenne Twister. It is full-compatible to the built-in
mt_rand()
.// Also, the initial seed algorithm is full-compatible to the built-in `mt_srand()` $engine = new MT19937Engine(/* $seed */); // Get a next random number from the current generator state. $number = $engine->next(); // as int $number = $engine->nextDouble(); // as float // Get the minimum and maximum number which generate a value by the engine. $minimum = $engine->min(); $maximum = $engine->max(); // Iterate the generator engine. foreach (new LimitIterator($engine, 0, 100) as $n) { }
-
MTRandWrapper
The wrapper for the built-in
mt_rand()
. -
ShuffleOrderEngine
-
XorShift128Engine
The random generator engine according to Xorshift 128 bit algorithm.
Distribution
BernoulliDistribution
BinomialDistribution
DiscreteDistribution
DistributionIterator
ExponentialDistribution
GammaDistribution
GeometricDistribution
LogNormalDistribution
NormalDistribution
PiecewiseConstantDistribution
PiecewiseLinerDistribution
UniformIntDistribution
UniformRealDistribution