4.1.1 • Published 7 months ago

alea-deck v4.1.1

Weekly downloads
4
License
MIT
Repository
github
Last release
7 months ago

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.

4.1.0

8 months ago

4.1.1

7 months ago

4.0.1

1 year ago

4.0.0

1 year ago

3.0.0

2 years ago

2.0.1

2 years ago

2.0.0

8 years ago

1.1.7

9 years ago

1.1.6

9 years ago

1.1.5

9 years ago

1.1.4

10 years ago

1.1.3

10 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.0

10 years ago