Skip to contents

This function returns a random number generator from a gamma distribution that has a weekly period and configurable degree of additional variability around weekly pattern. It is suited to delays of things like testing which may depend on the day of week.

Usage

cfg_weekly_gamma_rng(
  mean = c(1, 1, 1, 1, 4, 3, 2),
  sd = sqrt(mean),
  week_starts = weekdays(as.Date("2024-10-14"))
)

Arguments

mean

a mean amount of delay for each day of the week

sd

the SD of the delay

week_starts

locale description of first day of week (default is a "Monday").

Value

a random number generator taking t time parameter and returning a duration the that time t depending on the day of the week.

Examples

fn = cfg_weekly_gamma_rng(c(1,1,1,1,4,3,2))
matrix(fn(1:42),ncol=7,byrow=TRUE)
#>            [,1]      [,2]      [,3]       [,4]      [,5]      [,6]      [,7]
#> [1,] 1.55052391 0.9345371 0.8842994 4.12789573 4.3817637 4.8689147 0.7934611
#> [2,] 0.03933357 1.0073317 0.5344318 2.18536425 1.6142306 6.3931658 2.0508549
#> [3,] 2.22731570 0.8543931 0.6416130 0.06361773 6.3169688 0.7769338 0.4975902
#> [4,] 1.32168469 0.8802695 0.1804067 0.53048240 3.6359255 2.9786923 1.9336943
#> [5,] 1.15368866 0.3358088 0.5335274 0.78839729 0.5108545 4.0479716 0.1951924
#> [6,] 0.33348461 0.7118283 1.8344688 0.68615325 3.2840124 2.1744995 1.9013039