The following sections describe solutions to the preceding problems. You can download the example solutions to see additional details and to experiment with the programs at
https://github.com/PacktPublishing/The-Modern-CSharp-Challenge/tree/master/Chapter02.
Solutions
20. Monte Carlo π
The following code uses a Monte Carlo algorithm to estimate π:
// Use Monte Carlo simulation to estimate pi.
private double MonteCarloPi(long numPoints)
{
Random rand = new Random();
// Make a bitmap to show points.
int wid = pointsPictureBox.ClientSize.Width;
int hgt = pointsPictureBox.ClientSize.Height;
Bitmap bm = new Bitmap(wid, hgt);
using (Graphics gr = Graphics.FromImage(bm))
{
gr.Clear(Color.White...