Code for the http://randomalgorithms.blogspot.com/2014/11/randomsample-divpadding-top0.html post