49 lines
1.1 KiB
C#
49 lines
1.1 KiB
C#
|
|
using System.Collections.Generic;
|
|||
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
public class RandomSelect : MonoBehaviour
|
|||
|
|
{
|
|||
|
|
public List<Card> deck = new List<Card>();
|
|||
|
|
public int total = 0;
|
|||
|
|
public List<int> result = new List<int>();
|
|||
|
|
|
|||
|
|
public void ResultSelect()
|
|||
|
|
{
|
|||
|
|
int randomIndex = RandomCard();
|
|||
|
|
result[randomIndex]++;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private int RandomCard()
|
|||
|
|
{
|
|||
|
|
int weight = 0;
|
|||
|
|
int selectNum = Mathf.RoundToInt(total * Random.Range(0.0f, 1.0f));
|
|||
|
|
for (int i = 0; i < deck.Count; i++)
|
|||
|
|
{
|
|||
|
|
weight += deck[i].weight;
|
|||
|
|
if (selectNum <= weight)
|
|||
|
|
{
|
|||
|
|
return i;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void Start()
|
|||
|
|
{
|
|||
|
|
for (int i = 0; i < deck.Count; i++)
|
|||
|
|
{
|
|||
|
|
total += deck[i].weight;
|
|||
|
|
result.Add(0); // <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>Ʈ <20>ʱ<EFBFBD>ȭ
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
for (int i = 0; i < 10000; i++)
|
|||
|
|
{
|
|||
|
|
ResultSelect(); // ī<><C4AB> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
for (int i = 0; i < result.Count; i++)
|
|||
|
|
{
|
|||
|
|
Debug.Log(result[i]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|