outcloud / geometric-array-random
This package can be used to get random value from an array with given probability for each value
Installs: 16 437
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=7.1
This package is not auto-updated.
Last update: 2025-04-13 06:55:53 UTC
README
This package can be used to get values of given array with given geometric probability
Examples:
'Together' Input Mode
$matrix = [ [1, 0.1], // value, probablility [2, 0.1], [3, 0.1], [4, 0.3], [5, 0.2], [null, 0.2], ]; $generator = new GeometricArrayRandom($matrix); $result = $generator->nextNValues(10); // possible result: [4, null, 5, 1, null, 5, 5, 4, null, 4] $singleValue = $generator->nextValue(); // possible result : 4
'Separately' Input Mode
$matrix = [ [1, 2, 3, 4, 5, null], // values [0.1, 0.1, 0.1, 0.3, 0.2, 0.2] // probabilities ]; $generator = new GeometricArrayRandom($matrix, GeometricArrayRandom::MODE_TWO_DIMENSIONS); $result = $generator->nextNValues(10); // possible result: [4, null, 5, 1, null, 5, 5, 4, null, 4] $singleValue = $generator->nextValue(); // possible result : 4
Additional info
- Sum of probabilities in single matrix must always be equal to 1.0 (Otherwise an exception will be thrown)
- Probability is 'float' value greater or equal to 0 and lower or equal to 1 (Otherwise an exception will be thrown)
- Each value must always have a probability assigned (Otherwise an exception will be thrown)
Installation:
composer require outcloud\geometric-array-random
I'm using Semantic Versioning http://semver.org/spec/v2.0.0.html