title: Mono Getting the same sequence using Random
body: <p>When I run the following code in Mono (and not in Microsoft's C# apparently) in the monodevelop IDE.  I get the same sequence of random numbers every time (00111111110110001001). If I change the range to something else e.g. r.Next(0, 5) then I do get random values.  This seems very weird to me .. is this a bug or am I doing something dumb?</p>
  
  <p>NOTE: it seems sometimes these numbers are negated.. e.g. I see 11000000001001110110 occasionally.</p>
  
  <pre><code>using System;
  
  namespace TestRNG
  {
      class MainClass
      {
          public static void Main (string[] args)
          {
              Random r = new Random ();
              for (int i = 0; i &lt; 20; i++) {
                  Console.Write(r.Next(0, 2));
              }
              Console.WriteLine();
          }
      }
  }
  </code></pre>
  
  <p>This is not the "Calling Next() on instances of Random called too closely together and therefore seeded with the same seed from the system clock problem".  </p>
  
  <p>Using the following code:</p>
  
  <pre><code>using System;
  
  namespace TestRNG
  {
      class MainClass
      {
          public static void Main (string[] args)
          {
              Random r = new Random (Guid.NewGuid().ToByteArray()[0]);
              for (int i = 0; i &lt; 20; i++) {
                  int rn = r.Next ();
                  Console.WriteLine(rn + " " + (rn % 2));
              }
              Console.WriteLine();
          }
      }
  }
  </code></pre>
  
  <p>I see that I get different values for rn every time but the sequence of values for rn % 2, which is what I suspect r.Next() is returning, is the same old values I always see.  This leads me to believe that the Russian? fellow who posted an answer before and was down-voted to oblivion was correct (he's subsequently removed his answer).  See <a href="http://eternallyconfuzzled.com/arts/jsw_art_rand.aspx" rel="nofollow">http://eternallyconfuzzled.com/arts/jsw_art_rand.aspx</a> for example.</p>
  
  <p>Based on one of the comments below this may only be a mono implementation thing.</p>