Luck system on rng

Hello, I have a function which randomly picks an item from a table depending on its rarity

What I want: I want the function to use a number value as “Luck”, so basically the higher the luck the easier to get a more rare item, but i do not know how to do that!

Here is my script below:

local SwordModule = {
	{model = script["Linked"], 		probability = 2,	annouce = false},
	{model = script["Ice Dagger"],  probability = 3,	annouce = false},
	{model = script["Windforce"],	probability = 5,	annouce = false},
	{model = script["Venomshank"],	probability = 10,	annouce = false},
	{model = script["Ghostwalker"], probability = 50,   annouce = false},
	{model = script["Darkheart"], 	probability = 3,	annouce = false},
	{model = script["Hellsword"],	probability = 2,	annouce = true},
}

SwordModule.get = function(player)
	local luck = 1 -- the more luck = easier to get rare items
	
	local totalInverseProbability = 0
	for _, item in ipairs(SwordModule) do
		totalInverseProbability = totalInverseProbability + 1 / item.probability
	end

	local randValue = math.random() * totalInverseProbability
	local accumulatedWeight = 0

	for _, item in ipairs(SwordModule) do
		accumulatedWeight = accumulatedWeight + 1 / item.probability
		if randValue <= accumulatedWeight then
			return item
		end
	end
end
	local luck = 0.01 -- the more luck = easier to get rare items

	local totalInverseProbability = 0
	totalInverseProbability += luck

Will increase the probability

huh? increasing the probability will make it harder to get rare items?

A simple solution would be this.

local roll = math.random(10000)/100 -- does so we can have two decimals in our roll

if luck_gamepass then -- or however you want luck to activate
	roll = (roll*((100-luck)/100)
end

For example roll is 50, luck is 10%. roll = (50*((100-10)/100) is equal to 45.
It is good to have luck being percentage based, so it is not overpowered when rolling a low number.

When you roll for a random number, if a larger random number means you get a rarer item, then you need to multiply the random number by the luck. Inversely, if a smaller random number means you get a rarer item, then you need to divide the random number by the luck.

I am sorry. I got it wrong. You return a item when randValue is smaller than accumulatedWeight. Then luck must be a negative value to increase the chance of getting items.

	local luck = -0.01 -- Higher negative number increase chance of getting item

	local totalInverseProbability = 0
	totalInverseProbability += luck