# How do I show the odds?

## Recommended Posts

```\$card1 = rand(1,3);
\$card2 = rand(1,3);

/// check money win ////////
if(\$card1 == "1" && \$card2 == "1" ){
echo "You won 100\$?";
exit;
mysql_query("UPDATE card SET money='\$win_money' WHERE name='\$name'");
}```

My code works wonderfully

prob tho

how can I show the odds of winning out of 100 to my suer?

##### Share on other sites

and thats on dice, but i figured dice are 6 and yours are 3, so i came up with 1 in 6, as each one has a 1 in 3 chance

'm not to good on odd calculating but the link might help a bit

##### Share on other sites

It's 1 in 9.

Basic statistics have nothing to do with  PHP.

Also, this code has an exit() call BEFORE the mysql_query, that query will never run.  There's also a random closing curly brace.

##### Share on other sites

If you have 3 picks from a pool of 36 numbers, and none of the numbers can repeat, the chances are 36*(36-1)*(36-2), or 1 in 42840. How to calculate the chances if the order of the numbers picked is required to match the order of the numbers drawn, I don't know.

##### Share on other sites

Pika.......what?  He has two numbers, 1-3 each.  And he wants to know the odds of getting a 1,1.

##### Share on other sites

Oh yeah, I kind of glossed over the code, thinking it was the same code from the other thread, with 3 non-repeating numbers from a pool of 36.

I are sorry : (

##### Share on other sites

Ok, at least you're not crazy.

##### Share on other sites

Oh, that doesn't mean I'm not crazy.

##### Share on other sites

Im still confused

```\$card1 = rand(1,4);
\$card2 = rand(1,4);
if (\$ibforums->input['id'] == "1"){
if(\$card1 == "1" && \$card2 == "1"){```

if my stuff is 1 in 4 chances

and it both has to equal the same "1"

that would be 25% divided by 2

which is

12.5% of winning right?

##### Share on other sites

Again, basic statistics have nothing to do with PHP.  You want to study basic probability.

The probability of the first number being 1 is 1/4.  The probability of the second number being 1 is also 1/4.  You multiply the odds together to get your answer: 1/4 x 1/4 = 1/16, or 6.25%

##### Share on other sites

This should allow you to dynamically determine the odds based upon a max number.

```\$max_num = 4;

\$card1 = rand(1, \$max_num);
\$card2 = rand(1, \$max_num);

\$odds = pow((1/\$max_num), 2); //2 is the number of 'cards'
```

##### Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.