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.08641963 2.09363044 0.2827077 3.9103619 4.090520 4.1242490 0.6676881
#> [2,] 0.17190983 2.22731570 0.8543931 0.6416130 2.004907 4.9447003 0.2756717
#> [3,] 0.03525481 1.32168469 0.8802695 0.1804067 3.579907 2.6150785 1.8755162
#> [4,] 0.76201598 1.15368866 0.3358088 0.5335274 4.209224 0.1806683 2.7408895
#> [5,] 2.51079346 0.01570596 0.6861532 0.4205036 3.112784 3.0111679 2.5005236
#> [6,] 1.48069895 0.24784653 0.4771234 1.1611859 3.676883 6.6165491 1.2530488