New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

weight-randomizer

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

weight-randomizer

Create random array sequence based on group weight. Implementation is based on fair die algorithm http://www.keithschwarz.com/darts-dice-coins/

latest
Source
npmnpm
Version
1.0.4
Version published
Maintainers
1
Created
Source

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 array[sequenceLength]. 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.

Keywords

weight

FAQs

Package last updated on 07 Apr 2019

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