Caffe2 - C++ API
A deep learning, cross platform ML framework
context.cc
1 
17 #include "caffe2/core/context.h"
18 
19 #include <atomic>
20 #if defined(_MSC_VER)
21 #include <process.h>
22 #endif
23 
24 namespace caffe2 {
25 
26 uint32_t RandomNumberSeed() {
27  // Originally copied from folly::randomNumberSeed (at 418ad4)
28  // modified to use chrono instead of sys/time.h
29  static std::atomic<uint32_t> seedInput(0);
30  auto tv = std::chrono::system_clock::now().time_since_epoch();
31  uint64_t usec = static_cast<uint64_t>(
32  std::chrono::duration_cast<std::chrono::microseconds>(tv).count());
33  uint32_t tv_sec = usec / 1000000;
34  uint32_t tv_usec = usec % 1000000;
35  const uint32_t kPrime0 = 51551;
36  const uint32_t kPrime1 = 61631;
37  const uint32_t kPrime2 = 64997;
38  const uint32_t kPrime3 = 111857;
39  return kPrime0 * (seedInput++) + kPrime1 * static_cast<uint32_t>(getpid()) +
40  kPrime2 * tv_sec + kPrime3 * tv_usec;
41 }
42 
43 } // namespace caffe2
Copyright (c) 2016-present, Facebook, Inc.
uint32_t RandomNumberSeed()
A function to generate a random number seed that is unique in a best-effort basis, using an ever-incrementing seed and the current time.
Definition: context.cc:26