# Thread: Sampling from a distribution

1. ## Sampling from a distribution

Assume I have a distribution governing the possible outcome from a single random variable X. This is something like [0.1, 0.4, 0.2, 0.3] for X being a value of either 1, 2, 3, 4.

Is it possible to sample from this distribution, i.e. generate pseudo random numbers upon each of the possible outcomes given the probability of that outcome. So if I wanted to know what the probability of getting a 2 is, the sampling operation may return 0.34 or something like that.

The reason I ask is that I'm trying to implement an action selection policy for a reinforcement learning method based on a research paper. From what I gather from the paper, the author is able to sample the distribution by "mapping the uniform distribution U[0,1] through cumulative probability density functions obtained by adaptive numerical integration". From this he then samples the transition probabilities for each trial...

I would be grateful for any info on this...

2. ## Re: Sampling from a distribution

If all you are asking about is if it's possible to obtain a random sample from an arbitrary discrete distribution - the answer is yes and it is quite easy to do if you have access to a random sample from a uniform distribution. However the following confused me because .34 isn't one of your specified outcomes or a probability you specified. I'm guessing it's unrelated to your original example but I'm still a little confused about what you're asking here.

Originally Posted by seabaz2000
Is it possible to sample from this distribution, i.e. generate pseudo random numbers upon each of the possible outcomes given the probability of that outcome. So if I wanted to know what the probability of getting a 2 is, the sampling operation may return 0.34 or something like that.

3. ## Re: Sampling from a distribution

Hi Dason,
Thanks for the reply, I think I have phrased it wrong and I think the terminology from the paper is throwing me.

If I plot a CDF using this distribution, then generate a uniform random number u [0,1].
Then if u<0.1 I output 1, if its between 0.1 and 0.5 I output 2 and so on. Would this be correct.

4. ## Re: Sampling from a distribution

Originally Posted by seabaz2000
Then if u<0.1 I output 1, if its between 0.1 and 0.5 I output 2 and so on. Would this be correct.
Yup - that's basically it.

 Tweet