Separated out most of the logic in sampleByKey

into StratifiedSampler in util.random