endroid/priority-shuffle-random

This package is abandoned and no longer maintained. No replacement package was suggested.

Endroid Priority Shuffle Random

Fund package maintenance!
endroid

2.0.3 2020-04-27 14:11 UTC

This package is auto-updated.

Last update: 2020-12-09 13:30:20 UTC


README

By endroid

Latest Stable Version Build Status Total Downloads Monthly Downloads License

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.