M
Muffin
I hope somebody can show me why I need to have a messagebox to get "random"
numbers in my example. If I comment out the message box call that is in
RollAbility() the numbers generated are not random , otherwise it works
fine. I really would like to get rid of the messagebox call.
thx
static class Die
{
public static int Roll(int numberOfSides)
{
Random die= new Random();
return die.Next(1, numberOfSides+1);
}
public static int RollAbility(out string rollResults, int
numberOfDice)//this will be called with more that 4 dice
{
string _rollResults="";
Random die = new Random();
List<int> abilityRolls = new List<int>();
for (int i = 0; i < numberOfDice; i++)
{
abilityRolls.Add(die.Next( 1,7));
}
abilityRolls.Sort();
abilityRolls.Reverse();
for (int i = 0; i < numberOfDice; i++)
{
_rollResults = _rollResults + abilityRolls.ToString()
+ ",";
}
rollResults = _rollResults;
MessageBox.Show(rollResults, "Dice Roles");//if this is commented
out the numbers are not random
return abilityRolls[0] + abilityRolls[1] + abilityRolls[2]; ;
}
}
numbers in my example. If I comment out the message box call that is in
RollAbility() the numbers generated are not random , otherwise it works
fine. I really would like to get rid of the messagebox call.
thx
static class Die
{
public static int Roll(int numberOfSides)
{
Random die= new Random();
return die.Next(1, numberOfSides+1);
}
public static int RollAbility(out string rollResults, int
numberOfDice)//this will be called with more that 4 dice
{
string _rollResults="";
Random die = new Random();
List<int> abilityRolls = new List<int>();
for (int i = 0; i < numberOfDice; i++)
{
abilityRolls.Add(die.Next( 1,7));
}
abilityRolls.Sort();
abilityRolls.Reverse();
for (int i = 0; i < numberOfDice; i++)
{
_rollResults = _rollResults + abilityRolls.ToString()
+ ",";
}
rollResults = _rollResults;
MessageBox.Show(rollResults, "Dice Roles");//if this is commented
out the numbers are not random
return abilityRolls[0] + abilityRolls[1] + abilityRolls[2]; ;
}
}