Page MenuHomeWickedGov Phorge

README.md
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

README.md

# 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](https://github.com/coverslide/node-alea/)
will exactly match those generated by this PHP port, and vice-versa.
## Install
This package is
[available on Packagist](https://packagist.org/packages/wikimedia/alea):
```bash
$ composer require wikimedia/alea
```
## Usage
```php
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.
```php
$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](https://github.com/coverslide).
Read more on [Johannes' site](https://web.archive.org/web/20120619002808/http://baagoe.org/en/wiki/Better_random_numbers_for_javascript).
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.

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 21, 18:22 (19 h, 37 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
ca/d5/239b42560d8c14440974253281be
Default Alt Text
README.md (1 KB)

Event Timeline