Begin merging randomization inference code

This code is entirely untested and incomplete. Do not use.