Replaced rand with mt_rand