- random_int: documentation ( source)
<?php
class Katana {
private $description = 'The katana is characterized by its distinctive appearance: a curved, single-edged blade with a circular or squared guard and long grip to accommodate two hands. Western historians have said that katana were among the finest cutting weapons in world military history.';
private $damage = 30;
public function applyDamage() {
$damageOutput = $this->damage;
// 5% chance of a critical hit. Double the damage.
$criticalHit = random_int(1, 100);
if ($criticalHit < 5) {
$damageOutput *= 2;
}
return $damageOutput;
}
public function description() {
return $this->description;
}
}
$weapon = new Katana;
echo $weapon->applyDamage();