Call random function on percents?
Posted
by
Angelena Godkin
on Stack Overflow
See other posts from Stack Overflow
or by Angelena Godkin
Published on 2012-12-15T10:42:14Z
Indexed on
2012/12/15
11:03 UTC
Read the original article
Hit count: 166
I cannot figure this out.
I need a solution to call a random function for it's percent.
Ex. there is 10% chances that the script calls subscriptions() and 3% chance that the system call the function "specialitems()".
I am stuck in this, so i hope someone can help me with this brainkiller.
<?php
class RandomGifts {
public $chances = '';
public function __construct($user) {
$this->user = $user;
//Find percent for each function
$this->chances = array(
'subscriptions' => 10, // 10%
'specialitems' => 3, // 5%
'normalitems' => 30, // 40%
'fuser' => 50, // 70%
'giftcards' => 7, // 7%
);
//This should call the function which has been calculated.
self::callFunction(?);
}
public function subscriptions(){}
public function specialitems(){}
public function normalitems(){}
public function fuser(){}
public function giftcards(){}
}
?>
© Stack Overflow or respective owner