refactor rand implementations.