How to randomize a number without duplication?

hello,i wanted to randomize a number x amount of time without getting a duplication

is there a way to do this without taxing the system too much?

You can use a hashset as this does it automatically.

int amountOfRandoms = 20;
HashSet<int> numbers = new HashSet<int>();
while (numbers.Count < amountOfRandoms ) {
    numbers.Add(random.Next(1, 49));