Instead of taking these scripts/functions, I suggest to have a look at the paper Stern and Coe (1982) and start with the equations given there. I did the same for the paper "Modelling daily precipitation features in the Volta Basin of West Africa" in 2009.
The links given above refer to Monte Carlo random sampling. You do not give details of your objectives, but I think it is NOT what you need, at least not at the beginning.
I'v read a lot about Markov chain and gamma distribution for rain simulation and I'v written that script in matlab but I am not sure about it. so I want to compare my written script with a correct one.