This preview shows page 1. Sign up to view the full content.
Unformatted text preview: double x = rgen.nextDouble(-1.0, +1.0); double y = rgen.nextDouble(-1.0, +1.0); if (x * x + y * y < 1.0) inside++; } double pi = 4.0 * inside / NDARTS; println("Pi is approximately " + pi); } /* Private constant */ private static final int NDARTS = 10000; /* Number of darts to throw */ /* Private instance variables */ private RandomGenerator rgen = RandomGenerator.getInstance(); }...
View Full Document
This note was uploaded on 03/26/2011 for the course CS 1md3 taught by Professor Skip during the Spring '11 term at McMaster University.
- Spring '11