1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef _LIBCPP___RANDOM_RANDOM_DEVICE_H
10 #define _LIBCPP___RANDOM_RANDOM_DEVICE_H
11 
12 #include <__config>
13 #include <string>
14 
15 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16 #pragma GCC system_header
17 #endif
18 
19 _LIBCPP_PUSH_MACROS
20 #include <__undef_macros>
21 
22 _LIBCPP_BEGIN_NAMESPACE_STD
23 
24 #if !defined(_LIBCPP_HAS_NO_RANDOM_DEVICE)
25 
26 class _LIBCPP_TYPE_VIS random_device
27 {
28 #ifdef _LIBCPP_USING_DEV_RANDOM
29     int __f_;
30 #endif // defined(_LIBCPP_USING_DEV_RANDOM)
31 public:
32     // types
33     typedef unsigned result_type;
34 
35     // generator characteristics
36     static _LIBCPP_CONSTEXPR const result_type _Min = 0;
37     static _LIBCPP_CONSTEXPR const result_type _Max = 0xFFFFFFFFu;
38 
39     _LIBCPP_INLINE_VISIBILITY
40     static _LIBCPP_CONSTEXPR result_type min() { return _Min;}
41     _LIBCPP_INLINE_VISIBILITY
42     static _LIBCPP_CONSTEXPR result_type max() { return _Max;}
43 
44     // constructors
45 #ifndef _LIBCPP_CXX03_LANG
46     random_device() : random_device("/dev/urandom") {}
47     explicit random_device(const string& __token);
48 #else
49     explicit random_device(const string& __token = "/dev/urandom");
50 #endif
51     ~random_device();
52 
53     // generating functions
54     result_type operator()();
55 
56     // property functions
57     double entropy() const _NOEXCEPT;
58 
59 private:
60     // no copy functions
61     random_device(const random_device&); // = delete;
62     random_device& operator=(const random_device&); // = delete;
63 };
64 
65 #endif // !_LIBCPP_HAS_NO_RANDOM_DEVICE
66 
67 _LIBCPP_END_NAMESPACE_STD
68 
69 _LIBCPP_POP_MACROS
70 
71 #endif // _LIBCPP___RANDOM_RANDOM_DEVICE_H
72