Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions robot-name.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
class Robot
{
protected $name;
public function __construct() {
$this->reset();
}
public function reset()
{
$this->name = RandomRobotNameGenerator::generate();
}
public function getName()
{
return $this->name;
}
}
class RandomRobotNameGenerator
{
public static function generate()
{
$chars = range('A', 'Z');
$nums = range('0', '9');

$randCharKeys = array_rand($chars, 2);
$randNumKeys = array_rand($nums, 3);
$robotName = array_merge(
[
$chars[$randCharKeys[0]],
$chars[$randCharKeys[1]],
],
[
$nums[$randNumKeys[0]],
$nums[$randNumKeys[1]],
$nums[$randNumKeys[2]],
]
);
return implode('', $robotName);
}
}