"With a chance" Function?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
joetheeskimo5
Forum Commoner
Posts: 43
Joined: Sun Dec 14, 2003 4:47 pm
Location: US
Contact:

"With a chance" Function?

Post 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!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

$percentage = mt_rand() / mt_getrandmax();
Post Reply