Here are three versions I wrote, in order.  Definitely not fast, but
they work.

# Version 1
(k, n) = ARGV.map { |s| s.to_i }
n.times do |i|
   r = rand * (n - i)
   unless (k < r)
      puts i
      k -= 1
   end
end


# Version 2
(k, n) = ARGV.map { |s| s.to_i }
puts (0...n).sort_by { rand }[0...k].sort!


# Version 3
(k, n) = ARGV.map { |s| s.to_i }
x = (0...n).to_a
k.times do |i|
   r = i + rand(n - i)
   x[i],x[r] = x[r],x[i]
end
x[0...k].sort