PHPackages                             tmarsteel/dprng - 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. tmarsteel/dprng

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

tmarsteel/dprng
===============

A deterministic pseudo-random number generator

1.0.1(10y ago)014MITPHPPHP &gt;=5.4

Since Feb 12Pushed 4y ago1 watchersCompare

[ Source](https://github.com/tmarsteel/php-dprng)[ Packagist](https://packagist.org/packages/tmarsteel/dprng)[ Docs](https://github.com/tmarsteel/php-dprng)[ RSS](/packages/tmarsteel-dprng/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

php-dprng
=========

[](#php-dprng)

Implementation of a DPRNG algorithm aimed at being simple to implement in almost any general-purpose programming language. Its intended use are simple games; scenarios where a pseudo-random sequence has to be replayed deterministically with low memory and computational cost. **The algorithm is not secure. DO NOT USE THIS FOR SECURITY RELATED TASKS.**

A JavaScript implementation that generates equal sequences for the same salts/seeds can be found [here](//github.com/tmarsteel/js-dprng)

Please contribute with your own implementation in your favorite language! A description of the algorithm and test vectors can be found in [algorithm.md](algorithm.md). I`ll cross-link compliant forks :)

Installation &amp; Usage
------------------------

[](#installation--usage)

`composer require tmarsteel/php-dprng:1.*` or just download the [single class file](tmarsteel/dprng/DPRNG.php).

```
use tmarsteel\dprng\DPRNG;

// secure random numbers (seeded from mcrypt_create_iv() if available, rand() otherwise)
$rng = new DPRNG();

// deterministic random sequence
$seed = 0xA2F38C0;
$rng = new DPRNG($seed);

// generate random numbers
$random = $rng->next(); // random float from 0 inclusive to 1 exclusive (same range as Math.random())

$random = $rng->nextInt(14, 300); // random integer in the range 14 to 299

$bytes = $rng->nextBytes(30); // 30 random integers in the range 0 to 255
```

Entropy / Randomness inspection
-------------------------------

[](#entropy--randomness-inspection)

[ENT](http://www.fourmilab.ch/random/) is a neat program to inspect the entropy and randomness of a sequence of bytes or bits. This table compares its output with values returned from rand(), mcrypt\_create\_iv() and this DPRNG. For explanations on the metrics see [the ENT Website](http://www.fourmilab.ch/random/) **These numbers do only show that output of this DPRNG is sufficently random to be indistinguishable from random noise to HUMANS. Computers will be able to work out the initial salt given a RIDICULOUSLY SMALL SAMPLE!**

RNGOSEntropyArithmetic meanChi-Square %Correlation coefficientMonte-Carlo PI error %rand()Windows 107.998118127.666999.99-0.0065200.55DPRNG seeded by mcrypt\_create\_iv()Windows 107.992490127.754829.170.0051920.02mcrypt\_create\_iv()Windows 107.993520127.663186.440.0109600.37rand()Ubuntu 15.107.992890127.676356.82-0.0049451.15DPRNG seeded by mcrypt\_create\_iv() *(a)*Ubuntu 15.107.993482127.845184.77-0.0002052.43mcrypt\_create\_iv()*(b)*Ubuntu 15.107.993261127.442973.700.0008310.4*You can run these tests yourself with the ent executable and the entTestfile.php script.*
*(a) source = MCRYPT\_DEV\_RANDOM*
*(b) source = MCRYPT\_DEV\_URANDOM*

Methods
-------

[](#methods)

Here is a full list of the methods supported by `tmarsteel\dprng\DPRNG` objects and their signatures + contracts:

**`float next()`**
Returns an uniformly distributed float value in the range `[0, 1)` (0 inclusive to 1 exclusive).

**`float nextFloat(float $from, float $to)`**
Returns an uniformly distributed float value in the range `[$from, $to)` (`$from` inclusive to `$to` exclusive).

**`int nextInt(int $from, int $to)`**
Returns an uniformly distributed integer in the range `[$from, $to]` (`$from` inclusive to `$to` inclusive).

**`array nextBytes(int $n)`**
Returns an array of length `$n`. Each entry is a uniformly distributed integer between 0 and 255.

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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 ~0 days

Total

2

Last Release

3790d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/13796579?v=4)[Tobias Marstaller](/maintainers/tmarsteel)[@tmarsteel](https://github.com/tmarsteel)

---

Top Contributors

[![tmarsteel](https://avatars.githubusercontent.com/u/13796579?v=4)](https://github.com/tmarsteel "tmarsteel (28 commits)")

---

Tags

randomgeneratorRNGdeterministicdprng

### Embed Badge

![Health badge](/badges/tmarsteel-dprng/health.svg)

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

###  Alternatives

[mistic100/randomcolor

Generate attractive random colors

2411.5M6](/packages/mistic100-randomcolor)[ihor/nspl

Non-standard PHP library (NSPL) - functional primitives toolbox and more

375369.1k](/packages/ihor-nspl)[nubs/random-name-generator

A library to create interesting, sometimes entertaining, random names.

132705.1k3](/packages/nubs-random-name-generator)[gladcodes/keygen

A fluent PHP random key generator.

119759.9k2](/packages/gladcodes-keygen)[genphrase/genphrase

Secure passphrase generator for PHP applications

117312.1k4](/packages/genphrase-genphrase)[hi-folks/rando-php

Random generator Library for PHP

12889.8k2](/packages/hi-folks-rando-php)

PHPackages © 2026

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