vendredi 23 octobre 2015

Any suggestions for creating random numbers for PHP?

I have a raffle website which based on lucks. And I am using mt_rand statement for picking random number.

However it mostly falls me down.

On a raffle who gets more tickets theoritcally they must have more chances,

Yet mostly people wins with 10% chances where there is 50% chances.

So is there better way to pick someone "mostly" who has better chance?

My current system is picking winner with less chances and it is more unfair who has more tickets.

So far I have tried this code to make sure there will be more winners with high chances, yet it didn't work out.

$tickets = $row["tickets"];
$win1 = mt_rand(0*100, $tickets*100) / 100;
$win2 = mt_rand(0*100, $tickets*100) / 100;
$allofthem = Array($win1,$win2);
$winner = $allofthem[array_rand($allofthem)];

Sorry for my unkonlwodge and English, I have tried everything I know yet nothing helped me, maybe you guys can help me since you guys are like expert on php.

Thank you for your time.




Aucun commentaire:

Enregistrer un commentaire