  Markov-chain Monte Carlo algorithms rely on trial moves that are either
rejected or accepted based on certain criteria. Here, we provide an efficient
algorithm to generate random rotation matrices in four dimensions (4D) covering
an arbitrary pre-defined range of rotation angles. The matrices can be combined
with Monte Carlo methods for the efficient sampling of the SO(4) group of 4D
rotations. The matrices are unbiased and constructed such that repeated
rotations result in uniform sampling over SO(4). 4D rotations can be used to
optimize the mass partitioning for stable time integration in coarse-grained
molecular dynamics simulations and should find further applications in the
fields of robotics and computer vision.
