summaryrefslogtreecommitdiff
path: root/math.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'math.cpp')
-rw-r--r--math.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/math.cpp b/math.cpp
index 568c306..c17f57e 100644
--- a/math.cpp
+++ b/math.cpp
@@ -84,7 +84,10 @@ static float randf(void) {
static float rand_gauss(void) {
// https://en.wikipedia.org/wiki/Normal_distribution#Generating_values_from_normal_distribution
- float U = randf(), V = randf();
+ float U, V;
+ do {
+ U = randf(), V = randf();
+ } while (U == 0 || V == 0);
return sqrtf(-2 * logf(U)) * cosf(TAUf * V);
}