| 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___CXX03___RANDOM_RANDOM_DEVICE_H |
| 10 |
#define _LIBCPP___CXX03___RANDOM_RANDOM_DEVICE_H |
| 11 |
|
| 12 |
#include <__cxx03/__config> |
| 13 |
#include <__cxx03/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 <__cxx03/__undef_macros> |
| 21 |
|
| 22 |
_LIBCPP_BEGIN_NAMESPACE_STD |
| 23 |
|
| 24 |
#if !defined(_LIBCPP_HAS_NO_RANDOM_DEVICE) |
| 25 |
|
| 26 |
class _LIBCPP_EXPORTED_FROM_ABI random_device { |
| 27 |
# ifdef _LIBCPP_USING_DEV_RANDOM |
| 28 |
int __f_; |
| 29 |
# elif !defined(_LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT) |
| 30 |
_LIBCPP_DIAGNOSTIC_PUSH |
| 31 |
_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-private-field") |
| 32 |
|
| 33 |
// Apple platforms used to use the `_LIBCPP_USING_DEV_RANDOM` code path, and now |
| 34 |
// use `arc4random()` as of this comment. In order to avoid breaking the ABI, we |
| 35 |
// retain the same layout as before. |
| 36 |
# if defined(__APPLE__) |
| 37 |
int __padding_; // padding to fake the `__f_` field above |
| 38 |
# endif |
| 39 |
|
| 40 |
// ... vendors can add workarounds here if they switch to a different representation ... |
| 41 |
|
| 42 |
_LIBCPP_DIAGNOSTIC_POP |
| 43 |
# endif |
| 44 |
|
| 45 |
public: |
| 46 |
// types |
| 47 |
typedef unsigned result_type; |
| 48 |
|
| 49 |
// generator characteristics |
| 50 |
static const result_type _Min = 0; |
| 51 |
static const result_type _Max = 0xFFFFFFFFu; |
| 52 |
|
| 53 |
_LIBCPP_HIDE_FROM_ABI static result_type min() { return _Min; } |
| 54 |
_LIBCPP_HIDE_FROM_ABI static result_type max() { return _Max; } |
| 55 |
|
| 56 |
// constructors |
| 57 |
explicit random_device(const string& __token = "/dev/urandom"); |
| 58 |
~random_device(); |
| 59 |
|
| 60 |
// generating functions |
| 61 |
result_type operator()(); |
| 62 |
|
| 63 |
// property functions |
| 64 |
double entropy() const _NOEXCEPT; |
| 65 |
|
| 66 |
random_device(const random_device&) = delete; |
| 67 |
void operator=(const random_device&) = delete; |
| 68 |
}; |
| 69 |
|
| 70 |
#endif // !_LIBCPP_HAS_NO_RANDOM_DEVICE |
| 71 |
|
| 72 |
_LIBCPP_END_NAMESPACE_STD |
| 73 |
|
| 74 |
_LIBCPP_POP_MACROS |
| 75 |
|
| 76 |
#endif // _LIBCPP___CXX03___RANDOM_RANDOM_DEVICE_H |