Skip to content

Instantly share code, notes, and snippets.

@tatat
Last active January 17, 2016 20:53
Show Gist options
  • Save tatat/aaa4d2d1c7bb1f1ee7a9 to your computer and use it in GitHub Desktop.
Save tatat/aaa4d2d1c7bb1f1ee7a9 to your computer and use it in GitHub Desktop.
ITEMS_BASIC = [
[:R, 82],
[:SR, 15],
[:SSR, 3],
]
ITEMS_SPECIAL = [
[:SR, 97],
[:SSR, 3],
]
def gacha(items)
total = items.map(&:last).reduce(:+)
current = Random.rand(total)
items.find {|(_, weight)| (current -= weight) <= 0 }[0]
end
result = Array.new(9) { gacha(ITEMS_BASIC) }
if result.include?(:SR) || result.include?(:SSR)
result << gacha(ITEMS_BASIC)
else
result << gacha(ITEMS_SPECIAL)
end
puts "[#{result.join(', ')}]"
puts result.include?(:SSR) ? "SSRが#{result.count {|i| i == :SSR}}つあります!!!" : "SSRはありませんでした。"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment