import string
import random


def gen_random_string(n=24):
    """Returns a random n-length string, suitable for a password or random secret"""
    # RFC 3986 section 2.3. unreserved characters (no special escapes required)
    char_set = string.ascii_letters +  string.digits + "-._~"
    return "".join(random.choices(char_set, k=n))