Library · Geometric Probability · Chapter 4
A random quadratic with real roots
Problem 4.1
Let be independent uniform random variables in . What is the probability that the quadratic has real roots?
Solution. The quadratic has real roots iff its discriminant is non-negative, i.e., , or equivalently . The parameter space is the square , of area .
The region inside the square is everything below the parabola . Its area is Hence the probability is
import numpy as np
p, q = np.random.uniform(-1, 1, (2, 10**7))
real_roots = p**2 >= q
print(f"sim: {real_roots.mean():.5f} exact: {2/3:.5f}")
# sim: 0.66659 exact: 0.66667