I was making a windows form project. in the project the user inputs the number of dice rolls he wants(2 dice will be rolled) and then i am suppose to give the number of times each number happened and the percent of times each number happened. The only problem is that i cant make the random number generator generator more than one roll using one name.
namespace Dice_Roll_assignment
{
public partial class diceRoll : Form
{
public diceRoll()
{
InitializeComponent();
}
private void rollDice_Click(object sender, EventArgs e)
{
AcceptButton = rollDice;
if (txtNumRolls.Text.Trim() == "")
{
MessageBox.Show("Must enter number of dice rolls");
}
else if (txtNumRolls.Text.Trim() == "0")
{
MessageBox.Show("Must enter a number greater than 0");
}
diceTotal.Text = "Dice Total" + "\n" + 2 + "\n" + 3 + "\n" + 4 + "\n" + 5 + "\n" + 6 + "\n" + 7 + "\n" + 8 + "\n" + 9 + "\n" + 10 + "\n" + 11 + "\n" + 12;
// This will lead the first label to show the number of dice total
int numRolls = int.Parse(txtNumRolls.Text);// Converting the textBox value to an interger for randGen
SimulateRolls(numRolls);
}
private void SimulateRolls(int iNumRolls)
{
int numrolls = int.Parse(txtNumRolls.Text);
Random randGen = new Random(numrolls);
int[] arrNumOccurrence = new int[13];
// randGen is the new random so we use randGen.Next();
int oneRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
// i want this to occur the number of times inputed
int twoRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
int threeRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
int fourRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
int fiveRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
int sixRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
int sevenRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
int eightRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
int nineRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
int tenRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
int elevenRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
int twelveRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
int thirteenRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
int fourteenRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
if (numrolls == 1)
{
arrNumOccurrence[oneRoll]++;
}
else if (numrolls == 2)
{
arrNumOccurrence[oneRoll]++;
arrNumOccurrence[twoRoll]++;
}
else if (numrolls ==3)
{
arrNumOccurrence[oneRoll]++;
arrNumOccurrence[twoRoll]++;
arrNumOccurrence[threeRoll]++;
}
else if (numrolls == 4)
{
arrNumOccurrence[oneRoll]++;
arrNumOccurrence[twoRoll]++;
arrNumOccurrence[threeRoll]++;
arrNumOccurrence[fourRoll]++;
}
else if (numrolls == 5)
{
arrNumOccurrence[oneRoll]++;
arrNumOccurrence[twoRoll]++;
arrNumOccurrence[threeRoll]++;
arrNumOccurrence[fourRoll]++;
arrNumOccurrence[fiveRoll]++;
}
else if (numrolls == 6)
{
arrNumOccurrence[oneRoll]++;
arrNumOccurrence[twoRoll]++;
arrNumOccurrence[threeRoll]++;
arrNumOccurrence[fourRoll]++;
arrNumOccurrence[fiveRoll]++;
arrNumOccurrence[sixRoll]++;
}
else if (numrolls == 7)
{
arrNumOccurrence[oneRoll]++;
arrNumOccurrence[twoRoll]++;
arrNumOccurrence[threeRoll]++;
arrNumOccurrence[fourRoll]++;
arrNumOccurrence[fiveRoll]++;
arrNumOccurrence[sixRoll]++;
arrNumOccurrence[sevenRoll]++;
}
else if (numrolls == 8)
{
arrNumOccurrence[oneRoll]++;
arrNumOccurrence[twoRoll]++;
arrNumOccurrence[threeRoll]++;
arrNumOccurrence[fourRoll]++;
arrNumOccurrence[fiveRoll]++;
arrNumOccurrence[sixRoll]++;
arrNumOccurrence[sevenRoll]++;
arrNumOccurrence[eightRoll]++;
}
else if (numrolls == 9)
{
arrNumOccurrence[oneRoll]++;
arrNumOccurrence[twoRoll]++;
arrNumOccurrence[threeRoll]++;
arrNumOccurrence[fourRoll]++;
arrNumOccurrence[fiveRoll]++;
arrNumOccurrence[sixRoll]++;
arrNumOccurrence[sevenRoll]++;
arrNumOccurrence[eightRoll]++;
arrNumOccurrence[nineRoll]++;
}
else if (numrolls == 10)
{
arrNumOccurrence[oneRoll]++;
arrNumOccurrence[twoRoll]++;
arrNumOccurrence[threeRoll]++;
arrNumOccurrence[fourRoll]++;
arrNumOccurrence[fiveRoll]++;
arrNumOccurrence[sixRoll]++;
arrNumOccurrence[sevenRoll]++;
arrNumOccurrence[eightRoll]++;
arrNumOccurrence[nineRoll]++;
arrNumOccurrence[tenRoll]++;
}
else if (numrolls == 11)
{
arrNumOccurrence[oneRoll]++;
arrNumOccurrence[twoRoll]++;
arrNumOccurrence[threeRoll]++;
arrNumOccurrence[fourRoll]++;
arrNumOccurrence[fiveRoll]++;
arrNumOccurrence[sixRoll]++;
arrNumOccurrence[sevenRoll]++;
arrNumOccurrence[eightRoll]++;
arrNumOccurrence[nineRoll]++;
arrNumOccurrence[tenRoll]++;
arrNumOccurrence[elevenRoll]++;
}
else if (numrolls == 12)
{
arrNumOccurrence[oneRoll]++;
arrNumOccurrence[twoRoll]++;
arrNumOccurrence[threeRoll]++;
arrNumOccurrence[fourRoll]++;
arrNumOccurrence[fiveRoll]++;
arrNumOccurrence[sixRoll]++;
arrNumOccurrence[sevenRoll]++;
arrNumOccurrence[eightRoll]++;
arrNumOccurrence[nineRoll]++;
arrNumOccurrence[tenRoll]++;
arrNumOccurrence[elevenRoll]++;
arrNumOccurrence[twelveRoll]++;
}
else if (numrolls == 13)
{
arrNumOccurrence[oneRoll]++;
arrNumOccurrence[twoRoll]++;
arrNumOccurrence[threeRoll]++;
arrNumOccurrence[fourRoll]++;
arrNumOccurrence[fiveRoll]++;
arrNumOccurrence[sixRoll]++;
arrNumOccurrence[sevenRoll]++;
arrNumOccurrence[eightRoll]++;
arrNumOccurrence[nineRoll]++;
arrNumOccurrence[tenRoll]++;
arrNumOccurrence[elevenRoll]++;
arrNumOccurrence[twelveRoll]++;
arrNumOccurrence[thirteenRoll]++;
}
else if (numrolls == 14)
{
arrNumOccurrence[oneRoll]++;
arrNumOccurrence[twoRoll]++;
arrNumOccurrence[threeRoll]++;
arrNumOccurrence[fourRoll]++;
arrNumOccurrence[fiveRoll]++;
arrNumOccurrence[sixRoll]++;
arrNumOccurrence[sevenRoll]++;
arrNumOccurrence[eightRoll]++;
arrNumOccurrence[nineRoll]++;
arrNumOccurrence[tenRoll]++;
arrNumOccurrence[elevenRoll]++;
arrNumOccurrence[twelveRoll]++;
arrNumOccurrence[thirteenRoll]++;
arrNumOccurrence[fourteenRoll]++;
}
numTimes.Text = "# of Times\n" + arrNumOccurrence[2]++ + "\n" + arrNumOccurrence[3]++ + "\n" + arrNumOccurrence[4]++ + "\n" + arrNumOccurrence[5]++ + "\n" + arrNumOccurrence[6]++ + "\n" + arrNumOccurrence[7]++ + "\n" + arrNumOccurrence[8]++ + "\n" + arrNumOccurrence[9]++ + "\n" + arrNumOccurrence[10]++ + "\n" + arrNumOccurrence[11]++ + "\n" + arrNumOccurrence[12]++ + "\n";
// Now This tallys the thing that happens only once
}