Implemented rng Matlab function