# rc4

> RC4 random number generator

Latest version **0.1.5** (published 2015-04-24) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.5 |
| Published | 2015-04-24 |
| First published | 2014-03-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Oleg Grenrus |
| Maintainers | phadej |
| Keywords | rc4, random, generator, seed |

## Links

- npm: https://www.npmjs.com/package/rc4
- Repository: git@github.com:phadej/rc4
- Homepage: https://github.com/phadej/rc4
- Issues: https://github.com/phadej/rc4/issues
- npm.io page: https://npm.io/package/rc4

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 0.1.5 (latest) — 2015-04-24
- 0.1.3 — 2014-06-30
- 0.1.2 — 2014-03-24
- 0.1.1 — 2014-03-24
- 0.1.0 — 2014-03-24

## 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** &mdash; *2015-04-24* &mdash; Better isInteger, random works with bigger ranges
- **0.1.4** &mdash; *2015-02-25* &mdash; Dev dependencies update

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