Estimate pi by simulation

Easydefault_rngrandomboolean mean· 10 XP

A classic warm-up for simulations: pick random points in a square from 0 to 1 on both sides. The share that land inside the quarter circle (x² + y² <= 1) is close to π/4.

With a generator seeded with 0, draw x and then y as 100,000 random numbers each (rng.random(100_000)). Store the estimate of π (4 × the share inside), rounded to 3 decimals.

Expected answer

Store your answer in result.

Hints, the later steps and the answer come with Pro.

import numpy as np

rng = np.random.default_rng(0)
result = ...