Question: Hi everyone I am trying to generate 6 different numbers on the same line in c# but the problem that i face is some of the numbers are repeating on the same line.Here is my code to

```
var rand = new Random();
List<int> listNumbers = new List<int>();
int numbers = rand.Next(1,49);
for (int i= 0 ; i < 6 ;i++)
    {
         listNumbers.Add(numbers);
         numbers = rand.Next(1,49);
    }

```

somewhere my output is

```
17 23 23 31 33 48

```

Answer: 
```
listNumbers.AddRange(Enumerable.Range(1, 48)
                               .OrderBy(i => rand.Next())
                               .Take(6))

```
```
   public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        int[] que = new int[6];
        int x, y, z;
        Random ran = new Random();            
        for ( x = 0; x < 6; x++)
        {
            que[x] = ran.Next(1,49);
            for (y = x; y >= 0; y--)
            {
                if (x == y)
                {
                    continue;
                }
                if (que[x] == que[y])
                {
                    que[x] = ran.Next(1,49);
                    y = x;
                }

            }
        }
        listBox1.Items.Clear();
        for (z = 0; z < 6; z++)
        {
            listBox1.Items.Add(que[z].ToString());
        }
    }
}

```