replace all rand with mt_rand because it generates better numbers