wladoD Posted September 16, 2021 Share Posted September 16, 2021 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? Please help me, Thank you. <?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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/313746-function-with-update-result/ Share on other sites More sharing options...
Barand Posted September 16, 2021 Share Posted September 16, 2021 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? Quote Link to comment https://forums.phpfreaks.com/topic/313746-function-with-update-result/#findComment-1589958 Share on other sites More sharing options...
wladoD Posted September 16, 2021 Author Share Posted September 16, 2021 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 Quote Link to comment https://forums.phpfreaks.com/topic/313746-function-with-update-result/#findComment-1589959 Share on other sites More sharing options...
Barand Posted September 16, 2021 Share Posted September 16, 2021 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 Quote Link to comment https://forums.phpfreaks.com/topic/313746-function-with-update-result/#findComment-1589960 Share on other sites More sharing options...
Barand Posted September 16, 2021 Share Posted September 16, 2021 return $bankroll = $bet * $odds - $bet + $bankroll; ^^^^^^ Are you sure you should be losing your stake when you win? Quote Link to comment https://forums.phpfreaks.com/topic/313746-function-with-update-result/#findComment-1589961 Share on other sites More sharing options...
wladoD Posted September 16, 2021 Author Share Posted September 16, 2021 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 Quote Link to comment https://forums.phpfreaks.com/topic/313746-function-with-update-result/#findComment-1589962 Share on other sites More sharing options...
Barand Posted September 16, 2021 Share Posted September 16, 2021 If you win the first bet, you should then have 600. If you win, they pay you. Quote Link to comment https://forums.phpfreaks.com/topic/313746-function-with-update-result/#findComment-1589964 Share on other sites More sharing options...
wladoD Posted September 16, 2021 Author Share Posted September 16, 2021 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 Quote Link to comment https://forums.phpfreaks.com/topic/313746-function-with-update-result/#findComment-1589965 Share on other sites More sharing options...
Barand Posted September 16, 2021 Share Posted September 16, 2021 The bankroll would become 450 only if you lost. Quote Link to comment https://forums.phpfreaks.com/topic/313746-function-with-update-result/#findComment-1589966 Share on other sites More sharing options...
wladoD Posted September 16, 2021 Author Share Posted September 16, 2021 When you place a bet, bankroll in reduced till the ticket is winning or loosing. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/313746-function-with-update-result/#findComment-1589967 Share on other sites More sharing options...
Barand Posted September 16, 2021 Share Posted September 16, 2021 But if you win, you get your stake back + winnings. Quote Link to comment https://forums.phpfreaks.com/topic/313746-function-with-update-result/#findComment-1589968 Share on other sites More sharing options...
wladoD Posted September 16, 2021 Author Share Posted September 16, 2021 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. Quote Link to comment https://forums.phpfreaks.com/topic/313746-function-with-update-result/#findComment-1589969 Share on other sites More sharing options...
Barand Posted September 16, 2021 Share Posted September 16, 2021 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 Quote Link to comment https://forums.phpfreaks.com/topic/313746-function-with-update-result/#findComment-1589970 Share on other sites More sharing options...
wladoD Posted September 16, 2021 Author Share Posted September 16, 2021 you win if first bet bankroll = 550 EURO if you loose first bet bankroll = 450 EURO. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/313746-function-with-update-result/#findComment-1589971 Share on other sites More sharing options...
Barand Posted September 16, 2021 Share Posted September 16, 2021 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 ? '✓' : '×', number_format($bankroll,2)); } } echo '<pre>'; printf("| %54.2f |<br>", $bankroll); betting($bankroll, $pcent, $odds); ?> Quote Link to comment https://forums.phpfreaks.com/topic/313746-function-with-update-result/#findComment-1589973 Share on other sites More sharing options...
wladoD Posted September 16, 2021 Author Share Posted September 16, 2021 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 ? '✓' : '×', number_format($bankroll,2)); } } echo '<pre>'; printf("| %54.2f |<br>", $bankroll); betting($bankroll, $pcent, $odds); ?> Quote Link to comment https://forums.phpfreaks.com/topic/313746-function-with-update-result/#findComment-1589975 Share on other sites More sharing options...
Barand Posted September 16, 2021 Share Posted September 16, 2021 1 hour ago, wladoD said: how could i see PROFIT for each winning unit ? Define "unit". 1 hour ago, wladoD said: 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). Quote Link to comment https://forums.phpfreaks.com/topic/313746-function-with-update-result/#findComment-1589976 Share on other sites More sharing options...
wladoD Posted September 16, 2021 Author Share Posted September 16, 2021 Units, EURO. I mean i know how to count %, i just meant to ask how to incorporate it in the formula. Thank you sir. Quote Link to comment https://forums.phpfreaks.com/topic/313746-function-with-update-result/#findComment-1589979 Share on other sites More sharing options...
Barand Posted September 16, 2021 Share Posted September 16, 2021 I still have no idea what you mean by "PROFIT for each winning unit" Quote Link to comment https://forums.phpfreaks.com/topic/313746-function-with-update-result/#findComment-1589980 Share on other sites More sharing options...
wladoD Posted September 16, 2021 Author Share Posted September 16, 2021 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 Quote Link to comment https://forums.phpfreaks.com/topic/313746-function-with-update-result/#findComment-1589982 Share on other sites More sharing options...
ginerjm Posted September 16, 2021 Share Posted September 16, 2021 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. Quote Link to comment https://forums.phpfreaks.com/topic/313746-function-with-update-result/#findComment-1589983 Share on other sites More sharing options...
wladoD Posted September 16, 2021 Author Share Posted September 16, 2021 (edited) 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 Edited September 16, 2021 by wladoD Quote Link to comment https://forums.phpfreaks.com/topic/313746-function-with-update-result/#findComment-1589984 Share on other sites More sharing options...
ginerjm Posted September 16, 2021 Share Posted September 16, 2021 (edited) 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? Are you sure about this? What county is there, cause I never want to gamble there! Edited September 16, 2021 by ginerjm 1 Quote Link to comment https://forums.phpfreaks.com/topic/313746-function-with-update-result/#findComment-1589985 Share on other sites More sharing options...
Barand Posted September 16, 2021 Share Posted September 16, 2021 @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. Quote Link to comment https://forums.phpfreaks.com/topic/313746-function-with-update-result/#findComment-1589986 Share on other sites More sharing options...
wladoD Posted September 17, 2021 Author Share Posted September 17, 2021 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? Are you sure about this? What county is there, cause I never want to gamble there! 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 Quote Link to comment https://forums.phpfreaks.com/topic/313746-function-with-update-result/#findComment-1589995 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.