fork download
  1. #include <iostream>
  2. #include<cmath>
  3. #include<random>
  4.  
  5. using namespace std;
  6. default_random_engine generator;
  7. uniform_real_distribution<double> distribution(0.0,1.0);
  8.  
  9. int accept(double p){
  10.  
  11. double r = distribution(generator);
  12. cout<<r;
  13. if(r<p)
  14. return 1;
  15. return 0;
  16.  
  17. }
  18.  
  19. int main() {
  20.  
  21. for(int i=0;i<10;i++)
  22. cout<<" "<<accept(0.999)<<endl;;
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
0.131538  1
0.45865  1
0.218959  1
0.678865  1
0.934693  1
0.519416  1
0.0345721  1
0.5297  1
0.00769819  1
0.0668422  1