Returns a valid index from `candidate_precip` based on the provided `idx`. If `idx` is missing, out of bounds, or invalid, a random index is sampled instead. If `candidate_precip` is empty, `NA_integer_` is returned.
Returns a valid index from `candidate_precip` based on the provided `idx`. If `idx` is missing, out of bounds, or invalid, a random index is sampled instead. If `candidate_precip` is empty, `NA_integer_` is returned.