|
| 12 Nov 2017 11:40 AM |
My scenario:
I have a folder with other folders in it (let's say 3, for the sake of it)
I want to randomly select either of the folders based on percentages assigned to them
What is the >best method to go about this?
|
|
|
| Report Abuse |
|
|
|
| 12 Nov 2017 11:40 AM |
| https://forum.roblox.com/Forum/ShowPost.aspx?PostID=227478748https://forum.roblox.com/Forum/ShowPost.aspx?PostID=227478748 |
|
|
| Report Abuse |
|
|
| |
|
|
| 12 Nov 2017 11:55 AM |
That’s weird..
The mods never delete anything, and there was nothing wrong with that thread.
But here is a script I made
local tab = { ["rockA"] = 100, ["rockB"] = 1 }
local totality = 0 local ind = 0 local actual = {} local pick
for i,v in next, tab do totality = totality + v end for i,v in next, tab do actual[i] = (100*v)/totality end for i,v in next,actual do ind = ind + 1 local rev = 100-v local rnd = math.random(1,100) if rnd >= rev then pick = i end if ind == #actual then
if pick == nil then pick = i
end end end
print(pick)
There’s another one that’s more efficient but I don’t know the name of who made it so I won’t post |
|
|
| Report Abuse |
|
|
|
| 12 Nov 2017 11:56 AM |
Actually the thread wasn’t deleted
https://forum.roblox.com/Forum/ShowPost.aspx?PostID=227478748 |
|
|
| Report Abuse |
|
|
| |
|
Quasiduck
|
  |
| Joined: 28 Sep 2008 |
| Total Posts: 2437 |
|
|
| 12 Nov 2017 05:59 PM |
If you want to set specific probabilities to an element in a table:
pastabin
/riphx8mx |
|
|
| Report Abuse |
|
|
|
| 12 Nov 2017 06:32 PM |
local chance = math.random()
if chance < 0.1 then --rare element if chance < 0.5 then --less rare element
etc |
|
|
| Report Abuse |
|
|