forked from vimaec/vim-format
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom.h
More file actions
33 lines (26 loc) · 1.3 KB
/
random.h
File metadata and controls
33 lines (26 loc) · 1.3 KB
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
27
28
29
30
31
32
33
#pragma once
#include "hash.h"
#include "structs.h"
namespace vim::math3d::statelessRandom {
template <typename T = std::size_t>
inline typename std::enable_if<std::is_arithmetic<T>::value, T>::type
random(int index, int seed = 0) { return (T)hash::combine(seed, index); }
template <typename T = float>
inline T randomNumb(T min, T max, int index, int seed) {
return (T)random<std::size_t>(index, seed) / std::numeric_limits<size_t>::max() * (max - min) + min;
}
template <typename T = float>
inline T randomNumb(int index, int seed = 0) { return randomNumb<T>(0, 1, index, seed); }
template <typename T = float>
inline Vector2<T> randomVector2(int index, int seed = 0) {
return Vector2<T>(randomNumb<T>(index * 2, seed), randomNumb<T>(index * 2 + 1, seed));
}
template <typename T = float>
inline Vector3<T> randomVector3(int index, int seed = 0) {
return Vector3(randomNumb<T>(index * 3, seed), randomNumb<T>(index * 3 + 1, seed), randomNumb<T>(index * 3 + 2, seed));
}
template <typename T = float>
inline Vector4<T> randomVector4(int index, int seed = 0) {
return Vector4(randomNumb<T>(index * 4, seed), randomNumb<T>(index * 4 + 1, seed), randomNumb<T>(index * 4 + 2, seed), randomNumb<T>(index * 4 + 3, seed));
}
}