showfreq.rb 424 B

1234567891011121314151617181920212223
  1. require 'redis'
  2. r = Redis.new
  3. r.select(9)
  4. r.del("myset");
  5. r.sadd("myset",(0..999).to_a)
  6. freq = {}
  7. 500.times {
  8. res = r.pipelined {
  9. 1000.times {
  10. r.srandmember("myset")
  11. }
  12. }
  13. res.each{|ele|
  14. freq[ele] = 0 if freq[ele] == nil
  15. freq[ele] += 1
  16. }
  17. }
  18. # Print the frequency each element was yeld to process it with gnuplot
  19. freq.each{|item,count|
  20. puts "#{item} #{count}"
  21. }