I need to generate random numbers until the condition(sum of the difference of each random number is 3000.) is satisfied.
and random numbers are already generated from the truncated normal distribution.
I already try to use while loop while(1) and if , but it didn't work properly.
How can I generate new random number sequence with the condition?
truncnorm_rn <- rtruncnorm(1000,0,30,0,1)
a <- 0
b <- 0
c <- 0 # sum of diffrences between truncnorm random number
d <- NULL # New sequnce with condition
while(1){
a <- truncnorm_rn[1]
b <- truncnorm_rn[2]
c <- sum(a - b)
if(c > 3000) break
}
Aucun commentaire:
Enregistrer un commentaire