fixed use of rand()