I aim to generate numbers 1 and 2, with the probability of 1/250 for the number 1 to happen and the probability of 249/250 for the number 2 to happen.
I used a loop to run it 10 times and see what i would get but I've been getting a negative number for the number times that 1 has happened and 11 times for 2. I'm not sure what went wrong there.
int x;
x= (rand()%1000);
if(x<4){
return 1;
}else{
return 2;
}
Aucun commentaire:
Enregistrer un commentaire