R Under development (unstable) (2024-06-07 r86704 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > > > haz <- c(0.2, 0.3, 0.5) > haz [1] 0.2 0.3 0.5 > haz_all <- sum(haz) > #new code, produces correct outputs > table(sample(1:3, size = 10^6, prob = haz / haz_all, replace = TRUE))/10^6 1 2 3 0.199788 0.300344 0.499868 > #old code, probs. dont match hazards > table(1L + stats::rbinom(n = 10^6, size = 2, prob = haz/haz_all))/10^6 1 2 3 0.459337 0.414133 0.126530 > > proc.time() user system elapsed 0.28 0.10 0.37