This is because the normal distribution is compilable (it's been programmed explicitly into the list of Compilable functions) whereas the Gamma distribution has not. You can see this by comparing at the InputForms of the byt-code compiled expressions. Normal Distribution:
CompiledFunction[{8, 9., 5468}, {_Integer}, {{2, 0, 0}, {3, 0, 0}},
{{1, {2, 0, 2}}, {4, {2, 0, 3}}, {3, {2, 0, 1}}}, {0, 4, 2, 0, 2},
{{34, 0, 2, 0}, {10, 1, 0}, {10, 2, 1}, {42, "RandomNormal", 3, 0, 0, 3, 0, 1,
2, 1, 0, 3, 1, 1}, {42, "TotalAll", 3, 1, 1, 2, 0, 3, 3, 0, 0}, {1}},
Function[{r}, Module[{gs = RandomVariate[NormalDistribution[3, 1], r]},
Total[gs]]], Evaluate]
GammaDistribution:
CompiledFunction[{8, 9., 5468}, {_Integer}, {{2, 0, 0}, {2, 0, 3}},
{{1, {2, 0, 2}}, {3, {2, 0, 1}}}, {0, 5, 0, 0, 1},
{{34, 0, 2, 0}, {46, Function[{r}, RandomVariate[GammaDistribution[3, 1], r]],
2, 0, 0, 2, 0, 4}, {47, Total, 2, 0, 4, 2, 0, 3}, {1}},
Function[{r}, Module[{gs = RandomVariate[GammaDistribution[3, 1], r]},
Total[gs]]], Evaluate]
Note the explicit Function[{r}, RandomVariate[GammaDistribution[3, 1], r] in the byte code part of Compile
|