generalizes the random generator function