<?php class Test { protected function generate(int $length = 4): string { $randomString = ''; $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; for ($i = 0; $i < $length; $i++) { $index = random_int(0, strlen($characters) - 1); $randomString .= $characters[$index]; } $uppercase = preg_match('@^[A-Z]+$@', $randomString); $number = preg_match('@^\d+$@', $randomString); if ($uppercase || $number) { $randomString = $this->generate(); } return $randomString; } public function getRandomString() { return $this->generate(); } } $test = new Test(); for ($i = 0; $i < 10; $i++) { echo $test->getRandomString() . PHP_EOL; }
You have javascript disabled. You will not be able to edit any code.