about summary refs log tree commit diff stats
path: root/Source/Random.h
blob: 36b6dc1bd7884fa64babeead957086c4467b7fc4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#pragma once

class Random
{
public:
    static void SetSeed(int seed);
    static int RandInt(int min, int max);

    template <typename T>
    static std::vector<T> SelectFromSet(std::vector<T> set, size_t count) {
        size_t setSize = set.size();
        assert(count < setSize);
        std::vector<T> selection;
        for (int i=0; i<count && i<setSize; i++) {
            int index = Random::RandInt(0, static_cast<int>(setSize - 1));
            selection.emplace_back(set[index]);
            set[index] = set[setSize-1];
            setSize--;
        }
        return selection;
    }

private:
    static uint32_t s_seed;
};