endroid / priority-shuffle-random
Endroid Priority Shuffle Random
Fund package maintenance!
endroid
Requires
- php: >=7.2
Requires (Dev)
- endroid/quality: dev-master
Suggests
- roave/security-advisories: Avoids installation of package versions with vulnerabilities
- symfony/security-checker: Checks your composer.lock for vulnerabilities
README
By endroid
This library extends the basic random functionality by ensuring that the appearance of items is evenly distributed while respecting their priority. Items with priority 3 will be shown three times as often as items with priority 1, while the shuffle algorithm ensures that the values are spreaded nicely.
Installation
Use Composer to install the library.
$ composer require endroid/priority-shuffle-random
Usage
<?php use Endroid\PriorityShuffleRandom; $random = new PriorityShuffleRandom(); $random->add('A', 1); $random->add('B', 2); // Show B two times as often as the other items $random->add('C', 1); $random->add('D', 1); for ($i = 0; $i < 12; $i++) { echo $random->next(); } // Example output: CABDBDBACBAC
Versioning
Version numbers follow the MAJOR.MINOR.PATCH scheme. Backwards compatibility breaking changes will be kept to a minimum but be aware that these can occur. Lock your dependencies for production and test your code when upgrading.
License
This bundle is under the MIT license. For the full copyright and license information please view the LICENSE file that was distributed with this source code.