diff --git a/include/util/common.hpp b/include/util/common.hpp index 52ed73ed..69e43c61 100644 --- a/include/util/common.hpp +++ b/include/util/common.hpp @@ -80,10 +80,12 @@ void randomInit(); uint32_t randomu32(); uint64_t randomu64(); /** Returns a uniform random float in the interval [0.0, 1.0) */ -float randomf(); +float randomUniform(); /** Returns a normal random number with mean 0 and std dev 1 */ float randomNormal(); +inline float DEPRECATED randomf() {return randomUniform();} + //////////////////// // String utilities // string.cpp diff --git a/src/app/ParamWidget.cpp b/src/app/ParamWidget.cpp index 2386a2d2..d3a23009 100644 --- a/src/app/ParamWidget.cpp +++ b/src/app/ParamWidget.cpp @@ -20,7 +20,7 @@ void ParamWidget::fromJson(json_t *rootJ) { void ParamWidget::randomize() { if (randomizable) - setValue(rescale(randomf(), 0.0, 1.0, minValue, maxValue)); + setValue(rescale(randomUniform(), 0.0, 1.0, minValue, maxValue)); } void ParamWidget::onMouseDown(EventMouseDown &e) { diff --git a/src/util/random.cpp b/src/util/random.cpp index 57cd864a..04d065fc 100644 --- a/src/util/random.cpp +++ b/src/util/random.cpp @@ -48,22 +48,22 @@ uint64_t randomu64() { return xoroshiro128plus_next(); } -float randomf() { +float randomUniform() { // 24 bits of granularity is the best that can be done with floats while ensuring that the return value lies in [0.0, 1.0). return (xoroshiro128plus_next() >> (64 - 24)) / powf(2, 24); } float randomNormal() { // Box-Muller transform - float radius = sqrtf(-2.f * logf(1.f - randomf())); - float theta = 2.f * M_PI * randomf(); + float radius = sqrtf(-2.f * logf(1.f - randomUniform())); + float theta = 2.f * M_PI * randomUniform(); return radius * sinf(theta); // // Central Limit Theorem // const int n = 8; // float sum = 0.0; // for (int i = 0; i < n; i++) { - // sum += randomf(); + // sum += randomUniform(); // } // return (sum - n / 2.f) / sqrtf(n / 12.f); }