  We prove new statistical results about the distribution of the cokernel of a
random integral matrix with a concentrated residue. Given a prime $p$ and a
positive integer $n$, consider a random $n \times n$ matrix $X_n$ over the ring
$\mathbb{Z}_p$ of $p$-adic integers whose entries are independent. Previously,
Wood showed that regardless of the distribution of $X_n$, as long as each entry
of $X_n$ is not too concentrated on a single residue modulo $p$, the
distribution of the cokernel $\mathrm{cok}(X_n)$ of $X_n$, up to isomorphism,
weakly converges to the Cohen--Lenstra distribution, as $n \rightarrow \infty$.
In this paper, we consider the case when $X_n$ has a concentrated residue $A_n$
so that $X_n = A_n + pB_n$, where $B_n$ is a random $n \times n$ matrix over
$\mathbb{Z}_p$. We show that for every fixed $n$ and a non-constant monic
polynomial $P(t) \in \mathbb{Z}_p[t]$, we can explicitly compute the
distribution of $\mathrm{cok}(P(X_n))$ when $B_n$ is a Haar-random matrix.
Using this, we also show that for specific choices of $A_n$ a much wider class
of random matrices $B_n$ gives the same distribution of $\mathrm{cok}(P(X_n))$.
For the Haar-random $B_n$, we deduce our result from an interesting
equidistribution result for matrices over $\mathbb{Z}_p[t]/(P(t))$, which we
prove by establishing a version of the Weierstrass preparation theorem for the
noncommutative ring $\mathrm{M}_n(\mathbb{Z}_p)$ of $n \times n$ matrices over
$\mathbb{Z}_p$.
