This is not for my purposes... this is for everybody who wants to know how to do this, since this is something I have always wondered about..
The question is: How can you spawn 3 items randomly but have them all spawn at different rates. Such as spawning by rank(Common, Uncommon, Rare, etc.).
So I have no idea how you would do this, but I was thinking of doing it by percentages but I wouldn't even know how to start, so I don't even know if that would be possible...
Again this isn't for me and my purposes, I am asking for everybody who wants to know.
Hello,
Your idea on percentage is correct and can be done by integrating it with math.random
so we can do it like this
local x = math.random(100) if x < 21 then print("I have a 20 percent chance to be spawned") else if x < 51 then print("I spawn 30 percent of the time ") else print("The remaining percentage is conquered by me (50 percent)")
Hope this answers
You could use math.random to generate a percentage like so...
local x = math.random(1,100) if x <= 5 then -- 5/100 chance to spawn (5% chance) print 'spawn rare' elseif x <= 40 then -- 40/100 chance to spawn (40% chance) print 'spawn uncommon' else print 'spawn common' -- defaults to common end