What exactly do you mean by "should not be repeated"? If you mean that you do not want to receive any duplicates, then you should basically take a list of numbers 1-20, shuffle them, and then grab one from the list header. For effective shuffling of a list, see this answer .
If you just mean that your current attempt gives 5, 5, 5, 5, 5, 5, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, and etc. then, most likely, you create a new instance of Random every time you select a number: do not do this. Each time you create an instance, it will use the current time as a "seed" for a random number generator (unless you specify it explicitly). This means that if you create multiple instances in quick succession, each will receive the same seed and therefore will give the same sequence of numbers.
Instead, use one instance of Random and reuse it. (Note that this is not thread safe, although it is a pain.) For example:
private static readonly Random Rng = new Random(); public int NextNumber() { return Rng.Next(20) + 1; }
This will not be thread safe, but let us know if this is a problem. An alternative is sometimes to pass Random to a method (which, of course, will, of course, be more complicated, of course):
public int NextNumber(Random rng) { return rng.Next(20) + 1; }
then the caller can reuse the instance accordingly.
If you need a thread-safe way to generate random numbers, you can look at my StaticRandom class in MiscUtil .
(Note that using rng.Next(1, 21) will also work fine - I prefer the version above, since I think it reduces the guesswork about inclusive / exclusive borders, but this is a matter of personal taste.)