Mail Archives: djgpp/1997/08/26/14:31:56
At 11:52 8/20/1997 GMT, Heathen wrote:
>In article <01bcaa71$4c08c200$0d5e4ec2 AT xyy>, xyy AT infonie DOT be says...
>>I still can't obtain truly random numbers with the srand(), random(), and
>>rand() functions, because, whatever the seed number i put in srand(), it is
>>_always the same results.
>>
>>What can i do about it ?
>Hey here's a neat trick I used with Borland's C++ 3.0 from awhile ago for
Random
>Number Generater:
> #include <dos.h>
> Main(){
> int Jims_Rand_Num;
> gettime(&ti_hund);
> Jims_Rand_Num = ti_hund;
>
> }
>
The very best method is to seed the random number generator from the current
time. In DJGPP, that looks like this:
#include <time.h>
#include <stdlib.h>
/* ... */
srand(time(NULL));
/* Now use rand() to get random numbers. */
HTH
Nate Eldredge
eldredge AT ap DOT net
- Raw text -