1 //===-------------------------- random.cpp --------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 // Must be defined before including stdlib.h to enable rand_s().
17 #include "system_error"
20 #define rename solaris_headers_are_broken
25 #endif // defined(_WIN32)
28 _LIBCPP_BEGIN_NAMESPACE_STD
31 random_device::random_device(const string
&)
35 random_device::~random_device()
40 random_device::operator()()
43 errno_t err
= rand_s(&r
);
45 __throw_system_error(err
, "random_device rand_s failed.");
49 random_device::random_device(const string
& __token
)
50 : __f_(open(__token
.c_str(), O_RDONLY
))
53 __throw_system_error(errno
, ("random_device failed to open " + __token
).c_str());
56 random_device::~random_device()
62 random_device::operator()()
65 read(__f_
, &r
, sizeof(r
));
68 #endif // defined(_WIN32)
71 random_device::entropy() const _NOEXCEPT
76 _LIBCPP_END_NAMESPACE_STD