edited to use mt_rand for faster calculation