from random import random
from math import pi, exp, cos, sin
n = 1000000
c = 0
for _ in range(n):
    x = random()
    r = abs(1 - complex(cos(2*pi*x), sin(2*pi*x)))
    c += r
f = c / n

# f ==> integral(2 sin(2*pi*x), x, 0, 1) = 4 / pi
print(f, 4/pi)

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: