diff options
author | Peter Palfrader <peter@palfrader.org> | 2015-07-05 20:00:27 +0200 |
---|---|---|
committer | Peter Palfrader <peter@palfrader.org> | 2015-07-05 20:00:27 +0200 |
commit | 521b4fda832cfb338d518533c7616faf0bc31a76 (patch) | |
tree | 80501de24d887906fa4610cf880b94e3d08b0318 /rl | |
parent | 252a5024d8a90c27a039aad9f55797dff2c4a42f (diff) |
Support sampling
Diffstat (limited to 'rl')
-rwxr-xr-x | rl | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -28,13 +28,21 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - +import argparse import random import sys +parser = argparse.ArgumentParser(description='Process some integers.') +parser.add_argument('-s', '--sample', metavar='LINES', type=int, nargs='?', const=1, help='Print only this many lines (1).') +args = parser.parse_args() + lines = sys.stdin.readlines() -random.SystemRandom().shuffle(lines) +r = random.SystemRandom() +if args.sample is None: + r.shuffle(lines) +else: + lines = r.sample(lines, args.sample) for l in lines: print(l, end='') |