From 1914ceab307a78c0d051f942e8d68edfb6ecd1aa Mon Sep 17 00:00:00 2001 From: Rex Schilasky <49162693+rex-schilasky@users.noreply.github.com> Date: Fri, 24 Nov 2023 15:56:23 +0100 Subject: [PATCH] core: initialize random udp package id using nanosecond timestamp (#1270) --- ecal/core/src/io/snd_raw_buffer.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ecal/core/src/io/snd_raw_buffer.cpp b/ecal/core/src/io/snd_raw_buffer.cpp index cadbe11f28..c3856d01e6 100644 --- a/ecal/core/src/io/snd_raw_buffer.cpp +++ b/ecal/core/src/io/snd_raw_buffer.cpp @@ -21,6 +21,8 @@ * @brief raw message buffer handling **/ +#include +#include #include #include "ecal_process.h" @@ -129,8 +131,18 @@ namespace eCAL msg_header.type = msg_type_header; { // create random number for message id - static unsigned long x = 123456789, y = 362436069, z = 521288629; - msg_header.id = xorshf96(x, y, z); + { + static std::mutex xorshf96_mtx; + const std::lock_guard lock(xorshf96_mtx); + + static unsigned long x = static_cast(std::chrono::duration_cast( + std::chrono::high_resolution_clock::now().time_since_epoch()).count() + ); + static unsigned long y = 362436069; + static unsigned long z = 521288629; + + msg_header.id = xorshf96(x, y, z); + } } msg_header.num = total_packet_num; msg_header.len = int32_t(buf_len_);