Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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.
5 #include "base/rand_util.h"
7 #include <fcntl.h>
8 #include <unistd.h>
10 #include "base/file_util.h"
11 #include "base/logging.h"
13 namespace base {
15 uint64_t RandUint64() {
16 uint64_t number;
18 int urandom_fd = open("/dev/urandom", O_RDONLY);
19 CHECK(urandom_fd >= 0);
20 bool success = file_util::ReadFromFD(urandom_fd,
21 reinterpret_cast<char*>(&number),
22 sizeof(number));
23 CHECK(success);
24 close(urandom_fd);
26 return number;
27 }
29 } // namespace base