This question has already been answered:

Something confuses me with random ...

public class Rand { List<int> tmp = new List<int>(); int max; int[] array; public Rand(int max) { this.max = max; array = new int[max]; for (int i = 0; i < this.max; i++) { tmp.Add(i); } } public int[] Next() { int t; for (int i = max-1; i >= 0; i--) { t = new Random().Next(i); array[i] = tmp[t]; tmp.RemoveAt(t); } return array; } } 

Why the random always looks like this enter image description here enter image description here

Not too random

And if about the task as a whole, you need to make an array of random numbers, but so that the numbers do not repeat

Reported as a duplicate by AK , tym32167 , Andrey NOP participants c # Nov 8 '18 at 9:33 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • If the proposed duplicate is not suitable - then apparently you need to explain what law of random number distribution you want to see (normal distribution or something more specific). - AK

1 answer 1

 t = new Random().Next(i); 

Take the generator to a separate variable (you can even in a static field) and do not recreate it.

  • Thanks a lot, your answer made the random more random, but the last number is still 1999 always, and with the rest it’s not even bad, but I think this is my joint (like the previous one) - Matrzaei
  • @Matrzaei Random never gives a number equal to the upper limit - and this is clearly described in the documentation . - AK
  • Okey, thanks again, very helpful) - Matrzaei