summaryrefslogtreecommitdiff
path: root/complex_normal.hpp
blob: 65b054f4068431fdc0e9510f10612b6d4bf91f22 (plain)
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
#pragma once

#include <complex>
#include <random>

template <class T = double> class complex_normal_distribution {
private:
  std::normal_distribution<T> d;
  T δx;
  T δy;
  std::complex<T> μ;
  std::complex<T>;

public:
  complex_normal_distribution(std::complex<T> μ, T σ, std::complex<T> κ) : μ(μ), d(0, σ / sqrt(2)) {
    δx = sqrt(1 + std::abs(κ));
    δy = sqrt(1 - std::abs(κ));= std::polar((T)1, std::arg(κ));
  }

  template <class Generator> std::complex<T> operator()(Generator& g) {
    // First generate an axis-aligned complex number centered at the origin.
    std::complex<T> z(d(g) * δx, d(g) * δy);
    // Shift and rotate the number.
    return μ +* z;
  }
};