# alea

> Implementation of the Alea PRNG by Johannes Baagøe

Latest version **1.0.1** (published 2021-09-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install alea
pnpm add alea
yarn add alea
bun add alea
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2021-09-07 |
| First published | 2012-10-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 104 |
| Author | Richard Hoffman |
| Maintainers | coverslide |
| Keywords | badass, pseudo, random, number, generator |

## Links

- npm: https://www.npmjs.com/package/alea
- Repository: https://github.com/coverslide/node-alea
- Homepage: https://github.com/coverslide/node-alea#readme
- Issues: https://github.com/coverslide/node-alea/issues
- npm.io page: https://npm.io/package/alea

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2021-09-07
- 1.0.0 — 2018-09-10
- 0.0.9 — 2013-01-18
- 0.0.8 — 2012-12-14
- 0.0.7 — 2012-12-14
- 0.0.5 — 2012-12-14
- 0.0.4 — 2012-12-14
- 0.0.3 — 2012-12-14
- 0.0.2 — 2012-12-14
- 0.0.1 — 2012-10-19
- 0.0.0 — 2012-10-19

## README

# Alea

A simple copy-and-paste implementation of Johannes Baagøe's Alea PRNG

Mostly packaged so I can easily include it in my projeccts. Nothing more

JavaScript's Math.random() is fast, but has problems. First, it isn't seedable, second, its randomness leaves a bit to be desired. [Johannes Baagøe](http://baagoe.org/) has done some great work in trying to find a more modern PRNG algorithm that performs well on JavaScript, and Alea seems to be the one that has come out ahead ([benchmarks](http://jsperf.com/prng-comparison)).

## Installation

	npm install alea

## Usage

	var Alea = require('alea')
	
	var prng = new Alea() // add an optional seed param

	var nextRandnum = prng() // just call the return value of Alea

## Additions

Also adds the ability to sync up two Alea PRNGs via the importState and exportState methods.

	var prng1 = new Alea(200)

	prng1()
	prng1()

	// after generating a few random numbers, we will initialize a new PRNG

	var prng2 = Alea.importState(prng1.exportState())

	// this should echo true, true, true
	console.log(prng2() == prng1())
	console.log(prng2() == prng1())
	console.log(prng2() == prng1())

The theory behind this is that while a server is running a simulation (for example, a game) and clients connect to the server, each client will run its own simulation without having to depend 100% on the server for every update of the simulation state. By importing the current generator state from the server, a client can join in at any time and have an accurate simulation fully in sync with the server.

## Acknowledgements

Everything in this module was made by Johannes Baagøe. I just wanted this in npm.
Read more on his [homepage](http://baagoe.org/).

---
_Source: https://npm.io/package/alea · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
