Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

alea-deck

Package Overview
Dependencies
Maintainers
0
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alea-deck

Uniform and weighted shuffling and sampling with Alea

  • 4.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
23
decreased by-78.9%
Maintainers
0
Weekly downloads
 
Created
Source

alea-deck

Uniform and weighted shuffling and sampling, just like deck, but utilizing Alea instead of Math.random.

Example

var deck = require('alea-deck');

deck.shuffle([1, 2, 3, 4]);
// => [1, 4, 2, 3]

deck.pick([1, 2, 3, 4]);
// => 2

deck.shuffle({
  a: 10,
  b: 8,
  c: 2,
  d: 1,
  e: 1
});
// => ['b', 'a', 'c', 'd', 'e']

deck.pick({
  a: 10,
  b: 8,
  c: 2,
  d: 1,
  e: 1
});
// => a

Installation

$ npm install alea-deck

API

var deck = require('alea-deck');

deck.shuffle(collection)

If collection is an Array, returns a new shuffled Array based on a unifrom distributionm without mutating the original Array.

Otherwise, if collection is an Object, returns a new shuffled Array of collection's visible keys based on the value weights of collection.

deck.pick(collection)

Samples collection without mutating collection.

If collection is an Array, returns a random element from collection with a uniform distribution.

Otherwise, if collection is an Object, returns a random key from collection biased by its normalized value.

deck.normalize(obj)

Return a new obj Object where the values have been divided by the sum of all the values such that the sum of all the values in the returned Object is 1.

If any weights are < 0, an Error is thrown.

Keywords

FAQs

Package last updated on 27 Dec 2024

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