<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">// An example of evaluating pi by throwing a dart to a
// unit square with 0&lt;x&lt;1 and 0&lt;y&lt;1 with a long period
// unform random number generator.

import java.lang.*;
import java.util.Date;
public class Dart2 {
  final static int n = 1000000;
  static long seed;
  public static void main(String argv[]) { 

 // Initiate the seed from the current time
    Date t = new Date();
    seed = t.getTime();
    if ((seed%2) == 0) seed = seed-1;

 // Throw the dart to the unit square
    int ic = 0;
    for (int i=0; i&lt;n; ++i) {
      double x = ranl();
      double y = ranl();
      if ((x*x+y*y) &lt; 1) ic++;
    }
    System.out.println("Estimated pi: " + (4.0*ic/n));
  }

// Method to generate a uniform random number in [0,1]
// following x(i+1)=a*x(i) mod c with a=pow(7,5) and
// c=pow(2,63)-1.  Here the seed is a global variable.

  public static double ranl() {
    final long a = 16807L, c = 9223372036854775807L,
      q = 548781581296767L, r = 12838L;
    final double cd = c;
    long h = seed/q;
    long l = seed%q;
    long t = a*l - r*h;
    if (t &gt; 0) seed = t;
    else seed = c + t;
    return seed/cd;
  }
}
</pre></body></html>