# Generating random numbers with skewed distribution

I want to generate random numbers with skewed distribution. But I have only following information about distribution from the paper :

skewed distribution where the value is 1 with probability 0.9 and 46 with probability 0.1. the distribution has mean (5.5)

I don't know how to generate random numbers with this information and I don't know what is the distribution function.

I'm using jdistlib for random number generation. If anyone has experience using this library can help me with this library for skewed distribution random number generation?

-
If you can generate a uniform distribution $u \in [0,1]$, then you can generate the above with $u \mapsto 1_{[0,0.9]}(u)+46 \cdot 1 _{(0.9,1]}(u)$ –  copper.hat Mar 25 '13 at 7:38
@copper.hat if I generate in the way you suggested, all numbers are near to 46 but I think according to distribution, numbers should be more near to 1. in the paper they said that the numbers mean is 5.5. –  user1031925 Mar 25 '13 at 9:04
If $u$ is distributed normally on $[0,1]$, then $E(1_{[0,0.9]}+46 \cdot 1 _{(0.9,1]}) = 0.9+0.1 \cdot 46 = 5.5$. I'm not sure why ou think all the numbers are near to $46$. Note the multiplier on 46 is $1_{[0.9,1]}$, and $E1_{[0.9,1]} = 0.1$. –  copper.hat Mar 25 '13 at 14:42
@copper.hat so maybe my problem is that I didn't know skewed distribution completely. I thought that this distribution should have numbers between 1 and 46 and mostly near to 1 so that their mean would be 5.5. but sth that you said is that we only have exact 46 and 1 numbers so that their mean would be 5.5. Do I understand you completely ? –  user1031925 Mar 25 '13 at 17:39
It depends on what you want, the question says that you want the value $1$ with probability $0.9$ and the value $46$ with probability $0.1$. So that is what I did... –  copper.hat Mar 25 '13 at 17:43

What copperhat is hinting at is the following algorithm:

Generate u, uniformly distributed in [0, 1]
If u < 0.9 then
return 1
else
return 46


(sorry, would be a mess as a comment).

In general, if you have a continuous distribution with cummulative distribution $c(x)$, to generate the respective numbers get $u$ as above, $c^{-1}(u)$ will have the required distribution. Can do the same with discrete distributions, essentially searching where the $u$ lies in the cummulative distribution.

An extensive treatment of generating random numbers (including non-uniform ones) is in Knuth's "Seminumerical Algorithms" (volume 2 of "The Art of Computer Programming"). Warning, heavy math involved.

-
so maybe my problem is that I didn't know skewed distribution completely. I thought that this distribution should have numbers between 1 and 46 and mostly near to 1 so that their mean would be 5.5. but sth that you said is that we only have exact 46 and 1 numbers so that their mean would be 5.5. Do I understand you completely ? –  user1031925 Mar 25 '13 at 17:40
@user1031925, 90% of the time 1, 10% of the time 46 is what I understood of your question. That nicely gives an average of 5.5, as stated. –  vonbrand Mar 25 '13 at 17:45