generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: How do I do probability math

Previous Thread :: Next Thread 
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
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
GeoVolcano is not online. GeoVolcano
Joined: 05 Jul 2012
Total Posts: 1433
18 Mar 2015 06:20 PM
nCr

or multiple the fractions 4/52 * 3/51
Report Abuse
warspykingAlt is not online. warspykingAlt
Joined: 16 Mar 2015
Total Posts: 37
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 is not online. 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
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
18 Mar 2015 06:28 PM
Okay thanks I just just wondering for use in other things
Report Abuse
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
18 Mar 2015 06:31 PM
Okay what would I do if I had multiple chances?
Report Abuse
amanda is not online. 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
warspykingAlt is not online. warspykingAlt
Joined: 16 Mar 2015
Total Posts: 37
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
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
18 Mar 2015 06:34 PM
https://www.khanacademy.org/math/precalculus/prob_comb/basic_prob_precalc/v/basic-probability
Report Abuse
Dinamics is not online. 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 is not online. 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
warspykingAlt is not online. warspykingAlt
Joined: 16 Mar 2015
Total Posts: 37
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
warspykingAlt is not online. warspykingAlt
Joined: 16 Mar 2015
Total Posts: 37
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image