24 inline std::default_random_engine& randomEngine() {
25 AI_THREAD_LOCAL std::default_random_engine engine;
29 inline void randomSeed (
unsigned int seed) {
30 randomEngine().seed(seed);
33 inline float randomf (
float max = 1.0f) {
34 std::uniform_real_distribution<float> distribution(0.0, max);
35 return distribution(randomEngine());
38 inline int random (
int min,
int max) {
39 std::uniform_int_distribution<int> distribution(min, max);
40 return distribution(randomEngine());
43 inline float randomBinomial (
float max = 1.0f) {
44 return randomf(max) - randomf(max);
48 inline I randomElement(I begin, I end) {
49 const int n =
static_cast<int>(std::distance(begin, end));
50 std::uniform_int_distribution<> dis(0, n - 1);
51 std::advance(begin, dis(randomEngine()));
59 inline void randomElements(std::vector<T>& vec,
int n) {
60 if (n >= (
int)vec.size()) {
63 std::shuffle(vec.begin(), vec.end(), randomEngine());
68 inline void shuffle(I begin, I end) {
69 std::shuffle(begin, end, randomEngine());