I think you are looking to generate samples of a Bernoulli random variable. A Bernoulli random variable is a special case of a binomial random variable. Therefore, you can try rbinom(N,1,p)
. This will generate N
samples, with value 1
with probability p
, value 0
with probability (1-p)
. To get values of a
and -a
you can use a*(2*rbinom(N,1,p)-1)
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…