2323#include < algorithm>
2424#include < cassert>
2525#include < iosfwd>
26+ #include < memory>
2627#include < random>
28+ #include < string>
2729#include < tuple>
2830#include < type_traits>
2931#include < utility>
3234#include " absl/container/internal/hash_policy_testing.h"
3335#include " absl/memory/memory.h"
3436#include " absl/meta/type_traits.h"
37+ #include " absl/random/random.h"
3538#include " absl/strings/string_view.h"
3639
3740namespace absl {
@@ -48,8 +51,6 @@ struct IsMap<Map, absl::void_t<typename Map::mapped_type>> : std::true_type {};
4851
4952} // namespace generator_internal
5053
51- std::mt19937_64* GetSharedRng ();
52-
5354enum Enum : uint64_t {
5455 kEnumEmpty ,
5556 kEnumDeleted ,
@@ -69,29 +70,27 @@ struct Generator;
6970
7071template <class T >
7172struct Generator <T, typename std::enable_if<std::is_integral<T>::value>::type> {
72- T operator ()() const {
73- std::uniform_int_distribution<T> dist;
74- return dist (*GetSharedRng ());
75- }
73+ T operator ()() const { return dist (gen); }
74+ mutable absl::InsecureBitGen gen;
75+ mutable std::uniform_int_distribution<T> dist;
7676};
7777
7878template <>
7979struct Generator <Enum> {
80- Enum operator ()() const {
81- std::uniform_int_distribution< typename std::underlying_type<Enum>::type>
82- dist;
83- return static_cast <Enum>( dist (* GetSharedRng ()));
84- }
80+ Enum operator ()() const { return static_cast <Enum>( dist (gen)); }
81+ mutable absl::InsecureBitGen gen;
82+ mutable std::uniform_int_distribution<
83+ typename std::underlying_type <Enum>::type>
84+ dist;
8585};
8686
8787template <>
8888struct Generator <EnumClass> {
89- EnumClass operator ()() const {
90- std::uniform_int_distribution<
91- typename std::underlying_type<EnumClass>::type>
92- dist;
93- return static_cast <EnumClass>(dist (*GetSharedRng ()));
94- }
89+ EnumClass operator ()() const { return static_cast <EnumClass>(dist (gen)); }
90+ mutable absl::InsecureBitGen gen;
91+ mutable std::uniform_int_distribution<
92+ typename std::underlying_type<EnumClass>::type>
93+ dist;
9594};
9695
9796template <>
@@ -135,17 +134,17 @@ struct Generator<std::unique_ptr<T>> {
135134
136135template <class U >
137136struct Generator <U, absl::void_t <decltype (std::declval<U&>().key()),
138- decltype (std::declval<U&>().value())>>
137+ decltype (std::declval<U&>().value())>>
139138 : Generator<std::pair<
140139 typename std::decay<decltype(std::declval<U&>().key())>::type,
141140 typename std::decay<decltype(std::declval<U&>().value())>::type>> {};
142141
143142template <class Container >
144- using GeneratedType = decltype (
145- std::declval<const Generator<
146- typename std::conditional< generator_internal::IsMap<Container>::value,
147- typename Container::value_type,
148- typename Container::key_type>::type>&>()());
143+ using GeneratedType =
144+ decltype ( std::declval<const Generator< typename std::conditional <
145+ generator_internal::IsMap<Container>::value,
146+ typename Container::value_type,
147+ typename Container::key_type>::type>&>()());
149148
150149// Naive wrapper that performs a linear search of previous values.
151150// Beware this is O(SQR), which is reasonable for smaller kMaxValues.
0 commit comments