| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 |
| 15 | #ifndef ABSL_RANDOM_INTERNAL_SEQUENCE_URBG_H_ |
| 16 | #define ABSL_RANDOM_INTERNAL_SEQUENCE_URBG_H_ |
| 17 |
| 18 | #include <cstdint> |
| 19 | #include <cstring> |
| 20 | #include <limits> |
| 21 | #include <type_traits> |
| 22 | #include <vector> |
| 23 |
| 24 | #include "absl/base/config.h" |
| 25 |
| 26 | namespace absl { |
| 27 | ABSL_NAMESPACE_BEGIN |
| 28 | namespace random_internal { |
| 29 |
| 30 | // `sequence_urbg` is a simple random number generator which meets the |
| 31 | // requirements of [rand.req.urbg], and is solely for testing absl |
| 32 | // distributions. |
| 33 | class sequence_urbg { |
| 34 | public: |
| 35 | using result_type = uint64_t; |
| 36 |
| 37 | static constexpr result_type(min)() { |
| 38 | return (std::numeric_limits<result_type>::min)(); |
| 39 | } |
| 40 | static constexpr result_type(max)() { |
| 41 | return (std::numeric_limits<result_type>::max)(); |
| 42 | } |
| 43 |
| 44 | sequence_urbg(std::initializer_list<result_type> data) : i_(0), data_(data) {} |
| 45 | void reset() { i_ = 0; } |
| 46 |
| 47 | result_type operator()() { return data_[i_++ % data_.size()]; } |
| 48 |
| 49 | size_t invocations() const { return i_; } |
| 50 |
| 51 | private: |
| 52 | size_t i_; |
| 53 | std::vector<result_type> data_; |
| 54 | }; |
| 55 |
| 56 | } // namespace random_internal |
| 57 | ABSL_NAMESPACE_END |
| 58 | } // namespace absl |
| 59 |
| 60 | #endif // ABSL_RANDOM_INTERNAL_SEQUENCE_URBG_H_ |
| 61 |