1.0.4 • Published 7 years ago

select-random v1.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

Select random item from plain object or array-like one.

The package contains fast random int generator in its core, based on bitwise shift. Another fully Math.random-based alternatives (e.g. lodash.random) are ~4-5 times slower:

// Chance to get number 3 in range 1-10 for 10000 iterations (average values of 100 sequential tests) 
bitwise-shift: 9.99%
bitwise-shift: 16.621ms
lodash: 9.96%
lodash: 75.952ms

Install

$ npm i -S select-random

or

$ yarn add select-random

Use

selectRandom({one: 1, two: 2, three: 3})
selectRandom([1, 2, 3])
1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago