def select_random_from_category(conn, cat):
    """
    Obtains a random fortune from a given category.
    :param conn: A handle to the database connection.
    :param cat: The category ID.
    :return: The text of the fortune.
    """
    conn[1].execute("SELECT data FROM fortunes WHERE category = ? ORDER BY "
                    + "RANDOM() LIMIT 1", (str(cat),))
    return conn[1].fetchall()[0][0]