Advertisement
Guest User

Untitled

a guest
Apr 16th, 2023
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | Software | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <inttypes.h>
  4. #include <stdint.h>
  5. #include <random>
  6.  
  7. double f1
  8. (
  9.   double x1, double y1, double z1,
  10.   double x2, double y2, double z2,
  11.   double x3, double y3, double z3
  12. )
  13. {
  14.   double a = fabsl((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))/2.0;
  15.   a = a*a*a;
  16.   return a;
  17. }
  18.  
  19.  
  20. int main()
  21. {
  22.   std::random_device rd;
  23.   std::mt19937 gen(rd());
  24.   std::uniform_real_distribution<> dis(0, 1);
  25.   double random_number = dis(gen);
  26.    
  27.   double acc = 0;
  28.   #define END INTMAX_C(500000000)
  29.   for (size_t i = 0; i < END; i++)
  30.   {
  31.     acc += f1(dis(gen),dis(gen),dis(gen),dis(gen),dis(gen),dis(gen),dis(gen),dis(gen),dis(gen));
  32.   }
  33.   printf("%f\n", (acc/1)/END);
  34.   return (0);
  35. }
Tags: monte-carlo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement