Random Number Generators for Different Distributions

Libraries

No special library routines are required for these routines

Download

Download sample code for rtriangle and rtrapezoid routines [Here]

Procedure

R provides built in routines to generate random (density dependent) samples from different distributions.   There are other routines to provide the density function or cumulative quantile probability for any value of x.  A sample of these routines is as follows:

runif (num, min, max)            for uniform distribution

rnorm (num, mean, sd)            for normal distribution

rlnorm(num, logmean, logsd)      for log normal distribution

rexp(num, rate)                  for exponential distribution

rgamma(num, shape, rate)         for gamma distribution

rbeta (num, shape1, shape2)      for beta distribution

Here num is the number of samples required, and the other variables are the parameters of each distribution.  Other statistical distributions are available (see R help files).

Two other routines have been written to provide random samples from the triangular or trapezoidal distributions

rtriangle (num, min, peak, max)            for triangular distribution

rtrapezoid (num, min, peak1, peak2, max)   for trapezoidal distribution