Skip to contents

Draws n POSIXct times uniformly in [origin, origin + duration_s], guaranteed distinct from each other and from any time in avoid. Resamples collisions rather than assuming they are rare.

Usage

uniqueEventTimes(
  n,
  origin,
  duration_s,
  avoid = NULL,
  sorted = TRUE,
  maxTries = 100L
)

Arguments

n

Number of times to draw.

origin

POSIXct start of the interval.

duration_s

Length of the interval in seconds.

avoid

Optional POSIXct vector of already-used times to stay clear of.

sorted

Return times in ascending order. Default TRUE.

maxTries

Give up after this many resampling rounds. Default 100.

Value

POSIXct vector of length n.

Details

Collision-freedom is a correctness requirement, not a nicety. simsTocaptureHistoryTable merges detector tables on exact datetime equality, and merge() on a duplicated key returns the cartesian product of the matching rows. With one duplicated time shared across N detector tables, a single event becomes 2^N rows.

Comparison is done on the underlying numeric representation, which is what merge() itself compares, so a time that passes this check cannot collide downstream.