function res=gen_HG(n,g)
% Cos (teta) generator for Henyey_Greenstain scattering
% phase function
% By Krzysztof Markowicz, Nov 2003
if g~=0
 res=1/(2*g)*(1+g^2-((1-g^2)./(1-g+2*g*rand(n,1))).^2);
elseif g==0
 res=2*rand(n,1)-1;
end 
