package bt6;
import java.util.Random;
/**
* 看到了一个 蒙特卡洛方法 随机数得出 圆周率的c++ 源码 ,复制过来 一个Java版的见笑了
* @author suifeng
*
*/
public class PITest {
public static void main(String[] args) {
int RAND_MAX = 1000000;
long i, in, N = 200000000;
double x, y, pi;
Random rd = new Random(System.currentTimeMillis());
for (i = 0, in = 0; i < N; i++)
{
x = 2.0 * rd.nextInt(RAND_MAX)/RAND_MAX-1 ;
y = 2.0 * rd.nextInt(RAND_MAX)/RAND_MAX-1;
if ((x * x + y * y) <= 1)
in++;
}
pi = 4.0 * in / N;
System.out.println(pi);
}
}