Skip to content

Commit

Permalink
Updated square function in GaussianBoxMuller
Browse files Browse the repository at this point in the history
Roughly halves execution time @100k sims.
  • Loading branch information
badge committed Sep 14, 2015
1 parent 9eef246 commit 6310ec4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion MonteCarlo/Model/Simulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public static double NextDouble()
{
x = 2 * RandomProvider.GetThreadRandom().NextDouble() - 1;
y = 2 * RandomProvider.GetThreadRandom().NextDouble() - 1;
square = Math.Pow(x, 2) + Math.Pow(y, 2);
square = (x * x) + (y * y);
} while (square >= 1);

return x * Math.Sqrt(-2 * Math.Log(square) / square);
Expand Down

0 comments on commit 6310ec4

Please sign in to comment.