Page 1 of 1

Looking for a way to make odds

Posted: Tue Dec 20, 2011 9:09 pm
by xwhitchx
Im looking to for a way to make something show up on a %, i need this to work with (if).

example, when the page is loaded text will say Good Day 95% of the time, and 4% says Hello, and 1% says You Win.


Sorry if I'm not making any sense, I'm finding this hard to put in to words.

Re: Looking for a way to make odds

Posted: Tue Dec 20, 2011 9:42 pm
by twinedev

Code: Select all

$intHit = rand(1,100);
if ($intHit <= 95) { 
  $strMsg = 'Good Day'; 
}
elseif ($intHit <= 99) { // 95 + 4, Anything 95 and under would have hit above 
  $strMsg = 'Hello'; 
}
else { // The only thing that would hit here is 100, which is 1% chance
  $strMsg = 'You Win'; 
}

Re: Looking for a way to make odds

Posted: Tue Dec 20, 2011 10:25 pm
by xwhitchx
thank you very much. this should help me a lot