// Copyright Catch2 Authors // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) // SPDX-License-Identifier: BSL-1.0 #ifndef CATCH_GENERATORS_RANDOM_HPP_INCLUDED #define CATCH_GENERATORS_RANDOM_HPP_INCLUDED #include #include #include #include namespace Catch { namespace Generators { template class RandomFloatingGenerator final : public IGenerator { Catch::SimplePcg32& m_rng; std::uniform_real_distribution m_dist; Float m_current_number; public: RandomFloatingGenerator(Float a, Float b): m_rng(rng()), m_dist(a, b) { static_cast(next()); } Float const& get() const override { return m_current_number; } bool next() override { m_current_number = m_dist(m_rng); return true; } }; template class RandomIntegerGenerator final : public IGenerator { Catch::SimplePcg32& m_rng; std::uniform_int_distribution m_dist; Integer m_current_number; public: RandomIntegerGenerator(Integer a, Integer b): m_rng(rng()), m_dist(a, b) { static_cast(next()); } Integer const& get() const override { return m_current_number; } bool next() override { m_current_number = m_dist(m_rng); return true; } }; // TODO: Ideally this would be also constrained against the various char types, // but I don't expect users to run into that in practice. template std::enable_if_t::value && !std::is_same::value, GeneratorWrapper> random(T a, T b) { return GeneratorWrapper( Catch::Detail::make_unique>(a, b) ); } template std::enable_if_t::value, GeneratorWrapper> random(T a, T b) { return GeneratorWrapper( Catch::Detail::make_unique>(a, b) ); } } // namespace Generators } // namespace Catch #endif // CATCH_GENERATORS_RANDOM_HPP_INCLUDED