Skip to content

Instantly share code, notes, and snippets.

@martint
Created January 17, 2012 19:03
Show Gist options
  • Save martint/1628169 to your computer and use it in GitHub Desktop.
Save martint/1628169 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
limit = ARGV[0].to_i
result = Array.new(limit)
count = 0
STDIN.each_line do |line|
if count < limit
result[count] = line
else
j = rand(count + 1)
result[j] = line if j < limit
end
count += 1
end
result.each { |l| print l }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment