fixes with rand, added test