Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:14:00

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___RANDOM_RANDOM_DEVICE_H
0010 #define _LIBCPP___RANDOM_RANDOM_DEVICE_H
0011 
0012 #include <__config>
0013 #include <string>
0014 
0015 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0016 #  pragma GCC system_header
0017 #endif
0018 
0019 _LIBCPP_PUSH_MACROS
0020 #include <__undef_macros>
0021 
0022 _LIBCPP_BEGIN_NAMESPACE_STD
0023 
0024 #if _LIBCPP_HAS_RANDOM_DEVICE
0025 
0026 class _LIBCPP_EXPORTED_FROM_ABI random_device {
0027 #  ifdef _LIBCPP_USING_DEV_RANDOM
0028   int __f_;
0029 #  elif !defined(_LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT)
0030   _LIBCPP_DIAGNOSTIC_PUSH
0031   _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-private-field")
0032 
0033   // Apple platforms used to use the `_LIBCPP_USING_DEV_RANDOM` code path, and now
0034   // use `arc4random()` as of this comment. In order to avoid breaking the ABI, we
0035   // retain the same layout as before.
0036 #    if defined(__APPLE__)
0037   int __padding_; // padding to fake the `__f_` field above
0038 #    endif
0039 
0040   // ... vendors can add workarounds here if they switch to a different representation ...
0041 
0042   _LIBCPP_DIAGNOSTIC_POP
0043 #  endif
0044 
0045 public:
0046   // types
0047   typedef unsigned result_type;
0048 
0049   // generator characteristics
0050   static _LIBCPP_CONSTEXPR const result_type _Min = 0;
0051   static _LIBCPP_CONSTEXPR const result_type _Max = 0xFFFFFFFFu;
0052 
0053   _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
0054   _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
0055 
0056   // constructors
0057 #  ifndef _LIBCPP_CXX03_LANG
0058   _LIBCPP_HIDE_FROM_ABI random_device() : random_device("/dev/urandom") {}
0059   explicit random_device(const string& __token);
0060 #  else
0061   explicit random_device(const string& __token = "/dev/urandom");
0062 #  endif
0063   ~random_device();
0064 
0065   // generating functions
0066   result_type operator()();
0067 
0068   // property functions
0069   double entropy() const _NOEXCEPT;
0070 
0071   random_device(const random_device&)  = delete;
0072   void operator=(const random_device&) = delete;
0073 };
0074 
0075 #endif // _LIBCPP_HAS_RANDOM_DEVICE
0076 
0077 _LIBCPP_END_NAMESPACE_STD
0078 
0079 _LIBCPP_POP_MACROS
0080 
0081 #endif // _LIBCPP___RANDOM_RANDOM_DEVICE_H