From: Burkhard P. <pl...@ip...> - 2004-10-01 13:02:34
|
>> You can use these two functions adapted from LiVES: >> >> static uint32_t fastrand_val; >> >> inline uint32_t fastrand(void) >> { >> return (fastrand_val=fastrand_val*1073741789+32749); >> } This one seems better: #define a 1664525L #define c 1013904223L return (fastrand_val= a * fastrand_val + c); a is suggested by Knuth c is suggested by H.W. Lewis and is a prime close to 2^32 * (sqrt(5) - 2) > #include <sys/time.h> > struct timeval tv; > > gettimeofday(&tv,NULL); > fastsrand(tv.tv_usec); Ok, maybe /dev/urandom is better, because with tv_usec, you'll never get seed values greater than 999999. But assuming a libvisual program is started at random times within a second, even with tv_usec the propability for the same sequence in 2 subsequent program runs is 10^(-6). I guess that should be enough. -- _____________________________ Dr.-Ing. Burkhard Plaum Institut fuer Plasmaforschung Pfaffenwaldring 31 70569 Stuttgart Tel.: +49 711 685-2187 Fax.: -3102 |