-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Libraries needed.
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <mcm.h> | ||
#include <cstdlib> | ||
#include <cmath> | ||
// the basic math functions should be in namespace | ||
// std but aren’t in VCPP6 | ||
#if !defined(_MSC_VER) | ||
using namespace std; | ||
#endif | ||
double GetOneGaussianBySummation() | ||
{ | ||
double result = 0; | ||
for (unsigned long j = 0; j < 12; j++) | ||
result += rand() / static_cast<double>(RAND_MAX); | ||
result -= 6.0; | ||
return result; | ||
} | ||
double GetOneGaussianByBoxMuller() | ||
{ | ||
double result; | ||
double x; | ||
double y; | ||
double sizeSquared; | ||
do | ||
{ | ||
x = 2.0 * rand() / static_cast<double>(RAND_MAX) - 1; | ||
y = 2.0 * rand() / static_cast<double>(RAND_MAX) - 1; | ||
sizeSquared = x * x + y * y; | ||
} while (sizeSquared >= 1.0); | ||
|
||
result = x * sqrt(-2 * log(sizeSquared) / sizeSquared); | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#ifndef MCM_H | ||
#define MCM_H | ||
double GetOneGaussianBySummation(); | ||
double GetOneGaussianByBoxMuller(); | ||
#endif |