[email protected] | 05f9b68 | 2008-09-29 22:18:01 | [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> | ||||
[email protected] | 05f9b68 | 2008-09-29 22:18:01 | [diff] [blame] | 8 | #include <unistd.h> |
9 | |||||
[email protected] | 4530149 | 2009-04-23 12:38:08 | [diff] [blame] | 10 | #include "base/file_util.h" |
[email protected] | 05f9b68 | 2008-09-29 22:18:01 | [diff] [blame] | 11 | #include "base/logging.h" |
12 | |||||
13 | namespace base { | ||||
14 | |||||
[email protected] | ba99012 | 2008-11-14 23:28:29 | [diff] [blame] | 15 | uint64 RandUint64() { |
[email protected] | 05f9b68 | 2008-09-29 22:18:01 | [diff] [blame] | 16 | uint64 number; |
17 | |||||
18 | int urandom_fd = open("/dev/urandom", O_RDONLY); | ||||
19 | CHECK(urandom_fd >= 0); | ||||
[email protected] | 4530149 | 2009-04-23 12:38:08 | [diff] [blame] | 20 | bool success = file_util::ReadFromFD(urandom_fd, |
21 | reinterpret_cast<char*>(&number), | ||||
22 | sizeof(number)); | ||||
23 | CHECK(success); | ||||
[email protected] | 05f9b68 | 2008-09-29 22:18:01 | [diff] [blame] | 24 | close(urandom_fd); |
25 | |||||
26 | return number; | ||||
27 | } | ||||
28 | |||||
29 | } // namespace base |