def apply_jitter(rand, jitter, n):
  """Reduce n by random amount from [0, jitter]. Ensures result is >=1."""
  if jitter <= 0.001:
    return n
  v = n - int(n * rand.uniform(0, jitter))
  if v:
    return v
  else:
    return 1