How to random generate a sample from {0,2} in R? There are some solutions online on how to do a random generation of the discrete uniform distribution, but only on consecutive integers. Like :
> library(purrr)
> rdunif(10,b=50,a=21)
[1] 38 33 28 36 48 32 47 27 29 24

But how can we do it from a set like {0,2} ?

Use sample:
> set.seed(1)
> sample(x=c(0,2),size=10,replace=TRUE)
 [1] 0 2 0 0 2 0 0 0 2 2

