# Function with update result

## Recommended Posts

6 hours ago, Barand said:

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

Morning,

Quote

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.

What you saying is (0,2), do i understand it correctly that now chance of 1 is only 33,3 % ?
2 odds in decimal should give you 50 % of winning  (2 decimal odds = 1/1 in fractional odds)

I was wondering how could i make a function like rand() but give conditions that number has to appear at least 60 % or any given number?

Thank you

##### Share on other sites

What you saying is (0,2), do i understand it correctly that now chance of 1 is only 33,3 % ?

Yes.

If you have an array of 10 elements and 6 of them are 1's, there is a 60% chance of selecting a 1.

\$win = percent_win(60);     // \$win will be 1 (true) approx 60% of the time

function percent_win(\$pc)
{
\$lose = 100 - \$pc;
\$a1 = array_fill(0, \$lose, 0);
\$a2 = array_fill(0, \$pc, 1);
\$a1 = array_merge(\$a1, \$a2);
shuffle(\$a1);
return \$a1[array_rand(\$a1)];
}

To test...

\$w = \$l = 0;
for (\$i=0; \$i<1000; \$i++) {
\$win = percent_win(20);
if (\$win)
++\$w;
else ++\$l;
}
printf ('%d - %d - %0.3f', \$w, \$l, \$w/(\$w + \$l) );

##### Share on other sites

NOTE: the win_percentage in

\$win = percent_win(20);

^^

(100 / \$odds)

should be equal to 100/\$odds

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