Here's a way to get unique random numbers. It uses a HashSet as was suggested by another contributor. Note that there is a single, instance-level instance of System.Random (you shouldn't be creating new ones all the time), and it's seeded with an indication of the time, which will result in a new sequence of random numbers each time.
private readonly System.Random _random = new System.Random((int) (DateTime.UtcNow.Ticks & 0x7fff_ffff));
private readonly HashSet<int> _previousNumbers = new HashSet<int>();
private const int Min = 0;
private const int Max = 9999;
public int GetNextRandom()
{
int next;
do
{
next = _random.Next(Min, Max);
} while (_previousNumbers.Contains(next) && _previousNumbers.Count < Max-Min);
_previousNumbers.Add(next);
return next;
}
Also note that it will stop handing out random number once there are none left to hand out (since they need to be unique, there can only be Max-Min calls of this before the well is exhausted). It will also get slower as that max number of calls is reached (since the likelihood of collisions keeps going up).
I haven't tried to decipher your code as posted, it's a bit muddled (and, it won't compile if just copied/pasted). But, your question was about generating unique random numbers.
However, there are a couple of points worth mentioning:
1. What are you trying to do
The comment from @mjwills (above) is the most pertinent one. Why do you want to do this?
2. Skipping previously generated random numbers likely reduces randomness
Pseudorandom number generators like System.Random create a sequence of numbers that show no autocorrelation at any frequency. It's the sequence that's random, not any particular number. By skipping some of them (the duplicates) you may be breaking that randomness.
3. System.Random is often the wrong choice
System.Random is not a good random number generator for most applications. System.Random is a repeatable pseudorandom number generator. If you give it the same seed, it will give you exactly the same sequence pseudorandom numbers over and over again (that's why I seed it from the clock above). If you really want to use this kind of algorithm, and you don't want this behavior, you need to get a seeding mechanism that has a lot of entropy (like a good random number generator, hey, oops!).
If you want to create a simple game - say a "Magic 8-Ball", System.Random (seeded with machine ticks like above) might be the right tool. If you want to have a game that includes wagering, don't do this (and, if you want to read about how not to use System.Random, look at the Wikipedia article on the casino in Montreal (search for "keno")).
If you want a better repeatable pseudorandom number algorithm, consider a Mersenne Twister implementation.
If you want to do something like create a gambling machine or do cryptography, you need something like System.Security.Cryptography.RNGCryptoServiceProvider. Generate a sequence of 128-bit random numbers and your are pretty much guaranteed unique-ness (or, for that matter, just use GUIDs).