Changed random generator function.