I know this topic has been covered before, but I am still a little confused. I am brand new to C, so please bare with me. I do know python and it is so simple to create a random number on a set interval but then in C it is a little more complicated it seems. So here is what I have by looking at other questions on stack overflow.
int diceroll_1;
diceroll_1=(rand()%3)+1;
printf("%d\n",diceroll_1);
The problem is that it gives me 3 every time. I want it to be different every time the program is compiled and run. I want it to be from 1 to 3 random. My understanding is that this might save it and that is why it is generating 3 every time and not what I want. How do I generate a random number every time and not the same number?
Aucun commentaire:
Enregistrer un commentaire