title: How do random numbers from the random object work?
body: <p>if I have this:
  (I already declared the variables)</p>
  
  <pre><code>random1 = new Random();
  Console.WriteLine(random1.Next(1, 100));
  Console.WriteLine(random1.Next(1, 100));
  </code></pre>
  
  <p>When I have that, it'll generate a different number for every time I call console.writeline, so this would generate ex. 10, 55 and if you do it again 20,60 so basically random numbers each time, good.
  But when I add this:</p>
  
  <pre><code>random2 = new Random();
  Console.WriteLine(random1.Next(1, 100));
  Console.WriteLine(random1.Next(1, 100));
  Console.WriteLine(random2.Next(1, 100));
  Console.WriteLine(random2.Next(1, 100));
  </code></pre>
  
  <p>Random1 will generate the same numbers as random! So it will be ex. 5,54,5,54 and if i do it again 70,34,70,34. But it's random2 is a new object so why is it generating the same numbers as random1??</p>
  
  <p>Another example: 
  If I have class like this </p>
  
  <pre><code> class RandomNumber
      {
          Random random = new Random();
          public int getrandomnumber { get { return random.Next(1, 5); } }
      }
  </code></pre>
  
  <p>After doing this</p>
  
  <pre><code>randomnumberobject = new RandomNumber();
  randomnumberobject2 = new RandomNumber();
  Console.WriteLine(randomnumberobject.getrandomnumber);
  Console.WriteLine(randomnumberobject2.getrandomnumber);
  </code></pre>
  
  <p>They'll generate a random number, but both of them will generate the exact same random number. So first time i'd get this 5,5 second time this 3,3 and so on.
  But if I change the class to this</p>
  
  <pre><code>class RandomNumber
      {
          Random random;
          public int getrandomnumber { get { return random.Next(1, 5); } }
          public RandomNumber(Random random) { this.random = random; }
      }
  </code></pre>
  
  <p>And do this instead</p>
  
  <pre><code>   random = new Random();
     randomnumberobject = new RandomNumber(random);
     randomnumberobject2 = new RandomNumber(random);
     Console.WriteLine(randomnumberobject.getrandomnumber);
     Console.WriteLine(randomnumberobject2.getrandomnumber);
  </code></pre>
  
  <p>Suddenly, they both generate different random numbers! So why does this happen? What's the reason? Keep in mind, I'm still kind of a beginner.</p>