Changed rand function