几何概率 clc,clear; N=100000; X=24*rand(N,1); Y=24*rand(N,1); M=0; for i=1:N if (Y(i)-X(i)>=1)||(X(i)-Y(i)>=2) M=M+1; end end p=M/N clc,clear; N=100000; X=8+4*rand(N,1); M=0; Y=7+2*rand(N,1); for i=1:N if abs(X(i)-Y(i))<=1/12 M=M+1; end end p=M/N