title: How to make randomizer randomize till it's the right number
body: <p>I'm making a sudoku game and at first I'm doing small version 3x3. After some coding I couldn't find a way to:</p>
  
  <p>How do I make S randomise till its the right number (S randomizes, Skaiciai.Neradau means it didn't find a repeating number, Skaiciai.Yra_Toks_Skaicius means he found the same number already used)</p>
  
  <p>EDIT: redone in English</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  namespace _3x3
  {
      public partial class Form1 : Form
      {
          TextBox[] Boxes;
  
          public Form1()
          {
              InitializeComponent();
              Boxes = new TextBox[] { textBox1, textBox2, textBox3};
          }
  
          public enum Numbers
          {
              Found_Number,
              NotFound
          };
  
          private void button1_Click(object sender, EventArgs e)
          {
              Random X = new Random();
  
              for (int i = 0; i &lt; 3; i++)
              {
                  int S = X.Next(1, 4);
  
                  switch (i)
                  {
                      case 0:
                          int A, B;
                          if (textBox2.Text == "") { A = 0; } else { A = int.Parse(textBox2.Text); }
                          if (textBox3.Text == "") { B = 0; } else { B = int.Parse(textBox3.Text); }
                          Numbers R = CheckIfThereIsNumber(S, new int[] { A, B });
                          if (R == Numbers.NotFound)
                          {
                              textBox1.Text = S.ToString();
                          }
                          break;
                      case 1:
                          int C, D;
                          if (textBox1.Text == "") { C = 0; } else { C = int.Parse(textBox1.Text); }
                          if (textBox3.Text == "") { D = 0; } else { D = int.Parse(textBox3.Text); }
                          Numbers T = CheckIfThereIsNumber(S, new int[] { C, D });
                          if (T == Numbers.NotFound)
                          {
                              textBox2.Text = S.ToString();
                          }
                          break;
                      case 2:
                          int E, F;
                          if (textBox1.Text == "") { E = 0; } else { E = int.Parse(textBox1.Text); }
                          if (textBox2.Text == "") { F = 0; } else { F = int.Parse(textBox2.Text); }
                          Numbers Y = CheckIfThereIsNumber(S, new int[] { E, F });
                          if (Y == Numbers.NotFound)
                          {
                              textBox3.Text = S.ToString();
                          }
                          break;
                  }
              }
          }
  
          Numbers CheckIfThereIsNumber(int _searchednumber, int[] _numbers)
          {
              Numbers Result = Numbers.NotFound;
              for (int i = 0; i &lt; _numbers.Length; i++)
              {
                  if (_numbers[i] == _searchednumber)
                  {
                      Result = Numbers.Found_Number;
                  }
              }
              return Result;
          }
      }
  }
  </code></pre>