Socket
Socket
Sign inDemoInstall

rc4

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rc4

RC4 random number generator


Version published
Weekly downloads
29K
decreased by-1.44%
Maintainers
1
Weekly downloads
 
Created
Source

rc4

RC4 random number generator

Build Status NPM version Dependency Status Code Climate

Synopsis

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] }

Keywords

FAQs

Package last updated on 24 Mar 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc