Browse Source

Rename randomf() to randomUniform()

tags/v0.6.0
Andrew Belt 7 years ago
parent
commit
0e29f19320
3 changed files with 8 additions and 6 deletions
  1. +3
    -1
      include/util/common.hpp
  2. +1
    -1
      src/app/ParamWidget.cpp
  3. +4
    -4
      src/util/random.cpp

+ 3
- 1
include/util/common.hpp View File

@@ -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


+ 1
- 1
src/app/ParamWidget.cpp View File

@@ -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) {


+ 4
- 4
src/util/random.cpp View File

@@ -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);
}


Loading…
Cancel
Save