[R] generate random number of any given distribution

Spencer Graves spencer.graves at pdf.com
Sat Jan 17 01:47:40 CET 2004

Hello, Yan: 

      Are you aware that for all the standard distributions, R provides 
the probability density, the cumulative distribution function, the 
quantile function, and random number generation?  When you said, 
"besides uniform and gaussian", I wondered.  The convention is that the 
first letter of the function is d, p, q, and r, for these 4 functions, 
followed by the name or abbreviation of the distribution.  Thus, rexp = 
random numbers for the exponential distribution, rbeta = beta r.n., rt = 
Student's t, rf = F distribution, etc. 

      hope this helps. 
      spencer graves    

Liaw, Andy wrote:

>If you can compute the quantile function of the distribution (i.e., the
>inverse of the integral of the pdf), then you can use the probability
>integral transform:  If U is a U(0,1) random variable and Q is the quantile
>function of the distribution F, then Q(U) is a random variable distributed
>as F.
>This is not necessarily the most efficient way of generating the random
>number, but it may be the only way in some cases.
>>From: Yan Yu
>>Is there a function in R to generate random number of any given
>>distribution (its pdf is given), besides uniform and gaussian
>Notice:  This e-mail message, together with any attachments,...{{dropped}}
>R-help at stat.math.ethz.ch mailing list
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

More information about the R-help mailing list