How would I make bigger items more rare than smaller items?

An example of what system I want to make includes the game “FISCH”. Basically, I want to make bigger objects/items more rare than smaller ones, or more smaller items more rare than bigger ones. Although, I don’t want there to be a limit on how big or how small an object can get, it would just be harder to get a smaller/bigger size.
I know how to make probability in Roblox Studio, such as selecting different items based on its value, but I need to figure out how to make probability work for an infinite number.

Hey there, I would recommend using tables and metatables and putting all items ranging from math.huge sizes and such. You then could classify a comparison of items based upon what table they are in

1 Like

so are you gonna have like a reference point? ex. size 10 = 1/100 or would it just be a mathematical function like exponential or linear without a reference point? if its linear then you would just do 1/size for the probability. this scales to size = infinity where 1/size = 0. if it’s exponential you could do something like (1/size)^1.25 or any exponent

Hey, could you give an example for your idea. Luckily, I learned how metatables work, so I could probably understand your explanation.

local bigItems = {}
local smallItems = {}
local metaTable = {}

for i,v in pairs(allItems:GetChildren()) do
if v.Size = --whatever 
then
setmetatable(bigItems or smallItems, metaTable)
table.insert(bigItems or smallItems, v)
end
end

You can also compare and use the metamethods to contrast if the selected Item is the most rare item or something

1 Like

its not possible to not have a limit but we can make the number very high

this statement is incorrect we can have it go up to infinity

local maxSize = 9007199254740992
local curve = 2

local size = (1 - math.random()) ^ curve * maxSize

and here is a video showing how curve effects the chance at higher sizes

here is another option

local maxSize = 9007199254740992
local curve = 2
local curveInverse = 1 / curve

local size = (1 - math.random() ^ curveInverse) ^ curve * maxSize

2 Likes

I tested this and the size was usually a mix of high and low numbers when I printed them out. How would you make the low numbers more common?

the higher the curve value the more likely it will be lower

The problem is that whenever the max size goes up, the average also goes up.
Think of the size as the scale of a model. For every 1000 models, the average size/scale of the model would be 16, as the maxSize would be 100.
As you increase the maxSize, the average would start to go up. That’s a problem already since a scale of 16 should be extremely hard to get.

right as you increases the maxSize your compressing more values onto the graph pushing the small values to be closer together so now math.random has a lower chance to select them lower number because it has so much more to pick from but this can be compensated with the curve


here is a small video showing what it looks like as we change the max value between 1 and 4

and here is a image showing how we can compensate with the curve


left maxvalue = 1, right maxvalue = 4
I increased the curve from 2 to 3.9

when looking at the green line
in both of these curves there is a 90% chance to get a value lower then 0.5
and a 10% chance it will be higher then 0.5


I have only shown you 2 curve formulas but there are infinite more you can make to adjust how the graph curves but this will come down to personal preference and how you want it to be

but it would be imposable to have a curve that gives you the exact same chances for getting a number as you increases the max value because it need to give room for more numbers to fit onto the graph for example

if there is 80% chance of getting 1 and 20% chance of getting 2

but now i want to also add the ability to get 3 i must reduce the chances of 1 and 2 to make room for 3

so maybe ill reduce 80% down to 75% and 20% 15% so now there
75% + 15% = 90%
now i have 10% space for 3 to fit in so now its

75% for 1 - 15% for 2 - 10% for 3
where before it was
80% for 1 - 20% for 2 - 0% for 3

one thing you could do is have it so we only take away from the last value as you increase the max value

for example if we have
80% for 1 - 20% for 2 - 0% for 3
we could change it to
80% for 1 - 15% for 2 - 5% for 3

1 stays at 80% but only 2 changed from 20% to 15% to give 3 space for 5%
then if we go from max 3 to max 4
80% for 1 - 15% for 2 - 3% for 3 - 2% for 4
now 1 stay at 80 2 stays at 15% but 3 changed from 5% to 3%

to do this we can make a curve that goes up to infinity then just clamp it


so in lua that would be

local curve = 1
local function GetRandomValue()
    return 1 / math.random() ^ curve - 1
end

this will return a number between 0 and infinite but we can put a limit on it like this

local curve = 1
local maxValue = 100
local function GetRandomValue()
    return math.min(1 / math.random() ^ curve - 1, maxValue)
end

now changing the maxValue does not effect the curve so the chances always stay the same apart from the maxValue

1 Like

Before you read this: you can try and tweak your own piecewise (continuous) probability functions–especially with tools like Desmos as @5uphi has done above, but I’m going to suggest the lognormal distribution to the list of continuous distributions with closed forms…

Since non-positive fish sizes are out of the picture and we want some sort of baseline (mean) size for our fish, let’s try to find a function that does not start at a high probability. We also wanted fish on the “small” end and “large” end of our size distribution to be rare, so let’s assume the smaller the fish, the lower the probability (with a probability of 0 at zero size). And for the larger fish, we want the idea that “the larger, the rarer,” right?

To propose a correction to the function shown in @5uphi’s above graphs: I believe that the sizes that approach zero should also have probabilities approaching zero. I’d assume that it’s to be less common to find infinitesimally smaller fish in this fictional sense, where it is possible to catch ones near that size.

In nature, sizes naturally follow a right-skewed normal-like distribution–I’m pretty sure this has to do with the application of the central limit theorem on a distribution modelled by size increases of organisms (which depend on their previous sizes). There’s a whole research paper I came across detailing the proof behind this in the context of biological organisms, but I don’t think I’m able to share the exact details. Here’s the doi link. Aside from the mathematical reasoning behind this distribution, you can see that many animals, including fish, follow a lognormal size distribution. Check this out.


Here’s a Desmos graph to visualize and play around with the distribution and its constraints ^^

For comedic effect in a Roblox game, we can accentuate the size of our fish on whichever end–it’s up to the developer, honestly. Also, I’m not the best at this kind of posting, and I’m sure there are probably better distributions to follow–I’m still learning. I mean, there’s the idea to just create your own distribution function since we’re programming here lol. Feel free to adjust the parameters for different types of fish areas. Heck, you could create your own (hence the piecewise stuff) functions for different types of catches…

Some other notable candidates I came across that you may want to take a look at if the lognormal feels too natural for your game:

Why’d I add the last suggestion? I was thinking: could a Tweedie distribution at all be tweaked to fit the case that you consider “sized 0 fish” as getting a fake bite and no fish? That is, assuming we are only catching a certain type of fish. Or, should you just handle the “fake” and “no fake” options as their own variable? If someone with more experience with probability distributions here could answer this, that would be much appreciated! Or maybe I’m just confusing myself… I’m still learning, thanks!

tl;dr: try modeling with lognormal

edit: the Desmos link I sent contains the general lognormal function with constraints you can edit yourself–when programming with this, just be aware that you should normalize its range to be between 0 and 1 such that this follows a legit probability function lol

edit 2: now that I reread all the posts above, did I misinterpret this question? lol mb

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.