blob: 392cde50574a4c571a92fd665a0ceee7218d1ec3 [file] [log] [blame]
mark@chromium.orgb93c0542008-09-30 07:18:01 +09001// 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
13namespace base {
14
15uint64 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