Last active
January 17, 2016 20:53
-
-
Save tatat/aaa4d2d1c7bb1f1ee7a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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