Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / include / __random / random_device.h
blobe7c37241a72c8e5974949fc82201122218b6414c
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 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___RANDOM_RANDOM_DEVICE_H
10 #define _LIBCPP___RANDOM_RANDOM_DEVICE_H
12 #include <__config>
13 #include <string>
15 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16 # pragma GCC system_header
17 #endif
19 _LIBCPP_PUSH_MACROS
20 #include <__undef_macros>
22 _LIBCPP_BEGIN_NAMESPACE_STD
24 #if !defined(_LIBCPP_HAS_NO_RANDOM_DEVICE)
26 class _LIBCPP_EXPORTED_FROM_ABI random_device
28 #ifdef _LIBCPP_USING_DEV_RANDOM
29 int __f_;
30 #elif !defined(_LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT)
31 _LIBCPP_DIAGNOSTIC_PUSH
32 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-private-field")
34 // Apple platforms used to use the `_LIBCPP_USING_DEV_RANDOM` code path, and now
35 // use `arc4random()` as of this comment. In order to avoid breaking the ABI, we
36 // retain the same layout as before.
37 # if defined(__APPLE__)
38 int __padding_; // padding to fake the `__f_` field above
39 # endif
41 // ... vendors can add workarounds here if they switch to a different representation ...
43 _LIBCPP_DIAGNOSTIC_POP
44 #endif
46 public:
47 // types
48 typedef unsigned result_type;
50 // generator characteristics
51 static _LIBCPP_CONSTEXPR const result_type _Min = 0;
52 static _LIBCPP_CONSTEXPR const result_type _Max = 0xFFFFFFFFu;
54 _LIBCPP_INLINE_VISIBILITY
55 static _LIBCPP_CONSTEXPR result_type min() { return _Min;}
56 _LIBCPP_INLINE_VISIBILITY
57 static _LIBCPP_CONSTEXPR result_type max() { return _Max;}
59 // constructors
60 #ifndef _LIBCPP_CXX03_LANG
61 _LIBCPP_HIDE_FROM_ABI random_device() : random_device("/dev/urandom") {}
62 explicit random_device(const string& __token);
63 #else
64 explicit random_device(const string& __token = "/dev/urandom");
65 #endif
66 ~random_device();
68 // generating functions
69 result_type operator()();
71 // property functions
72 double entropy() const _NOEXCEPT;
74 random_device(const random_device&) = delete;
75 void operator=(const random_device&) = delete;
78 #endif // !_LIBCPP_HAS_NO_RANDOM_DEVICE
80 _LIBCPP_END_NAMESPACE_STD
82 _LIBCPP_POP_MACROS
84 #endif // _LIBCPP___RANDOM_RANDOM_DEVICE_H