Given that one can sample unitaries from the Haar measure over $U(n)$ (as in [F. Mezzadri, Notices of the AMS 54 (2007), 592-604](https://arxiv.org/abs/math-ph/0609050)), how can one sample from the uniform distribution over the following subgroup,
$$
\mathcal{B} = \{ A \in U(n) : [A, B] = 0 \},
$$
where $B$ is another, fixed unitary in $U(n)$?



Haar unitaries with constraints
I assume all eigenvalues of $B$ are distinct, so that $B$ has a unique set of eigenvectors. Because of the constraint $[A,B]=0$, you wish to sample over unitary matrices $A$ that have the same set of eigenvectors as $B$, hence only the eigenvalues $e^{i\phi\_1},e^{i\phi\_2},\ldots e^{i\phi\_n}$ of $A$ matter. To achieve uniformity (meaning for any $A$ and $C$ in ${\cal B}$ both $A$ and $AC$ are sampled with the same probability) the distribution of the phases should leave $P(\phi\_1,\phi\_2,\ldots\phi\_n)$ invariant when any $\phi\_k\mapsto \phi\_k+\delta\phi$, $k\in\{1,2,\ldots n\}$, for arbitrary increment $\delta\phi$. To ensure that, take uniform distributions in $(0,2\pi]$, independently for each $\phi\_k$.


