Skip to content

Instantly share code, notes, and snippets.

@ecklf
Last active September 7, 2021 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecklf/a1eab45c3fc209756b3a to your computer and use it in GitHub Desktop.
Save ecklf/a1eab45c3fc209756b3a to your computer and use it in GitHub Desktop.
A simple script to calculate pi with random generated numbers using python3.
__author__ = 'ecklf'
# IMPORT
import random
# VAR
random.seed()
radius = 424242
loops = 10000
counter = 0
pi = 0.0
# DEF
def power(var):
return var**2
# FUNC
for i in range(0, loops):
x = random.randint(1, radius)
y = random.randint(1, radius)
if (power(x)+power(y)) < power(radius):
counter += 1
pi = 4.0 * counter / loops
print(str(counter) + " of " + str(loops) + " points were located in the circle district")
print(pi)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment