# Homework Help: Rejection sampling from gamma distribution

1. Dec 19, 2009

### coolnessitself

1. The problem statement, all variables and given/known data
So this isn't homework, but it's on the level of a homework question, so I'll put it here. I'm trying to figure out how to sample just one value from a gamma distribution using rejection sampling.

2. Relevant equations
How to do it:
page 10
http://www.thefutureofmath.com/matlabstuff/matlabintro.pdf [Broken]

3. The attempt at a solution
I understand the loop until a value is found, and I understand finding a maximum to compare [gammadistribution] against a [maxval*uniform(0,1)].
But for x in the gammadistribution, they use $$\left|kt^2 \mathrm{randn} +kt \right|$$ as x. What is this? Shape parameter times scale parameter squared times a normal distribution plus the scale parameter times the shape parameter? What? My eventual goal is to sample from an arbitrary function, and I think if I can figure out where they're picking this x from I understand the rest.

Last edited by a moderator: May 4, 2017