PDA

View Full Version : Is it possible to determine odds of winning with PHP?



Ban
11-04-2013, 04:21 PM
I mean, I want a set value/range of values to determine if I win or lose in a minigame for example.

It's for a website me and my friend are making, we need a game that upon clicking will bring another page telling you if you won or not based on odds previously coded for each opponent... the problem is coding the odds... :x

Anybody care to help? :3

Zachafer
11-04-2013, 04:43 PM
I mean, I want a set value/range of values to determine if I win or lose in a minigame for example.

It's for a website me and my friend are making, we need a game that upon clicking will bring another page telling you if you won or not based on odds previously coded for each opponent... the problem is coding the odds... :x

Anybody care to help? :3

If it's a simple true/false, totally random odds:



function rollOdds($winPercent)
{
$randPercent = mt_rand(1, 100);
return $randPercent <= $winPercent;
}

if(rollOdds(50))
{
$winner = $PLAYERS[0];
}
else
{
$winner = $PLAYERS[1];
}


But I'd recommend something more like this: [Only registered and activated users can see links]

Ban
11-04-2013, 04:47 PM
If it's a simple true/false, totally random odds:



function rollOdds($winPercent)
{
$randPercent = mt_rand(1, 100);
return $randPercent <= $winPercent;
}

if(rollOdds(50))
{
$winner = $PLAYERS[0];
}
else
{
$winner = $PLAYERS[1];
}


But I'd recommend something more like this: [Only registered and activated users can see links]

Yes!
That link, it's exactly what I was looking for, thanks <3