#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#define pi 3.14159
using namespace std;
void bai1()
{
double x1, y1, x2, y2, z2, r1, r2, r3, theta, phi, r;
double z1 = 0;
TH3F* h1 = new TH3F("h1", "1a", 50, -5, 5, 50, -5, 5, 50, -5, 5 );
TH3F* h2 = new TH3F("h2", "1b", 100, -5, 5, 100, -5, 5, 100, -5, 5 );
srand(time(NULL)); //Hàm khởi tạo số ngẫu nhiên
int a = -1;
int b = 1;
for(int i=1;i<10000;i++)
{
r1 = double(rand())/RAND_MAX;
r2 = double(rand())/RAND_MAX;
r3 = double(rand())/RAND_MAX;
// a,
x1 = r1*(b-a) + a;
y1 = r2*(b-a) + a;
if(x1*x1 + y1*y1< 1)
{
h1->Fill(x1, y1, z1);
}
// b,
r = r1;
theta = r2*pi;
phi = r3*2*pi;
x2 = r * sin(theta) * cos(phi);
y2 = r * sin(theta) * sin(phi);
z2 = r * cos(theta);
h2->Fill(x2,y2,z2);
}
TCanvas *c1 = new TCanvas("c1", "bai1 a", 800, 700);
h1->Draw();
TCanvas *c2 = new TCanvas("c2", "bai1 b", 800, 700);
h2->Draw();
}
Thats my code, when I run root bai1.C
, it just says it’s done and doesn’t show any histograms. (I’m running through WSL)**