PHPackages                             lortabac/alea - 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. lortabac/alea

ActiveLibrary

lortabac/alea
=============

Random selection from a weighted list

125PHP

Since Sep 8Pushed 12y agoCompare

[ Source](https://github.com/lortabac/alea)[ Packagist](https://packagist.org/packages/lortabac/alea)[ RSS](/packages/lortabac-alea/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

\#Alea

A tiny library to select a random element from a weighted list.

Installation
------------

[](#installation)

### With composer

[](#with-composer)

If you use [composer](http://getcomposer.org/), you just need to add `lortabac/alea` to your `composer.json` file.

```
{
    "require": {
        "lortabac/alea": "dev-master"
    }
}

```

### Manual installation

[](#manual-installation)

1. Copy the files in the `src` directory into your project.
2. Include the class you need (`WeightedList.php` or `Dice.php`).

Usage
-----

[](#usage)

### Weighted list

[](#weighted-list)

In weighted list mode, a relative weight is assigned to each element.

```
$criteria = [
	['foo', 50],
	['bar', 30],
	['baz', 20]
];

$weightedList = new Alea\WeightedList($criteria);
$element = $weightedList->getItem();
```

### Dice

[](#dice)

In dice mode, each element has a specific range. Only the upper limit is specified. The first range always starts from 1.

```
$criteria = [
    ['foo', 6], // from 1 to 6
    ['bar', 8], // 7 and 8
    ['baz', 12] // from 9 to 12
];

$dice = new Alea\Dice($criteria);
$element = $dice->getItem();
```

You can optionally include the dice roll. In this case the result is given as an associative array.

```
$itemData = $dice->getItem(Alea\Dice::INCLUDE_ROLL);
print_r($itemData);

/*
Array
(
    [roll] => 8
    [item] => bar
)
*/
```

License
-------

[](#license)

(The MIT License)

Copyright (C) 2013 Lorenzo Tabacchini

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/00525bcb5b3ad2027e0855818f05d55be5592d95d58fce66831bec3f6134f556?d=identicon)[lortabac](/maintainers/lortabac)

---

Top Contributors

[![lortabac](https://avatars.githubusercontent.com/u/1907333?v=4)](https://github.com/lortabac "lortabac (5 commits)")

### Embed Badge

![Health badge](/badges/lortabac-alea/health.svg)

```
[![Health](https://phpackages.com/badges/lortabac-alea/health.svg)](https://phpackages.com/packages/lortabac-alea)
```

PHPackages © 2026

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