Skip to content

AlexeyLegasov63/weightedrandom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WeightedRandom.luau

WeightedRandom.luau is a Roblox (Luau) module that allows selecting random items based on their weights, with optional dynamic probability adjustments on each pick.

Features

  • Add items with a unique ID, initial weight, and any associated data.
  • Weighted selection — items with higher weights have a greater chance of being picked.
  • Optional weight growth — automatically increase the weight of all items each time getRandom is called.
  • Probability balancing — drastically reduce the chance of the selected item to avoid repeats.

Example

local WeightedRandom = require(path.to.WeightedRandom)

local randomizer = WeightedRandom.new(true) -- true = enable auto-adjustment
randomizer:addItem("floor1", 1, {name = "First Floor"})
randomizer:addItem("floor2", 1, {name = "Second Floor"})

local picked = randomizer:getRandom()
print("Picked:", picked.id, picked.data.name)

Wally

WeightedRandom = "alexeylegasov63/weightedrandom@0.1.0"

About

A module for weighted random selection with dynamic probability adjustment.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages