First of all, try to understand the difference between ‘rand’ and ‘randn’.
‘rand’ will give you the values between the range of 0 and 1, like 0.24,0.47 etc, while ‘randn’ gives you all positive and negative values between the given range, with the center value as 0.
In your case, you were using rand, which was adjusting the weight with positive values only, due to which your network neurons were not learning different features effectively, which caused no change in your weight and biases.
That is why in the original code ‘randn’ was used so that we can get the weight in both positive and negative values, which will help my neurons to learn different features and perform effectively.