1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #include "random.h" 17 18 #include <tensorflow/core/platform/mutex.h> 19 #include <tensorflow/core/platform/types.h> 20 #include <random> 21 22 namespace tensorflow { 23 namespace random { 24 25 namespace { InitRngWithRandomSeed()26std::mt19937_64* InitRngWithRandomSeed() { 27 std::random_device device("/dev/urandom"); 28 return new std::mt19937_64(device()); 29 } InitRngWithDefaultSeed()30std::mt19937_64 InitRngWithDefaultSeed() { 31 return std::mt19937_64(); 32 } 33 34 } // anonymous namespace 35 New64()36uint64 New64() { 37 static std::mt19937_64* rng = InitRngWithRandomSeed(); 38 // static mutex mu(LINKER_INITIALIZED); 39 // mutex_lock l(mu); 40 return (*rng)(); 41 } 42 New64DefaultSeed()43uint64 New64DefaultSeed() { 44 static std::mt19937_64 rng = InitRngWithDefaultSeed(); 45 // static mutex mu(LINKER_INITIALIZED); 46 // mutex_lock l(mu); 47 return rng(); 48 } 49 50 } // namespace random 51 } // namespace tensorflow 52