Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
異なる発生確率の抽選をするよ
// メンバ変数を追加
// 抽選結果を保持する辞書
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
You can’t perform that action at this time.