categories: computer science
Hello everyone,
Below you will find a video with a detailed explanation of the Monte Carlo algorithm. Its operation, time complexity, and usefulness. Below you will also find ready-to-use code that you can copy if needed.
Code:
import random
punktyPoczatek = 100000
punktyKolo = 0
for i in range(punktyPoczatek):
wspolrzednaX = random.uniform(-1, 1)
wspolrzednaY = random.uniform(-1, 1)
if wspolrzednaX**2 + wspolrzednaY**2 <= 1:
punktyKolo += 1
print(4 * punktyKolo / punktyPoczatek)
Video:
Thank you for reading!
Read more