# Number of draws
n <- 1000
# Do normal sampling
set.seed(42)
draws_1 <- DDD:::rng_respecting_sample(
1:3, size = n, replace = TRUE, prob = c(1.0, 1.0, 1.0)
)
# Do a sampling with one element of probability zero
set.seed(42)
draws_2 <- DDD:::rng_respecting_sample(
1:4, size = n, replace = TRUE, prob = c(1.0, 1.0, 1.0, 0.0)
)
testit::assert(sum(draws_2 == 4) == 0)
testit::assert(draws_1 == draws_2)
# Use base sampling will give different results,
# as it results in different RNG values
set.seed(42)
draws_3 <- sample(
1:4, size = n, replace = TRUE, prob = c(1.0, 1.0, 1.0, 0.0)
)
testit::assert(sum(draws_3 == 4) == 0)
testit::assert(!all(draws_1 == draws_3))
Run the code above in your browser using DataLab