Hello everyone, for my game i would like to implement random size system similar to grow a garden’s
but I couldnt figure out how do they gradually make higher size have a lower chance of spawning and how sprinklers affect its size aswell? I would like to see few examples and some explaining, tysm in advance
2 Likes
weighted chance system.
Althrough they use something more easier like math.log probably
1 Like
yeh i use it myself but ive only used it for item tables ect. and i have no idea how would i apply it to this, could you give me an example
1 Like
Goal: Random size, large sizes rarer
Let’s say size can go from 1 to 100.
Basic Version (log-based rarity)
function getRandomSize(minSize, maxSize)
minSize = minSize or 1
maxSize = maxSize or 100
local r = math.random() -- Random float from 0 to 1
local scale = math.log(maxSize + 1) -- +1 to avoid log(0)
local size = math.floor(math.exp(r * scale)) - 1
return math.clamp(size, minSize, maxSize)
end
Explanation:
ris a random float between 0 and 1.math.exp(r * log(max + 1))biases the result toward small values.math.floor(...)-1adjusts the scale so size ranges from 0 tomaxSize.
Adding Sprinklers: Boost the Size
Let’s say each sprinkler gives a small bonus chance to grow bigger.
Option 1: Bias r upward with sprinklers
function getRandomSizeWithSprinklers(minSize, maxSize, sprinklerLevel)
minSize = minSize or 1
maxSize = maxSize or 100
local r = math.random()
-- Apply a bias by raising r to a power < 1 (pushes r higher)
local bias = 1 / (1 + 0.1 * sprinklerLevel)
local biasedR = math.pow(r, bias)
local scale = math.log(maxSize + 1)
local size = math.floor(math.exp(biasedR * scale)) - 1
return math.clamp(size, minSize, maxSize)
end
How this works:
- No sprinklers →
bias = 1→ no effect. - More sprinklers → smaller bias exponent →
rmoves closer to 1 → higher sizes more likely.
| Sprinkler Level | Bias Exponent | Result |
|---|---|---|
| 0 | 1 | Normal |
| 5 | ~0.666 | Higher sizes more often |
| 10 | ~0.5 | Big boost to size chance |
Summary
You now have a logarithmic-based size system in Roblox:
math.exp(math.random() * math.log(max + 1))→ biased toward small sizes.- Add sprinkler influence by adjusting the randomness curve via exponent.
5 Likes