probability selector php
Method export() added
Selection Manager para elegir los próximos elementos para usar desde la fuente de datos en función de la distribución uniforme de las selecciones.
use Smoren ProbabilitySelector ProbabilitySelector ;
$ ps = new ProbabilitySelector ([
// data // weight // initial usage counter
[ ' first ' , 1 , 0 ],
[ ' second ' , 2 , 0 ],
[ ' third ' , 3 , 4 ],
]);
foreach ( $ ps as $ datum ) {
echo "{ $ datum } , " ;
}
// second, second, first, second, third, third, second, first, third, second, third, third, second, first, third, ... use Smoren ProbabilitySelector ProbabilitySelector ;
$ ps = new ProbabilitySelector ([
// data // weight
[ ' first ' , 1 ],
[ ' second ' , 2 ],
]);
foreach ( $ ps -> getIterator ( 6 ) as $ datum ) {
echo "{ $ datum } , " ;
}
// second, second, first, second, second, first
print_r ( $ ps -> export ());
/*
[
['first', 1, 2],
['second', 2, 4],
]
*/ use Smoren ProbabilitySelector ProbabilitySelector ;
$ ps = new ProbabilitySelector ([
// data // weight
[ ' first ' , 1 ],
[ ' second ' , 2 ],
]);
$ ps -> decide (); // second
$ ps -> decide (); // second
$ ps -> decide (); // first composer install
composer test-init
composer test
El selector de probabilidad de PHP se ajusta a los siguientes estándares:
El selector de probabilidad de PHP tiene licencia bajo la licencia MIT.