public class PiEstimation extends Object implements Serializable
Thus Pi = 4 * (area of circle / area of square).
The idea is to find a way to estimate the circle to square area ratio. The Monte Carlo method suggests collecting random points (within the square) and then counting the number of points that fall within the circle
x = Math.random()
y = Math.random()
x * x + y * y < 1
Modifier and Type | Class and Description |
---|---|
static class |
PiEstimation.Sampler
Sampler randomly emits points that fall within a square of edge x * y.
|
static class |
PiEstimation.SumReducer
Simply sums up all long values.
|
Constructor and Description |
---|
PiEstimation() |
Copyright © 2014–2019 The Apache Software Foundation. All rights reserved.