PrevUpHomeNext

esv::uniform_distribution


The eyes of hope are not only for you.

esv::uniform_distribution

esv::uniform_distribution is a class derived from std::uniform_int_distribution or std::uniform_real_distribution. Which base_type is is choosed is determined by template specialization.

The advantage of using esv::uniform_distribution is that it does not only unify std::uniform_int_distribution and std::uniform_real_distribution in one class, but also supports esv::real_meric types.

esv::uniform_distribution has almost the same usage of std::uniform_int_distribution or std::uniform_real_distribution, all of the methods are derived from them properly.

template <esv::real_meric type_xt = esv::i32>
	requires (sizeof (type_xt) > 1)
class uniform_distribution: public ...;

If std::integral_meric<real_type>, esv::uniform_distribution is derived from std::uniform_int_distribution;

if std::floating_meric<real_type>, esv::uniform_distribution is derived from std::uniform_real_distribution.

c++ example

#include <esvcpp/core.hpp>
#include <esvcpp/random.hpp>

int main()
{
	// std::mt19937 works too.
	auto rng = std::mt19937_64{std::random_device{}()};

	auto dist1 = esv::uniform_distribution<>{100,200};
	auto dist2 = esv::uniform_distribution<esv::i64>{50,150};
	auto dist3 = esv::uniform_distribution<esv::fx32>{300,400};

	esv::print(dist1(rng), dist2(rng), dist3(rng));

	esv::same_strip_assert<decltype(dist1(rng)), esv::i32>();
	esv::same_strip_assert<decltype(dist2(rng)), esv::i64>();
	esv::same_strip_assert<decltype(dist3(rng)), esv::fx32>();
}

See Also

esv::real_meric

esv::ix32

esv::ix64

esv::fx32

esv::print

esv::random

esv::same_assert, esv::same_strip_assert


PrevUpHomeNext

esv::print