diff -u b/core/lib/Drupal/Component/Utility/Random.php b/core/lib/Drupal/Component/Utility/Random.php --- b/core/lib/Drupal/Component/Utility/Random.php +++ b/core/lib/Drupal/Component/Utility/Random.php @@ -53,6 +53,7 @@ */ public static function string($length = 8) { $counter = 0; + do { if ($counter == static::MAXIMUM_TRIES) { throw new \RuntimeException('Unable to generate a unique random name'); @@ -64,6 +65,7 @@ $counter++; } while (isset(static::$strings[$str])); static::$strings[$str] = TRUE; + return $str; } @@ -85,12 +87,13 @@ * @see \Drupal\Component\Utility\Random::string() */ public static function name($length = 8) { + $values = array_merge(range(65, 90), range(97, 122), range(48, 57)); $counter = 0; + do { if ($counter == static::MAXIMUM_TRIES) { throw new \RuntimeException('Unable to generate a unique random name'); } - $values = array_merge(range(65, 90), range(97, 122), range(48, 57)); $max = count($values) - 1; $str = chr(mt_rand(97, 122)); for ($i = 1; $i < $length; $i++) { @@ -99,6 +102,7 @@ $counter++; } while (isset(static::$names[$str])); static::$names[$str] = TRUE; + return $str; }