added random sampling option

@robertzk please review. I've tested it and it should work