daily pastebin goal
91%
SHARE
TWEET

Untitled

a guest May 27th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/ruby
  2.  
  3. filename = "test.txt"
  4.  
  5. def mkrandom length, max, array
  6.   if length > 0
  7.     r = rand(max)
  8.     unless array.include? r
  9.       array << r
  10.       length -= 1
  11.     end
  12.     mkrandom length, max, array
  13.   else
  14.     array
  15.   end
  16. end
  17.  
  18. lines = File.readlines(filename)
  19.  
  20. ra = mkrandom 2, lines.size, []
  21.  
  22. i = 0
  23. lines.each do |line|
  24.   if ra.include? i
  25.     puts line
  26.   end
  27.   i += 1
  28. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top