from datetime import datetime
import random


def random_date(year):
    """Returns a random date in a given year."""
    try:
        return datetime.strptime("{} {}".format(random.randint(1, 366), year), "%j %Y")
    # accounts for leap year values
    except ValueError:

        random_date(year)