blob: b4f3ac2596227a1473e6fc75c11d78038f00472c [file] [log] [blame]
[email protected]05f9b682008-09-29 22:18:011// 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]05f9b682008-09-29 22:18:018#include <unistd.h>
9
[email protected]45301492009-04-23 12:38:0810#include "base/file_util.h"
[email protected]05f9b682008-09-29 22:18:0111#include "base/logging.h"
12
13namespace base {
14
[email protected]ba990122008-11-14 23:28:2915uint64 RandUint64() {
[email protected]05f9b682008-09-29 22:18:0116 uint64 number;
17
18 int urandom_fd = open("/dev/urandom", O_RDONLY);
19 CHECK(urandom_fd >= 0);
[email protected]45301492009-04-23 12:38:0820 bool success = file_util::ReadFromFD(urandom_fd,
21 reinterpret_cast<char*>(&number),
22 sizeof(number));
23 CHECK(success);
[email protected]05f9b682008-09-29 22:18:0124 close(urandom_fd);
25
26 return number;
27}
28
29} // namespace base