docs: def random(length, chars=None):
      """Generates a random string.
  
      :param length: Length of the string to generate.
                     This can be a numbe or a pair: ``(min_length, max_length)``
      :param chars: String of characters to choose from
      """
      if chars is None:
          chars = string.ascii_letters + string.digits
      else:
          ensure_string(chars)
          if not chars:
              raise ValueError("character set must not be empty")
  
      if is_pair(length):
          length = randint(*length)
      elif isinstance(length, Integral):
          if not length > 0:
              raise ValueError(
                  "random string length must be positive (got %r)" % (length,))
      else:
          raise TypeError("random string length must be an integer; "
                          "got '%s'" % type(length).__name__)
  
      return join(chars.__class__(), (choice(chars) for _ in xrange(length)))