Update: my problem has been solved, I updated the code source in my question to match with Jason\'s answer. Note that rikitikitik answer is solving the issu
You could do this:
Card GetCard(List cards)
{
int total = 0;
foreach (Card c in cards)
{
total += AttributionRate;
}
int index = Random.Next(0, total - 1);
foreach(Card c in cards)
{
index -= c.AttributionRate;
if (index < 0)
{
return c;
}
}
}
Card PopCard(List cards)
{
Card c = GetCard(cards);
cards.Remove(c);
}
In theory this should work.