summary refs log tree commit diff stats
path: root/Source/Random.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Random.h')
-rw-r--r--Source/Random.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/Source/Random.h b/Source/Random.h index e809c1e..36b6dc1 100644 --- a/Source/Random.h +++ b/Source/Random.h
@@ -6,6 +6,20 @@ public:
6 static void SetSeed(int seed); 6 static void SetSeed(int seed);
7 static int RandInt(int min, int max); 7 static int RandInt(int min, int max);
8 8
9 template <typename T>
10 static std::vector<T> SelectFromSet(std::vector<T> set, size_t count) {
11 size_t setSize = set.size();
12 assert(count < setSize);
13 std::vector<T> selection;
14 for (int i=0; i<count && i<setSize; i++) {
15 int index = Random::RandInt(0, static_cast<int>(setSize - 1));
16 selection.emplace_back(set[index]);
17 set[index] = set[setSize-1];
18 setSize--;
19 }
20 return selection;
21 }
22
9private: 23private:
10 static uint32_t s_seed; 24 static uint32_t s_seed;
11}; 25};