outcloud/geometric-array-random
Composer 安装命令:
composer require outcloud/geometric-array-random
包简介
This package can be used to get random value from an array with given probability for each value
README 文档
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
统计信息
- 总下载量: 16.72k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-08-23