Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/phadej/rc4
RC4 random number generator
https://github.com/phadej/rc4
Last synced: 2 months ago
JSON representation
RC4 random number generator
- Host: GitHub
- URL: https://github.com/phadej/rc4
- Owner: phadej
- License: mit
- Created: 2014-03-24T07:46:06.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2019-11-07T17:31:51.000Z (about 5 years ago)
- Last Synced: 2024-10-11T23:41:25.051Z (3 months ago)
- Language: JavaScript
- Size: 23.4 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rc4
[RC4](http://en.wikipedia.org/wiki/RC4) random number generator
[![Build Status](https://secure.travis-ci.org/phadej/rc4.svg?branch=master)](http://travis-ci.org/phadej/rc4)
[![NPM version](https://badge.fury.io/js/rc4.svg)](http://badge.fury.io/js/rc4)
[![Dependency Status](https://gemnasium.com/phadej/rc4.svg)](https://gemnasium.com/phadej/rc4)
[![Code Climate](https://img.shields.io/codeclimate/github/phadej/rc4.svg)](https://codeclimate.com/github/phadej/rc4)## Synopsis
```js
var RC4 = require("rc4");var generator = new RC4("my seed"); // string or array of integers
// without the seed RNG is seeded with random data from Math.random// byte := integer ∈ [0, 255]
console.log(generator.randomByte());// float := number ∈ [0, 1)
console.log(generator.randomFloat());// save & load state
var state = generator.currentState();
console.log(generator.randomFloat()); // 0.14815412228927016
generator.setState(state);
console.log(generator.randomFloat()); // 0.14815412228927016
```## 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