-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCRandom16Impl.hpp
More file actions
50 lines (41 loc) · 963 Bytes
/
CRandom16Impl.hpp
File metadata and controls
50 lines (41 loc) · 963 Bytes
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef PRIME_WATCH_DUMP_CRANDOM16IMPL_HPP
#define PRIME_WATCH_DUMP_CRANDOM16IMPL_HPP
using u32 = uint32_t;
using s32 = int32_t;
class CRandom16Impl
{
u32 m_seed;
public:
CRandom16Impl() = default;
CRandom16Impl(u32 p) : m_seed(p) {}
inline u32 Next()
{
m_seed = (m_seed * 0x41c64e6d) + 0x00003039;
return m_seed >> 16;
}
inline u32 GetSeed() const
{
return m_seed;
}
inline void SetSeed(u32 p)
{
m_seed = p;
}
inline float Float()
{
return Next() * 0.000015259022;
}
inline float Range(float min, float max)
{
return min + Float() * (max - min);
}
inline s32 Range(s32 min, s32 max)
{
s32 diff = max - min;
s32 rand = -1;
while (rand < 0)
rand = s32((Next() << 16) | Next());
return rand % diff + min;
}
};
#endif //PRIME_WATCH_DUMP_CRANDOM16IMPL_HPP