MCPcopy Create free account
hub / github.com/VCVRack/Rack / normal

Function normal

include/random.hpp:129–142  ·  view source on GitHub ↗

Returns a normal random number with mean 0 and standard deviation 1 */

Source from the content-addressed store, hash-verified

127
128/** Returns a normal random number with mean 0 and standard deviation 1 */
129inline float normal() {
130 // Box-Muller transform
131 float radius = std::sqrt(-2.f * std::log(1.f - get<float>()));
132 float theta = 2.f * M_PI * get<float>();
133 return radius * std::sin(theta);
134
135 // // Central Limit Theorem
136 // const int n = 8;
137 // float sum = 0.0;
138 // for (int i = 0; i < n; i++) {
139 // sum += get<float>();
140 // }
141 // return (sum - n / 2.f) / std::sqrt(n / 12.f);
142}
143
144/** Fills an array with random bytes. */
145inline void buffer(uint8_t* out, size_t len) {

Callers 1

randomNormalFunction · 0.85

Calls 3

sqrtFunction · 0.85
sinFunction · 0.85
logFunction · 0.50

Tested by

no test coverage detected