From c8e8f2a24cd339c548e06f75a3cef96454671a85 Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Fri, 15 Jul 2011 11:24:33 +0200 Subject: ZMQ_IDENTITY socket option removed This patch simplifies the whole codebase significantly, including dropping depedency on libuuid. Signed-off-by: Martin Sustrik --- src/random.cpp | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) (limited to 'src/random.cpp') diff --git a/src/random.cpp b/src/random.cpp index 2a1d7d6..9f7768c 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -18,23 +18,35 @@ along with this program. If not, see . */ +#include + +#include "platform.hpp" +#if defined ZMQ_HAVE_WINDOWS +#include "windows.hpp" +#else +#include +#endif + #include "random.hpp" #include "stdint.hpp" -#include "uuid.hpp" -#include "err.hpp" +#include "clock.hpp" + +void zmq::seed_random () +{ +#if defined ZMQ_HAVE_WINDOWS + int pid = (int) GetCurrentProcessId (); +#else + int pid = (int) getpid (); +#endif + srand ((unsigned int) (clock_t::now_us () + pid)); +} -// Here we can use different ways of generating random data, as avialable -// on different platforms. At the moment, we'll assume the UUID is random -// enough to use for that purpose. -void zmq::generate_random (void *buf_, size_t size_) +uint32_t zmq::generate_random () { - // Collapsing an UUID into 4 bytes. - zmq_assert (size_ == 4); - uint32_t buff [4]; - generate_uuid ((void*) buff); - uint32_t result = buff [0]; - result ^= buff [1]; - result ^= buff [2]; - result ^= buff [3]; - *((uint32_t*) buf_) = result; + // Compensate for the fact that rand() returns signed integer. + uint32_t low = (uint32_t) rand (); + uint32_t high = (uint32_t) rand (); + high <<= (sizeof (int) * 8 - 1); + return high | low; } + -- cgit v1.2.3