Let (Xi)i∈ℕ be a sequence of independent and identically distributed random variables with values in the set ℕ0
of nonnegative integers. Motivated by applications in enumerative combinatorics and analysis of algorithms we investigate the number of gaps and the length of the longest gap in the set {X1,…,Xn} of the first n values. We obtain necessary and sufficient conditions in terms of the tail sequence (qk)k∈ℕ0,
qk=P(X1≥ k), for the gaps to vanish asymptotically as n→∞: these are ∑k=0∞qk+1/qk <∞ and limk→∞qk+1/qk=0 for convergence almost surely and convergence in probability, respectively. We further show that the length of the longest gap tends to ∞ in probability if qk+1/qk→ 1. For the family of geometric distributions, which can be regarded as the borderline case between the light-tailed and the heavy-tailed situations and which is also of particular interest in applications, we study the distribution of the length of the longest gap, using a construction based on the Sukhatme–Rényi representation of exponential order statistics to resolve the asymptotic distributional periodicities.