Skip to content
This repository was archived by the owner on Dec 5, 2020. It is now read-only.

abandroid/priority-shuffle-random

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Priority Shuffle Random

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.

About

Random that evenly distributes items while respecting their priority

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages