aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/lib/random/random.cc
blob: 2959b05382c50415c7bb3074b8909b23b9b2ec0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "tensorflow/core/lib/random/random.h"

#include <random>
#include "tensorflow/core/platform/port.h"

namespace tensorflow {
namespace random {

std::mt19937_64* InitRng() {
  std::random_device device("/dev/random");
  return new std::mt19937_64(device());
}

uint64 New64() {
  static std::mt19937_64* rng = InitRng();
  static mutex mu;
  mutex_lock l(mu);
  return (*rng)();
}

}  // namespace random
}  // namespace tensorflow