How would I make a proper RNG system?

So for a project I’m making for fun and to upgrade my skills a little more, I’m doing something inspired by Sols’ RNG.

I’ve tried a weighted system, but I’d prefer higher rarity → more rare and lower rarity → less rare.

Also, no matter what I try the system always prefers David out of the following (this is psuedocode so don’t worry):

David = 1000,
Jill = 1500,
Tom = 40

Help would be greatly appreciated, thanks :slight_smile:

2 Likes

This is how I implemented luck in an RNG type game. (This also takes into account a luck value so you can easily implement potions/upgrades into your game)

local random = Random.new()
local ChancesModule = require(SharedModules.ChancesModule)

local function selectRandom(plr)
	local lastIndex = 1

	for index,value in ChancesModule do
		if (random:NextInteger(1,value[2]) / plr.playerValues.Luck.Value) <= 1 and value[2] > ChancesModule[lastIndex][2] then
			lastIndex = index
		end
	end

	return lastIndex
end

ChancesModule:

local Chances = {
	{"Common", 2, Color3.fromRGB(202, 202, 202), "bad rarity"},
	{"Uncommon", 4, Color3.fromRGB(132, 202, 116), "kinda bad"},
	{"Rare", 10, Color3.fromRGB(61, 64, 255), "wow so rare"},
	{"Epic", 25, Color3.fromRGB(141, 0, 202), "so epic"},
	{"Legendary", 50, Color3.fromRGB(255, 213, 0), "legendary????"},
	{"Mythical", 100, Color3.fromRGB(110,255,224),"no way its a mythical"},
}

return Chances

If you want any further explanation as to how this works feel free to ask.

Thanks, this works like I needed it to!