
% gives a uniform random distribution on a sphere in 3d

i=1;
R2=1;

while i<=2000
theta= acosd(1.-2.*rand());      %uniform theta
Phi= 2.*180.*rand();         % uniform phi
x1= R2*sind(theta)*cosd(Phi);     % measured in the source coordinate
y1= R2*sind(theta)*sind(Phi);     %measured in the source coordinate
z1= R2*cosd(theta);
i=i+1;
plot3(x1,y1,z1,'.');
hold on
end 

sphere(25);
colormap([1,1,1]);
hold on
daspect([1 1 1])    %streches the sphere
axis equal;
xlabel('x-axis')
ylabel('y-axis')
zlabel('z-axis')
rotate3d on