llaserx
|
  |
| Joined: 10 Dec 2011 |
| Total Posts: 53069 |
|
|
| 10 Mar 2017 09:18 AM |
espically one that doesnt need percents that needs to add up to 100%
|
|
|
| Report Abuse |
|
|
|
| 10 Mar 2017 09:56 AM |
Is this what you're talking about?
Probability = 50 if math.random(1,100)<=Probability then |
|
|
| Report Abuse |
|
|
llaserx
|
  |
| Joined: 10 Dec 2011 |
| Total Posts: 53069 |
|
| |
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 10 Mar 2017 10:46 AM |
Give things weights, sum the weights, roll a die, and then figure out what bucket you're in. Do something with specific thing.
sumOfWeights = 0 for thing, weight do sumOfWeights = sumOfWeights+weight end local event = math.random(sumOfWeights) for thing, weight do if event <= weight then -- do something with the thing break else event = event-weight end end |
|
|
| Report Abuse |
|
|
RogueMage
|
  |
| Joined: 28 Jan 2012 |
| Total Posts: 1235 |
|
|
| 10 Mar 2017 11:28 AM |
I call it math
You should've learned this in Algebra II or Pre-Calculus |
|
|
| Report Abuse |
|
|
llaserx
|
  |
| Joined: 10 Dec 2011 |
| Total Posts: 53069 |
|
|
| 10 Mar 2017 07:36 PM |
ya because everyone has those 2 classes o________________o
|
|
|
| Report Abuse |
|
|
|
| 10 Mar 2017 07:39 PM |
local stuff = { {10,'apple'}, {20.5,'potato'}, {35.5,'pear'}, {34,'mango'} }
table.sort(stuff,function(a,b) return a[1] < b[1] end)
local num = math.random() * 100
local old = 0
local chosen
for i=1, #stuff do old = old + stuff[i][1] if old <= num then chosen = stuff[i][2] break end end
print(chosen)
something like that should work
|
|
|
| Report Abuse |
|
|
|
| 10 Mar 2017 07:40 PM |
you can change the math.random() * 100 to math.random() * totalchanceofallthingsinthetable
|
|
|
| Report Abuse |
|
|
llaserx
|
  |
| Joined: 10 Dec 2011 |
| Total Posts: 53069 |
|
|
| 11 Mar 2017 09:48 AM |
it seems like everyone suggests <= for this
thx |
|
|
| Report Abuse |
|
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 11 Mar 2017 11:48 AM |
| @Disillusions that will always pick the first thing in your table. |
|
|
| Report Abuse |
|
|
| |
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 11 Mar 2017 05:54 PM |
Could u plz be more specific, what kinda of probability would u like exactly?
|
|
|
| Report Abuse |
|
|
|
| 11 Mar 2017 06:40 PM |
Simpler version:
local probability = 20
chances = math.random (1, # probability) print(chances) end
or something like that idk |
|
|
| Report Abuse |
|
|