Commit a225d4bd authored by Bednárek David RNDr. Ph.D.'s avatar Bednárek David RNDr. Ph.D.
Browse files

well_defined_uniform distribution used in macro

parent 80522e54
......@@ -4179,6 +4179,24 @@ namespace fmwkng {
};
#pragma endregion
#pragma region random
class well_defined_uniform {
public:
well_defined_uniform(std::size_t mn, std::size_t mx)
: mn_(mn), mod_(mx - mn + 1)
{}
template< typename E>
std::size_t operator()(E&& e)
{
auto r = e();
return mn_ + (r % mod_);
}
private:
std::size_t mn_;
std::size_t mod_;
};
#pragma endregion
}
#endif
......@@ -15,7 +15,7 @@ namespace macroasgn {
auto M = 26 * exp_length;
auto N = M + 26;
std::uniform_int_distribution<std::size_t> char_distro(0, N - 1);
fmwkng::well_defined_uniform char_distro(0, N - 1);
auto generate_name = [&char_distro, &engine, M, exp_length, level_count, nonlevel_weight]()
{
......@@ -53,11 +53,11 @@ namespace macroasgn {
}
}
std::uniform_int_distribution<std::size_t> space_distro(0, exp_spaces);
std::uniform_int_distribution<std::size_t> width_distro(0, exp_width);
std::uniform_int_distribution<std::size_t> level_distro(0, (level_count + nonlevel_weight) * (exp_width + 1) - 1);
std::uniform_int_distribution<std::size_t> macro_distro(0, level_count + nonmacro_weight - 1);
std::uniform_int_distribution<std::size_t> name_distro(0, name_count - 1);
fmwkng::well_defined_uniform space_distro(0, exp_spaces);
fmwkng::well_defined_uniform width_distro(0, exp_width);
fmwkng::well_defined_uniform level_distro(0, (level_count + nonlevel_weight) * (exp_width + 1) - 1);
fmwkng::well_defined_uniform macro_distro(0, level_count + nonmacro_weight - 1);
fmwkng::well_defined_uniform name_distro(0, name_count - 1);
auto space_gen = [&space_distro, &engine](std::string& s) {
for (;;)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment