Randomly Generate Uniformly Distributed Data in R

Your goal

You need to randomly generate uniformly distributed data in R.

Step-by-step tutorial

We will use the runif function from the stats package to do this.

For the sake of this example, let's say we want to generate 50 values in the range 60-100.

> data <- runif(n=50, min=60, max=100)
> data
 [1] 87.54489 67.54065 88.97808 62.70184 68.98950 98.44978 76.38789 89.90482
 [9] 98.96136 79.44138 73.65247 73.48446 72.50686 97.81398 61.42516 86.81577
[17] 63.78087 75.86120 68.10029 92.52243 62.74936 76.50691 86.59031 66.31251
[25] 78.19338 98.08484 98.90018 65.25945 99.47216 73.48978 95.63106 83.75710
[33] 71.02181 64.38957 61.22293 80.31371 92.53529 73.97297 84.22327 93.86252
[41] 72.91183 91.58719 61.26284 79.13631 94.79609 68.08033 90.80016 88.42833
[49] 73.62931 81.69667

We can use hist to generate a histogram for the distribution:

> hist(data)
Histogram of uniformly distributed data
Histogram of uniformly distributed data