Sampling from a distribution with given probabilities
Just a suggestion: 

I think you can use better variable names than pp and q.

cdf can be clonedArray, and the same for other variable names.

This doesn't matter so much but increases the readability of the program.