Search notes:

R: generate uniform randum numbers with runif(…)

runif can be used to produce random numbers; runif does not stand for run if.
runif(n) generates n uniform random numbers between 0 and 1.
runif(n, a, b) generates n uniform random numbers between a and b.
In order to create the same random numbers, set.seed(…) can be used.

Example

The following example first creates 10 random numbers in the interval 1 … 10 and assigns it to the variable r and evaluates r to print its values.
Then, it creates another 1000 random variables and uses plot(…) and hist(…) to demonstrate that the distrribution of runif is (more or less) uniform:
set.seed(123)

r <- runif(10, -1, 1)
r
# [1] -0.46469398 -0.45269714  0.18161681  0.03550296  0.08549162  0.35735277
# [7]  0.47083597 -0.84420644  0.77130939  0.87615484

X11()

r <- runif(1000, 0, 1)

plot(1:1000, r)

z <- locator(1) # wait for mouse click or enter pressed

hist(r)

z <- locator(1) # wait for mouse click or enter pressed
Github repository about-r, path: /functions/runif.R
This is the plot:
This is the historgram;

See also

Random numbers (distribution)
Index to (some) R functions

Index