rbx-weighted-random-picker
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

Weighted Random Picker

Generates option-picker functions from relative probabilities:

// When relative probabilities are not provided, it gives equal weight to each option
const CoinFlip = RandomPicker(["Heads", "Tails"])
 
print(CoinFlip()) // "Heads"
print(CoinFlip()) // "Tails"
 
const DiceRoll = RandomPicker([1, 2, 3, 4, 5, 6])
 
const CoinFlipOrDiceRoll = RandomPicker(
    // calls CoinFlip over DiceRoll at a 3:1 ratio
    // in other words, CoinFlip gets set to 0.75, DiceRoll becomes 0.25
    [CoinFlip, DiceRoll],
    [       3,        1]
)
 
CoinFlipOrDiceRoll()() // 1
CoinFlipOrDiceRoll()() // Heads
CoinFlipOrDiceRoll()() // 5

Package Sidebar

Install

npm i rbx-weighted-random-picker

Weekly Downloads

1

Version

0.0.5

License

ISC

Unpacked Size

3.22 kB

Total Files

4

Last publish

Collaborators

  • validark