mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-16 03:12:43 +00:00
1b81bb49b4
Official docs: Some headers from C library were deprecated in C++ and are no longer welcome in C++ codebases. Some have no effect in C++. For more details refer to the C++ 14 Standard [depr.c.headers] section. This check replaces C standard library headers with their C++ alternatives and removes redundant ones.
35 lines
755 B
C++
35 lines
755 B
C++
#include <ctime>
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#include <Common/Exception.h>
|
|
#include <Common/randomSeed.h>
|
|
#include <Common/SipHash.h>
|
|
#include <base/getThreadId.h>
|
|
#include <base/types.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
namespace ErrorCodes
|
|
{
|
|
extern const int CANNOT_CLOCK_GETTIME;
|
|
}
|
|
}
|
|
|
|
|
|
DB::UInt64 randomSeed()
|
|
{
|
|
struct timespec times;
|
|
if (clock_gettime(CLOCK_MONOTONIC, ×))
|
|
DB::throwFromErrno("Cannot clock_gettime.", DB::ErrorCodes::CANNOT_CLOCK_GETTIME);
|
|
|
|
/// Not cryptographically secure as time, pid and stack address can be predictable.
|
|
|
|
SipHash hash;
|
|
hash.update(times.tv_nsec);
|
|
hash.update(times.tv_sec);
|
|
hash.update(getThreadId());
|
|
hash.update(×);
|
|
return hash.get64();
|
|
}
|