Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Libraries needed.
  • Loading branch information
PyPatel authored Jun 16, 2018
1 parent 50f3e2c commit 6699181
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Monte Carlo Model/mcm.cpp
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;
}
5 changes: 5 additions & 0 deletions Monte Carlo Model/mcm.h
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

0 comments on commit 6699181

Please sign in to comment.