summaryrefslogtreecommitdiff
path: root/sample
diff options
context:
space:
mode:
Diffstat (limited to 'sample')
-rwxr-xr-xsample25
1 files changed, 25 insertions, 0 deletions
diff --git a/sample b/sample
new file mode 100755
index 0000000..b4706c6
--- /dev/null
+++ b/sample
@@ -0,0 +1,25 @@
+#!/usr/bin/env ruby
+
+require 'trollop'
+
+
+STDIN.set_encoding 'utf-8'
+STDOUT.set_encoding 'utf-8'
+
+def usage
+ STDERR.write "./sample --size <n> < <line separated data>\n"
+ exit 1
+end
+usage if ARGV.size!=4
+
+opts = Trollop::options do
+ opt :size, "Sample n% (percentage).", :type => :int
+end
+
+
+prng = Random.new(Random.new_seed)
+
+while line = STDIN.gets
+ STDOUT.write line if prng.rand(1..opts[:size])==0
+end
+