Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Can one add probability to math.Random()?

Asked by 5 years ago

For example, can you make math.Random(1,10) have a higher probability to choose 1-5, rather than the same probability for all the numbers (1-10)?

0
This is a really good question. I'm looking forward to seeing what the answer is. This is the most elegant solution that I could think of, and I'm not even sure it works properly: https://pastebin.com/3XEv1ziw SummerEquinox 643 — 5y
0
idk if there’s a better way but like SummerEquinox’s example you could always make a “tree” where if the number falls in between a certain range then X else if then Y. Maybe there’s a more sophisticated method using randomseed and some imaginative seed? ABK2017 406 — 5y
0
Ah, I would think it would be a helpful math function for everyone, but I doubt roblox would ever implement something like it. Stephenthefox 94 — 5y
0
There are a lot of different distribution functions that a random variable can take - could you be a bit more specific as to how you'd like it to look? fredfishy 833 — 5y
0
I'm just thinking that there should be a way to make it more likely that math.Random() will choose a certain number or set of numbers, but still have a chance to chose the rest (just less likely to). Stephenthefox 94 — 5y

1 answer

Log in to vote
1
Answered by
Nickzus 24
5 years ago

I dont know if you can add probability to a a math.random, but you can use it to make probabilistic events:

local gen = math.random(1,100)

if gen <= 10 then
-- 10% chances
elseif gen >= 10 and gen <= 30 then
-- 20% chances
elseif gen >= 30 and gen <= 60 then
-- 30% chances
elseif gen >= 60 and gen <= 100 then
-- 40% chances
end
0
I know, but even then, the number is "random". Stephenthefox 94 — 5y
0
Add another math.random inside the ifs, for example: you could add a math.random(1,5) to a 40% and a math.random(6,10) to a 10%, using the same variable Nickzus 24 — 5y
Ad

Answer this question