As I try to write a function in c that could generate a random integer in the range from 0 to n, I found a weird output. Could anyone help me look into this?
Here is my code(I wrote this question on my phone so I am not sure how to present the code in “code way”, sorry for the inconvenience.)
Basically, all the include file like time.h
#define VERT 6
#define HOR 7
int ranNum(){
int m;
srand(time(0));
m=rand()%(HOR);
return m;}
int main(){
printf(“%d”, ranNum);
return 0;}
So the output printed on the screen will always be 0, while it should be 0-6 right? However, when I changed HOR to VERT in the ranNum() function, the output printed on the screen can be 0,1,2,3,4,5 as expected.
So can anyone help me figure out this that puzzled me a lot? Thanks in advance :)
Aucun commentaire:
Enregistrer un commentaire