added fclose to random generator