tshm
1/31/2014 - 8:27 AM

random_doubtful.rb

#!/usr/bin/env ruby

def sample(n, m)
  if m.zero?
    []
  else
    s = sample(n-1, m-1)
    t = [rand(n+1)]
    s.concat(s.include?(t) ? n : t)
  end
end

n,m = [100,50]
a = [];
1000.times {
  a.concat(sample(n,m));
}

h = Array.new(n+1,0)
a.each {|x|
  h[x] += 1
}
n.times {|x|
  print "#{x} #{h[x]}\n"
}