PHPackages                             davidgorges/php-biased-random - 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. davidgorges/php-biased-random

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

davidgorges/php-biased-random
=============================

2461PHP

Since Jul 12Pushed 11y ago1 watchersCompare

[ Source](https://github.com/davidgorges/php-biased-random)[ Packagist](https://packagist.org/packages/davidgorges/php-biased-random)[ RSS](/packages/davidgorges-php-biased-random/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

php-biased-random
=================

[](#php-biased-random)

Get random elements based on probabilty

How to Use
----------

[](#how-to-use)

```
$randomizer = new Randomizer();
$randomizer->add( new Element('Banana', 70))
           ->add( new Element('Apple',  30));

$randomFruit = $randomizer->get(); // Chance of Banana is 70%

```

### Calculate Probability

[](#calculate-probability)

In some cases, you want to add multiple items and retrieve the probabilty of an item.

```
$randomizer = new Randomizer();
$randomizer->add( new Element('Banana', 2))
           ->add( new Element('Apple',  1))
           ->add( new Element('Banana', 2));

$probability = $randomizer->getProbabilityFor('Banana');
echo $probability; // outputs 0.8

```

### Shorthand methods

[](#shorthand-methods)

You don't need to create Element wrapper objects. You can just add your elements to the Randomizer:

```
$randomizer = new Randomizer();
$randomizer->add('banana')->add('apple');

// with weight
$randomizer->add('banana', 10)->add('apple', 5);

```

Note: If you add multiple identical items, they will be combined into a single element with adjusted weight.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

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/6abaff8e3d8d647d1cd8d3479bb3793b16a66ee24877d195e697a646439730ba?d=identicon)[dgorges](/maintainers/dgorges)

---

Top Contributors

[![davidgorges](https://avatars.githubusercontent.com/u/3885619?v=4)](https://github.com/davidgorges "davidgorges (11 commits)")

### Embed Badge

![Health badge](/badges/davidgorges-php-biased-random/health.svg)

```
[![Health](https://phpackages.com/badges/davidgorges-php-biased-random/health.svg)](https://phpackages.com/packages/davidgorges-php-biased-random)
```

###  Alternatives

[roundcube/carddav

CardDAV adapter for connecting to CardDAV-enabled addressbooks

28155.3k](/packages/roundcube-carddav)[fale/isbn

ISBN library

88524.8k6](/packages/fale-isbn)[izniburak/laravel-auto-routes

Auto Route Generating (Auto-Discovery) Package for Laravel

23645.3k](/packages/izniburak-laravel-auto-routes)[nystudio107/craft-typogrify

Typogrify prettifies your web typography by preventing ugly quotes and 'widows' and more

70381.7k18](/packages/nystudio107-craft-typogrify)[efureev/laravel-trees

Multi-Tree structures for Laravel

14253.3k4](/packages/efureev-laravel-trees)[tuupola/base32

Base32 encoder and decoder for arbitrary data

14552.2k6](/packages/tuupola-base32)

PHPackages © 2026

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