about summary refs log tree commit diff stats
path: root/Source/Random.h
blob: e3737ed03ab662f433f8562f167b32fe7b307c8d (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
26
#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--;
        }
        assert(selection.size() == count);
        return selection;
    }

private:
    static uint32_t s_seed;
};