# -*- coding: utf-8 -*-
$LOAD_PATH.unshift "../lib"
require "lottery_box"
require "pp"
box = [
  {:robj => "S", :rate => 0.01},
  {:robj => "A", :rate => 0.1},
  {:robj => "B", :rate => 0.2},
  {:robj => "C"},
]

# 普通の使い方
LotteryBox.pick(box)            # => "C"

# 分布数を確認する例
10000.times.each_with_object(Hash.new(0)){|*, m| m[LotteryBox.pick(box)] += 1 }.sort_by{|k, v|v} # => [["S", 85], ["A", 1012], ["B", 1978], ["C", 6925]]

# 各レートをパーセンテージに変換する例
LotteryBox::Base.new(box).table.each do |e|
  p e.summary
end

require "org_tp"
tt LotteryBox::Base.new(box).table.collect(&:to_h)

puts LotteryBox.summary(box)

# >> "   1.00 %  S"
# >> "  10.00 %  A"
# >> "  20.00 %  B"
# >> "  69.00 %  C"
# >> +-------------------------------------------------------------------------------+-------------------------------------+------+
# >> | range                                                                         | rate                                | robj |
# >> +-------------------------------------------------------------------------------+-------------------------------------+------+
# >> | 0/1...5764607523034235/576460752303423488                                     | 5764607523034235/576460752303423488 | S    |
# >> | 5764607523034235/576460752303423488...63410682753376587/576460752303423488    |  3602879701896397/36028797018963968 | A    |
# >> | 63410682753376587/576460752303423488...178702833214061291/576460752303423488  |  3602879701896397/18014398509481984 | B    |
# >> | 178702833214061291/576460752303423488...576460752303423499/576460752303423488 | 12429934971542569/18014398509481984 | C    |
# >> +-------------------------------------------------------------------------------+-------------------------------------+------+
# >> +---------+------+
# >> | 確率(%) | robj |
# >> +---------+------+
# >> |    1.00 | S    |
# >> |   10.00 | A    |
# >> |   20.00 | B    |
# >> |   69.00 | C    |
# >> +---------+------+
