rc4
RC4 random number generator
![Code Climate](https://img.shields.io/codeclimate/github/phadej/rc4.svg)
Synopsis
var RC4 = require("rc4");
var generator = new RC4("my seed");
console.log(generator.randomByte());
console.log(generator.randomFloat());
var state = generator.currentState();
console.log(generator.randomFloat());
generator.setState(state);
console.log(generator.randomFloat());
RC4small
There is also RC4small
generator, with smaller internal state:
var RC4small = require("rc4").RC4small;
var generator = new RC4small("my seed");
var stateString = generator.currentStateString(); // 18 character hexadecimal string
console.log(generator.randomFloat()); // 0.9362740234937519
generator.setStateString(stateString);
console.log(generator.randomFloat()); // 0.9362740234937519
API
Both RC4
and RC4small
have following random value generating methods:
randomByte : () ⇒ { x : ℕ | x ∈ [0, 255] }
randomUInt32 : () ⇒ { x : ℕ | x ∈ [0, 2^32-1] }
randomFloat : () ⇒ { x : R | x ∈ [0, 1) }
random : (a : ℤ) ⇒ { x : ℤ | x ∈ [0, a] }
random : (a : ℤ, b : ℤ) ⇒ { x : ℤ | x ∈ [a, b] }
Changelog
- 0.1.5 — 2015-04-24 — Better isInteger, random works with bigger ranges
- 0.1.4 — 2015-02-25 — Dev dependencies update