I am using the following code to generate some random number from a custom distribution:
me =511000;
M = 938*10^6;
z = 1;
\[Rho] = 19.32;
\[Tau][T_?NumericQ] := T/M ;
\[Beta][T_?NumericQ] := Sqrt[1 - (1/(\[Tau][T] + 1))^2];
wm[T_?NumericQ] := (2 me \[Beta][T]^2)/(1 - \[Beta][T]^2);
Zs[T_?NumericQ] = z (1 - Exp[-((125 \[Beta][T])/z^(2/3))]);
(*Numero delta prodotti da protone da 100 MeV*)
pr[en_] :=
ProbabilityDistribution[(0.307075*79/196.96655 (10^6 \[Rho])/2 (
10^-4 Zs[en]^2)/(\[Beta][en]^2 (w)^2) (1 - (\[Beta][en]^2 (w))/
wm[en] + (Pi \[Beta][en] Zs[en]^2)/
137 Sqrt[(w)/wm[en]] (1 - (w)/wm[en])))/
Integrate[
0.307075*79/196.96655 (10^6 \[Rho])/2 (
10^-4 Zs[en]^2)/(\[Beta][en]^2 (w)^2) (1 - (\[Beta][en]^2 (w))/
wm[en] + (Pi \[Beta][en] Zs[en]^2)/
137 Sqrt[(w)/wm[en]] (1 - (w)/wm[en])), {w, 10, wm[en]}], {w,
10, wm[en]}]
Table[RandomVariate@pr[10^11], 10]
but I get some negative values as a result:
{23.6665, -4.36639*10^9, 18.1011, 12.4939, 10.6993,
2.23713*10^8, 12.4214, 12.8859, 24.9426, 67.1775}
Why does it happen? If I understand correctly the documentation {w, 10, wm[en]}
sets the possible range of results between 10 and wm[en]
and both are positive numbers so I should get no negative numbers.
I use version 11.3 for windows