Origin of the division of labour and a stochastic mechanism of differentiation