The R function runif generates from the uniform. To get a full description type:
help(runif)
The general form is runif(n, min=0, max=1), where n is a non-optional argument specifying how many observations you want and min and max specify the endpoints; these arguments have default values of 0 and 1, resp.
In class we did the following experiment. (Note that anything after the # symbol is a comment that R ignores.)
x <- runif(100) # generate the numbers
x # look at the numbers
sort(x) # look at the numbers in increasing order
hist(x) # see a histogram of the numbers
We learned that you can see such a histogram in one fell swoop by: hist(runif(100))
We had some uproarious fun by using the up-arrow key and
If you typed:
hist(runif(100,20,100))
You would get a similar experience, except that your random numbers would be
between 20 and 100 instead of 0 and 1.
Here is a list of other "standard" probability functions that R makes
available.
Distribution R name
beta beta
binomial binom
Cauchy cauchy
chi-squared chisq
exponential exp
F f
gamma gamma
geometric geom
hypergeometric hyper
log-normal lnorm
logistic logis
negative binomial nbinom
normal norm
Poisson pois
Student's t t
uniform unif
Weibull weibull
Wilcoxon wilcox