improved randFile code