## Randomization for a single patient
sample(c("T", "C"), size=1)
[1] "C"
## Randomize 20 independent patients
<- sample(c("T", "c"), size=20, replace=TRUE)) (patients
[1] "c" "T" "T" "c" "c" "c" "c" "T" "c" "T" "T" "c" "c" "T" "T" "c" "T" "T" "c"
[20] "T"
## How many patients are assigned to treatment group?
sum(patients == "T")
[1] 10
## Simulate by repeating 10000 times
<- replicate(10000, {
Ntreat <- sample(c("T", "C"), size=20, replace=TRUE)
patients sum(patients == "T")
})