Created
March 22, 2011 23:59
-
-
Save Ang3lFir3/882362 to your computer and use it in GitHub Desktop.
Monte Carlo Pi
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
using System; | |
public class Foo | |
{ | |
public static void Main() | |
{ | |
int insideCounter = 0; | |
var iteration = 60000000; | |
var randomiser = new Random((int)DateTime.Now.Ticks); | |
for(var i = 0; i < iteration; i++) | |
{ | |
var x = randomiser.NextDouble(); | |
var y = randomiser.NextDouble(); | |
if(Math.Sqrt(Math.Pow(x,2) + Math.Pow(y,2)) <= 1.0d) | |
{ | |
insideCounter++; | |
} | |
} | |
Console.WriteLine("{0} Hits were inside the area of the circle.", insideCounter); | |
Console.WriteLine(4d * insideCounter / iteration); | |
Console.ReadLine(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment