Path: blob/main/contrib/llvm-project/libcxx/include/__random/random_device.h
35233 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef _LIBCPP___RANDOM_RANDOM_DEVICE_H9#define _LIBCPP___RANDOM_RANDOM_DEVICE_H1011#include <__config>12#include <string>1314#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)15# pragma GCC system_header16#endif1718_LIBCPP_PUSH_MACROS19#include <__undef_macros>2021_LIBCPP_BEGIN_NAMESPACE_STD2223#if !defined(_LIBCPP_HAS_NO_RANDOM_DEVICE)2425class _LIBCPP_EXPORTED_FROM_ABI random_device {26# ifdef _LIBCPP_USING_DEV_RANDOM27int __f_;28# elif !defined(_LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT)29_LIBCPP_DIAGNOSTIC_PUSH30_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-private-field")3132// Apple platforms used to use the `_LIBCPP_USING_DEV_RANDOM` code path, and now33// use `arc4random()` as of this comment. In order to avoid breaking the ABI, we34// retain the same layout as before.35# if defined(__APPLE__)36int __padding_; // padding to fake the `__f_` field above37# endif3839// ... vendors can add workarounds here if they switch to a different representation ...4041_LIBCPP_DIAGNOSTIC_POP42# endif4344public:45// types46typedef unsigned result_type;4748// generator characteristics49static _LIBCPP_CONSTEXPR const result_type _Min = 0;50static _LIBCPP_CONSTEXPR const result_type _Max = 0xFFFFFFFFu;5152_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type min() { return _Min; }53_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type max() { return _Max; }5455// constructors56# ifndef _LIBCPP_CXX03_LANG57_LIBCPP_HIDE_FROM_ABI random_device() : random_device("/dev/urandom") {}58explicit random_device(const string& __token);59# else60explicit random_device(const string& __token = "/dev/urandom");61# endif62~random_device();6364// generating functions65result_type operator()();6667// property functions68double entropy() const _NOEXCEPT;6970random_device(const random_device&) = delete;71void operator=(const random_device&) = delete;72};7374#endif // !_LIBCPP_HAS_NO_RANDOM_DEVICE7576_LIBCPP_END_NAMESPACE_STD7778_LIBCPP_POP_MACROS7980#endif // _LIBCPP___RANDOM_RANDOM_DEVICE_H818283