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

1.0.1 • 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 = new RandomPicker(["Heads", "Tails"])

print(CoinFlip()) // "Heads"
print(CoinFlip()) // "Tails"

const DiceRoll = new RandomPicker([1, 2, 3, 4, 5, 6])

const CoinFlipOrDiceRoll = new 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

/@rbxts/weighted-random-picker/

    Package Sidebar

    Install

    npm i @rbxts/weighted-random-picker

    Weekly Downloads

    5

    Version

    1.0.1

    License

    ISC

    Unpacked Size

    3.39 kB

    Total Files

    4

    Last publish

    Collaborators

    • validark