Femboy_GP/tests/include/lilfbtf/test2.h

87 lines
2.2 KiB
C
Raw Permalink Normal View History

2024-03-04 10:58:42 -05:00
/*
* <Short Description>
* Copyright (C) 2024 Brett Terpstra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef LILFBTF5_TEST2_H
#define LILFBTF5_TEST2_H
2024-03-07 15:46:12 -05:00
#include <random>
#include <blt/std/types.h>
2024-03-04 10:58:42 -05:00
namespace fb
{
2024-03-07 15:46:12 -05:00
void test2();
static constexpr blt::u64 SEED = 691;
struct random_engine
{
private:
std::mt19937_64 engine{SEED};
public:
random_engine() = default;
void reset(blt::u64 seed = SEED)
{
engine = std::mt19937_64{seed};
}
auto& get()
{
return engine;
}
};
inline random_engine engine;
enum class type_t
{
ADD, SUB, MUL, DIV, VALUE, END
};
2024-03-04 10:58:42 -05:00
2024-03-08 12:26:54 -05:00
inline type_t random_type()
2024-03-07 15:46:12 -05:00
{
static std::random_device dev;
static std::uniform_int_distribution dist(0, static_cast<int>(type_t::END) - 1);
return static_cast<type_t>(dist(engine.get()));
}
2024-03-05 12:14:36 -05:00
2024-03-08 12:26:54 -05:00
inline type_t random_type_sub()
2024-03-07 15:46:12 -05:00
{
static std::random_device dev;
static std::uniform_int_distribution dist(0, static_cast<int>(type_t::END) - 2);
return static_cast<type_t>(dist(engine.get()));
}
2024-03-08 12:26:54 -05:00
inline double random_value()
2024-03-07 15:46:12 -05:00
{
static std::random_device dev;
static std::uniform_real_distribution dist(-2.0, 2.0);
return dist(engine.get());
}
2024-03-04 10:58:42 -05:00
2024-03-08 12:26:54 -05:00
inline bool choice()
2024-03-04 10:58:42 -05:00
{
2024-03-07 15:46:12 -05:00
static std::random_device dev;
static std::uniform_int_distribution dist(0, 1);
return dist(engine.get());
2024-03-04 10:58:42 -05:00
}
}
#endif //LILFBTF5_TEST2_H