|
| 18 Mar 2015 06:15 PM |
I don't know where I would go to learn this, so here it goes.
Let's start with cards because it seems easiest.
The chance of getting a Ace is 4/52, and the chance of getting another one is 3/51, How would I figure out the chances of getting both the first ace and the second? Multiply? Add? Divide? (4/52) * (3/51)?? |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2015 06:20 PM |
nCr
or multiple the fractions 4/52 * 3/51 |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2015 06:21 PM |
Well, the probablities are independent of eachother you'd multiply like so:
4 3 12 1 -- X -- = ---- = --- 52 51 2652 221
If the math above came out weird, the basic idea is you multiply the numerators, and the denominators (standard way of multiplying fractions) and then simplify. |
|
|
| Report Abuse |
|
|
amanda
|
  |
| Joined: 21 Nov 2006 |
| Total Posts: 5925 |
|
|
| 18 Mar 2015 06:27 PM |
a deck of cards sounds like some good OOP
multiply the fractions, or even the decimals |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2015 06:28 PM |
| Okay thanks I just just wondering for use in other things |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2015 06:31 PM |
Okay what would I do if I had multiple chances?
|
|
|
| Report Abuse |
|
|
amanda
|
  |
| Joined: 21 Nov 2006 |
| Total Posts: 5925 |
|
|
| 18 Mar 2015 06:33 PM |
If you are trying to draw a specific card from a full deck, the chance is 1/52
if you put it back and try to draw the same card again, the chance is still 1/52
if you don't put it back, the chance is 1/51
--
if you try to draw 2 specific cards in a row, the chance is 1/52 * 1/51, whatever that comes out to be. |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2015 06:34 PM |
...
function Probs(Nums, Dens) local NumPro = 0 local DenPro = 0 for i,v in pairs(Nums) do NumPro = NumPro*v end for i,v in pairs(Dens) do DenPro = DenPro*v end return NumPro, DenPro end
print(Probs({4, 3, 2, 1}, {52, 51, 50, 49})) |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2015 06:34 PM |
| https://www.khanacademy.org/math/precalculus/prob_comb/basic_prob_precalc/v/basic-probability |
|
|
| Report Abuse |
|
|
Dinamics
|
  |
| Joined: 08 Oct 2013 |
| Total Posts: 60 |
|
|
| 18 Mar 2015 06:37 PM |
Use this -- Chance = math.random(LOW,HIGH) and then compare it to a number you already made.
Say, i want to have a 50% chance to do something.
Chance = math.random(0,100) local ChanceComp = 50 local Print = false
if Chance = ChanceComp then Print = true (Just put your code on this line) end
FYI, if you have this running every second(Split second, whatever) then whenever Chance = ChanceComp, your code is going to activate, and in my case will print every 0.2 seconds (Or whatever, half of the time). |
|
|
| Report Abuse |
|
|
amanda
|
  |
| Joined: 21 Nov 2006 |
| Total Posts: 5925 |
|
|
| 18 Mar 2015 06:37 PM |
function Probs(Nums, Dens) local NumPro = 0 local DenPro = 0 for i,v in pairs(Nums) do NumPro = NumPro*v end for i,v in pairs(Dens) do DenPro = DenPro*v end return NumPro, DenPro end
--
won't that just return 0, 0?
no matter what you put in? |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2015 06:38 PM |
function Probs(Nums, Dens) local NumPro = 1 local DenPro = 1 for i,v in pairs(Nums) do NumPro = NumPro*v end for i,v in pairs(Dens) do DenPro = DenPro*v end return NumPro, DenPro end
print(Probs({4, 3, 2, 1}, {52, 51, 50, 49}))
Sorry, I meant the above. |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2015 06:41 PM |
In fact, I'll be generous and give you one that can simplify:
function Probs(Nums, Dens) local NumPro = 1 local DenPro = 1 for i,v in pairs(Nums) do NumPro = NumPro*v end for i,v in pairs(Dens) do DenPro = DenPro*v end for i = DenPro, 1, -1 do if DenPro%i == 0 and NumPro%i == 0 then NumPro = NumPro/i DenPro = DenPro/i end end return NumPro, DenPro end
print(Probs({4, 3, 2, 1}, {52, 51, 50, 49})) |
|
|
| Report Abuse |
|
|