mirror of
https://github.com/linux-can/can-utils.git
synced 2026-09-20 14:29:55 +02:00
cangen: set seed value for pseudo random numbers
As pointed out by Andre Naujoks the pseudo random generator should be initialized with a seed to prevend this ugly behaviour: $ ./cangen vcan2 -v & ./cangen vcan1 -v [1] 5995 vcan2 567#69.98.3C.64.73.48 vcan1 567#69.98.3C.64.73.48 vcan2 451#4A.94.E8.2A.EC.58.55.62 vcan1 451#4A.94.E8.2A.EC.58.55.62 vcan2 729#BA.58.1B.3D.AB.D7.7E.50 vcan1 729#BA.58.1B.3D.AB.D7.7E.50 (..) Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
This commit is contained in:
@@ -155,6 +155,11 @@ int main(int argc, char **argv)
|
|||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
|
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
|
struct timeval now;
|
||||||
|
|
||||||
|
/* set seed value for pseudo random numbers */
|
||||||
|
gettimeofday(&now, NULL);
|
||||||
|
srandom(now.tv_usec);
|
||||||
|
|
||||||
signal(SIGTERM, sigterm);
|
signal(SIGTERM, sigterm);
|
||||||
signal(SIGHUP, sigterm);
|
signal(SIGHUP, sigterm);
|
||||||
|
|||||||
Reference in New Issue
Block a user