Nearly early filling of 2-string C#



  • There's a 5x5. We need to fill it with zeros, and two elements randomly selected by units.



  • You really need to pick two random indexes from 0 to 24.

    Itple easier to do so using standard Random:

    1. Help

      i1 = random.Next(25)
      

      You get the first index.

    2. For the second index, 24 values remain, but all values not equal. i1♪ It's the best way to write this:

      i2 = random.Next(24);
      if (i2 >= i1) i2++;
      

    Okay, now you have to turn every index into a double index of 0 to 4. This is done with help.

    x = i / 5;
    y = i % 5;
    

    It's more obvious. Fill the pool of zeros on the two items counted.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2