fixed a bug in random generator