Greetings! I was wandring how ide make a roll system with rarities 1 out of ___ . Not sure how to do like 1 out of 2 and then so on but not making it out if 100% chance probability
So like it doesent all amout to 100% it warps the probibility to account for all the probibilitys, thanks for any help!
Iâm not an experienced scriptor, and Iâve seen people using different techniques, but what I would do is something like this:
local rollNum = math.random(1,5)
if rollNum <= 3 then
--Give item or something
elseif rollNum >= 4 then
--Give other item idk how you are storing them
end
I am not experienced in the slightest and I wouldnât take my own advice but thatâs how I would do it
I donât really know how to âwarp the probabilityâ but Iâm offering any advice I have
Wish you luck on your game!
Thank you! The math.random is how you would do it but sence im not doing it out of 100% i couldent because thatd be say 1 out of 2 1 out of 4 and 1 out of 4 and thatd add up to the 10 say youd be math.randoming out of, if you raiee that number then the probibility no longer is accurate
Ive gota go for a little while
Yea I understand, I just replied in case no one else replies and I wanted to give you at least one solution you could use, even if it is not very good, it worked in testing and it kinda does need to add up to 100% but at least itâs something
Hope you figure it out
Use Random
for that.
local randomNumber = Random.new():NextNumber(0, 1) -- a random number between 0 to 1
local rarity = math.floor(1/randomNumber) -- A number between 1 and basically infinity
Yes you would just make a system that randomly generates a number
local number = math.random(1, 1000) â make the 1000 whatever you want
Then check what number it is and award the player.
if number >= 5 then
âreward
end
If number < 5 then
âother reward
end
Hope this helps you and if you want a more advanced way, use a table rarity system
there are many ways of doing it the way i prefer doing it is adding the Rolls in a table and give each Roll a weight so i donot have to hard type alot of if statments checking for value i couldnot explain it well so i will just add a video
Complex Room Generation - Doors Game Tutorial #2 (youtube.com)
skip to the RoomGenerationProbabilty Part it will be explain better there
Note: if u willnot have alot of rolls then no need for this or you can use alot of if statements to do it
that is the only vidio that i found there may be videos about it specifically
cc. @1_Lukeskyiwalker explained what i was trying to say read read his reply if u donot want to watch the video
If you plan on making an RNG game with many items and different rarities, I think that the easiest solution would be to create a table like this :
- key : item name/identifier
- value : probability weight
Then, you would build a function which will first calculate the sum of all the weights in the table (easy), then roll a random number between 1 and that sum (easy), and finally, iterate through each item in the table, cumulating the weights and finding the first item which the cumulated weight is higher than the rolled number (medium).
This function then returns the item rolled.
Seems like everyone is ignoring what youâre actually asking for and just telling you how to do weighted chance.
Obviously you know that itâs impossible to have the 1 in x chances ACTUALLY be 1 in x if they all donât add up to 100%, but you can still make them somewhat representational of the chance.
If you perform a weighted chance algorithm where each rarity has a weight of 1/x, that will make it so something with â1 in 2 chanceâ is much more common than something with â1 in 400 chanceâ, even if the chances are not in reality 1 in 2 or 1 in 400.
Hope this is what you were looking for.
What @goldenguy9 said is absolutely right, it doesnât always to have to be out of 100, it has to be out of the total. Letâs say you have a â1 in 5â chance, then itâs weight wouldnât be like â10â, it would be 1/5 = .2. Then you add up all the weights to get a representative total
Sorry ibhavnt replyed in a bit, how would i do somthing like that?
local RNGSystem.Rarities = {
['1 in 2'] = 0.5
['1 in 4'] = 0.25
...
['1 in 100000'] = 0.00001
}
function RNGSystem.ChooseAura()
local total = 0.5+0.25+...+0.00001
local num = math. Random(0,total)
-- Write your random selection code here
end
Thanks everyone! (Char limmit)
Bro poached the solution from međ
Im so sorry man, but I was thinking of the same thing when I first saw the post and scrolled down to see your one similar to my thoughts
Edit: @ElipsGames mark @goldenguy9 's post as the solution, i feel so guilty
Ty i changed the solution
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.