Skip to content

johnnykramer/chanced-element

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chanced element

Get a random array element with a specific chance

How to

Install

yarn add chanced-element

or

npm install --save chanced-element

Run

Sum of chances should be equals 100, like 50% chance + 50% chance = 100%.

Param data can be any type.

const { chancedElement } = require('chanced-element')()

const { data } = chancedElement({
  variants: [
    { chance: 50, data: 'JS Developer' },
    { chance: 30, data: 'Superhero!' },
    { chance: 20, data: 'Duuude' },
  ],
})
console.log(`I Am ${data}`)

TODO

  • Add more random engines
  • Make it more customizable

About

Get a random array element with a specific chance

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published