Skip to content

Instantly share code, notes, and snippets.

@null-none
Created May 27, 2020 08:42
Code example: Estimating Pi with Fiber
from fiber import Pool
import random
NUM_SAMPLES = int(1e6)
def is_inside(p):
x, y = random.random(), random.random()
return x * x + y * y < 1
def main():
pool = Pool(processes=4)
pi = 4.0 * sum(pool.map(is_inside, range(0, NUM_SAMPLES))) / NUM_SAMPLES
print("Pi is roughly {}".format(pi))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment