mark@chromium.org | b93c054 | 2008-09-30 07:18:01 +0900 | [diff] [blame^] | 1 | // Copyright (c) 2008 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/rand_util.h" |
| 6 | |
| 7 | #include <fcntl.h> |
| 8 | #include <sys/stat.h> |
| 9 | #include <unistd.h> |
| 10 | |
| 11 | #include "base/logging.h" |
| 12 | |
| 13 | namespace base { |
| 14 | |
| 15 | uint64 RandUInt64() { |
| 16 | uint64 number; |
| 17 | |
| 18 | int urandom_fd = open("/dev/urandom", O_RDONLY); |
| 19 | CHECK(urandom_fd >= 0); |
| 20 | ssize_t bytes_read = read(urandom_fd, &number, sizeof(number)); |
| 21 | CHECK(bytes_read == sizeof(number)); |
| 22 | close(urandom_fd); |
| 23 | |
| 24 | return number; |
| 25 | } |
| 26 | |
| 27 | } // namespace base |