# Function with update result

## Recommended Posts

Hi Guys,

I am new here, hope you are all well. I am very new in php. I would like to ask a question.

I am trying to calculate my bets.

Basically you start with 500 EUR, you bet 10 % with avg odds 2. It all fine. How can i run this function 500 times for example with update bankroll?

<?php
function betting(\$bankroll, \$betPerc, \$odds)
{

\$number = rand(0,1);
\$bet = \$bankroll * \$betPerc;

if(\$number == 1){

return  \$bankroll =  \$bet * \$odds - \$bet + \$bankroll;

}else

return  \$bankroll - \$bet;
}

echo betting(500, 0.1, 2);

?>

##### Share on other sites

Clarification required.

• Your bet is 10%. Does that mean that, if you start with 500.00, you will always bet 50.00, or will your next bet be 10% of your current bankroll?
• You say 500 times, but what if you are unlucky and run out of cash?
##### Share on other sites

3 minutes ago, Barand said:

Clarification required.

• Your bet is 10%. Does that mean that, if you start with 500.00, you will always bet 50.00, or will your next bet be 10% of your current bankroll?
• You say 500 times, but what if you are unlucky and run out of cash?

hey, always 10% of bankroll, so if you win first bet your bankroll will be 550 hence next bet will be 55 EUR.
yes, very true, it would be great to indicate in which occurrence it happens. lets say 349 bet for example.

Big Thanks

##### Share on other sites

One more question - is there a minimum bet?

If it's 10% of the current bankroll and you keep losing, you could, at some point, be betting 0.0000000001 euros

##### Share on other sites

```return  \$bankroll =  \$bet * \$odds - \$bet + \$bankroll;
^^^^^^```

Are you sure you should be losing your stake when you win?

##### Share on other sites

I reckon 0.5 EURO should be the lowest.

You aren't loosing the stake, i calculated lest say you win first bet = 500 + 50 , i guess you can calculated is 450 + 100.

Thank you

##### Share on other sites

If you win the first bet, you should then have 600.

If you win, they pay you.

##### Share on other sites

I thought the same at begging but consider this;

500 Bankroll
1. Bet is 50 EURO / 2.00 ODDS (possible winning 100 EURO)

When you place the bet, you bankroll became 450 EURO and will stay the same if you loose; however if you win you bankroll is now 450 + 100 = 550 EUR.

Thank you

##### Share on other sites

The bankroll would become 450 only if you lost.

##### Share on other sites

When you place a bet, bankroll in reduced till the ticket is winning or loosing.

Thanks

##### Share on other sites

But if you win, you get your stake back + winnings.

##### Share on other sites

Yes, sure as  i mentioned above.

500 Bankroll
1. Bet is 50 EURO / 2.00 ODDS (possible winning 100 EURO)

When you place the bet, you bankroll became 450 EURO and will stay the same if you loose; however if you win you bankroll is now 450 + 100 = 550 EUR.

##### Share on other sites

No - in that case you have won your bet but still lost your 50.00 stake.

If you lose you pay them

If you win, they pay you

You are doing both at the same time

##### Share on other sites

you win if first bet bankroll = 550 EURO
if you loose first bet bankroll = 450 EURO.

Thanks

##### Share on other sites

Something like this?

```<?php
const BETS = 500;

\$bankroll = 500;
\$pcent    = 0.1;
\$odds     = 2;

function betting(&\$bankroll, \$betPerc, \$odds)
{
for (\$i=1; \$i <= BETS; \$i++) {
if (\$bankroll < 0.5) break;
\$win = rand(0,1);
\$bet = \$bankroll * \$betPerc;
\$bankroll +=  (\$win ? \$bet * \$odds - \$bet : - \$bet);
printf("| %3d | %20.2f | %s  | %20s |<br>", \$i, \$bet, \$win ? '&check;' : '&times;', number_format(\$bankroll,2));
}
}

echo '<pre>';
printf("| %54.2f |<br>", \$bankroll);
betting(\$bankroll, \$pcent, \$odds);

?>```

##### Share on other sites

3 hours ago, Barand said:

Something like this?

Amazing, looks pretty straight forward, how could i see PROFIT for each winning unit ? Plus one more question how to calculate how many wins in 500 in % please ?

Big Thanks

3 hours ago, Barand said:
```<?php
const BETS = 500;

\$bankroll = 500;
\$pcent    = 0.1;
\$odds     = 2;

function betting(&\$bankroll, \$betPerc, \$odds)
{
for (\$i=1; \$i <= BETS; \$i++) {
if (\$bankroll < 0.5) break;
\$win = rand(0,1);
\$bet = \$bankroll * \$betPerc;
\$bankroll +=  (\$win ? \$bet * \$odds - \$bet : - \$bet);
printf("| %3d | %20.2f | %s  | %20s |<br>", \$i, \$bet, \$win ? '&check;' : '&times;', number_format(\$bankroll,2));
}
}

echo '<pre>';
printf("| %54.2f |<br>", \$bankroll);
betting(\$bankroll, \$pcent, \$odds);

?>```

##### Share on other sites

how could i see PROFIT for each winning unit ?

Define "unit".

how to calculate how many wins in 500 in %

Count the wins, multiply by 100 and divide by number of bets (which may be less than 500 if you run out of funds).

##### Share on other sites

Units, EURO.
I mean i know how to count %, i just meant to ask how to incorporate it in the formula.

Thank you sir.

##### Share on other sites

I still have no idea what you mean by "PROFIT for each winning unit"

##### Share on other sites

When you place the bet, you bankroll became 450 EURO and will stay the same if you loose; however if you win you bankroll is now 450 + 100 = 550 EUR.

If you loose profit is 0, if you win your profit is 50 EUR - so basically you could see profit next to each bet.

Thank you

##### Share on other sites

Over and over you keep saying the wrong numbers.

If you bet 50 and win, you get back that 50 as well as the winnings.

500 goes down to 450 but if you win you get back your bet as well as the 100 in winnings which yields 600, not 550.

##### Share on other sites

Hello there,

Not sure why it is wrong as i have bet before; maybe its different in each country but i doubt it.

Bank = 500 EURO
Bet 50 x 2 (odss) = 100 EURO
Bank After bet = 450 EURO and if win = 550 EURO.

This is how it works in my country. You never get back your bet + winnings as you mention above.

Thank you

##### Share on other sites

You never get back your money that you wagered.  So what you are using as an example is NOT correct still.  If the odds are 2 to 1 that means you win twice as much as  you bet.  So the result is 100  But in actually all you did was get your money back and a 50 profit which is a 1 to 1 bet, not 2 to 1.

So if the odds are even (1 to 1), what do you get back?  Just the 50 that you bet?

Edited by ginerjm
##### Share on other sites

@ginerjm That was my argument too, but I relented when I ran the simulation over 500 runs

If I took out the - \$bet from a winning payout (so you weren't losing your stake money) but keeping the odds = 2 and the chance of win = rand(0, 1) then the accumulated bankroll would have made Elon Musk green with envy. EG

Thinking about it, the odds of winning are even but you are being paid out at 2-1. So not surprising the gains are exponential.

To get it back on an even keel I then changed the chance of a win to \$win = rand(0, \$odds)==1 so the chance matched the odds.

Going back to the original method I decided was a matter of interpretation. The OP's odds of "2", I guess, is actually 1 in 2 (evens) so the OP's formaula works if the stake is lost but double is paid back.

##### Share on other sites

7 hours ago, ginerjm said:

You never get back your money that you wagered.  So what you are using as an example is NOT correct still.  If the odds are 2 to 1 that means you win twice as much as  you bet.  So the result is 100  But in actually all you did was get your money back and a 50 profit which is a 1 to 1 bet, not 2 to 1.

So if the odds are even (1 to 1), what do you get back?  Just the 50 that you bet?

Morning,

i get your point, we are from different part of the world, hence you guys are using different betting odds.

Quote

Fractional Odds
Fractional odds are displayed as 10/1 or 7/2.  There are several ways to try and understand them but the easiest way is “how much you will win”/”how much you stake”. So for example if you stake £1 at 10/1 you will win £10 (remember that’s your profit, you will receive your pound back too!). If you stake £2 at 7/2 then you will win £7 and get your £2 stake back.

I was always talking about decimal odds;

Quote

Decimal Odds
Now fractional odds are confusing and just by writing the above section I am wondering why on earth anyone still uses fractional odds! In the opinion of this bookmaker, decimal odds are far easier to understand. If I asked you quickly to say which is the bigger price, 7/4 or 9/5? You’d have to think about it, right? But if I asked which is the bigger number 2.75 or 2.80?  It’s not so hard.

With decimal odds your stake is automatically included in your returns and it makes for a far easier calculation
So the equation for calculating returns from decimal odds (which are written as 1.80 or 4.50) the equation is so much simpler:

Thank you

## 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.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×

• #### Activity

• Chat
×
• Create New...