So I have a die roll application ...
When I look at the code, it functions normally, and the "results" contain the correct number of throw results, and they seem random when I leave the code to run and do exactly the same thing that it creates a set of identical numbers.
I am sure that this is a logical mistake that I do not see, but messing with it for several hours did not improve the situation, so any help is significant. :)
class Dice
{
public int[] Roll(int _throws, int _sides, int _count)
{
Random rnd = new Random();
int[] results = new int[_throws];
for (int i = 0; i < _throws; i++)
{
int thisThrow = Calculate(_sides, _count);
results[i] = thisThrow;
}
return results;
}
private int Calculate(int _sides, int _count)
{
Random rnd = new Random();
int[] result = new int[_count];
int total = 0;
for (int i = 0; i < _count; i++)
{
result[i] = rnd.Next(1, _sides);
}
for (int x = 0; x < _count; x++)
{
total = total + result[x];
}
return total;
}
}
source
share