Clone this repo:
  1. 5d78a0e build: Updating mediawiki/mediawiki-codesniffer to 43.0.0 by libraryupgrader · 5 weeks ago master
  2. 2b1995f build: Updating mediawiki/mediawiki-phan-config to 0.14.0 by libraryupgrader · 2 months ago
  3. c3930fe build: Upgrade phpunit to 9.6.16 by James D. Forrester · 3 months ago
  4. f65b819 build: Switch phan to special library mode by James D. Forrester · 1 year ago
  5. 4b4434c build: Updating mediawiki/mediawiki-codesniffer to 41.0.0 by libraryupgrader · 1 year, 1 month ago

alea.php

alea.php is a port of the non-cryptographic Alea pseudo-random number generator to PHP.

Alea was designed to be very fast (in JavaScript) and to generate non-platform-dependent repeatable sets of random numbers (when supplied with matching seeds). Given portable seeds (strings or integers, for example), numbers generated by the JavaScript version of alea will exactly match those generated by this PHP port, and vice-versa.

Install

This package is available on Packagist:

$ composer require wikimedia/alea

Usage

use Wikimedia\Alea\Alea;

$prng = new Alea(); // add an optional seed parameter
$nextRandom = $prng->random(); // or ->uint32() or ->fract53()

We also have the ability to sync up two Alea PRNGs (even across platforms) via the importState and exportState methods.

$prng1 = new Alea(200);

$prng1->random();
$prng1->random();

$prng2 = Alea::createWithState( $prng1->exportState() );

assert( $prng1->random() === $prng2->random() );
assert( $prng1->random() === $prng2->random() );
assert( $prng1->random() === $prng2->random() );

Acknowledgements

The Alea code was written (in JavaScript) by Johannes Baagøe, and packaged for npm by coverslide.

Read more on Johannes' site.

The port to PHP was initially done by C. Scott Ananian and is (c) Copyright 2019-2021 Wikimedia Foundation.

Both the original alea codebase and this port are distributed under the MIT license; see LICENSE for more info.