Fixed bugs with RNG