import random
import string


def id_generator(N):
    """ Generate a random string of length N consisting of uppercase letters
    and digits. Used for generating names for temporary files, etc.
    """
    return ''.join(random.SystemRandom().choice(
        string.ascii_uppercase + string.digits) for _ in range(N))