Created
July 26, 2021 09:18
-
-
Save recuraki/184a6e613cd45aa32b4b06be3d4e1ebf to your computer and use it in GitHub Desktop.
ガチャシミュレーション
This file contains hidden or 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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
ガチャシミュレーション | |
./try.py [percent] [kai] | |
percentパーセント(1.5%なら1.5と入力)であたりがでるガチャを、あたりが出るまで引きます。 | |
これをkai回試して、何回で引くことができたかの分布を出力します。 | |
実行例 | |
./try2.py 1.5 100 | |
1回で引けたのは1回 | |
2回で引けたのは1回 | |
3回で引けたのは3回 | |
... | |
247回で引けたのは1回 | |
261回で引けたのは1回 | |
581回で引けたのは1回 | |
> 1.5%であたりが引けるはずですが、580回引いても当たらないこともあります | |
""" | |
import sys, random, collections | |
percent, trycount = float(sys.argv[1]), int(sys.argv[2]) | |
assert percent >= 0.001 | |
percent *= 100 * 1000 | |
result=collections.defaultdict(int) | |
for _ in range(trycount): | |
cnt = 1 | |
while random.randint(0, 10000000) >= percent: cnt += 1 | |
result[cnt] += 1 | |
for kai in sorted(list(result.keys())): print("{0}回で引けたのは{1}回".format(kai, result[kai])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment