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