code: static public function generate($length = 16, $algorithm = 'sha256')
      {
          if (!in_array($algorithm, self::$allowedAlgorithm)) {
              throw new Exception("Hash algorithm $algorithm doesn't exists!");    
          }
  
          $salt = hash($algorithm, time());
  
          return substr(hash($algorithm, (mt_rand(self::RAND_MIN, self::RAND_MAX) % $length) . $salt . mt_rand(self::RAND_MIN, self::RAND_MAX)), self::CUT_LEN, $length);
      }
docs: Generate random string
  
  @param int $length
  @param string $algorithm
  @return string
  @throws \Extlib\Exception