Last active
June 23, 2018 12:54
-
-
Save todorok1/0fb543e73f023aeddf23fd18f007305e 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
// メンバ変数を追加 | |
// 抽選結果を保持する辞書 | |
Dictionary<int, int> itemResultDict; | |
// 抽選回数 | |
int rollNum = 10000; | |
void GetDropItem(){ | |
// 各種辞書の初期化 | |
InitializeDicts(); | |
// ここから確認用 | |
for (int i = 0 ; i < rollNum; i++){ | |
int itemId = Choose(); | |
if (itemResultDict.ContainsKey(itemId)){ | |
itemResultDict[itemId]++; | |
} else { | |
itemResultDict.Add(itemId, 1); | |
} | |
} | |
foreach (KeyValuePair<int, int> pair in itemResultDict){ | |
string itemName = itemInfo[pair.Key]; | |
Debug.Log(itemName + " は " + pair.Value + " 回でした。"); | |
} | |
} | |
void InitializeDicts(){ | |
// 中略 | |
itemResultDict = new Dictionary<int, int>(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment