We study random weighted averaging dynamics which are widely used in distributed and decentralized control and estimation problems. We define the infinite flow property and study the relation of this property with the ergodicity and consensus of a chain of stochastic matrices. We show that the infinite flow property is a necessary condition for the ergodicity of any stochastic chain, and under some additional conditions, this property is also sufficient for ergodicity. Moreover, we prove that for those chains, even if the infinite flow property is not present, the resulted dynamics are stable almost surely and we show that the set of the equilibrium points of the dynamics is a subspace that can be fully characterized using the connected components of the infinite flow graph, which is a graph associated with the random chain. Using these results, we propose and study the gossip and broadcast gossip algorithms over the time-varying and random networks.