RNG Helper
In reminiscence of this recently posted video:
I heavily disagree with it (even though it’s probably ragebait). So, I am publishing a custom resource (by me) that implements a simple customizable RNG system, just to prove how easy it is. This is a premade resource, something I used for a game/project that already exists.
I don’t want to make it seem like I’m attacking this Youtuber; I’m just sharing a personal opinion, and I want to share this with the community.
Overview
Returns a RNG objects, from a dictionary of weights.
RNGModule.new(weights: { [string]: number }): {}
Returns a single string value based on a randomization algorithm calculated by the provided weights.
RNGModule:Generate(): string
Modifies a single rarity value internally (useful for luck based multipliers)
RNGModule:UpdateRarity(item: string, value: number)
Updates all rarities based on current internal weights
NOTE: There is no need to call this after modifying a weight using :UpdateRarity()
, it is done internally.
RNGModule:UpdateRarities()
Example
Here’s an example of it’s use:
local module = require(workspace.RNGModule)
local rarities = {
Apple = 1,
Banana = 9
}
local myGenerator = module.new(rarities)
for i = 1, 10 do
print(myGenerator:Generate())
end
Bananas on average will be generated 9x times more frequently than apples.
And here are the results!
Conclusion
Thank you for using my system. As a heads up, I will be taking any recommendations for optimizations or nitpicks on this code, and it will be changing constantly.
The Resource
RNGModulev2.rbxm (1.5 KB)