I've encountered a strange problem with a c# program. The purpose of the program is to roll dice and display their outputs. The Logic for the program is fine and only works for reason when I output to a message box. Here's teh code:
private void btnRoll_Click(object sender, EventArgs e)
{
lbDice.Items.Clear();
int[] rolls = new int[13];
for (int i = 1; i < numTxt.Value; i++) {
int index = new Random().Next(1, 7) + new Random().Next(1, 7);
//MessageBox.Show(index + ""); THIS LINE IS REQUIRED
rolls[index] += 1;
}
updateList(rolls);
}
public void updateList(int[] rolls)
{
for (int i = 1; i < rolls.Length; i++)
{
lbDice.Items.Add("" + i + " " + rolls[i]);
}
}
If it's not there, the program will only add 1 to each index.