I need to know how to make something randomly fail.
E.x someone sends a form to roll a dice, with 75% luck, how to make that 75% real?
I tried doin' it with rand(); but I didnt make it x[
Elite.
Printable View
I need to know how to make something randomly fail.
E.x someone sends a form to roll a dice, with 75% luck, how to make that 75% real?
I tried doin' it with rand(); but I didnt make it x[
Elite.
PHP Code:<?php
// Create a rand() for 100 possibilities
$rand = rand(1,100);
// A 75% success rate would be either ">= 25" OR "<= 75"
if($rand >= 25)
{
// If its within the given amount, show the dice...
// For this example, I chose the 75% chance to roll a 6
echo '<img src="6.jpg">';
}
// Else... Failed and it will choose between the other sides of the dice
else
{
// 6 had the 75% and failed
// So the remaining sides on the dice are 1 - 5
$card_rand = rand(1,5);
// Echo the image
echo '<img src="' . $card_rand . '.jpg">';
}
// Final Notes!
// This is assuming your using images and the images are
// 1.jpg, 2.jpg, upto 6.jpg
?>
Thanks, I just forgot the method I did it =p
Thanks for the help,
Elite.
you should use the mt_rand() function istead, it's four times faster ;P