Browse Source

Fix box muller transform in common/math.cpp.

Random numbers have to be in (0:1], not in [0:1).
vrld 12 years ago
parent
commit
d842c5d28d
1 changed files with 2 additions and 2 deletions
  1. 2 2
      src/common/math.cpp

+ 2 - 2
src/common/math.cpp

@@ -24,8 +24,8 @@ float random_normal(float o)
 	}
 
 	// else: generate numbers using the Box-Muller transform
-	float a = sqrt(-2.0f * log(random()));
-	float b = float(LOVE_M_PI) * 2.0f * random();
+	float a = sqrt(-2.0f * log(1. - random()));
+	float b = float(LOVE_M_PI) * 2.0f * (1. - random());
 	last_randnormal = a * cos(b);
 	return a * sin(b) * o;
 }