public static function random(int $length = 10, string $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') : string
  {
    $pieces = [];
    $max = mb_strlen($keyspace, '8bit') - 1;
    for ($i = 0; $i < $length; ++$i) {
      $pieces[] = $keyspace[random_int(0, $max)];
    }
    return implode('', $pieces);
  }
public static function random(int $length = 10, string $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') : string
  {
    $pieces = [];
    $max = mb_strlen($keyspace, '8bit') - 1;
    for ($i = 0; $i < $length; ++$i) {
      $pieces[] = $keyspace[random_int(0, $max)];
    }
    return implode('', $pieces);
  }
public static function random ( int $ length = 10 , string $ keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ) : string { $ pieces = [ ] ; $ max = mb_strlen ( $ keyspace , '8bit' ) - 1 ; for ( $ i = 0 ; $ i < $ length ; ++ $ i ) { $ pieces [ ] = $ keyspace [ random_int ( 0 , $ max ) ] ; } return implode ( '' , $ pieces ) ; }
Creating a random string

@param  int    $length
@param  string $keyspace
@return string
Creating a random string