import random


def fillTwoOrFour(board, iter=1):
    """
    Randomly fill 2 or 4 in available spaces on the board.

    Parameters:
        board (list): game board
        iter (int): number of times to repeat the process
    Returns:
        board (list): updated game board
    """
    for _ in range(iter):
        a = random.randint(0, 3)
        b = random.randint(0, 3)
        while(board[a][b] != 0):
            a = random.randint(0, 3)
            b = random.randint(0, 3)

        if sum([cell for row in board for cell in row]) in (0, 2):
            board[a][b] = 2
        else:
            board[a][b] = random.choice((2, 4))
    return board