ipc/chromium/src/base/rand_util_posix.cc

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:b8faa2abeed0
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 <unistd.h>
9
10 #include "base/file_util.h"
11 #include "base/logging.h"
12
13 namespace base {
14
15 uint64_t RandUint64() {
16 uint64_t number;
17
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);
25
26 return number;
27 }
28
29 } // namespace base

mercurial