Mail Archives: djgpp/1996/11/21/04:17:58
It seems that rand() and random() always return the same numbers when
a program is started.
I fixed this by setting the seed to a number depending on the clock:
unsigned long u;
u = time(0);
u = u ^ (u << 16);
srand(u);
You need to wait at least 1 second between different runs to get other
random numbers.
It would be better to use a function that changes more often than
time(), but I didn't find one.
----
Koen Van Herck
Electronic Design Engineer
E-mail: Koen DOT VanHerck AT barco DOT com
BBBB AAA RRRR CCC OOO B A R C O V I S U A L S Y S T E M S
B B A A R R C O O A division of Barco Projection Systems
B BB A AAA R RR C OO O OO
B B A A R R C O O Noordlaan 5 Tel +32 (0)56 36 85 71
BBBB A A R R CCC OOO B-8520 Kuurne Fax +32 (0)56 36 83 55
- Raw text -