Skip to content

Instantly share code, notes, and snippets.

View Ben-Benston's full-sized avatar

Ben Benston Ben-Benston

  • India
View GitHub Profile
@Ben-Benston
Ben-Benston / monteCarlo.pde
Created November 17, 2023 13:29
A simple Processing sketch using the Monte Carlo method to estimate Pi.
// Set canvas size
size(640, 640);
// Draw a circle in the center of the canvas
circle(width / 2, height / 2, width);
// Define variables
int circleCenterX = width / 2;
int circleCenterY = height / 2;
int outsidePoints = 0;
@Ben-Benston
Ben-Benston / monteCarlo.py
Created September 15, 2023 03:22
This python script employs the Monte Carlo method, utilizing 1 million random points, to accurately estimate the value of Pi. It offers a console-based, no-frills approach for computing Pi with precision.
import random
import math
# Define radius of circle
r = 200.0
# Initialize variables
insideCirc = 0
totalCirc = 0
diff = 1.0