This function provides random date generation with a specified range, that defaults to the beginning and end of the current year.

rdate(
  n,
  min = paste0(format(Sys.Date(), "%Y"), "-01-01"),
  max = paste0(format(Sys.Date(), "%Y"), "-12-31"),
  ...
)

Arguments

n

number of observations. If length(n) > 1, the length is taken to be the number required.

min, max

lower and upper limits of the distribution. Must be (coercible to) valid dates.

...

parameters given to as.Date() for coercing the values of min and max

Examples

# generate a million random dates and check the distribution
hist(rdate(1000000), breaks = "months")