// ファイル名： Ch03/pi_MonteCarlo.cc 
#include <iostream> 
#include <random> 
using namespace std; 
 
int main() { 
  int nTrial(100000), nSuccess(0); 
  double x, y; 
  default_random_engine engine; 
  uniform_real_distribution<double> rnd(0.0, 1.0); 
  for (int i(0); i <= nTrial; i++){ 
    x = rnd(engine);     
    y = rnd(engine); 
    if( (x*x + y*y) < 1.0 ) nSuccess += 1; 
  } 
  cout << "pi = " << 4.0*nSuccess/nTrial << endl;  
  return 0; 
}
