import random
import string


def random_password(length=64):
    """Return a strong password valid for Redshift.

    Constraints:

    * 8 to 64 characters in length.
    * Must contain at least one uppercase letter, one lowercase letter,
      and one number.
    * Can use any printable ASCII characters (ASCII code 33 to 126)
      except ``'`` (single quote), ``\"`` (double quote), ``\\``, ``/``,
      ``@``, or space.
    * See `Redshift's CREATE USER docs
      <http://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_USER.html>`_
    """
    rand = random.SystemRandom()
    invalid_chars = r'''\/'"@ '''
    valid_chars_set = set(
        string.digits +
        string.ascii_letters +
        string.punctuation
    ) - set(invalid_chars)
    valid_chars = list(valid_chars_set)
    chars = [rand.choice(string.ascii_uppercase),
             rand.choice(string.ascii_lowercase),
             rand.choice(string.digits)]
    chars += [rand.choice(valid_chars) for x in range(length - 3)]
    rand.shuffle(chars)
    return ''.join(chars)