import java.lang.Math;
public class BuffonNeedle
{
public static void main(String args[])
{
double drops = 100;
int hit = 0;
for(int r=1; r<=6; r++)
{
for(int i = 1; i <= drops; i++)
{
double y = Math.random() * 2;
if(Math.sin(Math.random()*Math.PI) + y >= 2.){
hit++;
}
}
System.out.println(drops/hit);
drops = drops * 10;
}
}
}
Почему это не дает Pi , когда ограничения на расстоянии 2 дюйма друг от друга, а стрелка - один дюйм?
Симуляция запускается 6 раз: 100, 1000, 10000, 100000, 1000000, 10000000.