We consider the elementary divisors and determinant of a uniformly distributed n× n random matrix with entries in the ring of integers of an arbitrary local field. We show that the sequence of elementary divisors is in a simple bijective correspondence with a Markov chain on the non-negative integers. The transition dynamics of this chain do not depend on the size of the matrix. As n→∞, all but finitely many of the elementary divisors are 1, and the remainder arise from a Markov chain with these same transition dynamics. We also obtain the distribution of the determinant of M n and find the limit of this distribution as n→∞. Our formulae have connections with classical identities for q-series, and the q-binomial theorem, in particular.