// <experimental/random> -*- C++ -*-
-// Copyright (C) 2015 Free Software Foundation, Inc.
+// Copyright (C) 2015-2023 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
/** @file experimental/random
* This is a TS C++ Library header.
+ * @ingroup libfund-ts
*/
#ifndef _GLIBCXX_EXPERIMENTAL_RANDOM
#define _GLIBCXX_EXPERIMENTAL_RANDOM 1
+#include <bits/requires_hosted.h> // experimental is currently omitted
+
+#if __cplusplus >= 201402L
#include <random>
+#include <experimental/bits/lfts_config.h>
namespace std {
-namespace experimental {
-inline namespace fundamentals_v2 {
_GLIBCXX_BEGIN_NAMESPACE_VERSION
+namespace experimental {
+inline namespace fundamentals_v2 {
#define __cpp_lib_experimental_randint 201511
inline std::default_random_engine&
// 13.2.2.1, Function template randint
template<typename _IntType>
+ [[__nodiscard__]]
inline _IntType
randint(_IntType __a, _IntType __b)
{
static_assert(is_integral<_IntType>::value && sizeof(_IntType) > 1,
"argument must be an integer type");
using _Dist = std::uniform_int_distribution<_IntType>;
- static thread_local _Dist __dist;
- return __dist(_S_randint_engine(), typename _Dist::param_type{__a, __b});
+ // This relies on the fact our uniform_int_distribution is stateless,
+ // otherwise we'd need a static thread_local _Dist and pass it
+ // _Dist::param_type{__a, __b}.
+ return _Dist(__a, __b)(_S_randint_engine());
}
inline void
{
_S_randint_engine().seed(__value);
}
-
-_GLIBCXX_END_NAMESPACE_VERSION
} // namespace fundamentals_v2
} // namespace experimental
+
+_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std
-#endif
+#endif // C++14
+#endif // _GLIBCXX_EXPERIMENTAL_RANDOM