2
0

showdist.rb 581 B

123456789101112131415161718192021222324252627282930313233
  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. 100.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. # Convert into frequency distribution
  19. dist = {}
  20. freq.each{|item,count|
  21. dist[count] = 0 if dist[count] == nil
  22. dist[count] += 1
  23. }
  24. min = dist.keys.min
  25. max = dist.keys.max
  26. (min..max).each{|x|
  27. count = dist[x]
  28. count = 0 if count == nil
  29. puts "#{x} -> #{"*"*count}"
  30. }