modified test, val, rank to support rand num