Let f(g;n,m) be the chance that the minimum, a(1), equals g; that is, the sample consists of g and an n−1-subset of {g+1,g+2,…,m}. There are (m−gn−1) such subsets out of the (mn) equally likely subsets, whence
Pr(a(1)=g=f(g;n,m)=(m−gn−1)(mn).
Adding f(k;n,m) for all possible values of k greater than g yields the survival function
Pr(a(1)>g)=Q(g;n,m)=(m−g)(m−g−1n−1)n(mn).
Let Gn,m be the random variable given by the largest gap:
Gn,m=max(a(1),a(2)−a(1),…,a(n)−a(n−1)).
(This responds to the question as originally framed, before it was modified to include a gap between a(n) and m.)
We will compute its survival function
P(g;n,m)=Pr(Gn,m>g),
from which the entire distribution of
Gn,m is readily derived. The method is a dynamic program beginning with
n=1, for which it is obvious that
P(g;1,m)=Pr(G1,m>1)=m−gm, g=0,1,…,m.(1)
For larger n>1, note that the event Gn,m>g is the disjoint union of the event
a1>g,
for which the very first gap exceeds g, and the g separate events
a1=k and Gn−1,m−k>g, k=1,2,…,g
for which the first gap equals k and a gap greater than g occurs later in the sample. The Law of Total Probability asserts the probabilities of these events add, whence
P(g;n,m)=Q(g;n,m)+∑k=1gf(k;n,m)P(g;n−1,m−k).(2)
Fixing g and laying out a two-way array indexed by i=1,2,…,n and j=1,2,…,m, we may compute P(g;n,m) by using (1) to fill in its first row and (2) to fill in each successive row using O(gm) operations per row. Consequently the table can be completed in O(gmn) operations and all tables for g=1 through g=m−n+1 can be constructed in O(m3n) operations.
These graphs show the survival function g→P(g;n,64) for n=1,2,4,8,16,32,64. As n increases, the graph moves to the left, corresponding to the decreasing chances of large gaps.
Closed formulas for P(g;n,m) can be obtained in many special cases, especially for large n, but I have not been able to obtain a closed formula that applies to all g,n,m. Good approximations are readily available by replacing this problem with the analogous problem for continuous uniform variables.
Finally, the expectation of Gn,m is obtained by summing its survival function starting at g=0:
E(Gn,m)=∑g=0m−n+1P(g;n,m).
This contour plot of the expectation shows contours at 2,4,6,…,32, graduating from dark to light.