PHPackages                             lucapuddu/php-provably-fair - 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. lucapuddu/php-provably-fair

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

lucapuddu/php-provably-fair
===========================

PhpProvablyFair is a library that generates and verifies provably fair games.

3.1.1(3y ago)155.5k3MITPHPPHP ^7.2|^8.0CI failing

Since Nov 3Pushed 3y ago2 watchersCompare

[ Source](https://github.com/LucaPuddu/php-provably-fair)[ Packagist](https://packagist.org/packages/lucapuddu/php-provably-fair)[ Docs](https://github.com/lpuddu/php-provably-fair)[ RSS](/packages/lucapuddu-php-provably-fair/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (5)Dependencies (3)Versions (9)Used By (0)

Php Provably Fair
=================

[](#php-provably-fair)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ec6134399e458bf9dd23991884efb809f80d1c37b7222577a2d3f542117d45de/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c75636170756464752f7068702d70726f7661626c792d666169722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lucapuddu/php-provably-fair)[![Total Downloads](https://camo.githubusercontent.com/99a22f4555228b2fab50bd86a7db359461a9b5b37d6a32e9565569c37d142f84/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c75636170756464752f7068702d70726f7661626c792d666169722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lucapuddu/php-provably-fair)

This library provides functions to generate and verify provably fair games.

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

[](#installation)

Via Composer

```
composer require lucapuddu/php-provably-fair
```

The algorithm
-------------

[](#the-algorithm)

#### Parameters values used in this example

[](#parameters-values-used-in-this-example)

```
$algorithm = 'sha256';
$serverSeed = 'server seed';
$clientSeed = 'client seed';
$nonce = '1';
$min = 15;
$max = 96;
```

#### Steps

[](#steps)

1. A hexadecimal string of variable length (depending on the algorithm used) is computed with [hash\_hmac](https://www.php.net/manual/en/function.hash-hmac.php). The function uses the `$serverSeed` as key, and the `$clientSeed` and `$nonce` as data, concatenated with an *hyphen*:

```
$output1 = hash_hmac($algorithm, "{$clientSeed}-{$nonce}", $serverSeed);
echo $output1; // 78ed9330f00055f15765cb141088f316d507204a745ad4800fd719fcbfca071a
```

2. `$output1` is then scaled to a number from `0` to `1`, by converting it to an integer number and then dividing it by the maximum result possible (which is equal to `16 ^ length of $output1`)

```
$output2 = hexdec($output1) / (16 ** strlen($output1));
echo $output2; // 0.47237510628475
```

3. `$output2` is scaled accordingly to `min` and `max`:

```
$result = $min + $output2 * ($max - $min);
echo $result; // 53.26238360906475‬
```

4. The **result** is returned.

Usage
-----

[](#usage)

### Create a `ProvablyFair` Object

[](#create-a-provablyfair-object)

```
$algorithm = 'sha256';
$serverSeed = 'server seed';
$clientSeed = 'client seed';
$nonce = 'nonce';
$min = 23.75;
$max = 44;
$generator = Builder::make()
                    ->algorithm($algorithm)
                    ->serverSeed($serverSeed)
                    ->clientSeed($clientSeed)
                    ->nonce($nonce)
                    ->range($min, $max)
                    ->build();

```

##### Default values

[](#default-values)

```
$algorithm = 'sha512/256';
$min = 0;
$max = 100;

```

Get the full list of supported algorithms [here](https://www.php.net/manual/en/function.hash-hmac-algos.php).

### Roll a number

[](#roll-a-number)

```
...
$output = $generator->roll();
echo $output;   //38.325308655221

// Change ProvablyFair state
$generator->setNonce('new nonce');

// Roll a new number
$output = $generator->roll();
echo $output;   //23.752100169784
```

### Verify a roll

[](#verify-a-roll)

```
...
$generator->verify(38.325308655221); // true

```

### Security

[](#security)

If you discover any security related issues, please use the issue tracker on github or email me at info\_\_at\_\_lucapuddu.com

Authors
-------

[](#authors)

- [Luca Puddu](https://github.com/LucaPuddu)

License
-------

[](#license)

MIT. Please see the [license file](license.md) for more information.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 96.4% 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 ~139 days

Recently: every ~214 days

Total

8

Last Release

1459d ago

Major Versions

1.0.1 → 2.0.02020-02-24

2.1.0 → 3.0.02020-02-29

PHP version history (2 changes)1.0.0PHP ^7.2

3.1.0PHP ^7.2|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/21961770?v=4)[Luca Puddu](/maintainers/LucaPuddu)[@lucapuddu](https://github.com/lucapuddu)

---

Top Contributors

[![lucapuddu](https://avatars.githubusercontent.com/u/21961770?v=4)](https://github.com/lucapuddu "lucapuddu (27 commits)")[![ErriourMe](https://avatars.githubusercontent.com/u/43105218?v=4)](https://github.com/ErriourMe "ErriourMe (1 commits)")

---

Tags

gamblingfairprovably

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/lucapuddu-php-provably-fair/health.svg)

```
[![Health](https://phpackages.com/badges/lucapuddu-php-provably-fair/health.svg)](https://phpackages.com/packages/lucapuddu-php-provably-fair)
```

###  Alternatives

[beyondcode/laravel-favicon

Create dynamic favicons based on your environment settings.

37549.4k](/packages/beyondcode-laravel-favicon)[nex/yii2-chosen

Bootstrap Chosen widget for Yii2

28100.0k](/packages/nex-yii2-chosen)[nepster-web/gambling-tech

Gambling Algorithms for Certification.

122.0k](/packages/nepster-web-gambling-tech)

PHPackages © 2026

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