diff --git a/inst/include/monty/random/multinomial.hpp b/inst/include/monty/random/multinomial.hpp index 6d3770b6..f64b8f80 100644 --- a/inst/include/monty/random/multinomial.hpp +++ b/inst/include/monty/random/multinomial.hpp @@ -53,7 +53,7 @@ namespace random { template __host__ __device__ -void multinomial(rng_state_type& rng_state, int size, const T& prob, +void multinomial(rng_state_type& rng_state, real_type size, const T& prob, int prob_len, U ret) { real_type p_tot = 0; for (int i = 0; i < prob_len; ++i) { diff --git a/tests/testthat/test-rng.R b/tests/testthat/test-rng.R index 43d170cf..d2365cb7 100644 --- a/tests/testthat/test-rng.R +++ b/tests/testthat/test-rng.R @@ -632,6 +632,15 @@ test_that("can validate multinomial inputs", { }) +test_that("deterministic multinomial returns expectation", { + r <- monty_rng_create(seed = 1, deterministic = TRUE) + p <- runif(10) + p <- p / sum(p) + res <- monty_random_multinomial(100, p, r) + expect_equal(res, 100 * p) +}) + + test_that("deterministic rbinom returns mean", { m <- 10 n <- as.numeric(sample(10, m, replace = TRUE))