summaryrefslogtreecommitdiff
path: root/rl
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2015-07-05 20:00:27 +0200
committerPeter Palfrader <peter@palfrader.org>2015-07-05 20:00:27 +0200
commit521b4fda832cfb338d518533c7616faf0bc31a76 (patch)
tree80501de24d887906fa4610cf880b94e3d08b0318 /rl
parent252a5024d8a90c27a039aad9f55797dff2c4a42f (diff)
Support sampling
Diffstat (limited to 'rl')
-rwxr-xr-xrl12
1 files changed, 10 insertions, 2 deletions
diff --git a/rl b/rl
index 316e23c..e5a6a92 100755
--- a/rl
+++ b/rl
@@ -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='')