Use the runif() function (with set.seed(32078)) to generate 10 pseudorandom numbers from

(a) the uniform (0, 1) distribution
(b) the uniform (3, 7) distribution
(c) the uniform (-2, 2) distribution.

Solution

(a) the uniform (0, 1) distribution

set.seed(32078)
n<-10   ## Sample size
a<-runif(n,0,1)  # Generate 10 Uniform(0,1) pseudorandom numbers
a
 [1] 0.2564626 0.4988177 0.5266549 0.6269816 0.8052754 0.1843452 0.5102327
 [8] 0.3683905 0.1708176 0.7432888

(b) the uniform (3, 7) distribution

b<-runif(n,3,7) # Generate 10 Uniform(3,7) pseudorandom numbers
b
 [1] 3.056989 3.893914 4.441298 6.186232 3.062636 4.622070 5.606054 6.640532
 [9] 6.082923 5.043795

(c) the uniform (-2, 2) distribution

c<-runif(n,-2,2) # Generate 10 Uniform(-2,2) pseudorandom numbers
c
 [1]  0.3696431 -0.5422788  1.3220533 -1.8308456 -1.0533042 -0.4795504
 [7] -1.5585568 -1.4941803 -1.2035684  0.3528563

Further Reading