Skip to content

Instantly share code, notes, and snippets.

@cvonkleist
Created August 24, 2012 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cvonkleist/3455471 to your computer and use it in GitHub Desktop.
Save cvonkleist/3455471 to your computer and use it in GitHub Desktop.
line_starts = []
filename = "/usr/share/dict/words"
# preprocess
File.open(filename, "r") do |input|
until input.eof?
pos = input.pos
input.readline
line_starts << pos
end
end
# random sort, retrieve from file
line_starts.shuffle!
File.open(filename, "r") do |input|
until line_starts.empty?
input.seek(line_starts.shift)
puts input.readline
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment