fix to random generator function