Have you set the random seed before both experiments. In the above two cases you are generating random numbers using different seeds and thus their value is different. With different values you get different gradients.