: I've tried but i dont know what I'm doing wrong.
: Do you know..??
: Greatings
: John.
If you want to have different numbers every time you run the program, you have to seed the random number generator different every time. The easiest way to do this is to seed with current time.
Comments
: Can "you" tell me why the same numbers occur every time.
: I whant different , each time.
: Thanks in advance.
: #include
: .
: .
: .
: random();
: for ( t = 0; t < 10; t++){
: rnd_s[t] = rand() % 10;
: }
You have to initialize the random number generator. Use the function randomize.
I've initilized , but still gets
the same numbers every time.
I have a djgpp compiler.
I've tried but i dont know what I'm doing wrong.
Do you know..??
Greatings
John.
: I've initilized , but still gets
: the same numbers every time.
: I have a djgpp compiler.
: I've tried but i dont know what I'm doing wrong.
: Do you know..??
: Greatings
: John.
If you want to have different numbers every time you run the program, you have to seed the random number generator different every time. The easiest way to do this is to seed with current time.
unsigned int seed;
// ...... put current time in seed here.
srand(seed);
// seed the sequence first ...
time_t now = time(NULL);
srand((unsigned long)now);
// use rand() to get some numbers ...
Please note - you will have to re-seed the sequence if you start a new thread and want to
use rand() in the new thread.
Hope this helps
Derek