ClickHouse/dbms/src/Common/randomSeed.cpp

25 lines
456 B
C++
Raw Normal View History

2016-07-31 03:53:16 +00:00
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <DB/Common/Exception.h>
#include <DB/Common/randomSeed.h>
namespace DB
{
namespace ErrorCodes
{
extern const int CANNOT_CLOCK_GETTIME;
}
}
uint64_t randomSeed()
{
struct timespec times;
if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &times))
DB::throwFromErrno("Cannot clock_gettime.", DB::ErrorCodes::CANNOT_CLOCK_GETTIME);
return times.tv_nsec + times.tv_sec + getpid();
}