Changed rand() to mtrand()