michael@0: // Copyright (c) 2008 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #include "base/rand_util.h" michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include "base/file_util.h" michael@0: #include "base/logging.h" michael@0: michael@0: namespace base { michael@0: michael@0: uint64_t RandUint64() { michael@0: uint64_t number; michael@0: michael@0: int urandom_fd = open("/dev/urandom", O_RDONLY); michael@0: CHECK(urandom_fd >= 0); michael@0: bool success = file_util::ReadFromFD(urandom_fd, michael@0: reinterpret_cast(&number), michael@0: sizeof(number)); michael@0: CHECK(success); michael@0: close(urandom_fd); michael@0: michael@0: return number; michael@0: } michael@0: michael@0: } // namespace base