blob: 269a5974e1c08b858ba4c4c1d2ac58c48bb70100 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001//===-------------------------- random.cpp --------------------------------===//
2//
3// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "random"
11#include "system_error"
12
13#include <fcntl.h>
14#include <unistd.h>
15#include <errno.h>
16
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20random_device::random_device(const string& __token)
21 : __f_(open(__token.c_str(), O_RDONLY))
22{
23 if (__f_ <= 0)
24 __throw_system_error(errno, ("random_device failed to open " + __token).c_str());
25}
26
27random_device::~random_device()
28{
29 close(__f_);
30}
31
32unsigned
33random_device::operator()()
34{
35 unsigned r;
36 read(__f_, &r, sizeof(r));
37 return r;
38}
39
40double
41random_device::entropy() const
42{
43 return 0;
44}
45
46_LIBCPP_END_NAMESPACE_STD