Note that we loop over all spins but that we choose the lattice positions \( x \) and \( y \) randomly. If the move is accepted after performing the Metropolis test, we update the energy and the magnetisation. The new values are used to update the averages computed in the main function.