diff options
Diffstat (limited to 'tensorflow/core/lib/random/random.cc')
-rw-r--r-- | tensorflow/core/lib/random/random.cc | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/tensorflow/core/lib/random/random.cc b/tensorflow/core/lib/random/random.cc index a30bad2b1b..723c1100f8 100644 --- a/tensorflow/core/lib/random/random.cc +++ b/tensorflow/core/lib/random/random.cc @@ -22,17 +22,28 @@ limitations under the License. namespace tensorflow { namespace random { -std::mt19937_64* InitRng() { +namespace { +std::mt19937_64* InitRngWithRandomSeed() { std::random_device device("/dev/urandom"); return new std::mt19937_64(device()); } +std::mt19937_64 InitRngWithDefaultSeed() { return std::mt19937_64(); } + +} // anonymous namespace uint64 New64() { - static std::mt19937_64* rng = InitRng(); + static std::mt19937_64* rng = InitRngWithRandomSeed(); static mutex mu; mutex_lock l(mu); return (*rng)(); } +uint64 New64DefaultSeed() { + static std::mt19937_64 rng = InitRngWithDefaultSeed(); + static mutex mu; + mutex_lock l(mu); + return rng(); +} + } // namespace random } // namespace tensorflow |