PHPackages                             smoren/probability-selector - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. smoren/probability-selector

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

smoren/probability-selector
===========================

Probability selector

v2.1.0(3y ago)138201MITPHPPHP &gt;=7.4

Since Jun 26Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Smoren/probability-selector-php)[ Packagist](https://packagist.org/packages/smoren/probability-selector)[ RSS](/packages/smoren-probability-selector/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (5)Versions (4)Used By (1)

PHP Probability Selector
========================

[](#php-probability-selector)

[![Packagist PHP Version Support](https://camo.githubusercontent.com/4bb1a96f1e689598f5c4aeaf989b941d3578b9b51ad163981743051cd019791e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f736d6f72656e2f70726f626162696c6974792d73656c6563746f72)](https://camo.githubusercontent.com/4bb1a96f1e689598f5c4aeaf989b941d3578b9b51ad163981743051cd019791e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f736d6f72656e2f70726f626162696c6974792d73656c6563746f72)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/6e5d48c01cae3fd9f968e47db1a423ebb9c5860bb46e9230b93af75635688f3b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f536d6f72656e2f70726f626162696c6974792d73656c6563746f722d7068702f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Smoren/probability-selector-php/?branch=master)[![Coverage Status](https://camo.githubusercontent.com/42a4b902bd460b5cce9e049c543ef0ffdb79f80e5a7a6c8e510ddfca4c5cf894/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f536d6f72656e2f70726f626162696c6974792d73656c6563746f722d7068702f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/Smoren/probability-selector-php?branch=master)[![Build and test](https://github.com/Smoren/probability-selector-php/actions/workflows/test_master.yml/badge.svg)](https://github.com/Smoren/probability-selector-php/actions/workflows/test_master.yml/badge.svg)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)

Selection manager for choosing next elements to use from data source based on uniform distribution of selections.

#### Infinite iteration

[](#infinite-iteration)

```
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, ...
```

#### Iteration limit and export

[](#iteration-limit-and-export)

```
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],
]
 */
```

#### Single decision

[](#single-decision)

```
use Smoren\ProbabilitySelector\ProbabilitySelector;

$ps = new ProbabilitySelector([
    // data     // weight
    ['first',   1],
    ['second',  2],
]);
$ps->decide(); // second
$ps->decide(); // second
$ps->decide(); // first
```

Unit testing
------------

[](#unit-testing)

```
composer install
composer test-init
composer test

```

Standards
---------

[](#standards)

PHP Probability Selector conforms to the following standards:

- PSR-1 — [Basic coding standard](https://www.php-fig.org/psr/psr-1/)
- PSR-4 — [Autoloader](https://www.php-fig.org/psr/psr-4/)
- PSR-12 — [Extended coding style guide](https://www.php-fig.org/psr/psr-12/)

License
-------

[](#license)

PHP Probability Selector is licensed under the MIT License.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~488 days

Total

3

Last Release

1167d ago

Major Versions

1.0.0 → v2.0.02023-02-27

PHP version history (2 changes)1.0.0PHP &gt;=7.2.0

v2.0.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/fdc9e8df44cbbc0fc88885a4f1daa2cad755266e73eb0bac15efaf0d47ecbae2?d=identicon)[smoren](/maintainers/smoren)

---

Top Contributors

[![Smoren](https://avatars.githubusercontent.com/u/7403235?v=4)](https://github.com/Smoren "Smoren (3 commits)")

---

Tags

helperphp-libraryprobability-distributionhelperfrequencyprobability

###  Code Quality

TestsCodeception

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/smoren-probability-selector/health.svg)

```
[![Health](https://phpackages.com/badges/smoren-probability-selector/health.svg)](https://phpackages.com/packages/smoren-probability-selector)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M683](/packages/barryvdh-laravel-ide-helper)[markrogoyski/math-php

Math Library for PHP. Features descriptive statistics and regressions; Continuous and discrete probability distributions; Linear algebra with matrices and vectors, Numerical analysis; special mathematical functions; Algebra

2.4k7.1M40](/packages/markrogoyski-math-php)[bryanjhv/slim-session

Session middleware and helper for Slim framework 4.

233961.5k15](/packages/bryanjhv-slim-session)[laravelista/ekko

Framework agnostic PHP package for marking navigation items active.

278673.4k4](/packages/laravelista-ekko)[beste/json

A simple JSON helper to decode and encode JSON

4222.7M3](/packages/beste-json)[chillerlan/php-settings-container

A container class for immutable settings objects. Not a DI container.

3427.3M21](/packages/chillerlan-php-settings-container)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
