1.0.4 • Published 5 years ago

weight-randomizer v1.0.4

Weekly downloads
4
License
ISC
Repository
github
Last release
5 years ago

weight randomizer

creates random array sequence based on group weight and provided length of sequence. Implementation is based on fair die algorithm http://www.keithschwarz.com/darts-dice-coins/. Algorithm complexity is O(N) at setup time, and guaranteed O(1) run time for every random selection.

get started

  • run
npm i weight-randomizer
  • require into your project via
import WeightRandomizer from "./weight.randomizer";

how it works

Method getSequence accepts two arguments:

  • objectWeights: Array of objects and its weights. Objects are of any[] type.
  • sequenceLength: Number of elements in resulted array

Result of method execution will be arraysequenceLength. Elements will be of type any. Distribution of elements in resulted array is based on groups weight. Every element inside group has same possibilty to be picked up.

Example is available in the src/weight.randomier.spec.ts test file.

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago