3 (define (random-in-range low high)
4 (let ((range (- high low)))
5 (+ low (* (random) range))))
7 (define (point-stream x1 x2 y1 y2)
9 (list (random-in-range x1 x2)
10 (random-in-range y1 y2))
11 (point-stream x1 x2 y1 y2)))
14 (define (inside-circle? radius centre-x centre-y)
15 (<= (+ (square (- x centre-x))
16 (square (- y centre-y)))
18 (inside-circle? 1.0 0 0))
20 (define (monte-carlo experiment-stream passed failed)
21 (define (next passed failed)
23 (/ passed (+ passed failed))
25 (stream-cdr experiment-stream) passed failed)))
26 (if (stream-car experiment-stream)
27 (next (+ passed 1) failed)
28 (next passed (+ failed 1))))
30 (define (estimate-integral P x1 x2 y1 y2)
31 (monte-carlo (stream-map (lambda (p)
33 (point-stream x1 x2 y1 y2))
37 (* (stream-ref (estimate-integral P 1 -1 1 -1) 100000) 4.0)