Page 1 of 1

"With a chance" Function?

Posted: Mon Nov 06, 2006 4:53 pm
by joetheeskimo5
I'm wondering if there is a function in PHP that can be told to perform certain actions with a chance.

For example:

Code: Select all

chance(50%) {
// code here
}
...So that 50% of the time, the said action(s) would happen, but otherwise it would skip to the closing bracket.

If not, I have an alternative using a database, but this would save me a lot of trouble.

Thanks!

Posted: Mon Nov 06, 2006 4:58 pm
by feyd

Code: Select all

$percentage = mt_rand() / mt_getrandmax();