Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, the following for-loop is wrong:</p> <pre><code>for (Int32 i = 0; i &lt; _DiceSize; i++) { roll[i] = rnd.Next(1,_NoOfDice); } </code></pre> <p>Obviously you switched _DiceSize and _NoOfDice. The correct loop would look like</p> <pre><code>for (Int32 i = 0; i &lt; _NoOfDice; i++) { roll[i] = rnd.Next(1,_DiceSize); } </code></pre> <p>Because of that, the line</p> <pre><code>Int32[] roll = new Int32[_DiceSize]; </code></pre> <p>has to be changed to</p> <pre><code>Int32[] roll = new Int32[_NoOfDice]; </code></pre> <p>Maybe you should think about renaming these variables, so it's more clearly, which means what.</p> <p>If you modify your code that way, you will mention that your analisys won't work that way you implemented it. Actually, what you are showing is the result of each throw, which is not what you want, if I understood you right.</p> <p>UPDATE:</p> <p>Sorry, I misunderstood you. You do want to show the result for every roll. So, why don't you just move the StringBuilder.AppendFormat to your "rolling-for-loop"?</p> <p>UPDATE #2:</p> <p>For me, the following Die-class works exactly the way you want it:</p> <pre><code>public class Die { private int maxValue; private int numberOfRolls; private Random random; public Die(int maxValue, int numberOfRolls) { this.maxValue = maxValue; this.numberOfRolls = numberOfRolls; this.random = new Random(); } public string Roll() { StringBuilder resultString = new StringBuilder(); for (int i = 0; i &lt; this.numberOfRolls; i++) { resultString.AppendFormat("Roll #{0} - Result: {1}" + Environment.NewLine, i + 1, this.random.Next(1, maxValue + 1)); } return resultString.ToString(); } } </code></pre> <p>Hope I could help you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload