chenlh
2026-03-10 0f65a1a9267b8a7ab4678ef20b07532e4c8377ca
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
 
#pragma once
 
#include <stdint.h>
 
namespace ReverbHallRoom
{
    class LcgRandom
    {
    private:
        uint64_t x;
        uint64_t a;
        uint64_t c;
 
        double doubleInv;
        float floatUintInv;
        float floatIntInv;
 
    public:
        inline LcgRandom(uint64_t seed = 0)
        {
            x = seed;
            a = 22695477;
            c = 1;
 
            doubleInv = 1.0 / (double)UINT32_MAX;
            floatUintInv = 1.0 / (float)UINT32_MAX;
            floatIntInv = 1.0 / (float)INT32_MAX;
        }
 
        inline void SetSeed(uint64_t seed)
        {
            x = seed;
        }
 
        inline uint32_t NextUInt()
        {
            uint64_t axc = a * x + c;
            //x = axc % m;
            x = axc & 0xFFFFFFFF;
            return (uint32_t)x;
        }
 
        inline int32_t NextInt()
        {
            int64_t axc = a * x + c;
            //x = axc % m;
            x = axc & 0x7FFFFFFF;
            return (int32_t)x;
        }
 
        inline double NextDouble()
        {
            auto n = NextUInt();
            return n * doubleInv;
        }
 
        inline float NextFloat()
        {
            auto n = NextInt();
            return n * floatIntInv;
        }
 
        inline void GetFloats(float* buffer, int len)
        {
            for (int i = 0; i < len; i++)
                buffer[i] = NextFloat();
        }
 
        inline void GetFloatsBipolar(float* buffer, int len)
        {
            for (int i = 0; i < len; i++)
                buffer[i] = NextFloat() * 2 - 1;
        }
    };
}