R
Red Dragon
Good news.
Problem solved.
Earlier I did not understand the passing of data and wrote the program wrongly.
I have now discovered my error in the structure of the program writing.
Now I have rewritten and the program is working perfectly. I am getting 2 different random numbers each time now.
So the srand() seeding thing got blamed for nothing.
Here is my correct program.
Rgds,
Khoon.
Correction,
Actually, srand has got problem as rightly pointed out and also as stated in the Q&A as seen below. In fact the authority does not recommend to call srand more than once during a run of a program which I dont understand why.
Rgds,
Khoon.
Question 13.17
Each time I run my program, I get the same sequence of numbers back from rand().
------------------------------------------------------------------------------
You can call srand to seed the pseudo-random number generator with a truly random initial value. Popular seed values are the time of day, or the elapsed time before the user presses a key (although keypress times are hard to determine portably; see question 19.37). (Note also that it's rarely useful to call srand more than once during a run of a program; in particular, don't try calling srand before each call to rand, in an attempt to get ``really random'' numbers.)
References: K&R2 Sec. 7.8.7 p. 168
ANSI Sec. 4.10.2.2
ISO Sec. 7.10.2.2
H&S Sec. 17.7 p. 393
Problem solved.
Earlier I did not understand the passing of data and wrote the program wrongly.
I have now discovered my error in the structure of the program writing.
Now I have rewritten and the program is working perfectly. I am getting 2 different random numbers each time now.
So the srand() seeding thing got blamed for nothing.
Here is my correct program.
Rgds,
Khoon.
Correction,
Actually, srand has got problem as rightly pointed out and also as stated in the Q&A as seen below. In fact the authority does not recommend to call srand more than once during a run of a program which I dont understand why.
Rgds,
Khoon.
Question 13.17
Each time I run my program, I get the same sequence of numbers back from rand().
------------------------------------------------------------------------------
You can call srand to seed the pseudo-random number generator with a truly random initial value. Popular seed values are the time of day, or the elapsed time before the user presses a key (although keypress times are hard to determine portably; see question 19.37). (Note also that it's rarely useful to call srand more than once during a run of a program; in particular, don't try calling srand before each call to rand, in an attempt to get ``really random'' numbers.)
References: K&R2 Sec. 7.8.7 p. 168
ANSI Sec. 4.10.2.2
ISO Sec. 7.10.2.2
H&S Sec. 17.7 p. 393