I'm working on a scratch card game for a website. The game is simple, win or lose.
I found this code in php for the game, it's working great :
function winningChance(int $percentage): string
{
if ($percentage < 0 || $percentage > 100) {
throw new \Exception('Invalid percentage');
}
return rand(1, 100) <= $percentage ? 'won' : 'lost';
}
echo "You've " . winningChance(1) . '!';
But I have a problem, I need to limit the number of playing cards and generate randomly just one time a winning card and don't know how to do that.
For exemple :
I limit the game to 150 playing cards, so I have 150 players, 149 losers, 1 winner ?
How can i do that in php ? Can someone help me ?
Thank you !