File size: 785 Bytes
9fcf2b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#ifndef __RNG_H__
#define __RNG_H__

#include <random>
#include <vector>

class RNG {
   public:
    virtual void manual_seed(uint64_t seed) = 0;
    virtual std::vector<float> randn(uint32_t n) = 0;
};

class STDDefaultRNG : public RNG {
   private:
    std::default_random_engine generator;

   public:
    void manual_seed(uint64_t seed) {
        generator.seed(seed);
    }

    std::vector<float> randn(uint32_t n) {
        std::vector<float> result;
        float mean = 0.0;
        float stddev = 1.0;
        std::normal_distribution<float> distribution(mean, stddev);
        for (int i = 0; i < n; i++) {
            float random_number = distribution(generator);
            result.push_back(random_number);
        }
        return result;
    }
};

#endif  // __RNG_H__