좋아요. 주사위를 던지려면 ...C# 코드는 단계별로 예상 결과 만 제공합니까?
코드를 단계별로 실행하면 정상적으로 작동하며 '결과'에 정확한 수의 결과가 포함되어 있으며 코드를 남겨 둘 때 임의로 표시됩니다. 똑같은 번호를 만들어 낸 것과 똑같은 일을합니다.
나는 이것이 볼 수없는 논리적 오류라고 확신하지만 몇 시간 동안은 그다지 신경 쓰지 않아도 상황이 개선되지 않으므로 도움이 많이 필요하다. :)
class Dice
{
public int[] Roll(int _throws, int _sides, int _count)
{
Random rnd = new Random();
int[] results = new int[_throws];
// for each set of dice to throw pass data to calculate method
for (int i = 0; i < _throws; i++)
{
int thisThrow = Calculate(_sides, _count);
//add each throw to a new index of array... repeat for every throw
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 each dice to throw put data into result
for (int i = 0; i < _count; i++)
{
result[i] = rnd.Next(1, _sides);
}
//count the values in result
for (int x = 0; x < _count; x++)
{
total = total + result[x];
}
//return total of all dice to Roll method
return total;
}
}
감사 수정 :) – Yoda
젠장 빨리 그려! –
@Ian : 나는 이것을 즉시 발견하지 못하여 너무 많은 일이 일어나는 것을 보았습니다. – leppie