Alexei's rho-sampling implementation.