fixed bug for testing rand() and for loop