import random


def random_cell(grid, snake):
    """
    Generates a new random position on the space of free cells.
    :param grid: The grid.
    :param snake: The snake whose body will represent occupied cells.
    :returns: Position of a free cell.
    """
    while True:
        x = random.randrange(grid.rows)
        y = random.randrange(grid.rows)
        if len(list(filter(lambda z: z.pos == (x, y), snake.body))) > 0:
            continue
        else:
            break

    return x, y