Replaced instances of rand() with mt_rand()