Download the PHP package savvot/random without Composer
On this page you can find all versions of the php package savvot/random. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download savvot/random
More information about savvot/random
Files in savvot/random
Package random
Short Description Deterministic pseudo-random generators library with dozens of useful functions and several sources of randomness
License MIT
Informations about the package random
PHP pseudo random generators library
This set of classes provides basic abstraction around different pseudo random generators with the same generic API. Also it contains many useful helper methods like weighted random, text generation, shuffling, array functions, etc.
WARNING: This PRNGs are non cryptographically secure (mt_rand() too)
Why not mt_rand()?
PHP builtin mt_rand() and rand() are global functions, so it is not possible to create several generators with different predefined seeds and use them simultaneously. There is also no control over current state of random sequences.
Features
- Deterministic random generators with optional seeds
- Correct uniform distribution
- Gaussian sampler for normally distributed random numbers based on Ziggurat algorithm
- Extensible architecture: it is easy to add your own source of randomness
- Seeds can be strings of any length you want
- Possibility to save and restore current PRNG's state at any time, so one can replay the sequence from known state
- Different random types: int, float, boolean
- Weighted random: random array key by weights, weighted shuffle
- Random binary data generation
- Random text generation from specified characters list with optional multi-byte support
- Array methods, alternatives to array_rand, shuffle
PRNG sources
-
XorShiftRand Fast and good quality random generator, based on XorShift+ algorithm with 128bit state. Should be used in most cases.
-
MtRand Pure PHP implementation of builtin mt_rand variation of Mersenne twister algorithm. Random sequences from both methods with same int seed will match perfectly, therefore this generator is fully compatible with mt_rand() and can be used as replacement.
- HashRand Proof-of-concept that md5 hash is uniformly distributed and can be used as source for pseudo random numbers. Pretty fast and straightforward.
Examples
More info
- PRNG: https://en.wikipedia.org/wiki/Pseudorandom_number_generator
- XorShift: https://en.wikipedia.org/wiki/Xorshift
- Mersenne Twister: https://en.wikipedia.org/wiki/Mersenne_Twister
- Some PRNGs benchmark: http://xorshift.di.unimi.it/
- Normal distribution: https://en.wikipedia.org/wiki/Normal_distribution
- Ziggurat algorithm: https://en.wikipedia.org/wiki/Ziggurat_algorithm