/** * @return float|int */ protected function spareChange() { if (Randomizer::boolOnPercentage(50)) { return rand(1, 5) / 10.0; } else { return -1 * (rand(1, 5) / 10.0); } }
/** * @group rand * */ public function testRandomizer() { $yes = 0; $no = 0; for ($i = 1; $i <= 100; $i++) { if (\App\Lib\DsManager\Helpers\Randomizer::boolOnPercentage(20)) { $yes++; } else { $no++; } } $this->assertNotEmpty($yes); $this->assertNotEmpty($no); $this->assertGreaterThan($yes, $no); }
/** * @param Team $team * @return Player */ private function pickAScorer(Team $team) { $player = null; if (Randomizer::boolOnPercentage(70)) { $roles = Config::get('modules.roles'); $forwards = array_splice($roles, count($roles) / 2); $pos = array_rand($forwards); unset($forwards[$pos]); $player = $team->getBestPlayerForRole($pos); while (empty($player)) { if (!empty($forwards)) { $pos = array_rand($forwards); unset($forwards[$pos]); $player = $team->getBestPlayerForRole($pos); } else { $player = $team->roster[array_rand($team->roster)]; } } } else { $player = $team->roster[array_rand($team->roster)]; } return $player; }
/** * @param null $locale * @return Team */ public function getTeam($locale = null) { $rosterConf = Config::get('generic.rosters'); $numberOfPlayers = rand($rosterConf['min'], $rosterConf['max']); $this->setFaker($locale); $team = new Team(); $team->name = $this->getTeamName(); $team->nationality = $this->nationalityFromLocale($this->locale); $players = []; for ($i = 0; $i < $numberOfPlayers; $i++) { $players[] = $this->getPlayer(); } //Adding some forced role $players[] = $this->getPlayer("GK", $this->getLocale()); $players[] = $this->getPlayer("CD", $this->getLocale()); $players[] = $this->getPlayer("CD", $this->getLocale()); $players[] = $this->getPlayer("CM", $this->getLocale()); $players[] = $this->getPlayer("CM", $this->getLocale()); $players[] = $this->getPlayer("CS", $this->getLocale()); // $team->roster = $players; //setting random Nationality Coach (20%) $coachNationality = Randomizer::boolOnPercentage(20) ? $this->getLocale() : null; $team->coach = $this->getCoach($coachNationality); return $team; }
/** * @return int */ private function bonusHome() { return Randomizer::boolOnPercentage(66) ? 1 : 0; }