Random as you use it is initialized with a seed derived from your DateTime.Now - you use it to generate a number between 0 and 4 (exluded) - so 25% of the time you'll get the same number:
using System;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
Random x= new Random();
List<int> ints = new List<int>();
for(int i=0; i< 100; i++) ints.Add(x.Next(4));
Console.WriteLine(string.Join(", ",ints));
}
}
Output (reformatted):
3, 0, 1, 1, 1, 1, 3, 0, 2, 0, 1, 2, 1, 0, 3, 1, 3, 0, 2, 2, 3, 1, 1, 2, 1,
2, 3, 3, 2, 3, 3, 2, 0, 3, 3, 3, 0, 0, 3, 0, 2, 1, 3, 3, 1, 0, 2, 1, 3, 0,
2, 2, 3, 3, 1, 1, 2, 3, 3, 2, 2, 0, 2, 2, 1, 2, 2, 1, 1, 3, 1, 3, 1, 2, 0,
2, 2, 1, 0, 1, 3, 1, 0, 1, 1, 1, 2, 0, 2, 1, 1, 0, 0, 0, 1, 2, 3, 0, 2, 2
It produces different ones. You were just un-lucky.
You should move the declaration Random x=new Random()
(badname btw) outside where you use it, so you do not create it over and over again, maybe getting the similar runs for "different" seeds based on your time. You can have the same 100 digits in different seeded runs of Random (by chance). Random does not mean different, especially if you only use 4 values to mapp all your randomness to.
After the remark in the comment - Illustrate "same" starting sequences for different random seeds:
using System;
using System.Linq;
using System.Collections.Generic;
public class Program
{
static IEnumerable<int> FirstNumbersFromSeed(int seed, int num)
{
var r = new Random(seed);
for (int i=0;i<num;i++)
yield return r.Next(4);
}
public static void Main()
{
Dictionary<string,List<int>> dict = new Dictionary<string,List<int>>();
int num = 5;
for (int i =0;i<2000; i++)
{
var key = string.Join(",",FirstNumbersFromSeed(i,num));
if (dict.ContainsKey(key)) dict[key].Add(i);
else dict[key] = new List<int>(i);
}
foreach(var kvp in dict.Where(d => d.Value.Count > 1))
Console.WriteLine(string.Join(", ",kvp.Key) + " same first " + num + " values for seed with ints: " + string.Join(",",kvp.Value));
}
}
Output:
2,3,3,2,0 same first 5 values for seed with ints: 239,890
0,0,1,3,2 same first 5 values for seed with ints: 1463,1576
3,1,0,3,0 same first 5 values for seed with ints: 540,653,1876
1,1,1,2,1 same first 5 values for seed with ints: 656,769,895
<snipped 300 more output lines>
1,0,1,3,3 same first 5 values for seed with ints: 1862,1988
So you have about 305 "collisions" which deliver the same 5 starting "random" values for seeds between 0 and 2000 if you draw random values from 0 to 4(exclusive).