New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

arbit

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arbit

A tiny pseudo-random number generator.

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
59
increased by40.48%
Maintainers
1
Weekly downloads
 
Created
Source

arbit

A tiny pseudo-random number generator.

Example

var arbit = require('arbit');

var random = arbit();

var HIT_CHANCE = 0.75;
var MIN_DAMAGE = 15, MAX_DAMAGE = 21;

if (random() <= HIT_CHANCE) {
  var damage = random.nextInt(MIN_DAMAGE, MAX_DAMAGE);
  console.log('You hit the zombie for %d damage!', damage);
} else {
  console.log('You missed!');
}

Functions

var generator = arbit(seed)

The package itself is just a single function which returns a number generator using the provided seed.

var generator = arbit.fromState(state)

Returns a number generator initialized to be in the provided state.

var number = generator()

Calling the generator itself returns a value greater than or equal to zero, and less than one.

var number = generator.nextFloat(max)

Returns a floating point that somewhere between zero and max. If a negative number is provided, the range will instead be (max, 0].

var number = generator.nextFloat(min, max)

Returns a floating point number within either the range [min, max) or (max, min] (if the range is reversed).

var number = generator.nextInt(max)

Same as nextFloat(max), but coerces the value to an integer with Math.floor.

var number = generator.nextInt(min, max)

Same as nextFloat(min, max), but coerces the value to an integer with Math.floor.

var state = generator.getState()

Returns the current state of the generator. This can be passed into arbit.fromState(state) to get back another generator in the same state (i.e., it will generate the same sequence of numbers).

Keywords

FAQs

Package last updated on 28 Jun 2015

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