Select n from N Random Numbers

Suppose that you want to select (n=)10 individuals from (N=)736 individuals.

sample(736,10)
##  [1] 690 620  48 384 534 437 216 731  68 448

 

Randomly Allocate N Individuals

Suppose that you want to randomly (and evenly) allocate 24 individuals to 3 treatments.

( alloc <- sample(24) )
##  [1]  2  6 21  9 14 15  4  3 22 11  5 13 18 19 16  7 17  1 12 20  8 24 23
## [24] 10
alloc[1:8]
## [1]  2  6 21  9 14 15  4  3
alloc[9:16]
## [1] 22 11  5 13 18 19 16  7
alloc[17:24]
## [1] 17  1 12 20  8 24 23 10